blob: 0f1f906ef2e278450e7a588b763c2123bc910ec7 [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;
Adrian Roos5f2c9a12019-07-03 18:31:46 +020023import static android.app.WindowConfiguration.isSplitScreenWindowingMode;
24import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
chaviw40234662018-02-07 09:37:16 -080025import static android.os.PowerManager.DRAW_WAKE_LOCK;
Jorim Jaggi02886a82016-12-06 09:10:06 -080026import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Jorim Jaggia5e10572017-11-15 14:36:26 +010027import static android.view.SurfaceControl.Transaction;
Adrian Roos019a52b2019-07-02 16:47:44 +020028import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
29import static android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080030import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
31import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
32import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
33import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Jorim Jaggi956ca412019-01-07 14:49:14 +010034import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080035import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
36import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
37import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Jorim Jaggi02886a82016-12-06 09:10:06 -080038import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
39import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
40import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
41import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
42import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
43import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080044import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
45import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
46import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080047import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080048import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Adrian Roosfa02da62018-01-15 16:01:18 +010049import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080050import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
52import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
53import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
54import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
55import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
56import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Philip P. Moltmann66ce2382018-10-09 13:46:11 -070057import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080058import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carr0eff1872017-12-01 14:27:04 -080059import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Vishnu Nair1d0fa072018-01-04 07:53:00 -080060import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080061import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
62import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
63import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
64import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
65import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
66import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Robert Carrb1579c82017-09-05 14:54:47 -070067import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
68import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Robert Carree4d4b92017-11-22 12:21:46 -080069import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070070import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080071import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070072import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080073import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
74import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
75import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
76import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Vishnu Nairddd80742018-08-21 14:12:46 -070077
Yunfan Chenb4fe58c2019-03-27 18:35:06 +090078import static com.android.server.am.ActivityManagerService.MY_PID;
Adrian Roose99bc052017-11-20 17:55:31 +010079import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
80import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
81import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
82import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Vishnu Nairddd80742018-08-21 14:12:46 -070083import static com.android.server.wm.AnimationSpecProto.MOVE;
Adrian Roos5f2c9a12019-07-03 18:31:46 +020084import static com.android.server.wm.DisplayContent.logsGestureExclusionRestrictions;
Jorim Jaggi02886a82016-12-06 09:10:06 -080085import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
86import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Vishnu Nairddd80742018-08-21 14:12:46 -070087import static com.android.server.wm.IdentifierProto.HASH_CODE;
88import static com.android.server.wm.IdentifierProto.TITLE;
89import static com.android.server.wm.IdentifierProto.USER_ID;
90import static com.android.server.wm.MoveAnimationSpecProto.DURATION_MS;
91import static com.android.server.wm.MoveAnimationSpecProto.FROM;
92import static com.android.server.wm.MoveAnimationSpecProto.TO;
Adrian Roosb125e0b2019-10-02 14:55:14 +020093import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ADD_REMOVE;
94import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS;
95import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS;
96import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT;
97import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION;
98import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_RESIZE;
99import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_STARTING_WINDOW;
lumark9bca6b42019-10-17 18:35:22 +0800100import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS;
101import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION;
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200102import static com.android.server.wm.WindowManagerDebugConfig.DEBUG;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800103import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800104import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800105import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800106import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Tiger Huang50d45462018-05-25 22:57:52 +0800107import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800108import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200109import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800110import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800111import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
112import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
113import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100114import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800115import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
116import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
117import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Tiger Huang8af6ba42018-06-07 19:24:09 +0800118import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800119import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
120import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800121import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
122import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
123import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
Tiger Huang9c8ee262019-02-19 20:44:27 +0800124import static com.android.server.wm.WindowStateAnimator.PRESERVED_SURFACE_LAYER;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800125import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700126import static com.android.server.wm.WindowStateProto.ANIMATING_EXIT;
127import static com.android.server.wm.WindowStateProto.ANIMATOR;
128import static com.android.server.wm.WindowStateProto.ATTRIBUTES;
129import static com.android.server.wm.WindowStateProto.CHILD_WINDOWS;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700130import static com.android.server.wm.WindowStateProto.DESTROYING;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700131import static com.android.server.wm.WindowStateProto.DISPLAY_ID;
Vishnu Nairddd80742018-08-21 14:12:46 -0700132import static com.android.server.wm.WindowStateProto.FINISHED_SEAMLESS_ROTATION_FRAME;
133import static com.android.server.wm.WindowStateProto.FORCE_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700134import static com.android.server.wm.WindowStateProto.GIVEN_CONTENT_INSETS;
135import static com.android.server.wm.WindowStateProto.HAS_SURFACE;
136import static com.android.server.wm.WindowStateProto.IDENTIFIER;
137import static com.android.server.wm.WindowStateProto.IS_ON_SCREEN;
138import static com.android.server.wm.WindowStateProto.IS_READY_FOR_DISPLAY;
139import static com.android.server.wm.WindowStateProto.IS_VISIBLE;
Vishnu Nairddd80742018-08-21 14:12:46 -0700140import static com.android.server.wm.WindowStateProto.PENDING_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700141import static com.android.server.wm.WindowStateProto.REMOVED;
142import static com.android.server.wm.WindowStateProto.REMOVE_ON_EXIT;
143import static com.android.server.wm.WindowStateProto.REQUESTED_HEIGHT;
144import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700145import static com.android.server.wm.WindowStateProto.STACK_ID;
146import static com.android.server.wm.WindowStateProto.SURFACE_INSETS;
147import static com.android.server.wm.WindowStateProto.SURFACE_POSITION;
148import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY;
149import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700150import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER;
chaviw553b0212018-07-12 13:37:01 -0700151import static com.android.server.wm.WindowStateProto.WINDOW_FRAMES;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800152
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700153import android.annotation.CallSuper;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200154import android.annotation.Nullable;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800155import android.app.AppOpsManager;
156import android.content.Context;
157import android.content.res.Configuration;
158import android.graphics.Matrix;
159import android.graphics.PixelFormat;
160import android.graphics.Point;
161import android.graphics.Rect;
162import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700163import android.os.Binder;
Adrian Roos019a52b2019-07-02 16:47:44 +0200164import android.os.Build;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700165import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800166import android.os.IBinder;
167import android.os.PowerManager;
Michael Wrighte3001042019-02-05 00:13:14 +0000168import android.os.PowerManager.WakeReason;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800169import android.os.RemoteCallbackList;
170import android.os.RemoteException;
171import android.os.SystemClock;
172import android.os.Trace;
173import android.os.UserHandle;
174import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800175import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800176import android.text.TextUtils;
Jackal Guoc43a0a62019-04-23 09:15:14 +0800177import android.util.ArraySet;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800178import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200179import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800180import android.util.Slog;
Adrian Roos5f2c9a12019-07-03 18:31:46 +0200181import android.util.StatsLog;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800182import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700183import android.util.proto.ProtoOutputStream;
Brad Stenningaf596412018-04-02 12:03:19 -0700184import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100185import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800186import android.view.DisplayInfo;
187import android.view.Gravity;
188import android.view.IApplicationToken;
189import android.view.IWindow;
190import android.view.IWindowFocusObserver;
191import android.view.IWindowId;
192import android.view.InputChannel;
193import android.view.InputEvent;
194import android.view.InputEventReceiver;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800195import android.view.InputWindowHandle;
Jorim Jaggi956ca412019-01-07 14:49:14 +0100196import android.view.InsetsState;
Vishnu Nairba183352018-11-21 11:16:49 -0800197import android.view.Surface.Rotation;
Robert Carrb1579c82017-09-05 14:54:47 -0700198import android.view.SurfaceControl;
199import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800200import android.view.View;
201import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700202import android.view.WindowInfo;
Tarandeep Singh0bedd942019-09-26 13:34:03 -0700203import android.view.WindowInsets.Type.InsetType;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800204import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100205import android.view.animation.Animation;
206import android.view.animation.AnimationUtils;
207import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800208
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100209import com.android.internal.annotations.VisibleForTesting;
Vishnu Nair539334a2019-09-20 10:46:21 -0700210import com.android.internal.policy.KeyInterceptionInfo;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800211import com.android.internal.util.ToBooleanFunction;
Adrian Roose99bc052017-11-20 17:55:31 +0100212import com.android.server.policy.WindowManagerPolicy;
Adrian Roosb125e0b2019-10-02 14:55:14 +0200213import com.android.server.protolog.common.ProtoLog;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100214import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100215import com.android.server.wm.utils.WmDisplayCutout;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800216
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800217import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200218import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800219import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700220import java.util.Comparator;
Adrian Roos4ffc8972019-02-07 20:45:11 +0100221import java.util.List;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800222import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800223
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700224/** A window in the window manager. */
Jorim Jaggi28620472019-01-02 23:21:49 +0100225class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState,
226 InsetsControlTarget {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800227 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800228
Skuhne81c524a2015-08-12 13:34:14 -0700229 // The minimal size of a window within the usable area of the freeform stack.
Vishnu Nair93d68c22019-03-22 13:45:31 -0700230 // TODO(multi-window): fix the min sizes when we have minimum width/height support,
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700231 // use hard-coded min sizes for now.
232 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
233 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700234
235 // The thickness of a window resize handle outside the window bounds on the free form workspace
236 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700237 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700238
Adrian Roos5f2c9a12019-07-03 18:31:46 +0200239 static final int EXCLUSION_LEFT = 0;
240 static final int EXCLUSION_RIGHT = 1;
241
Craig Mautnere7ae2502012-03-26 17:11:19 -0700242 final WindowManagerPolicy mPolicy;
243 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 final Session mSession;
245 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800246 final int mAppOp;
247 // UserId and appId of the owner. Don't display windows of non-current user.
248 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800249 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
250 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200251 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700253 // The same object as mToken if this is an app window and null for non-app windows.
Garfield Tane8d84ab2019-10-11 09:49:40 -0700254 ActivityRecord mActivityRecord;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700255
256 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
257 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800258 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
259 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700260 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 final int mBaseLayer;
262 final int mSubLayer;
263 final boolean mLayoutAttached;
264 final boolean mIsImWindow;
265 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700266 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700267 int mSeq;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700269 int mSystemUiVisibility;
chaviw15ad49f2019-04-24 15:05:39 -0700270
Wale Ogunwale571771c2016-08-26 13:18:50 -0700271 /**
chaviw15ad49f2019-04-24 15:05:39 -0700272 * The visibility flag of the window based on policy like {@link WindowManagerPolicy}.
Wale Ogunwale571771c2016-08-26 13:18:50 -0700273 * Normally set by calling {@link #showLw} and {@link #hideLw}.
chaviw15ad49f2019-04-24 15:05:39 -0700274 *
275 * TODO: b/131253938 This will eventually be split into individual visibility policy flags.
Wale Ogunwale571771c2016-08-26 13:18:50 -0700276 */
chaviw15ad49f2019-04-24 15:05:39 -0700277 static final int LEGACY_POLICY_VISIBILITY = 1;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700278 /**
chaviw15ad49f2019-04-24 15:05:39 -0700279 * The visibility flag that determines whether this window is visible for the current user.
Wale Ogunwale571771c2016-08-26 13:18:50 -0700280 */
chaviw15ad49f2019-04-24 15:05:39 -0700281 private static final int VISIBLE_FOR_USER = 1 << 1;
282 private static final int POLICY_VISIBILITY_ALL = VISIBLE_FOR_USER | LEGACY_POLICY_VISIBILITY;
283 /**
284 * The Bitwise-or of flags that contribute to visibility of the WindowState
285 */
286 private int mPolicyVisibility = POLICY_VISIBILITY_ALL;
287
288 /**
289 * Whether {@link #LEGACY_POLICY_VISIBILITY} flag should be set after a transition animation.
290 * For example, {@link #LEGACY_POLICY_VISIBILITY} might be set during an exit animation to hide
291 * it and then unset when the value of {@link #mLegacyPolicyVisibilityAfterAnim} is false
292 * after the exit animation is done.
293 *
294 * TODO: b/131253938 Determine whether this can be changed to use a visibility flag instead.
295 */
296 boolean mLegacyPolicyVisibilityAfterAnim = true;
Suprabh Shukla69c71422018-04-02 18:39:01 -0700297 // overlay window is hidden because the owning app is suspended
298 private boolean mHiddenWhileSuspended;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700299 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700300 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700301 // This is a non-system overlay window that is currently force hidden.
302 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800304 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700306 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200307 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700308 private int mResizeMode;
Vishnu Nair83537a72018-07-19 21:27:48 -0700309 /**
310 * Special mode that is intended only for the rounded corner overlay: during rotation
311 * transition, we un-rotate the window token such that the window appears as it did before the
312 * rotation.
Vishnu Nair83537a72018-07-19 21:27:48 -0700313 */
314 final boolean mForceSeamlesslyRotate;
Vishnu Nairddd80742018-08-21 14:12:46 -0700315 SeamlessRotator mPendingSeamlessRotate;
316 long mFinishSeamlessRotateFrameNumber;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700317
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700318 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800319
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700320 /**
321 * The window size that was requested by the application. These are in
322 * the application's coordinate space (without compatibility scale applied).
323 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 int mRequestedWidth;
325 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700326 private int mLastRequestedWidth;
327 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700328
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800329 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 boolean mHaveFrame;
331 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332
333 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700334
Jackal Guoc43a0a62019-04-23 09:15:14 +0800335 /** @see #addEmbeddedDisplayContent(DisplayContent dc) */
336 private final ArraySet<DisplayContent> mEmbeddedDisplayContents = new ArraySet<>();
337
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700338 /**
339 * Used to store last reported to client configuration and check if we have newer available.
340 * We'll send configuration to client only if it is different from the last applied one and
341 * client won't perform unnecessary updates.
342 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700343 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700344
Jorim Jaggi381cd722019-03-27 17:33:02 +0100345 /** @see #isLastConfigReportedToClient() */
346 private boolean mLastConfigReportedToClient;
347
Yunfan Chen75157d72018-07-27 14:47:21 +0900348 private final Configuration mTempConfiguration = new Configuration();
349
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700350 /**
Robert Carr18f622f2017-05-08 11:20:43 -0700351 * The last content insets returned to the client in relayout. We use
352 * these in the bounds animation to ensure we only observe inset changes
353 * at the same time that a client resizes it's surface so that we may use
354 * the geometryAppliesWithResize synchronization mechanism to keep
355 * the contents in place.
356 */
357 final Rect mLastRelayoutContentInsets = new Rect();
358
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700359 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 * Set to true if we are waiting for this window to receive its
361 * given internal insets before laying out other windows based on it.
362 */
363 boolean mGivenInsetsPending;
364
365 /**
366 * These are the content insets that were given during layout for
367 * this window, to be applied to windows behind it.
368 */
369 final Rect mGivenContentInsets = new Rect();
370
371 /**
372 * These are the visible insets that were given during layout for
373 * this window, to be applied to windows behind it.
374 */
375 final Rect mGivenVisibleInsets = new Rect();
376
377 /**
378 * This is the given touchable area relative to the window frame, or null if none.
379 */
380 final Region mGivenTouchableRegion = new Region();
381
382 /**
383 * Flag indicating whether the touchable region should be adjusted by
384 * the visible insets; if false the area outside the visible insets is
385 * NOT touchable, so we must use those to adjust the frame during hit
386 * tests.
387 */
388 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
389
390 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400391 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700392 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800393 float mHScale=1, mVScale=1;
394 float mLastHScale=1, mLastVScale=1;
395 final Matrix mTmpMatrix = new Matrix();
396
chaviw553b0212018-07-12 13:37:01 -0700397 private final WindowFrames mWindowFrames = new WindowFrames();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700398
Jorim Jaggidc249c42015-12-15 14:57:31 -0800399 /**
400 * Usually empty. Set to the task's tempInsetFrame. See
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700401 *{@link android.app.IActivityTaskManager#resizeDockedStack}.
Jorim Jaggidc249c42015-12-15 14:57:31 -0800402 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700403 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800404
Adrian Roos4ffc8972019-02-07 20:45:11 +0100405 /**
406 * List of rects where system gestures should be ignored.
407 *
408 * Coordinates are relative to the window's position.
409 */
410 private final List<Rect> mExclusionRects = new ArrayList<>();
411
Adrian Roos5f2c9a12019-07-03 18:31:46 +0200412 // 0 = left, 1 = right
413 private final int[] mLastRequestedExclusionHeight = {0, 0};
414 private final int[] mLastGrantedExclusionHeight = {0, 0};
415 private final long[] mLastExclusionLogUptimeMillis = {0, 0};
416
417 private boolean mLastShownChangedReported;
418
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419 // If a window showing a wallpaper: the requested offset for the
420 // wallpaper; if a wallpaper window: the currently applied offset.
421 float mWallpaperX = -1;
422 float mWallpaperY = -1;
423
424 // If a window showing a wallpaper: what fraction of the offset
425 // range corresponds to a full virtual screen.
426 float mWallpaperXStep = -1;
427 float mWallpaperYStep = -1;
428
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700429 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
430 // to its window; if a wallpaper window: not used.
431 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
432 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
433
Craig Mautner2268e7e2012-12-13 15:40:00 -0800434 /**
435 * This is set after IWindowSession.relayout() has been called at
436 * least once for the window. It allows us to detect the situation
437 * where we don't yet have a surface, but should have one soon, so
438 * we can give the window focus before waiting for the relayout.
439 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800440 boolean mRelayoutCalled;
441
Robert Carrfed10072016-05-26 11:48:49 -0700442 boolean mInRelayout;
443
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800444 /**
445 * If the application has called relayout() with changes that can
446 * impact its window's size, we need to perform a layout pass on it
447 * even if it is not currently visible for layout. This is set
448 * when in that case until the layout is done.
449 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800450 boolean mLayoutNeeded;
451
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800452 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800453 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800454
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800455 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456 boolean mDestroying;
457
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800458 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800459 boolean mRemoveOnExit;
460
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800461 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800462 * Whether the app died while it was visible, if true we might need
463 * to continue to show it until it's restarted.
464 */
465 boolean mAppDied;
466
467 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800468 * Set when the orientation is changing and this window has not yet
469 * been updated for the new orientation.
470 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700471 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800472
Dianne Hackborna57c6952013-03-29 14:46:40 -0700473 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700474 * Sometimes in addition to the mOrientationChanging
475 * flag we report that the orientation is changing
476 * due to a mismatch in current and reported configuration.
477 *
478 * In the case of timeout we still need to make sure we
479 * leave the orientation changing state though, so we
480 * use this as a special time out escape hatch.
481 */
482 private boolean mOrientationChangeTimedOut;
483
484 /**
Robert Carr237028a2016-07-26 10:39:45 -0700485 * The orientation during the last visible call to relayout. If our
486 * current orientation is different, the window can't be ready
487 * to be shown.
488 */
489 int mLastVisibleLayoutRotation = -1;
490
491 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800492 * Set when we need to report the orientation change to client to trigger a relayout.
493 */
494 boolean mReportOrientationChanged;
495
496 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700497 * How long we last kept the screen frozen.
498 */
499 int mLastFreezeDuration;
500
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800501 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800502 boolean mRemoved;
503
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800504 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800505 * It is save to remove the window and destroy the surface because the client requested removal
506 * or some other higher level component said so (e.g. activity manager).
507 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800508 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700509 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800510
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800511 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700512 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800513 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700514 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800515
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800516 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700517 private String mStringNameCache;
518 private CharSequence mLastTitle;
519 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800520
Craig Mautnera2c77052012-03-26 12:14:43 -0700521 final WindowStateAnimator mWinAnimator;
522
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700523 boolean mHasSurface = false;
524
Craig Mautner88400d32012-09-30 12:35:45 -0700525 /** When true this window can be displayed on screens owther than mOwnerUid's */
526 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700527
Robert Carra1eb4392015-12-10 12:43:51 -0800528 // This window will be replaced due to relaunch. This allows window manager
529 // to differentiate between simple removal of a window and replacement. In the latter case it
530 // will preserve the old window until the new one is drawn.
531 boolean mWillReplaceWindow = false;
532 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700533 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800534 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700535 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800536 // If not null, the window that will be used to replace the old one. This is being set when
537 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700538 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700539 // For the new window in the replacement transition, if we have
540 // requested to replace without animation, then we should
541 // make sure we also don't apply an enter animation for
542 // the new window.
543 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800544 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700545 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800546
Jeff Brownc2932a12014-11-20 18:04:05 -0800547 /**
548 * Wake lock for drawing.
549 * Even though it's slightly more expensive to do so, we will use a separate wake lock
550 * for each app that is requesting to draw while dozing so that we can accurately track
551 * who is preventing the system from suspending.
552 * This lock is only acquired on first use.
553 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700554 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800555
Riddle Hsub398da32019-01-21 21:48:16 +0800556 private final Rect mTmpRect = new Rect();
557 private final Point mTmpPoint = new Point();
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700558
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800559 /**
Jackal Guoc43a0a62019-04-23 09:15:14 +0800560 * If a window is on a display which has been re-parented to a view in another window,
561 * use this offset to indicate the correct location.
562 */
563 private final Point mLastReportedDisplayOffset = new Point();
564
565 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800566 * Whether the window was resized by us while it was gone for layout.
567 */
568 boolean mResizedWhileGone = false;
569
Robert Carr6da3cc02016-06-16 15:17:07 -0700570 /**
571 * During seamless rotation we have two phases, first the old window contents
572 * are rotated to look as if they didn't move in the new coordinate system. Then we
573 * have to freeze updates to this layer (to preserve the transformation) until
574 * the resize actually occurs. This is true from when the transformation is set
575 * and false until the transaction to resize is sent.
576 */
577 boolean mSeamlesslyRotated = false;
578
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700579 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800580 * Surface insets from the previous call to relayout(), used to track
581 * if we are changing the Surface insets.
582 */
583 final Rect mLastSurfaceInsets = new Rect();
584
585 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700586 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
587 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
588 * make sure all children have been considered.
589 */
590 private boolean mDrawnStateEvaluated;
591
Jorim Jaggia5e10572017-11-15 14:36:26 +0100592 private final Point mSurfacePosition = new Point();
593
Bryce Leed390deb2017-06-22 13:14:28 -0700594 /**
Tiger Huang04dc4cc2019-01-17 18:41:41 +0800595 * A region inside of this window to be excluded from touch.
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800596 */
597 private TapExcludeRegionHolder mTapExcludeRegionHolder;
598
599 /**
chaviw40234662018-02-07 09:37:16 -0800600 * Used for testing because the real PowerManager is final.
601 */
602 private PowerManagerWrapper mPowerManagerWrapper;
603
604 /**
chaviwbe43ac82018-04-04 15:14:49 -0700605 * A frame number in which changes requested in this layout will be rendered.
606 */
607 private long mFrameNumber = -1;
608
chaviwc65fa582018-08-09 15:33:13 -0700609 private static final StringBuilder sTmpSB = new StringBuilder();
610
chaviwbe43ac82018-04-04 15:14:49 -0700611 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700612 * 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 -0700613 * of z-order and 1 otherwise.
614 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800615 private static final Comparator<WindowState> sWindowSubLayerComparator =
616 new Comparator<WindowState>() {
617 @Override
618 public int compare(WindowState w1, WindowState w2) {
619 final int layer1 = w1.mSubLayer;
620 final int layer2 = w2.mSubLayer;
621 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
622 // We insert the child window into the list ordered by
623 // the sub-layer. For same sub-layers, the negative one
624 // should go below others; the positive one should go
625 // above others.
626 return -1;
627 }
628 return 1;
629 };
630 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700631
Robert Carrf59b8dd2017-10-02 18:58:36 -0700632 /**
633 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
634 * container.
635 */
636 private boolean mIsDimming = false;
637
Jorim Jaggi956ca412019-01-07 14:49:14 +0100638 private @Nullable InsetsSourceProvider mControllableInsetProvider;
Tiger Huang0dbd5372019-10-26 00:24:22 +0800639 private InsetsState mClientInsetsState;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200640
Robert Carrf59b8dd2017-10-02 18:58:36 -0700641 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
Vishnu Nair539334a2019-09-20 10:46:21 -0700642 private KeyInterceptionInfo mKeyInterceptionInfo;
Robert Carrf59b8dd2017-10-02 18:58:36 -0700643
Jorim Jaggi956ca412019-01-07 14:49:14 +0100644 InsetsState getClientInsetsState() {
645 return mClientInsetsState;
646 }
647
648 void setClientInsetsState(InsetsState state) {
649 mClientInsetsState = state;
650 }
651
Vishnu Nairba183352018-11-21 11:16:49 -0800652 void seamlesslyRotateIfAllowed(Transaction transaction, @Rotation int oldRotation,
653 @Rotation int rotation, boolean requested) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700654 // Invisible windows and the wallpaper do not participate in the seamless rotation animation
655 if (!isVisibleNow() || mIsWallpaper) {
656 return;
657 }
Adrian Roosfaa102f2018-08-02 15:56:15 +0200658
Vishnu Nairddd80742018-08-21 14:12:46 -0700659 if (mPendingSeamlessRotate != null) {
660 oldRotation = mPendingSeamlessRotate.getOldRotation();
661 }
662
663 if (mForceSeamlesslyRotate || requested) {
664 mPendingSeamlessRotate = new SeamlessRotator(oldRotation, rotation, getDisplayInfo());
Vishnu Nairec634062018-09-20 20:16:18 -0700665 mPendingSeamlessRotate.unrotate(transaction, this);
Riddle Hsuccf09402019-08-13 00:33:06 +0800666 getDisplayContent().getDisplayRotation().markForSeamlessRotation(this,
667 true /* seamlesslyRotated */);
Vishnu Nairddd80742018-08-21 14:12:46 -0700668 }
669 }
670
Vishnu Nairba183352018-11-21 11:16:49 -0800671 void finishSeamlessRotation(boolean timeout) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700672 if (mPendingSeamlessRotate != null) {
Vishnu Nairba183352018-11-21 11:16:49 -0800673 mPendingSeamlessRotate.finish(this, timeout);
Vishnu Nairddd80742018-08-21 14:12:46 -0700674 mFinishSeamlessRotateFrameNumber = getFrameNumber();
675 mPendingSeamlessRotate = null;
Riddle Hsuccf09402019-08-13 00:33:06 +0800676 getDisplayContent().getDisplayRotation().markForSeamlessRotation(this,
677 false /* seamlesslyRotated */);
Vishnu Nair83537a72018-07-19 21:27:48 -0700678 }
679 }
680
Adrian Roos4ffc8972019-02-07 20:45:11 +0100681 List<Rect> getSystemGestureExclusion() {
682 return mExclusionRects;
683 }
684
685 /**
686 * Sets the system gesture exclusion rects.
687 *
688 * @return {@code true} if anything changed
689 */
690 boolean setSystemGestureExclusion(List<Rect> exclusionRects) {
691 if (mExclusionRects.equals(exclusionRects)) {
692 return false;
693 }
694 mExclusionRects.clear();
695 mExclusionRects.addAll(exclusionRects);
696 return true;
697 }
698
Adrian Roos019a52b2019-07-02 16:47:44 +0200699 boolean isImplicitlyExcludingAllSystemGestures() {
700 final int immersiveStickyFlags =
701 SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
702 final boolean immersiveSticky =
703 (mSystemUiVisibility & immersiveStickyFlags) == immersiveStickyFlags;
Adrian Roos1c2e9a12019-08-20 18:23:47 +0200704 return immersiveSticky && mWmService.mConstants.mSystemGestureExcludedByPreQStickyImmersive
Garfield Tane8d84ab2019-10-11 09:49:40 -0700705 && mActivityRecord != null && mActivityRecord.mTargetSdk < Build.VERSION_CODES.Q;
Adrian Roos019a52b2019-07-02 16:47:44 +0200706 }
707
Adrian Roos5f2c9a12019-07-03 18:31:46 +0200708 void setLastExclusionHeights(int side, int requested, int granted) {
709 boolean changed = mLastGrantedExclusionHeight[side] != granted
710 || mLastRequestedExclusionHeight[side] != requested;
711
712 if (changed) {
713 if (mLastShownChangedReported) {
714 logExclusionRestrictions(side);
715 }
716
717 mLastGrantedExclusionHeight[side] = granted;
718 mLastRequestedExclusionHeight[side] = requested;
719 }
720 }
721
chaviw40234662018-02-07 09:37:16 -0800722 interface PowerManagerWrapper {
Michael Wrighte3001042019-02-05 00:13:14 +0000723 void wakeUp(long time, @WakeReason int reason, String details);
chaviw40234662018-02-07 09:37:16 -0800724
725 boolean isInteractive();
726
727 }
728
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800729 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800730 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
731 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
732 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
733 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
734 @Override
Michael Wrighte3001042019-02-05 00:13:14 +0000735 public void wakeUp(long time, @WakeReason int reason, String details) {
736 service.mPowerManager.wakeUp(time, reason, details);
chaviw40234662018-02-07 09:37:16 -0800737 }
738
739 @Override
740 public boolean isInteractive() {
741 return service.mPowerManager.isInteractive();
742 }
743 });
744 }
745
746 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
747 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
748 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
749 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100750 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800751 mSession = s;
752 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800753 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800754 mToken = token;
Garfield Tane8d84ab2019-10-11 09:49:40 -0700755 mActivityRecord = mToken.asActivityRecord();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700756 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800757 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200758 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800759 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700760 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800761 mViewVisibility = viewVisibility;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800762 mPolicy = mWmService.mPolicy;
763 mContext = mWmService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800764 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700765 mSeq = seq;
chaviw40234662018-02-07 09:37:16 -0800766 mPowerManagerWrapper = powerManagerWrapper;
Vishnu Nair83537a72018-07-19 21:27:48 -0700767 mForceSeamlesslyRotate = token.mRoundedCornerOverlay;
Tiger Huang0dbd5372019-10-26 00:24:22 +0800768 mClientInsetsState =
769 getDisplayContent().getInsetsStateController().getInsetsForDispatch(this);
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200770 if (DEBUG) {
771 Slog.v(TAG, "Window " + this + " client=" + c.asBinder()
772 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
773 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800774 try {
775 c.asBinder().linkToDeath(deathRecipient, 0);
776 } catch (RemoteException e) {
777 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700778 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800779 mLayoutAttached = false;
780 mIsImWindow = false;
781 mIsWallpaper = false;
782 mIsFloatingLayer = false;
783 mBaseLayer = 0;
784 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700785 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700786 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800787 return;
788 }
789 mDeathRecipient = deathRecipient;
790
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700791 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800792 // The multiplier here is to reserve space for multiple
793 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800794 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700795 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800796 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700797 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900798
Adrian Roosb125e0b2019-10-02 14:55:14 +0200799 ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Adding %s to %s", this, parentWindow);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700800 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900801
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800802 mLayoutAttached = mAttrs.type !=
803 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700804 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
805 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
806 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800807 } else {
808 // The multiplier here is to reserve space for multiple
809 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800810 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700811 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800812 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700813 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800814 mLayoutAttached = false;
815 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
816 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
817 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800818 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700819 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800820
Garfield Tane8d84ab2019-10-11 09:49:40 -0700821 if (mActivityRecord != null && mActivityRecord.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700822 // Windows for apps that can show for all users should also show when the device is
823 // locked.
824 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700825 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800826
Craig Mautner322e4032012-07-13 13:35:20 -0700827 mWinAnimator = new WindowStateAnimator(this);
828 mWinAnimator.mAlpha = a.alpha;
829
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800830 mRequestedWidth = 0;
831 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700832 mLastRequestedWidth = 0;
833 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800834 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800835 mInputWindowHandle = new InputWindowHandle(
Garfield Tane8d84ab2019-10-11 09:49:40 -0700836 mActivityRecord != null ? mActivityRecord.mInputApplicationHandle : null,
837 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800838 }
839
840 void attach() {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200841 if (DEBUG) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800842 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800843 }
844
Bryce Leed390deb2017-06-22 13:14:28 -0700845 /**
Riddle Hsub398da32019-01-21 21:48:16 +0800846 * @return {@code true} if the application runs in size compatibility mode.
847 * @see android.content.res.CompatibilityInfo#supportsScreen
848 * @see ActivityRecord#inSizeCompatMode
849 */
850 boolean inSizeCompatMode() {
851 return (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0
Garfield Tane8d84ab2019-10-11 09:49:40 -0700852 || (mActivityRecord != null && mActivityRecord.hasSizeCompatBounds()
Riddle Hsub398da32019-01-21 21:48:16 +0800853 // Exclude starting window because it is not displayed by the application.
854 && mAttrs.type != TYPE_APPLICATION_STARTING);
855 }
856
857 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700858 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
859 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700860 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700861 return mDrawnStateEvaluated;
862 }
863
864 /**
865 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
866 * be cleared when detached from parent.
867 */
868 void setDrawnStateEvaluated(boolean evaluated) {
869 mDrawnStateEvaluated = evaluated;
870 }
871
872 @Override
Wale Ogunwalec17418e2019-10-13 23:00:40 +0200873 void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) {
874 super.onParentChanged(newParent, oldParent);
Bryce Leed390deb2017-06-22 13:14:28 -0700875 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700876
877 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -0700878 }
879
Craig Mautnera2c77052012-03-26 12:14:43 -0700880 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800881 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800882 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800883 }
884
885 @Override
886 public String getOwningPackage() {
887 return mAttrs.packageName;
888 }
889
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800890 @Override
891 public boolean canAddInternalSystemWindow() {
892 return mOwnerCanAddInternalSystemWindow;
893 }
894
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200895 @Override
896 public boolean canAcquireSleepToken() {
897 return mSession.mCanAcquireSleepToken;
898 }
899
Jorim Jaggif5834272016-04-04 20:25:41 -0700900 /**
901 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
902 * from {@param frame}. In other words, it applies the insets that would result if
903 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700904 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
905 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700906 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700907 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
908 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
909 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
910 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
911 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700912 frame.inset(left, top, right, bottom);
913 }
914
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800915 @Override
Evan Roskyed6767f2018-10-26 17:21:06 -0700916 public Rect getDisplayedBounds() {
917 final Task task = getTask();
918 if (task != null) {
919 Rect bounds = task.getOverrideDisplayedBounds();
920 if (!bounds.isEmpty()) {
921 return bounds;
922 }
923 }
924 return super.getDisplayedBounds();
925 }
926
927 @Override
chaviw1454b392018-08-06 09:54:04 -0700928 public void computeFrameLw() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800929 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700930 // This window is being replaced and either already got information that it's being
931 // removed or we are still waiting for some information. Because of this we don't
932 // want to apply any more changes to it, so it remains in this state until new window
933 // appears.
934 return;
935 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800936 mHaveFrame = true;
937
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700938 final Task task = getTask();
Evan Rosky4fb1e912019-03-06 13:54:43 -0800939 final boolean isFullscreenAndFillsDisplay = !inMultiWindowMode() && matchesDisplayBounds();
Robert Carre6275582016-02-29 15:45:45 -0800940 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700941 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800942
Evan Roskyed6767f2018-10-26 17:21:06 -0700943 mInsetFrame.set(getBounds());
Chong Zhangae35fef2016-03-16 15:56:55 -0700944
Jorim Jaggif5834272016-04-04 20:25:41 -0700945 // Denotes the actual frame used to calculate the insets and to perform the layout. When
946 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
947 // insets temporarily. By the notion of a task having a different layout frame, we can
948 // achieve that while still moving the task around.
949 final Rect layoutContainingFrame;
950 final Rect layoutDisplayFrame;
951
952 // The offset from the layout containing frame to the actual containing frame.
953 final int layoutXDiff;
954 final int layoutYDiff;
Evan Rosky0d654cb2019-02-26 10:59:10 -0800955 final WindowState imeWin = mWmService.mRoot.getCurrentInputMethodWindow();
956 final boolean isImeTarget =
957 imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget();
Evan Rosky4fb1e912019-03-06 13:54:43 -0800958 if (isFullscreenAndFillsDisplay || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800959 // We use the parent frame as the containing frame for fullscreen and child windows
chaviw1454b392018-08-06 09:54:04 -0700960 mWindowFrames.mContainingFrame.set(mWindowFrames.mParentFrame);
961 layoutDisplayFrame = mWindowFrames.mDisplayFrame;
962 layoutContainingFrame = mWindowFrames.mParentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700963 layoutXDiff = 0;
964 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800965 } else {
Evan Roskyed6767f2018-10-26 17:21:06 -0700966 mWindowFrames.mContainingFrame.set(getDisplayedBounds());
Garfield Tane8d84ab2019-10-11 09:49:40 -0700967 if (mActivityRecord != null && !mActivityRecord.mFrozenBounds.isEmpty()) {
Jorim Jaggi0429f352015-12-22 16:29:16 +0100968
969 // If the bounds are frozen, we still want to translate the window freely and only
970 // freeze the size.
Garfield Tane8d84ab2019-10-11 09:49:40 -0700971 Rect frozen = mActivityRecord.mFrozenBounds.peek();
chaviw553b0212018-07-12 13:37:01 -0700972 mWindowFrames.mContainingFrame.right =
973 mWindowFrames.mContainingFrame.left + frozen.width();
974 mWindowFrames.mContainingFrame.bottom =
975 mWindowFrames.mContainingFrame.top + frozen.height();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100976 }
Robert Carrfc03b2b2016-03-31 15:22:02 -0700977 // IME is up and obscuring this window. Adjust the window position so it is visible.
Evan Rosky0d654cb2019-02-26 10:59:10 -0800978 if (isImeTarget) {
979 if (inFreeformWindowingMode()) {
980 // Push the freeform window up to make room for the IME. However, don't push
981 // it up past the top of the screen.
982 final int bottomOverlap = mWindowFrames.mContainingFrame.bottom
983 - mWindowFrames.mVisibleFrame.bottom;
984 if (bottomOverlap > 0) {
985 final int distanceToTop = Math.max(mWindowFrames.mContainingFrame.top
986 - mWindowFrames.mDisplayFrame.top, 0);
987 int offs = Math.min(bottomOverlap, distanceToTop);
988 mWindowFrames.mContainingFrame.top -= offs;
989 }
chaviw553b0212018-07-12 13:37:01 -0700990 } else if (!inPinnedWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700991 > mWindowFrames.mParentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700992 // But in docked we want to behave like fullscreen and behave as if the task
993 // were given smaller bounds for the purposes of layout. Skip adjustments for
994 // the pinned stack, they are handled separately in the PinnedStackController.
chaviw1454b392018-08-06 09:54:04 -0700995 mWindowFrames.mContainingFrame.bottom = mWindowFrames.mParentFrame.bottom;
Winson Chungd73e94b2017-05-31 16:25:30 -0700996 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700997 }
Skuhne81c524a2015-08-12 13:34:14 -0700998
Robert Carre6275582016-02-29 15:45:45 -0800999 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -07001000 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
1001 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -08001002 // "content frame" since it is allowed to be outside the visible desktop.
chaviw553b0212018-07-12 13:37:01 -07001003 if (mWindowFrames.mContainingFrame.isEmpty()) {
chaviw1454b392018-08-06 09:54:04 -07001004 mWindowFrames.mContainingFrame.set(mWindowFrames.mContentFrame);
Skuhne81c524a2015-08-12 13:34:14 -07001005 }
Doris Liu06d582d2015-06-01 13:18:43 -07001006 }
Adrian Roos604ef952018-05-15 20:13:13 +02001007
Louis Changdc077272019-11-12 16:52:56 +08001008 final ActivityStack stack = getStack();
Adrian Roos604ef952018-05-15 20:13:13 +02001009 if (inPinnedWindowingMode() && stack != null
1010 && stack.lastAnimatingBoundsWasToFullscreen()) {
1011 // PIP edge case: When going from pinned to fullscreen, we apply a
1012 // tempInsetFrame for the full task - but we're still at the start of the animation.
1013 // To prevent a jump if there's a letterbox, restrict to the parent frame.
chaviw1454b392018-08-06 09:54:04 -07001014 mInsetFrame.intersectUnchecked(mWindowFrames.mParentFrame);
1015 mWindowFrames.mContainingFrame.intersectUnchecked(mWindowFrames.mParentFrame);
Adrian Roos604ef952018-05-15 20:13:13 +02001016 }
1017
chaviw1454b392018-08-06 09:54:04 -07001018 layoutDisplayFrame = new Rect(mWindowFrames.mDisplayFrame);
chaviw553b0212018-07-12 13:37:01 -07001019 mWindowFrames.mDisplayFrame.set(mWindowFrames.mContainingFrame);
Evan Roskyed6767f2018-10-26 17:21:06 -07001020 layoutXDiff = mInsetFrame.left - mWindowFrames.mContainingFrame.left;
1021 layoutYDiff = mInsetFrame.top - mWindowFrames.mContainingFrame.top;
1022 layoutContainingFrame = mInsetFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001023 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
chaviw1454b392018-08-06 09:54:04 -07001024 subtractInsets(mWindowFrames.mDisplayFrame, layoutContainingFrame, layoutDisplayFrame,
1025 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -07001026 if (!layoutInParentFrame()) {
chaviw553b0212018-07-12 13:37:01 -07001027 subtractInsets(mWindowFrames.mContainingFrame, layoutContainingFrame,
chaviw1454b392018-08-06 09:54:04 -07001028 mWindowFrames.mParentFrame, mTmpRect);
1029 subtractInsets(mInsetFrame, layoutContainingFrame, mWindowFrames.mParentFrame,
chaviw553b0212018-07-12 13:37:01 -07001030 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -07001031 }
Jorim Jaggif5834272016-04-04 20:25:41 -07001032 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -07001033 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001034
chaviw553b0212018-07-12 13:37:01 -07001035 final int pw = mWindowFrames.mContainingFrame.width();
1036 final int ph = mWindowFrames.mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001037
Dianne Hackborn1743b642012-03-12 17:04:43 -07001038 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1039 mLastRequestedWidth = mRequestedWidth;
1040 mLastRequestedHeight = mRequestedHeight;
chaviw1454b392018-08-06 09:54:04 -07001041 mWindowFrames.setContentChanged(true);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001042 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001043
chaviw492139a2018-07-16 16:07:35 -07001044 final int fw = mWindowFrames.mFrame.width();
1045 final int fh = mWindowFrames.mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001046
Jorim Jaggif5834272016-04-04 20:25:41 -07001047 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
1048
Craig Mautnera248eee2013-05-07 11:41:27 -07001049 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001050 // final window frame.
chaviw492139a2018-07-16 16:07:35 -07001051 if (windowsAreFloating && !mWindowFrames.mFrame.isEmpty()) {
Evan Rosky0d654cb2019-02-26 10:59:10 -08001052 final int visBottom = mWindowFrames.mVisibleFrame.bottom;
1053 final int contentBottom = mWindowFrames.mContentFrame.bottom;
Evan Rosky60dba2f2019-02-01 10:58:38 -08001054 mWindowFrames.mContentFrame.set(mWindowFrames.mFrame);
chaviw553b0212018-07-12 13:37:01 -07001055 mWindowFrames.mVisibleFrame.set(mWindowFrames.mContentFrame);
1056 mWindowFrames.mStableFrame.set(mWindowFrames.mContentFrame);
Evan Rosky0d654cb2019-02-26 10:59:10 -08001057 if (isImeTarget && inFreeformWindowingMode()) {
1058 // After displacing a freeform window to make room for the ime, any part of
1059 // the window still covered by IME should be inset.
1060 if (contentBottom + layoutYDiff < mWindowFrames.mContentFrame.bottom) {
1061 mWindowFrames.mContentFrame.bottom = contentBottom + layoutYDiff;
1062 }
1063 if (visBottom + layoutYDiff < mWindowFrames.mVisibleFrame.bottom) {
1064 mWindowFrames.mVisibleFrame.bottom = visBottom + layoutYDiff;
1065 }
1066 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001067 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw492139a2018-07-16 16:07:35 -07001068 dc.getDockedDividerController().positionDockedStackedDivider(mWindowFrames.mFrame);
1069 mWindowFrames.mContentFrame.set(mWindowFrames.mFrame);
1070 if (!mWindowFrames.mFrame.equals(mWindowFrames.mLastFrame)) {
Jorim Jaggi192086e2016-03-11 17:17:03 +01001071 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -08001072 }
Skuhne81c524a2015-08-12 13:34:14 -07001073 } else {
chaviw492139a2018-07-16 16:07:35 -07001074 mWindowFrames.mContentFrame.set(
1075 Math.max(mWindowFrames.mContentFrame.left, mWindowFrames.mFrame.left),
1076 Math.max(mWindowFrames.mContentFrame.top, mWindowFrames.mFrame.top),
1077 Math.min(mWindowFrames.mContentFrame.right, mWindowFrames.mFrame.right),
1078 Math.min(mWindowFrames.mContentFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001079
chaviw492139a2018-07-16 16:07:35 -07001080 mWindowFrames.mVisibleFrame.set(
1081 Math.max(mWindowFrames.mVisibleFrame.left, mWindowFrames.mFrame.left),
1082 Math.max(mWindowFrames.mVisibleFrame.top, mWindowFrames.mFrame.top),
1083 Math.min(mWindowFrames.mVisibleFrame.right, mWindowFrames.mFrame.right),
1084 Math.min(mWindowFrames.mVisibleFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001085
chaviw492139a2018-07-16 16:07:35 -07001086 mWindowFrames.mStableFrame.set(
1087 Math.max(mWindowFrames.mStableFrame.left, mWindowFrames.mFrame.left),
1088 Math.max(mWindowFrames.mStableFrame.top, mWindowFrames.mFrame.top),
1089 Math.min(mWindowFrames.mStableFrame.right, mWindowFrames.mFrame.right),
1090 Math.min(mWindowFrames.mStableFrame.bottom, mWindowFrames.mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -07001091 }
Adrian Roosfa104232014-06-20 16:10:14 -07001092
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001093 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw1454b392018-08-06 09:54:04 -07001094 final WmDisplayCutout c = mWindowFrames.mDisplayCutout.calculateRelativeTo(
chaviw553b0212018-07-12 13:37:01 -07001095 mWindowFrames.mDisplayFrame);
chaviw9c81e632018-07-31 11:17:52 -07001096 mWindowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets());
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001097 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -08001098 getDisplayContent().getBounds(mTmpRect);
Evan Rosky4fb1e912019-03-06 13:54:43 -08001099 mWindowFrames.calculateInsets(
1100 windowsAreFloating, isFullscreenAndFillsDisplay, mTmpRect);
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001101 }
Adrian Roosfa104232014-06-20 16:10:14 -07001102
chaviwcdba9a42018-07-19 11:36:42 -07001103 mWindowFrames.setDisplayCutout(
chaviw1454b392018-08-06 09:54:04 -07001104 mWindowFrames.mDisplayCutout.calculateRelativeTo(mWindowFrames.mFrame));
Jorim Jaggibae2b152018-04-18 17:27:27 +02001105
Jorim Jaggi656f6502016-04-11 21:08:17 -07001106 // Offset the actual frame by the amount layout frame is off.
chaviw9c81e632018-07-31 11:17:52 -07001107 mWindowFrames.offsetFrames(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001108
chaviw9c81e632018-07-31 11:17:52 -07001109 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Riddle Hsub398da32019-01-21 21:48:16 +08001110 if (inSizeCompatMode()) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001111 // If there is a size compatibility scale being applied to the
1112 // window, we need to apply this to its insets so that they are
1113 // reported to the app in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001114 mWindowFrames.scaleInsets(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001115
1116 // Also the scaled frame that we report to the app needs to be
1117 // adjusted to be in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001118 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001119 }
1120
chaviw492139a2018-07-16 16:07:35 -07001121 if (mIsWallpaper && (fw != mWindowFrames.mFrame.width()
1122 || fh != mWindowFrames.mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001123 final DisplayContent displayContent = getDisplayContent();
1124 if (displayContent != null) {
1125 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw553b0212018-07-12 13:37:01 -07001126 getDisplayContent().mWallpaperController.updateWallpaperOffset(this,
1127 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001128 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001129 }
1130
Evan Rosky70213702019-11-05 10:26:24 -08001131 // Calculate relative frame
1132 mWindowFrames.mRelFrame.set(mWindowFrames.mFrame);
1133 WindowContainer parent = getParent();
1134 int parentLeft = 0;
1135 int parentTop = 0;
1136 if (mIsChildWindow) {
1137 parentLeft = ((WindowState) parent).mWindowFrames.mFrame.left;
1138 parentTop = ((WindowState) parent).mWindowFrames.mFrame.top;
1139 } else if (parent != null) {
1140 final Rect parentBounds = parent.getDisplayedBounds();
1141 parentLeft = parentBounds.left;
1142 parentTop = parentBounds.top;
1143 }
1144 mWindowFrames.mRelFrame.offsetTo(mWindowFrames.mFrame.left - parentLeft,
1145 mWindowFrames.mFrame.top - parentTop);
1146
Adam Pardyl8c2d19c2019-09-16 17:15:38 +02001147 if (DEBUG_LAYOUT || DEBUG) {
1148 Slog.v(TAG, "Resolving (mRequestedWidth="
1149 + mRequestedWidth + ", mRequestedheight="
1150 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1151 + "): frame=" + mWindowFrames.mFrame.toShortString()
1152 + " " + mWindowFrames.getInsetsInfo()
1153 + " " + mAttrs.getTitle());
1154 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001155 }
1156
Bryce Leef3c6a472017-11-14 14:53:06 -08001157 // TODO: Look into whether this override is still necessary.
1158 @Override
1159 public Rect getBounds() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001160 if (mActivityRecord != null) {
1161 return mActivityRecord.getBounds();
Bryce Leef3c6a472017-11-14 14:53:06 -08001162 } else {
1163 return super.getBounds();
1164 }
1165 }
1166
Craig Mautnera2c77052012-03-26 12:14:43 -07001167 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001168 public Rect getFrameLw() {
chaviw492139a2018-07-16 16:07:35 -07001169 return mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001170 }
1171
Evan Rosky70213702019-11-05 10:26:24 -08001172 /** Accessor for testing */
1173 Rect getRelativeFrameLw() {
1174 return mWindowFrames.mRelFrame;
1175 }
1176
Craig Mautnera2c77052012-03-26 12:14:43 -07001177 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001178 public Rect getDisplayFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001179 return mWindowFrames.mDisplayFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001180 }
1181
Craig Mautnera2c77052012-03-26 12:14:43 -07001182 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001183 public Rect getContentFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001184 return mWindowFrames.mContentFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001185 }
1186
Craig Mautnera2c77052012-03-26 12:14:43 -07001187 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001188 public Rect getVisibleFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001189 return mWindowFrames.mVisibleFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001190 }
1191
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001192 Rect getStableFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001193 return mWindowFrames.mStableFrame;
1194 }
1195
1196 Rect getDecorFrame() {
1197 return mWindowFrames.mDecorFrame;
1198 }
1199
1200 Rect getParentFrame() {
1201 return mWindowFrames.mParentFrame;
1202 }
1203
1204 Rect getContainingFrame() {
1205 return mWindowFrames.mContainingFrame;
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001206 }
1207
chaviwcdba9a42018-07-19 11:36:42 -07001208 WmDisplayCutout getWmDisplayCutout() {
1209 return mWindowFrames.mDisplayCutout;
1210 }
1211
chaviw9c81e632018-07-31 11:17:52 -07001212 void getCompatFrame(Rect outFrame) {
1213 outFrame.set(mWindowFrames.mCompatFrame);
1214 }
1215
1216 void getCompatFrameSize(Rect outFrame) {
1217 outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height());
1218 }
1219
Craig Mautnera2c77052012-03-26 12:14:43 -07001220 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001221 public boolean getGivenInsetsPendingLw() {
1222 return mGivenInsetsPending;
1223 }
1224
Craig Mautnera2c77052012-03-26 12:14:43 -07001225 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001226 public Rect getGivenContentInsetsLw() {
1227 return mGivenContentInsets;
1228 }
1229
Craig Mautnera2c77052012-03-26 12:14:43 -07001230 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001231 public Rect getGivenVisibleInsetsLw() {
1232 return mGivenVisibleInsets;
1233 }
1234
Craig Mautnera2c77052012-03-26 12:14:43 -07001235 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001236 public WindowManager.LayoutParams getAttrs() {
1237 return mAttrs;
1238 }
1239
Craig Mautner812d2ca2012-09-27 15:35:34 -07001240 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001241 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001242 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001243 }
1244
Craig Mautner19d59bc2012-09-04 11:15:56 -07001245 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001246 public int getSystemUiVisibility() {
1247 return mSystemUiVisibility;
1248 }
1249
Craig Mautner19d59bc2012-09-04 11:15:56 -07001250 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001251 public int getSurfaceLayer() {
1252 return mLayer;
1253 }
1254
Craig Mautner812d2ca2012-09-27 15:35:34 -07001255 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001256 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001257 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001258 }
1259
1260 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001261 public IApplicationToken getAppToken() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001262 return mActivityRecord != null ? mActivityRecord.appToken : null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001263 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001264
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001265 @Override
1266 public boolean isVoiceInteraction() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001267 return mActivityRecord != null && mActivityRecord.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001268 }
1269
Robert Carr31aa98b2016-07-20 15:29:03 -07001270 boolean setReportResizeHints() {
chaviw9c81e632018-07-31 11:17:52 -07001271 return mWindowFrames.setReportResizeHints();
Craig Mautner4c5eb222013-11-18 12:59:05 -08001272 }
1273
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001274 /**
1275 * Adds the window to the resizing list if any of the parameters we use to track the window
1276 * dimensions or insets have changed.
1277 */
1278 void updateResizingWindowIfNeeded() {
1279 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001280 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001281 return;
1282 }
1283
1284 final Task task = getTask();
1285 // In the case of stack bound animations, the window frames will update (unlike other
1286 // animations which just modify various transformation properties). We don't want to
1287 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1288 // the frame may not correspond to the surface size or the onscreen area at various
1289 // phases in the animation, and the client will become sad and confused.
Wale Ogunwale8577a052019-10-26 23:22:34 -07001290 if (task != null && task.getTaskStack().isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001291 return;
1292 }
1293
chaviw9c81e632018-07-31 11:17:52 -07001294 boolean didFrameInsetsChange = setReportResizeHints();
Jorim Jaggi381cd722019-03-27 17:33:02 +01001295 boolean configChanged = !isLastConfigReportedToClient();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001296 if (DEBUG_CONFIGURATION && configChanged) {
1297 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1298 }
1299
1300 final boolean dragResizingChanged = isDragResizeChanged()
1301 && !isDragResizingChangeReported();
1302
Adam Pardyl8c2d19c2019-09-16 17:15:38 +02001303 if (DEBUG) {
1304 Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1305 + " dragResizingChanged=" + dragResizingChanged
1306 + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame);
1307 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001308
1309 // We update mLastFrame always rather than in the conditional with the last inset
1310 // variables, because mFrameSizeChanged only tracks the width and height changing.
chaviw492139a2018-07-16 16:07:35 -07001311 mWindowFrames.mLastFrame.set(mWindowFrames.mFrame);
Evan Rosky70213702019-11-05 10:26:24 -08001312 mWindowFrames.mLastRelFrame.set(mWindowFrames.mRelFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001313
chaviw9c81e632018-07-31 11:17:52 -07001314 if (didFrameInsetsChange
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001315 || winAnimator.mSurfaceResized
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001316 || configChanged
1317 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001318 || mReportOrientationChanged) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001319 ProtoLog.v(WM_DEBUG_RESIZE,
1320 "Resize reasons for w=%s: %s surfaceResized=%b configChanged=%b "
1321 + "dragResizingChanged=%b reportOrientationChanged=%b",
1322 this, mWindowFrames.getInsetsChangedInfo(), winAnimator.mSurfaceResized,
1323 configChanged, dragResizingChanged, mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001324
1325 // If it's a dead window left on screen, and the configuration changed, there is nothing
1326 // we can do about it. Remove the window now.
Garfield Tane8d84ab2019-10-11 09:49:40 -07001327 if (mActivityRecord != null && mAppDied) {
1328 mActivityRecord.removeDeadWindows();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001329 return;
1330 }
1331
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001332 updateLastInsetValues();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001333 mWmService.makeWindowFreezingScreenIfNeededLocked(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001334
1335 // If the orientation is changing, or we're starting or ending a drag resizing action,
1336 // then we need to hold off on unfreezing the display until this window has been
1337 // redrawn; to do that, we need to go through the process of getting informed by the
1338 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001339 if (getOrientationChanging() || dragResizingChanged) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001340 if (getOrientationChanging()) {
1341 Slog.v(TAG_WM, "Orientation start waiting for draw"
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001342 + ", mDrawState=DRAW_PENDING in " + this
1343 + ", surfaceController " + winAnimator.mSurfaceController);
1344 }
Adrian Roosb125e0b2019-10-02 14:55:14 +02001345 if (dragResizingChanged) {
1346 ProtoLog.v(WM_DEBUG_RESIZE,
1347 "Resize start waiting for draw, "
1348 + "mDrawState=DRAW_PENDING in %s, surfaceController %s",
1349 this, winAnimator.mSurfaceController);
1350 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001351 winAnimator.mDrawState = DRAW_PENDING;
Garfield Tane8d84ab2019-10-11 09:49:40 -07001352 if (mActivityRecord != null) {
1353 mActivityRecord.clearAllDrawn();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001354 }
1355 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001356 if (!mWmService.mResizingWindows.contains(this)) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001357 ProtoLog.v(WM_DEBUG_RESIZE, "Resizing window %s", this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001358 mWmService.mResizingWindows.add(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001359 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001360 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001361 if (isDrawnLw()) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001362 ProtoLog.v(WM_DEBUG_ORIENTATION,
1363 "Orientation not waiting for draw in %s, surfaceController %s", this,
1364 winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001365 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001366 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001367 - mWmService.mDisplayFreezeTime);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001368 }
1369 }
1370 }
1371
Bryce Lee8c3cf382017-07-06 19:47:10 -07001372 boolean getOrientationChanging() {
1373 // In addition to the local state flag, we must also consider the difference in the last
1374 // reported configuration vs. the current state. If the client code has not been informed of
1375 // the change, logic dependent on having finished processing the orientation, such as
1376 // unfreezing, could be improperly triggered.
1377 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1378 // this is not necessarily what the client has processed yet. Find a
1379 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001380 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001381 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001382 && !mSeamlesslyRotated
1383 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001384 }
1385
1386 void setOrientationChanging(boolean changing) {
1387 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001388 mOrientationChangeTimedOut = false;
1389 }
1390
1391 void orientationChangeTimedOut() {
1392 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001393 }
1394
Tiger Huanged6794e2019-05-07 20:07:59 +08001395 @Override
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001396 DisplayContent getDisplayContent() {
1397 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001398 }
1399
Adrian Roos5251b1d2018-03-23 18:57:43 +01001400 @Override
1401 void onDisplayChanged(DisplayContent dc) {
1402 super.onDisplayChanged(dc);
1403 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
Garfield Tane223e682019-04-15 09:59:25 -07001404 if (dc != null && mInputWindowHandle.displayId != dc.getDisplayId()) {
Adrian Roos5251b1d2018-03-23 18:57:43 +01001405 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001406 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001407 }
1408 }
1409
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001410 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001411 final DisplayContent displayContent = getDisplayContent();
1412 return displayContent != null ? displayContent.getDisplayInfo() : null;
1413 }
1414
Jorim Jaggife762342016-10-13 14:33:27 +02001415 @Override
1416 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001417 final DisplayContent displayContent = getDisplayContent();
1418 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001419 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001420 }
1421 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001422 }
1423
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001424 Task getTask() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001425 return mActivityRecord != null ? mActivityRecord.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001426 }
1427
Louis Changdc077272019-11-12 16:52:56 +08001428 ActivityStack getStack() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001429 Task task = getTask();
1430 if (task != null) {
Wale Ogunwale8577a052019-10-26 23:22:34 -07001431 if (task.getTaskStack() != null) {
1432 return task.getTaskStack();
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001433 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001434 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001435 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1436 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001437 final DisplayContent dc = getDisplayContent();
1438 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001439 }
1440
Skuhnef932e562015-08-20 12:07:30 -07001441 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001442 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001443 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001444 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001445 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001446 final Task task = getTask();
1447 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001448 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001449 mTmpRect.setEmpty();
1450 if (intersectWithStackBounds) {
Louis Changdc077272019-11-12 16:52:56 +08001451 final ActivityStack stack = task.getTaskStack();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001452 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001453 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001454 } else {
1455 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001456 }
1457 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001458
chaviw553b0212018-07-12 13:37:01 -07001459 bounds.set(mWindowFrames.mVisibleFrame);
Chong Zhang9184ec62015-09-24 12:32:21 -07001460 if (intersectWithStackBounds) {
1461 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001462 }
1463
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001464 if (bounds.isEmpty()) {
chaviw492139a2018-07-16 16:07:35 -07001465 bounds.set(mWindowFrames.mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001466 if (intersectWithStackBounds) {
1467 bounds.intersect(mTmpRect);
1468 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001469 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001470 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001471 }
1472
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001473 public long getInputDispatchingTimeoutNanos() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001474 return mActivityRecord != null
1475 ? mActivityRecord.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001476 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1477 }
1478
Craig Mautnere8552142012-11-07 13:55:47 -08001479 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001480 public boolean hasAppShownWindows() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001481 return mActivityRecord != null && (mActivityRecord.firstWindowDrawn || mActivityRecord.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001482 }
1483
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001484 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1485 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1486 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1487 if (dtdx < -.000001f || dtdx > .000001f) return false;
1488 if (dsdy < -.000001f || dsdy > .000001f) return false;
1489 return true;
1490 }
1491
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001492 void prelayout() {
Riddle Hsub398da32019-01-21 21:48:16 +08001493 if (inSizeCompatMode()) {
1494 mGlobalScale = mToken.getSizeCompatScale();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001495 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001496 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001497 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001498 }
1499 }
1500
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001501 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001502 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001503 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
lumark9bca6b42019-10-17 18:35:22 +08001504 || (isAnimating(TRANSITION | PARENTS)
1505 && !getDisplayContent().mAppTransition.isTransitionSet()))) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001506 return true;
1507 }
1508
Wale Ogunwale44f21802016-09-02 12:49:48 -07001509 return super.hasContentToDisplay();
1510 }
1511
1512 @Override
1513 boolean isVisible() {
chaviw15ad49f2019-04-24 15:05:39 -07001514 return wouldBeVisibleIfPolicyIgnored() && isVisibleByPolicy()
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001515 // If we don't have a provider, this window isn't used as a window generating
1516 // insets, so nobody can hide it over the inset APIs.
Jorim Jaggi956ca412019-01-07 14:49:14 +01001517 && (mControllableInsetProvider == null
1518 || mControllableInsetProvider.isClientVisible());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001519 }
1520
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001521 /**
chaviw15ad49f2019-04-24 15:05:39 -07001522 * Ensures that all the policy visibility bits are set.
1523 * @return {@code true} if all flags about visiblity are set
1524 */
1525 boolean isVisibleByPolicy() {
1526 return (mPolicyVisibility & POLICY_VISIBILITY_ALL) == POLICY_VISIBILITY_ALL;
1527 }
1528
1529 void clearPolicyVisibilityFlag(int policyVisibilityFlag) {
1530 mPolicyVisibility &= ~policyVisibilityFlag;
chaviwbb6bd8a2019-05-28 17:05:28 -07001531 mWmService.scheduleAnimationLocked();
chaviw15ad49f2019-04-24 15:05:39 -07001532 }
1533
1534 void setPolicyVisibilityFlag(int policyVisibilityFlag) {
1535 mPolicyVisibility |= policyVisibilityFlag;
chaviwbb6bd8a2019-05-28 17:05:28 -07001536 mWmService.scheduleAnimationLocked();
chaviw15ad49f2019-04-24 15:05:39 -07001537 }
1538
1539 private boolean isLegacyPolicyVisibility() {
1540 return (mPolicyVisibility & LEGACY_POLICY_VISIBILITY) != 0;
1541 }
1542
1543 /**
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001544 * @return {@code true} if the window would be visible if we'd ignore policy visibility,
1545 * {@code false} otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001546 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001547 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001548 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001549 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001550 }
1551
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001552 @Override
1553 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001554 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001555 }
1556
1557 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001558 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1559 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001560 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001561 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1562 boolean isWinVisibleLw() {
Issei Suzuki1669ea42019-11-06 14:20:59 +01001563 return (mActivityRecord == null || mActivityRecord.mVisibleRequested
lumark9bca6b42019-10-17 18:35:22 +08001564 || mActivityRecord.isAnimating(TRANSITION)) && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001565 }
1566
1567 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001568 * The same as isVisible(), but follows the current hidden state of the associated app token,
1569 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001570 */
1571 boolean isVisibleNow() {
Issei Suzuki7b9e2572019-11-14 16:19:54 +01001572 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001573 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001574 }
1575
1576 /**
1577 * Can this window possibly be a drag/drop target? The test here is
1578 * a combination of the above "visible now" with the check that the
1579 * Input Manager uses when discarding windows from input consideration.
1580 */
1581 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001582 return isVisibleNow() && !mRemoved
1583 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001584 }
1585
1586 /**
1587 * Same as isVisible(), but we also count it as visible between the
1588 * call to IWindowSession.add() and the first relayout().
1589 */
1590 boolean isVisibleOrAdding() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001591 final ActivityRecord atoken = mActivityRecord;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001592 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
chaviw15ad49f2019-04-24 15:05:39 -07001593 && isVisibleByPolicy() && !isParentWindowHidden()
Issei Suzuki1669ea42019-11-06 14:20:59 +01001594 && (atoken == null || atoken.mVisibleRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001595 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001596 }
1597
1598 /**
1599 * Is this window currently on-screen? It is on-screen either if it
1600 * is visible or it is currently running an animation before no longer
1601 * being visible.
1602 */
1603 boolean isOnScreen() {
chaviw15ad49f2019-04-24 15:05:39 -07001604 if (!mHasSurface || mDestroying || !isVisibleByPolicy()) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001605 return false;
1606 }
Garfield Tane8d84ab2019-10-11 09:49:40 -07001607 final ActivityRecord atoken = mActivityRecord;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001608 if (atoken != null) {
Issei Suzuki1669ea42019-11-06 14:20:59 +01001609 return ((!isParentWindowHidden() && atoken.mVisibleRequested)
lumark9bca6b42019-10-17 18:35:22 +08001610 || isAnimating(TRANSITION | PARENTS));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001611 }
lumark9bca6b42019-10-17 18:35:22 +08001612 return !isParentWindowHidden() || isAnimating(TRANSITION | PARENTS);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001613 }
1614
1615 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001616 * Whether this window's drawn state might affect the drawn states of the app token.
1617 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001618 * @return true if the window should be considered while evaluating allDrawn flags.
1619 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001620 boolean mightAffectAllDrawn() {
1621 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1622 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1623 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001624 }
1625
1626 /**
1627 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1628 * it must be drawn before allDrawn can become true.
1629 */
1630 boolean isInteresting() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001631 return mActivityRecord != null && !mAppDied
1632 && (!mActivityRecord.isFreezingScreen() || !mAppFreezing)
Jorim Jaggi995e1062019-06-06 14:03:41 +02001633 && mViewVisibility == View.VISIBLE;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001634 }
1635
1636 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001637 * Like isOnScreen(), but we don't return true if the window is part
1638 * of a transition that has not yet been started.
1639 */
1640 boolean isReadyForDisplay() {
lumark588a3e82018-07-20 18:53:54 +08001641 if (mToken.waitingToShow && getDisplayContent().mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001642 return false;
1643 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001644 final boolean parentAndClientVisible = !isParentWindowHidden()
Issei Suzuki7b9e2572019-11-14 16:19:54 +01001645 && mViewVisibility == View.VISIBLE && !mToken.isHidden();
chaviw15ad49f2019-04-24 15:05:39 -07001646 return mHasSurface && isVisibleByPolicy() && !mDestroying
lumark9bca6b42019-10-17 18:35:22 +08001647 && (parentAndClientVisible || isAnimating(TRANSITION | PARENTS));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001648 }
1649
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001650 // TODO: Another visibility method that was added late in the release to minimize risk.
1651 @Override
1652 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001653 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001654 if (translucent) {
1655 return false;
1656 }
Garfield Tane8d84ab2019-10-11 09:49:40 -07001657 if (mActivityRecord == null) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001658 final boolean shown = mWinAnimator.getShown();
1659 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001660 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001661 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001662 final Task task = getTask();
1663 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
Issei Suzuki7b9e2572019-11-14 16:19:54 +01001664 return canFromTask && !mActivityRecord.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001665 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001666 }
1667
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001668 /**
1669 * Like isOnScreen, but returns false if the surface hasn't yet
1670 * been drawn.
1671 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001672 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001673 public boolean isDisplayedLw() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001674 final ActivityRecord atoken = mActivityRecord;
chaviw15ad49f2019-04-24 15:05:39 -07001675 return isDrawnLw() && isVisibleByPolicy()
Issei Suzuki1669ea42019-11-06 14:20:59 +01001676 && ((!isParentWindowHidden() && (atoken == null || atoken.mVisibleRequested))
lumark9bca6b42019-10-17 18:35:22 +08001677 || isAnimating(TRANSITION | PARENTS));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001678 }
1679
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001680 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001681 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001682 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001683 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001684 public boolean isAnimatingLw() {
lumark9bca6b42019-10-17 18:35:22 +08001685 return isAnimating(TRANSITION | PARENTS);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001686 }
1687
Craig Mautner812d2ca2012-09-27 15:35:34 -07001688 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001689 public boolean isGoneForLayoutLw() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001690 final ActivityRecord atoken = mActivityRecord;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001691 return mViewVisibility == View.GONE
1692 || !mRelayoutCalled
Issei Suzuki7b9e2572019-11-14 16:19:54 +01001693 || (atoken == null && mToken.isHidden())
Issei Suzuki1669ea42019-11-06 14:20:59 +01001694 || (atoken != null && !atoken.mVisibleRequested)
Jorim Jaggib52b0452019-07-16 17:43:15 +02001695 || isParentWindowGoneForLayout()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001696 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001697 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001698 }
1699
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001700 /**
1701 * Returns true if the window has a surface that it has drawn a
1702 * complete UI in to.
1703 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001704 public boolean isDrawFinishedLw() {
1705 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001706 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1707 || mWinAnimator.mDrawState == READY_TO_SHOW
1708 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001709 }
1710
1711 /**
1712 * Returns true if the window has a surface that it has drawn a
1713 * complete UI in to.
1714 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001715 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001716 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001717 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001718 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001719 }
1720
1721 /**
1722 * Return true if the window is opaque and fully drawn. This indicates
1723 * it may obscure windows behind it.
1724 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001725 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001726 // When there is keyguard, wallpaper could be placed over the secure app
1727 // window but invisible. We need to check wallpaper visibility explicitly
1728 // to determine if it's occluding apps.
1729 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1730 || (mIsWallpaper && mWallpaperVisible))
lumark9bca6b42019-10-17 18:35:22 +08001731 && isDrawnLw() && !isAnimating(TRANSITION | PARENTS);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001732 }
1733
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001734 @Override
1735 void onMovedByResize() {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001736 ProtoLog.d(WM_DEBUG_RESIZE, "onMovedByResize: Moving %s", this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001737 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001738 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001739 }
1740
1741 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1742 boolean changed = false;
1743
1744 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001745 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001746 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1747 }
1748
1749 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1750 // Starting window that's exiting will be removed when the animation finishes.
1751 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1752 // to actually remove it.
lumark9bca6b42019-10-17 18:35:22 +08001753 if (!visible && isVisibleNow() && mActivityRecord.isAnimating(TRANSITION)) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001754 mAnimatingExit = true;
1755 mRemoveOnExit = true;
1756 mWindowRemovalAllowed = true;
1757 }
1758 return changed;
1759 }
1760
chaviwe390cbd2018-04-16 15:29:38 -07001761 final boolean isVisibleNow = isVisibleNow();
1762 if (visible != isVisibleNow) {
1763 // Run exit animation if:
1764 // 1. App visibility and WS visibility are different
1765 // 2. App is not running an animation
1766 // 3. WS is currently visible
1767 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001768 final AccessibilityController accessibilityController =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001769 mWmService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001770 final int winTransit = TRANSIT_EXIT;
1771 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Rhed Jao02655dc2018-10-30 20:44:52 +08001772 if (accessibilityController != null) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001773 accessibilityController.onWindowTransitionLocked(this, winTransit);
1774 }
1775 }
1776 changed = true;
1777 setDisplayLayoutNeeded();
1778 }
1779
1780 return changed;
1781 }
1782
1783 boolean onSetAppExiting() {
1784 final DisplayContent displayContent = getDisplayContent();
1785 boolean changed = false;
1786
1787 if (isVisibleNow()) {
1788 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Rhed Jao02655dc2018-10-30 20:44:52 +08001789 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001790 mWmService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001791 }
1792 changed = true;
1793 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001794 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001795 }
1796 }
1797
1798 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001799 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001800 changed |= c.onSetAppExiting();
1801 }
1802
1803 return changed;
1804 }
1805
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001806 @Override
1807 void onResize() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001808 final ArrayList<WindowState> resizingWindows = mWmService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001809 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001810 ProtoLog.d(WM_DEBUG_RESIZE, "onResize: Resizing %s", this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001811 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001812 }
1813 if (isGoneForLayoutLw()) {
1814 mResizedWhileGone = true;
1815 }
1816
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001817 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001818 }
1819
1820 void onUnfreezeBounds() {
1821 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001822 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001823 c.onUnfreezeBounds();
1824 }
1825
1826 if (!mHasSurface) {
1827 return;
1828 }
1829
1830 mLayoutNeeded = true;
1831 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001832 if (!mWmService.mResizingWindows.contains(this)) {
1833 mWmService.mResizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001834 }
1835 }
1836
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001837 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001838 * If the window has moved due to its containing content frame changing, then notify the
1839 * listeners and optionally animate it. Simply checking a change of position is not enough,
1840 * because being move due to dock divider is not a trigger for animation.
1841 */
chaviw161ea3e2018-01-31 12:01:12 -08001842 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001843 if (!hasMoved()) {
1844 return;
1845 }
1846
1847 // Frame has moved, containing content frame has also moved, and we're not currently
1848 // animating... let's do something.
chaviw492139a2018-07-16 16:07:35 -07001849 final int left = mWindowFrames.mFrame.left;
1850 final int top = mWindowFrames.mFrame.top;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001851 final Task task = getTask();
1852 final boolean adjustedForMinimizedDockOrIme = task != null
Wale Ogunwale8577a052019-10-26 23:22:34 -07001853 && (task.getTaskStack().isAdjustedForMinimizedDockedStack()
1854 || task.getTaskStack().isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001855 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001856 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1857 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001858 && getWindowConfiguration().hasMovementAnimations()
Adrian Roos0e7b70a2018-06-07 15:29:34 +02001859 && !mWinAnimator.mLastHidden
1860 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08001861 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001862 }
1863
Jacky Kaof93252b2019-07-18 15:19:52 +08001864 if (mWmService.mAccessibilityController != null) {
1865 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(getDisplayId());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001866 }
Jackal Guoc43a0a62019-04-23 09:15:14 +08001867 updateLocationInParentDisplayIfNeeded();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001868
1869 try {
1870 mClient.moved(left, top);
1871 } catch (RemoteException e) {
1872 }
1873 mMovedByResize = false;
1874 }
1875
1876 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001877 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001878 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1879 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001880 private boolean hasMoved() {
chaviw1454b392018-08-06 09:54:04 -07001881 return mHasSurface && (mWindowFrames.hasContentChanged() || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001882 && !mAnimatingExit
Evan Rosky70213702019-11-05 10:26:24 -08001883 && (mWindowFrames.mRelFrame.top != mWindowFrames.mLastRelFrame.top
1884 || mWindowFrames.mRelFrame.left != mWindowFrames.mLastRelFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001885 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001886 }
1887
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001888 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001889 Task task = getTask();
Wale Ogunwale8577a052019-10-26 23:22:34 -07001890 if (task != null && task.getTaskStack() != null && !task.getTaskStack().fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001891 return false;
1892 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001893 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001894 }
1895
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001896 boolean fillsDisplay() {
1897 final DisplayInfo displayInfo = getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07001898 return mWindowFrames.mFrame.left <= 0 && mWindowFrames.mFrame.top <= 0
1899 && mWindowFrames.mFrame.right >= displayInfo.appWidth
1900 && mWindowFrames.mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001901 }
1902
Evan Rosky4fb1e912019-03-06 13:54:43 -08001903 private boolean matchesDisplayBounds() {
1904 return getDisplayContent().getBounds().equals(getBounds());
1905 }
1906
Jorim Jaggi381cd722019-03-27 17:33:02 +01001907 /**
1908 * @return {@code true} if last applied config was reported to the client already, {@code false}
1909 * otherwise.
1910 */
1911 boolean isLastConfigReportedToClient() {
1912 return mLastConfigReportedToClient;
1913 }
1914
1915 @Override
1916 void onMergedOverrideConfigurationChanged() {
1917 super.onMergedOverrideConfigurationChanged();
1918 mLastConfigReportedToClient = false;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001919 }
1920
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001921 void onWindowReplacementTimeout() {
1922 if (mWillReplaceWindow) {
1923 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001924 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001925 // delays removal on certain conditions, which will leave the stale window in the
1926 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1927 //
1928 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001929 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001930 } else {
1931 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001932 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001933 c.onWindowReplacementTimeout();
1934 }
1935 }
1936 }
1937
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001938 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001939 void forceWindowsScaleableInTransaction(boolean force) {
1940 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1941 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1942 }
1943
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001944 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001945 }
1946
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001947 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001948 void removeImmediately() {
1949 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001950
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001951 if (mRemoved) {
1952 // Nothing to do.
Adrian Roosb125e0b2019-10-02 14:55:14 +02001953 ProtoLog.v(WM_DEBUG_ADD_REMOVE,
1954 "WS.removeImmediately: %s Already removed...", this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001955 return;
1956 }
1957
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001958 mRemoved = true;
1959
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001960 mWillReplaceWindow = false;
1961 if (mReplacementWindow != null) {
1962 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1963 }
1964
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001965 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001966 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001967 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001968 }
1969
1970 final int type = mAttrs.type;
1971 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001972 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001973 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001974 if (mTapExcludeRegionHolder != null) {
1975 // If a tap exclude region container was initialized for this window, then it should've
1976 // also been registered in display.
1977 dc.mTapExcludeProvidingWindows.remove(this);
1978 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001979 dc.getDisplayPolicy().removeWindowLw(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001980
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001981 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001982
Craig Mautner96868332012-12-04 14:29:11 -08001983 mWinAnimator.destroyDeferredSurfaceLocked();
1984 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001985 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001986 try {
1987 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1988 } catch (RuntimeException e) {
1989 // Ignore if it has already been removed (usually because
1990 // we are doing this as part of processing a death note.)
1991 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001992
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001993 mWmService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001994 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001995
Wale Ogunwale571771c2016-08-26 13:18:50 -07001996 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001997 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001998 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001999 removeIfPossible(false /*keepVisibleDeadWindow*/);
2000 }
2001
Wale Ogunwale571771c2016-08-26 13:18:50 -07002002 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002003 mWindowRemovalAllowed = true;
Adrian Roosb125e0b2019-10-02 14:55:14 +02002004 ProtoLog.v(WM_DEBUG_ADD_REMOVE,
2005 "removeIfPossible: %s callers=%s", this, Debug.getCallers(5));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002006
2007 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
Adrian Roosb125e0b2019-10-02 14:55:14 +02002008 if (startingWindow) {
2009 ProtoLog.d(WM_DEBUG_STARTING_WINDOW, "Starting window removed %s", this);
Adam Pardyl8c2d19c2019-09-16 17:15:38 +02002010 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002011
Adrian Roosb125e0b2019-10-02 14:55:14 +02002012 ProtoLog.v(WM_DEBUG_FOCUS, "Remove client=%x, surfaceController=%s Callers=%s",
2013 System.identityHashCode(mClient.asBinder()),
2014 mWinAnimator.mSurfaceController,
2015 Debug.getCallers(5));
2016
2017
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002018 final long origId = Binder.clearCallingIdentity();
2019
Peter Visontay3556a3b2017-11-01 17:23:17 +00002020 try {
2021 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002022
Adrian Roosb125e0b2019-10-02 14:55:14 +02002023 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS,
2024 "Remove %s: mSurfaceController=%s mAnimatingExit=%b mRemoveOnExit=%b "
2025 + "mHasSurface=%b surfaceShowing=%b animating=%b app-animation=%b "
Issei Suzuki860fbc02019-10-31 16:49:35 +01002026 + "mWillReplaceWindow=%b mDisplayFrozen=%b callers=%s",
Adrian Roosb125e0b2019-10-02 14:55:14 +02002027 this, mWinAnimator.mSurfaceController, mAnimatingExit, mRemoveOnExit,
lumark9bca6b42019-10-17 18:35:22 +08002028 mHasSurface, mWinAnimator.getShown(),
2029 isAnimating(TRANSITION | PARENTS),
2030 mActivityRecord != null && mActivityRecord.isAnimating(TRANSITION),
2031 mWillReplaceWindow,
Adrian Roosb125e0b2019-10-02 14:55:14 +02002032 mWmService.mDisplayFrozen, Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002033
Peter Visontay3556a3b2017-11-01 17:23:17 +00002034 // Visibility of the removed window. Will be used later to update orientation later on.
2035 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002036
Peter Visontay3556a3b2017-11-01 17:23:17 +00002037 // First, see if we need to run an animation. If we do, we have to hold off on removing the
2038 // window until the animation is done. If the display is frozen, just remove immediately,
2039 // since the animation wouldn't be seen.
2040 if (mHasSurface && mToken.okToAnimate()) {
2041 if (mWillReplaceWindow) {
2042 // This window is going to be replaced. We need to keep it around until the new one
2043 // gets added, then we will get rid of this one.
Adrian Roosb125e0b2019-10-02 14:55:14 +02002044 ProtoLog.v(WM_DEBUG_ADD_REMOVE,
2045 "Preserving %s until the new one is added", this);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002046 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
2047 // been removed. We probably need another flag to indicate that window removal
2048 // should be deffered vs. overloading the flag that says we are playing an exit
2049 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002050 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00002051 mReplacingRemoveRequested = true;
2052 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002053 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002054
Peter Visontay3556a3b2017-11-01 17:23:17 +00002055 // If we are not currently running the exit animation, we need to see about starting one
2056 wasVisible = isWinVisibleLw();
2057
2058 if (keepVisibleDeadWindow) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002059 ProtoLog.v(WM_DEBUG_ADD_REMOVE,
2060 "Not removing %s because app died while it's visible", this);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002061
2062 mAppDied = true;
2063 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002064 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Peter Visontay3556a3b2017-11-01 17:23:17 +00002065
2066 // Set up a replacement input channel since the app is now dead.
2067 // We need to catch tapping on the dead window to restart the app.
2068 openInputChannel(null);
Arthur Hung95b38a92018-07-20 18:56:12 +08002069 getDisplayContent().getInputMonitor().updateInputWindowsLw(true /*force*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002070 return;
2071 }
2072
2073 if (wasVisible) {
2074 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
2075
2076 // Try starting an animation.
2077 if (mWinAnimator.applyAnimationLocked(transit, false)) {
2078 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02002079
2080 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
2081 // any change from that is performed immediately.
2082 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002083 mWmService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00002084 }
Rhed Jao02655dc2018-10-30 20:44:52 +08002085 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002086 mWmService.mAccessibilityController.onWindowTransitionLocked(this, transit);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002087 }
2088 }
lumark9bca6b42019-10-17 18:35:22 +08002089 final boolean isAnimating = isAnimating(TRANSITION | PARENTS)
Garfield Tane8d84ab2019-10-11 09:49:40 -07002090 && (mActivityRecord == null || !mActivityRecord.isWaitingForTransitionStart());
2091 final boolean lastWindowIsStartingWindow = startingWindow && mActivityRecord != null
2092 && mActivityRecord.isLastWindow(this);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002093 // We delay the removal of a window if it has a showing surface that can be used to run
2094 // exit animation and it is marked as exiting.
2095 // Also, If isn't the an animating starting window that is the last window in the app.
2096 // We allow the removal of the non-animating starting window now as there is no
2097 // additional window or animation that will trigger its removal.
2098 if (mWinAnimator.getShown() && mAnimatingExit
2099 && (!lastWindowIsStartingWindow || isAnimating)) {
2100 // The exit animation is running or should run... wait for it!
Adrian Roosb125e0b2019-10-02 14:55:14 +02002101 ProtoLog.v(WM_DEBUG_ADD_REMOVE,
2102 "Not removing %s due to exit animation", this);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002103 setupWindowForRemoveOnExit();
Garfield Tane8d84ab2019-10-11 09:49:40 -07002104 if (mActivityRecord != null) {
2105 mActivityRecord.updateReportedVisibilityLocked();
Peter Visontay3556a3b2017-11-01 17:23:17 +00002106 }
2107 return;
2108 }
2109 }
2110
2111 removeImmediately();
2112 // Removing a visible window will effect the computed orientation
2113 // So just update orientation if needed.
Riddle Hsu4e611772018-10-31 18:58:28 +08002114 if (wasVisible) {
2115 final DisplayContent displayContent = getDisplayContent();
Riddle Hsuccf09402019-08-13 00:33:06 +08002116 if (displayContent.updateOrientation()) {
Shivam Agrawal6472e0e2019-07-03 16:27:49 -07002117 displayContent.sendNewConfiguration();
Riddle Hsu4e611772018-10-31 18:58:28 +08002118 }
Peter Visontay3556a3b2017-11-01 17:23:17 +00002119 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002120 mWmService.updateFocusedWindowLocked(isFocused()
Tiger Huang8af6ba42018-06-07 19:24:09 +08002121 ? UPDATE_FOCUS_REMOVING_FOCUS
2122 : UPDATE_FOCUS_NORMAL,
2123 true /*updateInputWindows*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002124 } finally {
2125 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002126 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002127 }
2128
2129 private void setupWindowForRemoveOnExit() {
2130 mRemoveOnExit = true;
2131 setDisplayLayoutNeeded();
2132 // Request a focus update as this window's input channel is already gone. Otherwise
2133 // we could have no focused window in input manager.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002134 final boolean focusChanged = mWmService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002135 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002136 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002137 if (focusChanged) {
Arthur Hung95b38a92018-07-20 18:56:12 +08002138 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002139 }
2140 }
2141
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002142 void setHasSurface(boolean hasSurface) {
2143 mHasSurface = hasSurface;
2144 }
2145
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002146 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002147 if (mIsImWindow) {
2148 // IME windows can't be IME targets. IME targets are required to be below the IME
2149 // windows and that wouldn't be possible if the IME window is its own target...silly.
2150 return false;
2151 }
2152
Garfield Tane8d84ab2019-10-11 09:49:40 -07002153 final boolean windowsAreFocusable = mActivityRecord == null || mActivityRecord.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002154 if (!windowsAreFocusable) {
2155 // This window can't be an IME target if the app's windows should not be focusable.
2156 return false;
2157 }
2158
Louis Changdc077272019-11-12 16:52:56 +08002159 final ActivityStack stack = getStack();
lumarkf948afe2019-05-23 21:22:36 +08002160 if (stack != null && stack.shouldIgnoreInput()) {
2161 // Ignore when the stack shouldn't receive input event.
2162 // (i.e. the minimized stack in split screen mode.)
2163 return false;
2164 }
2165
Tarandeep Singh0ffa15a2019-11-04 13:40:15 -08002166 // Can be an IME target only if:
2167 // 1. FLAG_NOT_FOCUSABLE is not set
2168 // 2. FLAG_ALT_FOCUSABLE_IM is not set
2169 // 3. not a starting window.
2170 if (!WindowManager.LayoutParams.mayUseInputMethod(mAttrs.flags)
2171 || mAttrs.type == TYPE_APPLICATION_STARTING) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002172 return false;
2173 }
2174
2175 if (DEBUG_INPUT_METHOD) {
2176 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2177 if (!isVisibleOrAdding()) {
2178 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2179 + " relayoutCalled=" + mRelayoutCalled
2180 + " viewVis=" + mViewVisibility
chaviw15ad49f2019-04-24 15:05:39 -07002181 + " policyVis=" + isVisibleByPolicy()
2182 + " policyVisAfterAnim=" + mLegacyPolicyVisibilityAfterAnim
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002183 + " parentHidden=" + isParentWindowHidden()
2184 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
Garfield Tane8d84ab2019-10-11 09:49:40 -07002185 if (mActivityRecord != null) {
Issei Suzuki1669ea42019-11-06 14:20:59 +01002186 Slog.i(TAG_WM, " mActivityRecord.visibleRequested="
2187 + mActivityRecord.mVisibleRequested);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002188 }
2189 }
2190 }
2191 return isVisibleOrAdding();
2192 }
2193
Chong Zhangacf11402015-11-04 16:23:10 -08002194 private final class DeadWindowEventReceiver extends InputEventReceiver {
2195 DeadWindowEventReceiver(InputChannel inputChannel) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002196 super(inputChannel, mWmService.mH.getLooper());
Chong Zhangacf11402015-11-04 16:23:10 -08002197 }
2198 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002199 public void onInputEvent(InputEvent event) {
Chong Zhangacf11402015-11-04 16:23:10 -08002200 finishInputEvent(event, true);
2201 }
2202 }
2203 /**
2204 * Dummy event receiver for windows that died visible.
2205 */
2206 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2207
Chong Zhang112eb8c2015-11-02 11:17:00 -08002208 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002209 if (mInputChannel != null) {
2210 throw new IllegalStateException("Window already has an input channel.");
2211 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002212 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002213 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2214 mInputChannel = inputChannels[0];
2215 mClientChannel = inputChannels[1];
Vishnu Nair18782162019-10-08 14:57:16 -07002216 mWmService.mInputManager.registerInputChannel(mInputChannel);
Vishnu Nair18782162019-10-08 14:57:16 -07002217 mInputWindowHandle.token = mInputChannel.getToken();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002218 if (outInputChannel != null) {
2219 mClientChannel.transferTo(outInputChannel);
2220 mClientChannel.dispose();
2221 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002222 } else {
2223 // If the window died visible, we setup a dummy input channel, so that taps
2224 // can still detected by input monitor channel, and we can relaunch the app.
2225 // Create dummy event receiver that simply reports all events as handled.
2226 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002227 }
Vishnu Nair18782162019-10-08 14:57:16 -07002228 mWmService.mInputToWindowMap.put(mInputWindowHandle.token, this);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002229 }
2230
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002231 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002232 if (mDeadWindowEventReceiver != null) {
2233 mDeadWindowEventReceiver.dispose();
2234 mDeadWindowEventReceiver = null;
2235 }
2236
2237 // unregister server channel first otherwise it complains about broken channel
2238 if (mInputChannel != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002239 mWmService.mInputManager.unregisterInputChannel(mInputChannel);
Robert Carre0a353c2018-08-02 16:38:04 -07002240
Chong Zhangacf11402015-11-04 16:23:10 -08002241 mInputChannel.dispose();
2242 mInputChannel = null;
2243 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002244 if (mClientChannel != null) {
2245 mClientChannel.dispose();
2246 mClientChannel = null;
2247 }
Vishnu Nair539334a2019-09-20 10:46:21 -07002248 mWmService.mKeyInterceptionInfoForToken.remove(mInputWindowHandle.token);
Vishnu Nair18782162019-10-08 14:57:16 -07002249 mWmService.mInputToWindowMap.remove(mInputWindowHandle.token);
Robert Carreadae822018-10-11 19:07:03 -07002250 mInputWindowHandle.token = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002251 }
2252
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002253 /** Returns true if the replacement window was removed. */
2254 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2255 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2256 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2257 removeReplacedWindow();
2258 return true;
2259 }
2260
2261 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002262 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002263 if (c.removeReplacedWindowIfNeeded(replacement)) {
2264 return true;
2265 }
2266 }
2267 return false;
2268 }
2269
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002270 private void removeReplacedWindow() {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002271 ProtoLog.d(WM_DEBUG_ADD_REMOVE, "Removing replaced window: %s", this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002272 mWillReplaceWindow = false;
2273 mAnimateReplacingWindow = false;
2274 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002275 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002276 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002277 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002278 }
2279 }
2280
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002281 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2282 boolean replacementSet = false;
2283
2284 if (mWillReplaceWindow && mReplacementWindow == null
2285 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2286
2287 mReplacementWindow = replacementCandidate;
2288 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2289 replacementSet = true;
2290 }
2291
2292 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002293 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002294 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2295 }
2296
2297 return replacementSet;
2298 }
2299
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002300 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002301 final DisplayContent dc = getDisplayContent();
2302 if (dc != null) {
2303 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002304 }
2305 }
2306
Chong Zhang5117e272016-05-03 12:47:34 -07002307 void applyAdjustForImeIfNeeded() {
2308 final Task task = getTask();
Wale Ogunwale8577a052019-10-26 23:22:34 -07002309 if (task != null && task.getTaskStack() != null && task.getTaskStack().isAdjustedForIme()) {
2310 task.getTaskStack().applyAdjustForImeIfNeeded(task);
Chong Zhang5117e272016-05-03 12:47:34 -07002311 }
2312 }
2313
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002314 @Override
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -07002315 void switchUser(int userId) {
2316 super.switchUser(userId);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002317 if (isHiddenFromUserLocked()) {
2318 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2319 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
chaviw15ad49f2019-04-24 15:05:39 -07002320 clearPolicyVisibilityFlag(VISIBLE_FOR_USER);
2321 } else {
2322 setPolicyVisibilityFlag(VISIBLE_FOR_USER);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002323 }
2324 }
2325
Vishnu Nair93d68c22019-03-22 13:45:31 -07002326 int getSurfaceTouchableRegion(InputWindowHandle inputWindowHandle, int flags) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002327 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Vishnu Nair93d68c22019-03-22 13:45:31 -07002328 final Region region = inputWindowHandle.touchableRegion;
2329 setTouchableRegionCropIfNeeded(inputWindowHandle);
2330
Garfield Tane8d84ab2019-10-11 09:49:40 -07002331 if (modal && mActivityRecord != null) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002332 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002333 flags |= FLAG_NOT_TOUCH_MODAL;
Riddle Hsu69de5fb2019-02-23 01:19:50 +08002334 // If the inner bounds of letterbox is available, then it will be used as the touchable
2335 // region so it won't cover the touchable letterbox and the touch events can slip to
2336 // activity from letterbox.
Garfield Tane8d84ab2019-10-11 09:49:40 -07002337 mActivityRecord.getLetterboxInnerBounds(mTmpRect);
Riddle Hsu69de5fb2019-02-23 01:19:50 +08002338 if (mTmpRect.isEmpty()) {
2339 // If this is a modal window we need to dismiss it if it's not full screen and the
2340 // touch happens outside of the frame that displays the content. This means we need
2341 // to intercept touches outside of that window. The dim layer user associated with
2342 // the window (task or stack) will give us the good bounds, as they would be used to
2343 // display the dim layer.
2344 final Task task = getTask();
2345 if (task != null) {
2346 task.getDimBounds(mTmpRect);
2347 } else {
2348 getStack().getDimBounds(mTmpRect);
2349 }
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002350 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002351 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002352 // For freeform windows we the touch region to include the whole surface for the
2353 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002354 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2355 final int delta = WindowManagerService.dipToPixel(
2356 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2357 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002358 }
2359 region.set(mTmpRect);
Riddle Hsub5e960f2018-12-07 14:51:26 +08002360 cropRegionToStackBoundsIfNeeded(region);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002361 subtractTouchExcludeRegionIfNeeded(region);
2362 } else if (modal && mTapExcludeRegionHolder != null) {
2363 final Region touchExcludeRegion = Region.obtain();
2364 amendTapExcludeRegion(touchExcludeRegion);
2365 if (!touchExcludeRegion.isEmpty()) {
2366 // Remove touch modal because there are some areas that cannot be touched.
2367 flags |= FLAG_NOT_TOUCH_MODAL;
2368 // Give it a large touchable region at first because it was touch modal. The window
2369 // might be moved on the display, so the touchable region should be large enough to
2370 // ensure it covers the whole display, no matter where it is moved.
2371 getDisplayContent().getBounds(mTmpRect);
2372 final int dw = mTmpRect.width();
2373 final int dh = mTmpRect.height();
2374 region.set(-dw, -dh, dw + dw, dh + dh);
2375 // Subtract the area that cannot be touched.
2376 region.op(touchExcludeRegion, Region.Op.DIFFERENCE);
Vishnu Nair93d68c22019-03-22 13:45:31 -07002377 inputWindowHandle.setTouchableRegionCrop(null);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002378 }
2379 touchExcludeRegion.recycle();
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002380 } else {
2381 // Not modal or full screen modal
Riddle Hsub5e960f2018-12-07 14:51:26 +08002382 getTouchableRegion(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002383 }
Riddle Hsub5e960f2018-12-07 14:51:26 +08002384 // Translate to surface based coordinates.
2385 region.translate(-mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
Robert Carra80ad042018-08-14 12:54:20 -07002386
Shivam Agrawal780b5bb2019-07-17 10:17:11 -07002387 // TODO(b/139804591): sizecompat layout needs to be reworked. Currently mFrame is post-
2388 // scaling but the existing logic doesn't expect that. The result is that the already-
2389 // scaled region ends up getting sent to surfaceflinger which then applies the scale
2390 // (again). Until this is resolved, apply an inverse-scale here.
2391 if (mActivityRecord != null && mActivityRecord.hasSizeCompatBounds()
2392 && mGlobalScale != 1.f) {
2393 region.scale(mInvGlobalScale);
2394 }
2395
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002396 return flags;
2397 }
2398
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002399 void checkPolicyVisibilityChange() {
chaviw15ad49f2019-04-24 15:05:39 -07002400 if (isLegacyPolicyVisibility() != mLegacyPolicyVisibilityAfterAnim) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002401 if (DEBUG_VISIBILITY) {
2402 Slog.v(TAG, "Policy visibility changing after anim in " +
chaviw15ad49f2019-04-24 15:05:39 -07002403 mWinAnimator + ": " + mLegacyPolicyVisibilityAfterAnim);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002404 }
chaviw15ad49f2019-04-24 15:05:39 -07002405 if (mLegacyPolicyVisibilityAfterAnim) {
2406 setPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
2407 } else {
2408 clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
2409 }
2410 if (!isVisibleByPolicy()) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002411 mWinAnimator.hide("checkPolicyVisibilityChange");
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002412 if (isFocused()) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002413 ProtoLog.i(WM_DEBUG_FOCUS_LIGHT,
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002414 "setAnimationLocked: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002415 mWmService.mFocusMayChange = true;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002416 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002417 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002418 // Window is no longer visible -- make sure if we were waiting
2419 // for it to be displayed before enabling the display, that
2420 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002421 mWmService.enableScreenIfNeededLocked();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002422 }
2423 }
2424 }
2425
2426 void setRequestedSize(int requestedWidth, int requestedHeight) {
2427 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2428 mLayoutNeeded = true;
2429 mRequestedWidth = requestedWidth;
2430 mRequestedHeight = requestedHeight;
2431 }
2432 }
2433
Bryce Leef858b572017-06-29 14:03:33 -07002434 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002435 // We need to turn on screen regardless of visibility.
Riddle Hsu4bb06be2019-07-02 01:03:07 +08002436 final boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0
Garfield Tane8d84ab2019-10-11 09:49:40 -07002437 || (mActivityRecord != null && mActivityRecord.canTurnScreenOn());
chaviw40234662018-02-07 09:37:16 -08002438
2439 // The screen will turn on if the following conditions are met
Riddle Hsu4bb06be2019-07-02 01:03:07 +08002440 // 1. The window has the flag FLAG_TURN_SCREEN_ON or ActivityRecord#canTurnScreenOn.
chaviw40234662018-02-07 09:37:16 -08002441 // 2. The WMS allows theater mode.
2442 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2443 // per resume to prevent the screen getting getting turned on for each relayout. Set
Wale Ogunwaleda8b8272018-11-29 19:37:37 -08002444 // currentLaunchCanTurnScreenOn will be set to false so the window doesn't turn the screen
2445 // on again during this resume.
chaviw40234662018-02-07 09:37:16 -08002446 // 4. When the screen is not interactive. This is because when the screen is already
2447 // interactive, the value may persist until the next animation, which could potentially
2448 // be occurring while turning off the screen. This would lead to the screen incorrectly
2449 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002450 if (hasTurnScreenOnFlag) {
Jorim Jaggi4981f152019-03-26 18:58:45 +01002451 boolean allowTheaterMode = mWmService.mAllowTheaterModeWakeFromLayout
2452 || Settings.Global.getInt(mWmService.mContext.getContentResolver(),
2453 Settings.Global.THEATER_MODE_ON, 0) == 0;
Garfield Tane8d84ab2019-10-11 09:49:40 -07002454 boolean canTurnScreenOn = mActivityRecord == null || mActivityRecord.currentLaunchCanTurnScreenOn();
Jorim Jaggi4981f152019-03-26 18:58:45 +01002455
chaviw474093d2018-03-07 15:03:38 -08002456 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2457 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2458 Slog.v(TAG, "Relayout window turning screen on: " + this);
2459 }
2460 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
Michael Wrighte3001042019-02-05 00:13:14 +00002461 PowerManager.WAKE_REASON_APPLICATION, "android.server.wm:SCREEN_ON_FLAG");
chaviw40234662018-02-07 09:37:16 -08002462 }
chaviwb28de1f2018-03-02 10:42:36 -08002463
Garfield Tane8d84ab2019-10-11 09:49:40 -07002464 if (mActivityRecord != null) {
2465 mActivityRecord.setCurrentLaunchCanTurnScreenOn(false);
chaviwb28de1f2018-03-02 10:42:36 -08002466 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002467 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002468
2469 // If we were already visible, skip rest of preparation.
2470 if (wasVisible) {
2471 if (DEBUG_VISIBILITY) Slog.v(TAG,
2472 "Already visible and does not turn on screen, skip preparing: " + this);
2473 return;
2474 }
2475
2476 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2477 == SOFT_INPUT_ADJUST_RESIZE) {
2478 mLayoutNeeded = true;
2479 }
2480
David Stevens9440dc82017-03-16 19:00:20 -07002481 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002482 mWinAnimator.applyEnterAnimationLocked();
2483 }
Bryce Leef858b572017-06-29 14:03:33 -07002484 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002485
Yunfan Chen75157d72018-07-27 14:47:21 +09002486 private Configuration getProcessGlobalConfiguration() {
2487 // For child windows we want to use the pid for the parent window in case the the child
2488 // window was added from another process.
Yunfan Chenb4fe58c2019-03-27 18:35:06 +09002489 final WindowState parentWindow = getParentWindow();
2490 final int pid = parentWindow != null ? parentWindow.mSession.mPid : mSession.mPid;
Yunfan Chenc2ff6cf2018-12-04 16:56:21 -08002491 final Configuration processConfig =
2492 mWmService.mAtmService.getGlobalConfigurationForPid(pid);
Yunfan Chenb4fe58c2019-03-27 18:35:06 +09002493 return processConfig;
Yunfan Chen75157d72018-07-27 14:47:21 +09002494 }
2495
Bryce Leef858b572017-06-29 14:03:33 -07002496 void getMergedConfiguration(MergedConfiguration outConfiguration) {
Yunfan Chen75157d72018-07-27 14:47:21 +09002497 final Configuration globalConfig = getProcessGlobalConfiguration();
Bryce Leef858b572017-06-29 14:03:33 -07002498 final Configuration overrideConfig = getMergedOverrideConfiguration();
2499 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2500 }
2501
Bryce Lee2b17afd2017-09-21 10:38:20 -07002502 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2503 mLastReportedConfiguration.setTo(config);
Jorim Jaggi381cd722019-03-27 17:33:02 +01002504 mLastConfigReportedToClient = true;
Bryce Lee2b17afd2017-09-21 10:38:20 -07002505 }
2506
2507 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2508 config.setTo(mLastReportedConfiguration);
2509 }
2510
2511 private Configuration getLastReportedConfiguration() {
2512 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002513 }
2514
2515 void adjustStartingWindowFlags() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07002516 if (mAttrs.type == TYPE_BASE_APPLICATION && mActivityRecord != null
2517 && mActivityRecord.startingWindow != null) {
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002518 // Special handling of starting window over the base
2519 // window of the app: propagate lock screen flags to it,
2520 // to provide the correct semantics while starting.
2521 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2522 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Garfield Tane8d84ab2019-10-11 09:49:40 -07002523 WindowManager.LayoutParams sa = mActivityRecord.startingWindow.mAttrs;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002524 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2525 }
2526 }
2527
2528 void setWindowScale(int requestedWidth, int requestedHeight) {
2529 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2530
2531 if (scaledWindow) {
2532 // requested{Width|Height} Surface's physical size
2533 // attrs.{width|height} Size on screen
2534 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2535 mHScale = (mAttrs.width != requestedWidth) ?
2536 (mAttrs.width / (float)requestedWidth) : 1.0f;
2537 mVScale = (mAttrs.height != requestedHeight) ?
2538 (mAttrs.height / (float)requestedHeight) : 1.0f;
2539 } else {
2540 mHScale = mVScale = 1;
2541 }
2542 }
2543
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002544 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002545 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002546 public void binderDied() {
2547 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002548 boolean resetSplitScreenResizing = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002549 synchronized (mWmService.mGlobalLock) {
2550 final WindowState win = mWmService
2551 .windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002552 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002553 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002554 final DisplayContent dc = getDisplayContent();
Garfield Tane8d84ab2019-10-11 09:49:40 -07002555 if (win.mActivityRecord != null && win.mActivityRecord.findMainWindow() == win) {
2556 mWmService.mTaskSnapshotController.onAppDied(win.mActivityRecord);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002557 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002558 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002559 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2560 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002561 // just in case they have the divider at an unstable position. Better
2562 // also reset drag resizing state, because the owner can't do it
2563 // anymore.
Louis Changdc077272019-11-12 16:52:56 +08002564 final ActivityStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002565 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002566 if (stack != null) {
2567 stack.resetDockedStackToMiddle();
2568 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002569 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002570 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002571 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002572 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002573 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002574 }
2575 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002576 if (resetSplitScreenResizing) {
2577 try {
2578 // Note: this calls into ActivityManager, so we must *not* hold the window
2579 // manager lock while calling this.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002580 mWmService.mActivityTaskManager.setSplitScreenResizing(false);
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002581 } catch (RemoteException e) {
2582 // Local call, shouldn't return RemoteException.
2583 throw e.rethrowAsRuntimeException();
2584 }
2585 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002586 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002587 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002588 }
2589 }
2590 }
2591
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002592 /**
2593 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2594 * because we want to preserve its location on screen to be re-activated later when the user
2595 * interacts with it.
2596 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002597 private boolean shouldKeepVisibleDeadAppWindow() {
Issei Suzukie63eac72019-11-14 15:59:15 +01002598 if (!isWinVisibleLw() || mActivityRecord == null || mActivityRecord.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002599 // Not a visible app window or the app isn't dead.
2600 return false;
2601 }
2602
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002603 if (mAttrs.token != mClient.asBinder()) {
2604 // The window was add by a client using another client's app token. We don't want to
2605 // keep the dead window around for this case since this is meant for 'real' apps.
2606 return false;
2607 }
2608
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002609 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2610 // We don't keep starting windows since they were added by the window manager before
2611 // the app even launched.
2612 return false;
2613 }
2614
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002615 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002616 }
2617
Tiger Huang513d5e12018-07-16 21:49:50 +08002618 @Override
2619 public boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002620 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002621 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002622 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Garfield Tane8d84ab2019-10-11 09:49:40 -07002623 && (mActivityRecord == null || mActivityRecord.windowsAreFocusable())
Robert Carrebdf8582018-09-04 14:50:15 -07002624 && !cantReceiveTouchInput();
Matthew Nge15352e2016-12-20 15:36:29 -08002625 }
2626
lumark31e4f8e2019-01-10 20:48:18 +08002627 @Override
2628 public boolean canShowWhenLocked() {
2629 final boolean showBecauseOfActivity =
Garfield Tane8d84ab2019-10-11 09:49:40 -07002630 mActivityRecord != null && mActivityRecord.canShowWhenLocked();
lumark31e4f8e2019-01-10 20:48:18 +08002631 final boolean showBecauseOfWindow = (getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0;
2632 return showBecauseOfActivity || showBecauseOfWindow;
2633 }
2634
Issei Suzuki1669ea42019-11-06 14:20:59 +01002635 /** @return {@code false} if this window desires touch events. */
Robert Carrebdf8582018-09-04 14:50:15 -07002636 boolean cantReceiveTouchInput() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07002637 if (mActivityRecord == null || mActivityRecord.getTask() == null) {
Vinit Nayak8009e922019-09-05 11:49:53 -07002638 return false;
2639 }
2640
Wale Ogunwale8577a052019-10-26 23:22:34 -07002641 return mActivityRecord.getTask().getTaskStack().shouldIgnoreInput()
Issei Suzuki1669ea42019-11-06 14:20:59 +01002642 || !mActivityRecord.mVisibleRequested
Vinit Nayak8009e922019-09-05 11:49:53 -07002643 || isAnimatingToRecents();
2644 }
2645
2646 /**
2647 * Returns {@code true} if the window is animating to home as part of the recents animation.
2648 */
2649 private boolean isAnimatingToRecents() {
2650 final RecentsAnimationController recentsAnimationController =
2651 mWmService.getRecentsAnimationController();
2652 return recentsAnimationController != null
2653 && recentsAnimationController.isAnimatingTask(getTask())
Garfield Tane8d84ab2019-10-11 09:49:40 -07002654 && !recentsAnimationController.isTargetApp(mActivityRecord);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002655 }
2656
Craig Mautner749a7bb2012-04-02 13:49:53 -07002657 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002658 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002659 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002660 }
2661
Craig Mautner749a7bb2012-04-02 13:49:53 -07002662 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002663 public boolean showLw(boolean doAnimation) {
2664 return showLw(doAnimation, true);
2665 }
2666
2667 boolean showLw(boolean doAnimation, boolean requestAnim) {
chaviw15ad49f2019-04-24 15:05:39 -07002668 if (isLegacyPolicyVisibility() && mLegacyPolicyVisibilityAfterAnim) {
Jorim Jaggi50150152019-03-27 23:08:58 +01002669 // Already showing.
2670 return false;
2671 }
Craig Mautner5962b122012-10-05 14:45:52 -07002672 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002673 return false;
2674 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002675 if (!mAppOpVisibility) {
2676 // Being hidden due to app op request.
2677 return false;
2678 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002679 if (mPermanentlyHidden) {
2680 // Permanently hidden until the app exists as apps aren't prepared
2681 // to handle their windows being removed from under them.
2682 return false;
2683 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002684 if (mHiddenWhileSuspended) {
2685 // Being hidden due to owner package being suspended.
2686 return false;
2687 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002688 if (mForceHideNonSystemOverlayWindow) {
2689 // This is an alert window that is currently force hidden.
2690 return false;
2691 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002692 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002693 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002694 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
lumark9bca6b42019-10-17 18:35:22 +08002695 + isLegacyPolicyVisibility()
2696 + " animating=" + isAnimating(TRANSITION | PARENTS));
David Stevens9440dc82017-03-16 19:00:20 -07002697 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002698 doAnimation = false;
lumark9bca6b42019-10-17 18:35:22 +08002699 } else if (isLegacyPolicyVisibility() && !isAnimating(TRANSITION | PARENTS)) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002700 // Check for the case where we are currently visible and
2701 // not animating; we do not want to do animation at such a
2702 // point to become visible when we already are.
2703 doAnimation = false;
2704 }
2705 }
chaviw15ad49f2019-04-24 15:05:39 -07002706 setPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
2707 mLegacyPolicyVisibilityAfterAnim = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002708 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002709 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002710 }
2711 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002712 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002713 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002714 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002715 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002716 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002717 return true;
2718 }
2719
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002720 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002721 public boolean hideLw(boolean doAnimation) {
2722 return hideLw(doAnimation, true);
2723 }
2724
2725 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2726 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002727 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002728 doAnimation = false;
2729 }
2730 }
chaviw15ad49f2019-04-24 15:05:39 -07002731 boolean current =
2732 doAnimation ? mLegacyPolicyVisibilityAfterAnim : isLegacyPolicyVisibility();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002733 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002734 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002735 return false;
2736 }
2737 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002738 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
lumark9bca6b42019-10-17 18:35:22 +08002739 if (!isAnimating(TRANSITION | PARENTS)) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002740 doAnimation = false;
2741 }
2742 }
chaviw15ad49f2019-04-24 15:05:39 -07002743 mLegacyPolicyVisibilityAfterAnim = false;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002744 final boolean isFocused = isFocused();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002745 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002746 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
chaviw15ad49f2019-04-24 15:05:39 -07002747 clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002748 // Window is no longer visible -- make sure if we were waiting
2749 // for it to be displayed before enabling the display, that
2750 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002751 mWmService.enableScreenIfNeededLocked();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002752 if (isFocused) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002753 ProtoLog.i(WM_DEBUG_FOCUS_LIGHT,
Craig Mautner58458122013-09-14 14:59:50 -07002754 "WindowState.hideLw: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002755 mWmService.mFocusMayChange = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002756 }
2757 }
2758 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002759 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002760 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002761 if (isFocused) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002762 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002763 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002764 return true;
2765 }
2766
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002767 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2768 if (mOwnerCanAddInternalSystemWindow
2769 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2770 return;
2771 }
2772 if (mForceHideNonSystemOverlayWindow == forceHide) {
2773 return;
2774 }
2775 mForceHideNonSystemOverlayWindow = forceHide;
2776 if (forceHide) {
2777 hideLw(true /* doAnimation */, true /* requestAnim */);
2778 } else {
2779 showLw(true /* doAnimation */, true /* requestAnim */);
2780 }
2781 }
2782
Suprabh Shukla69c71422018-04-02 18:39:01 -07002783 void setHiddenWhileSuspended(boolean hide) {
2784 if (mOwnerCanAddInternalSystemWindow
2785 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2786 return;
2787 }
2788 if (mHiddenWhileSuspended == hide) {
2789 return;
2790 }
2791 mHiddenWhileSuspended = hide;
2792 if (hide) {
2793 hideLw(true, true);
2794 } else {
2795 showLw(true, true);
2796 }
2797 }
2798
Svet Ganovf7b47252018-02-26 11:11:27 -08002799 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002800 if (mAppOpVisibility != state) {
2801 mAppOpVisibility = state;
2802 if (state) {
2803 // If the policy visibility had last been to hide, then this
2804 // will incorrectly show at this point since we lost that
2805 // information. Not a big deal -- for the windows that have app
2806 // ops modifies they should only be hidden by policy due to the
2807 // lock screen, and the user won't be changing this if locked.
2808 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002809 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002810 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002811 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002812 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002813 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002814 }
2815
Svet Ganovf7b47252018-02-26 11:11:27 -08002816 void initAppOpsState() {
2817 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2818 return;
2819 }
2820 // If the app op was MODE_DEFAULT we would have checked the permission
2821 // and add the window only if the permission was granted. Therefore, if
2822 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2823 // shown.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002824 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp,
Svet Ganovf7b47252018-02-26 11:11:27 -08002825 getOwningUid(), getOwningPackage(), true);
2826 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2827 setAppOpVisibilityLw(false);
2828 }
2829 }
2830
2831 void resetAppOpsState() {
2832 if (mAppOp != OP_NONE && mAppOpVisibility) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002833 mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
Svet Ganovf7b47252018-02-26 11:11:27 -08002834 }
2835 }
2836
2837 void updateAppOpsState() {
2838 if (mAppOp == OP_NONE) {
2839 return;
2840 }
2841 final int uid = getOwningUid();
2842 final String packageName = getOwningPackage();
2843 if (mAppOpVisibility) {
2844 // There is a race between the check and the finish calls but this is fine
2845 // as this would mean we will get another change callback and will reconcile.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002846 int mode = mWmService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002847 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002848 mWmService.mAppOps.finishOp(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002849 setAppOpVisibilityLw(false);
2850 }
2851 } else {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002852 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002853 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2854 setAppOpVisibilityLw(true);
2855 }
2856 }
2857 }
2858
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002859 public void hidePermanentlyLw() {
2860 if (!mPermanentlyHidden) {
2861 mPermanentlyHidden = true;
2862 hideLw(true, true);
2863 }
2864 }
2865
Jeff Brownc2932a12014-11-20 18:04:05 -08002866 public void pokeDrawLockLw(long timeout) {
2867 if (isVisibleOrAdding()) {
2868 if (mDrawLock == null) {
2869 // We want the tag name to be somewhat stable so that it is easier to correlate
2870 // in wake lock statistics. So in particular, we don't want to include the
2871 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002872 final CharSequence tag = getWindowTag();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002873 mDrawLock = mWmService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002874 mDrawLock.setReferenceCounted(false);
2875 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2876 }
2877 // Each call to acquire resets the timeout.
2878 if (DEBUG_POWER) {
2879 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2880 + mAttrs.packageName);
2881 }
2882 mDrawLock.acquire(timeout);
2883 } else if (DEBUG_POWER) {
2884 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2885 + "owned by " + mAttrs.packageName);
2886 }
2887 }
2888
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002889 @Override
2890 public boolean isAlive() {
2891 return mClient.asBinder().isBinderAlive();
2892 }
2893
Craig Mautnera987d432012-10-11 14:07:58 -07002894 boolean isClosing() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07002895 return mAnimatingExit || (mActivityRecord != null && mActivityRecord.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002896 }
2897
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002898 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2899 animators.add(mWinAnimator);
2900
2901 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002902 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002903 c.addWinAnimatorToList(animators);
2904 }
2905 }
2906
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002907 void sendAppVisibilityToClients() {
2908 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002909
Issei Suzukie63eac72019-11-14 15:59:15 +01002910 final boolean clientHidden = mActivityRecord.isClientHidden();
2911 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002912 // Don't hide the starting window.
2913 return;
2914 }
2915
Issei Suzukie63eac72019-11-14 15:59:15 +01002916 if (clientHidden) {
Wale Ogunwale89973222017-04-23 18:39:45 -07002917 // Once we are notifying the client that it's visibility has changed, we need to prevent
2918 // it from destroying child surfaces until the animation has finished. We do this by
2919 // detaching any surface control the client added from the client.
2920 for (int i = mChildren.size() - 1; i >= 0; --i) {
2921 final WindowState c = mChildren.get(i);
2922 c.mWinAnimator.detachChildren();
2923 }
2924
2925 mWinAnimator.detachChildren();
2926 }
2927
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002928 try {
2929 if (DEBUG_VISIBILITY) Slog.v(TAG,
Issei Suzukie63eac72019-11-14 15:59:15 +01002930 "Setting visibility of " + this + ": " + (!clientHidden));
2931 mClient.dispatchAppVisibility(!clientHidden);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002932 } catch (RemoteException e) {
2933 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002934 }
2935
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002936 void onStartFreezingScreen() {
2937 mAppFreezing = true;
2938 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002939 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002940 c.onStartFreezingScreen();
2941 }
2942 }
2943
2944 boolean onStopFreezingScreen() {
2945 boolean unfrozeWindows = false;
2946 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002947 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002948 unfrozeWindows |= c.onStopFreezingScreen();
2949 }
2950
2951 if (!mAppFreezing) {
2952 return unfrozeWindows;
2953 }
2954
Wale Ogunwale953171d2016-09-30 09:17:30 -07002955 mAppFreezing = false;
2956
Bryce Lee8c3cf382017-07-06 19:47:10 -07002957 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002958 && mWmService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002959 ProtoLog.v(WM_DEBUG_ORIENTATION,
2960 "set mOrientationChanging of %s", this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002961 setOrientationChanging(true);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002962 mWmService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002963 }
2964 mLastFreezeDuration = 0;
2965 setDisplayLayoutNeeded();
2966 return true;
2967 }
2968
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002969 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2970 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002971
2972 // Copying to a different list as multiple children can be removed.
2973 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2974 for (int i = childWindows.size() - 1; i >= 0; --i) {
2975 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002976 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2977 }
2978
Robert Carrdb2f6e62017-03-01 20:17:58 -08002979 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2980 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002981 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002982
2983 if (appStopped || mWindowRemovalAllowed) {
2984 mWinAnimator.destroyPreservedSurfaceLocked();
2985 }
2986
2987 if (mDestroying) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002988 ProtoLog.e(WM_DEBUG_ADD_REMOVE, "win=%s"
2989 + " destroySurfaces: appStopped=%b"
2990 + " win.mWindowRemovalAllowed=%b"
2991 + " win.mRemoveOnExit=%b", this, appStopped,
2992 mWindowRemovalAllowed, mRemoveOnExit);
Robert Carrdb2f6e62017-03-01 20:17:58 -08002993 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002994 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002995 }
2996 if (mRemoveOnExit) {
2997 removeImmediately();
2998 }
2999 if (cleanupOnResume) {
3000 requestUpdateWallpaperIfNeeded();
3001 }
3002 mDestroying = false;
3003 destroyedSomething = true;
lumarka6681162019-04-12 01:47:54 +08003004
Garfield Tane8d84ab2019-10-11 09:49:40 -07003005 // Since mDestroying will affect ActivityRecord#allDrawn, we need to perform another
lumarka6681162019-04-12 01:47:54 +08003006 // traversal in case we are waiting on this window to start the transition.
3007 if (getDisplayContent().mAppTransition.isTransitionSet()
Garfield Tane8d84ab2019-10-11 09:49:40 -07003008 && getDisplayContent().mOpeningApps.contains(mActivityRecord)) {
lumarka6681162019-04-12 01:47:54 +08003009 mWmService.mWindowPlacerLocked.requestTraversal();
3010 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08003011 }
3012
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003013 return destroyedSomething;
3014 }
Chris Craik3131bde2016-05-06 13:39:08 -07003015
Robert Carr89a28ab2017-04-24 15:33:11 -07003016 // Destroy or save the application surface without checking
3017 // various indicators of whether the client has released the surface.
3018 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003019 void destroySurfaceUnchecked() {
3020 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08003021
Chong Zhang92147042016-05-09 12:47:11 -07003022 // Clear animating flags now, since the surface is now gone. (Note this is true even
3023 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
3024 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08003025 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07003026
Adrian Roos5f2c9a12019-07-03 18:31:46 +02003027 void onSurfaceShownChanged(boolean shown) {
3028 if (mLastShownChangedReported == shown) {
3029 return;
3030 }
3031 mLastShownChangedReported = shown;
3032
3033 if (shown) {
3034 initExclusionRestrictions();
3035 } else {
3036 logExclusionRestrictions(EXCLUSION_LEFT);
3037 logExclusionRestrictions(EXCLUSION_RIGHT);
3038 }
3039 }
3040
3041 private void logExclusionRestrictions(int side) {
3042 if (!logsGestureExclusionRestrictions(this)
3043 || SystemClock.uptimeMillis() < mLastExclusionLogUptimeMillis[side]
Adrian Roos1c2e9a12019-08-20 18:23:47 +02003044 + mWmService.mConstants.mSystemGestureExclusionLogDebounceTimeoutMillis) {
Adrian Roos5f2c9a12019-07-03 18:31:46 +02003045 // Drop the log if we have just logged; this is okay, because what we would have logged
3046 // was true only for a short duration.
3047 return;
3048 }
3049
3050 final long now = SystemClock.uptimeMillis();
3051 final long duration = now - mLastExclusionLogUptimeMillis[side];
3052 mLastExclusionLogUptimeMillis[side] = now;
3053
3054 final int requested = mLastRequestedExclusionHeight[side];
3055 final int granted = mLastGrantedExclusionHeight[side];
3056
3057 StatsLog.write(StatsLog.EXCLUSION_RECT_STATE_CHANGED,
3058 mAttrs.packageName, requested, requested - granted /* rejected */,
3059 side + 1 /* Sides are 1-indexed in atoms.proto */,
3060 (getConfiguration().orientation == ORIENTATION_LANDSCAPE),
3061 isSplitScreenWindowingMode(getWindowingMode()), (int) duration);
3062 }
3063
3064 private void initExclusionRestrictions() {
3065 final long now = SystemClock.uptimeMillis();
3066 mLastExclusionLogUptimeMillis[EXCLUSION_LEFT] = now;
3067 mLastExclusionLogUptimeMillis[EXCLUSION_RIGHT] = now;
3068 }
3069
Craig Mautner69b08182012-09-05 13:07:13 -07003070 @Override
3071 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003072 final DisplayContent displayContent = getDisplayContent();
3073 if (displayContent == null) {
3074 // Only a window that was on a non-default display can be detached from it.
3075 return false;
3076 }
Winson Chung47a3e652014-05-21 16:03:42 -07003077 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07003078 }
3079
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003080 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07003081 mShowToOwnerOnly = showToOwnerOnly;
3082 }
3083
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003084 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003085 // Child windows are evaluated based on their parent window.
3086 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003087 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Garfield Tane8d84ab2019-10-11 09:49:40 -07003088 && win.mActivityRecord != null && win.mActivityRecord.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07003089
3090 // All window frames that are fullscreen extend above status bar, but some don't extend
3091 // below navigation bar. Thus, check for display frame for top/left and stable frame for
3092 // bottom right.
chaviw492139a2018-07-16 16:07:35 -07003093 if (win.getFrameLw().left <= win.getDisplayFrameLw().left
3094 && win.getFrameLw().top <= win.getDisplayFrameLw().top
3095 && win.getFrameLw().right >= win.getStableFrameLw().right
3096 && win.getFrameLw().bottom >= win.getStableFrameLw().bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07003097 // Is a fullscreen window, like the clock alarm. Show to everyone.
3098 return false;
3099 }
3100 }
3101
Craig Mautner341220f2012-10-16 15:20:09 -07003102 return win.mShowToOwnerOnly
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003103 && !mWmService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07003104 }
3105
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003106 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
3107 outRegion.set(
3108 frame.left + inset.left, frame.top + inset.top,
3109 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04003110 }
3111
Riddle Hsuff03df52018-12-05 21:43:02 +08003112 /** Get the touchable region in global coordinates. */
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003113 void getTouchableRegion(Region outRegion) {
chaviw492139a2018-07-16 16:07:35 -07003114 final Rect frame = mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003115 switch (mTouchableInsets) {
3116 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003117 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003118 outRegion.set(frame);
3119 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003120 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003121 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003122 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003123 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003124 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003125 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003126 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003127 outRegion.set(mGivenTouchableRegion);
Riddle Hsub5e960f2018-12-07 14:51:26 +08003128 outRegion.translate(frame.left, frame.top);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003129 break;
3130 }
3131 }
Vishnu Nairb9246322018-12-06 13:54:02 -08003132 cropRegionToStackBoundsIfNeeded(outRegion);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08003133 subtractTouchExcludeRegionIfNeeded(outRegion);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003134 }
3135
Adrian Roosb1063792019-06-28 12:10:51 +02003136 /**
3137 * Get the effective touchable region in global coordinates.
3138 *
3139 * In contrast to {@link #getTouchableRegion}, this takes into account
3140 * {@link WindowManager.LayoutParams#FLAG_NOT_TOUCH_MODAL touch modality.}
3141 */
3142 void getEffectiveTouchableRegion(Region outRegion) {
3143 final boolean modal = (mAttrs.flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
3144 final DisplayContent dc = getDisplayContent();
3145
3146 if (modal && dc != null) {
3147 outRegion.set(dc.getBounds());
3148 cropRegionToStackBoundsIfNeeded(outRegion);
3149 subtractTouchExcludeRegionIfNeeded(outRegion);
3150 } else {
3151 getTouchableRegion(outRegion);
3152 }
3153 }
3154
Vishnu Nair93d68c22019-03-22 13:45:31 -07003155 private void setTouchableRegionCropIfNeeded(InputWindowHandle handle) {
3156 final Task task = getTask();
3157 if (task == null || !task.cropWindowsToStackBounds()) {
3158 return;
3159 }
3160
Louis Changdc077272019-11-12 16:52:56 +08003161 final ActivityStack stack = task.getTaskStack();
Vishnu Nair93d68c22019-03-22 13:45:31 -07003162 if (stack == null) {
3163 return;
3164 }
3165
3166 handle.setTouchableRegionCrop(stack.getSurfaceControl());
3167 }
3168
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003169 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003170 final Task task = getTask();
3171 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003172 return;
3173 }
3174
Louis Changdc077272019-11-12 16:52:56 +08003175 final ActivityStack stack = task.getTaskStack();
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003176 if (stack == null) {
3177 return;
3178 }
3179
3180 stack.getDimBounds(mTmpRect);
3181 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003182 }
3183
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003184 /**
Tiger Huang04dc4cc2019-01-17 18:41:41 +08003185 * If this window has areas that cannot be touched, we subtract those areas from its touchable
3186 * region.
3187 */
3188 private void subtractTouchExcludeRegionIfNeeded(Region touchableRegion) {
3189 if (mTapExcludeRegionHolder == null) {
3190 return;
3191 }
3192 final Region touchExcludeRegion = Region.obtain();
3193 amendTapExcludeRegion(touchExcludeRegion);
3194 if (!touchExcludeRegion.isEmpty()) {
3195 touchableRegion.op(touchExcludeRegion, Region.Op.DIFFERENCE);
3196 }
3197 touchExcludeRegion.recycle();
3198 }
3199
3200 /**
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003201 * Report a focus change. Must be called with no locks held, and consistently
3202 * from the same serialized thread (such as dispatched from a handler).
3203 */
Tiger Huang51c5a1d2018-12-11 20:24:51 +08003204 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003205 try {
Tiger Huang51c5a1d2018-12-11 20:24:51 +08003206 mClient.windowFocusChanged(focused, inTouchMode);
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003207 } catch (RemoteException e) {
3208 }
Tiger Huang51c5a1d2018-12-11 20:24:51 +08003209 if (mFocusCallbacks != null) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003210 final int N = mFocusCallbacks.beginBroadcast();
3211 for (int i=0; i<N; i++) {
3212 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
3213 try {
3214 if (focused) {
3215 obs.focusGained(mWindowId.asBinder());
3216 } else {
3217 obs.focusLost(mWindowId.asBinder());
3218 }
3219 } catch (RemoteException e) {
3220 }
3221 }
3222 mFocusCallbacks.finishBroadcast();
3223 }
3224 }
3225
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003226 @Override
3227 public Configuration getConfiguration() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07003228 if (mActivityRecord != null && mActivityRecord.mFrozenMergedConfig.size() > 0) {
3229 return mActivityRecord.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003230 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003231
Yunfan Chenb4fe58c2019-03-27 18:35:06 +09003232 // If the process has not registered to any display to listen to the configuration change,
3233 // we can simply return the mFullConfiguration as default.
3234 if (!registeredForDisplayConfigChanges()) {
3235 return super.getConfiguration();
3236 }
3237
Yunfan Chen75157d72018-07-27 14:47:21 +09003238 // We use the process config this window is associated with as the based global config since
Yunfan Chenb4fe58c2019-03-27 18:35:06 +09003239 // the process can override its config, but isn't part of the window hierarchy.
3240 mTempConfiguration.setTo(getProcessGlobalConfiguration());
3241 mTempConfiguration.updateFrom(getMergedOverrideConfiguration());
3242 return mTempConfiguration;
3243 }
3244
3245 /** @return {@code true} if the process registered to a display as a config listener. */
3246 private boolean registeredForDisplayConfigChanges() {
3247 final WindowState parentWindow = getParentWindow();
3248 final Session session = parentWindow != null ? parentWindow.mSession : mSession;
3249 // System process or invalid process cannot register to display config change.
3250 if (session.mPid == MY_PID || session.mPid < 0) return false;
3251 WindowProcessController app =
3252 mWmService.mAtmService.getProcessController(session.mPid, session.mUid);
3253 if (app == null || !app.registeredForDisplayConfigChanges()) return false;
3254 return true;
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003255 }
3256
Craig Mautnerdf88d732014-01-27 09:21:32 -08003257 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003258 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003259 try {
Adrian Roosb125e0b2019-10-02 14:55:14 +02003260 ProtoLog.v(WM_DEBUG_RESIZE,
3261 "Reporting new frame to %s: %s", this,
3262 mWindowFrames.mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07003263 final MergedConfiguration mergedConfiguration =
Andrii Kulian859f0a52019-05-20 12:18:09 +00003264 new MergedConfiguration(mWmService.mRoot.getConfiguration(),
Bryce Leef858b572017-06-29 14:03:33 -07003265 getMergedOverrideConfiguration());
3266
Bryce Lee2b17afd2017-09-21 10:38:20 -07003267 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07003268
Adrian Roosb125e0b2019-10-02 14:55:14 +02003269 if (mWinAnimator.mDrawState == DRAW_PENDING) {
3270 ProtoLog.i(WM_DEBUG_ORIENTATION,
3271 "Resizing %s WITH DRAW PENDING", this);
3272 }
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003273
Riddle Hsub398da32019-01-21 21:48:16 +08003274 final Rect frame = mWindowFrames.mCompatFrame;
chaviw9c81e632018-07-31 11:17:52 -07003275 final Rect contentInsets = mWindowFrames.mLastContentInsets;
3276 final Rect visibleInsets = mWindowFrames.mLastVisibleInsets;
3277 final Rect stableInsets = mWindowFrames.mLastStableInsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003278 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003279 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003280 final int displayId = getDisplayId();
chaviwcdba9a42018-07-19 11:36:42 -07003281 final DisplayCutout displayCutout = getWmDisplayCutout().getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07003282 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3283 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003284 // To prevent deadlock simulate one-way call if win.mClient is a local object.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003285 mWmService.mH.post(new Runnable() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003286 @Override
3287 public void run() {
3288 try {
Jorim Jaggif081f062019-10-24 16:24:54 +02003289 dispatchResized(frame, contentInsets, visibleInsets,
3290 stableInsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003291 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003292 } catch (RemoteException e) {
3293 // Not a remote call, RemoteException won't be raised.
3294 }
3295 }
3296 });
3297 } else {
Jorim Jaggif081f062019-10-24 16:24:54 +02003298 dispatchResized(frame, contentInsets, visibleInsets, stableInsets,
3299 reportDraw, mergedConfiguration, reportOrientation, displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003300 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003301 }
Jacky Kaof93252b2019-07-18 15:19:52 +08003302 if (mWmService.mAccessibilityController != null) {
3303 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(
3304 getDisplayId());
Svetoslav4604abc2014-06-10 18:59:30 -07003305 }
Jackal Guoc43a0a62019-04-23 09:15:14 +08003306 updateLocationInParentDisplayIfNeeded();
Svetoslav4604abc2014-06-10 18:59:30 -07003307
chaviw9c81e632018-07-31 11:17:52 -07003308 mWindowFrames.resetInsetsChanged();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003309 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003310 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003311 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003312 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003313 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003314 - mWmService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003315 // We are assuming the hosting process is dead or in a zombie state.
3316 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3317 + ", removing this window.");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003318 mWmService.mPendingRemove.add(this);
3319 mWmService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003320 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003321 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003322 }
3323
Jackal Guoc43a0a62019-04-23 09:15:14 +08003324 void updateLocationInParentDisplayIfNeeded() {
3325 final int embeddedDisplayContentsSize = mEmbeddedDisplayContents.size();
3326 // If there is any embedded display which is re-parented to this window, we need to
3327 // notify all windows in the embedded display about the location change.
3328 if (embeddedDisplayContentsSize != 0) {
3329 for (int i = embeddedDisplayContentsSize - 1; i >= 0; i--) {
3330 final DisplayContent edc = mEmbeddedDisplayContents.valueAt(i);
3331 edc.notifyLocationInParentDisplayChanged();
3332 }
3333 }
3334 // If this window is in a embedded display which is re-parented to another window,
3335 // we may need to update its correct on-screen location.
3336 final DisplayContent dc = getDisplayContent();
3337 if (dc.getParentWindow() == null) {
3338 return;
3339 }
3340
3341 final Point offset = dc.getLocationInParentDisplay();
3342 if (mLastReportedDisplayOffset.equals(offset)) {
3343 return;
3344 }
3345
3346 mLastReportedDisplayOffset.set(offset.x, offset.y);
3347 try {
3348 mClient.locationInParentDisplayChanged(mLastReportedDisplayOffset);
3349 } catch (RemoteException e) {
3350 Slog.e(TAG, "Failed to update offset from DisplayContent", e);
3351 }
3352 }
3353
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003354 /**
3355 * Called when the insets state changed.
3356 */
3357 void notifyInsetsChanged() {
3358 try {
3359 mClient.insetsChanged(
Jorim Jaggi956ca412019-01-07 14:49:14 +01003360 getDisplayContent().getInsetsPolicy().getInsetsForDispatch(this));
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003361 } catch (RemoteException e) {
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -07003362 Slog.w(TAG, "Failed to deliver inset state change w=" + this, e);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003363 }
3364 }
3365
Jorim Jaggi28620472019-01-02 23:21:49 +01003366 @Override
3367 public void notifyInsetsControlChanged() {
Jorim Jaggib6030952018-10-23 18:31:52 +02003368 final InsetsStateController stateController =
3369 getDisplayContent().getInsetsStateController();
Jorim Jaggi956ca412019-01-07 14:49:14 +01003370 final InsetsPolicy policy = getDisplayContent().getInsetsPolicy();
Jorim Jaggib6030952018-10-23 18:31:52 +02003371 try {
Jorim Jaggi956ca412019-01-07 14:49:14 +01003372 mClient.insetsControlChanged(policy.getInsetsForDispatch(this),
Jorim Jaggib6030952018-10-23 18:31:52 +02003373 stateController.getControlsForDispatch(this));
3374 } catch (RemoteException e) {
3375 Slog.w(TAG, "Failed to deliver inset state change", e);
3376 }
3377 }
3378
Tarandeep Singh0bedd942019-09-26 13:34:03 -07003379 @Override
3380 public void showInsets(@InsetType int types, boolean fromIme) {
3381 try {
3382 mClient.showInsets(types, fromIme);
3383 } catch (RemoteException e) {
3384 Slog.w(TAG, "Failed to deliver showInsets", e);
3385 }
3386 }
3387
Taran Singhf1e08872019-10-10 14:38:52 +02003388 @Override
3389 public void hideInsets(@InsetType int types, boolean fromIme) {
3390 try {
3391 mClient.hideInsets(types, fromIme);
3392 } catch (RemoteException e) {
3393 Slog.w(TAG, "Failed to deliver showInsets", e);
3394 }
3395 }
3396
Jorim Jaggi956ca412019-01-07 14:49:14 +01003397 @Override
3398 public boolean canShowTransient() {
3399 return (mAttrs.insetsFlags.behavior & BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE) != 0;
3400 }
3401
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003402 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003403 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3404 // start even if we haven't received the relayout window, so that the client requests
3405 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3406 // until the window to small size, otherwise the multithread renderer will shift last
3407 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3408 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003409 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003410 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Garfield Tanfbd8ea62018-10-16 17:09:49 -07003411 // Surface position is now inherited from parent, and BackdropFrameRenderer uses
3412 // backdrop frame to position content. Thus we just keep the size of backdrop frame, and
3413 // remove the offset to avoid double offset from display origin.
3414 mTmpRect.set(frame);
3415 mTmpRect.offsetTo(0, 0);
3416 return mTmpRect;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003417 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003418 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003419 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003420 return mTmpRect;
3421 }
3422
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003423 private int getStackId() {
Louis Changdc077272019-11-12 16:52:56 +08003424 final ActivityStack stack = getStack();
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003425 if (stack == null) {
3426 return INVALID_STACK_ID;
3427 }
3428 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003429 }
3430
Jorim Jaggif081f062019-10-24 16:24:54 +02003431 private void dispatchResized(Rect frame, Rect contentInsets,
3432 Rect visibleInsets, Rect stableInsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003433 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
3434 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003435 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08003436 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003437
Jorim Jaggif081f062019-10-24 16:24:54 +02003438 mClient.resized(frame, contentInsets, visibleInsets, stableInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003439 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Brad Stenninge0573692019-03-11 13:52:46 -07003440 getDisplayContent().getDisplayPolicy().areSystemBarsForcedShownLw(this), displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003441 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003442 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003443 }
3444
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003445 public void registerFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003446 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003447 if (mFocusCallbacks == null) {
3448 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3449 }
3450 mFocusCallbacks.register(observer);
3451 }
3452 }
3453
3454 public void unregisterFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003455 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003456 if (mFocusCallbacks != null) {
3457 mFocusCallbacks.unregister(observer);
3458 }
3459 }
3460 }
3461
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003462 boolean isFocused() {
3463 return getDisplayContent().mCurrentFocus == this;
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003464 }
3465
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003466
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003467 /** Is this window in a container that takes up the entire screen space? */
Evan Rosky4fb1e912019-03-06 13:54:43 -08003468 private boolean inAppWindowThatMatchesParentBounds() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07003469 return mActivityRecord == null || (mActivityRecord.matchParentBounds() && !inMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003470 }
3471
Evan Rosky4fb1e912019-03-06 13:54:43 -08003472 /** @return true when the window is in fullscreen mode, but has non-fullscreen bounds set, or
3473 * is transitioning into/out-of fullscreen. */
Andrii Kulian283acd22017-08-03 04:03:51 -07003474 boolean isLetterboxedAppWindow() {
Evan Rosky4fb1e912019-03-06 13:54:43 -08003475 return !inMultiWindowMode() && !matchesDisplayBounds()
Adrian Roos865c70f2018-01-10 17:32:27 +01003476 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003477 }
3478
Adrian Roos865c70f2018-01-10 17:32:27 +01003479 @Override
3480 public boolean isLetterboxedForDisplayCutoutLw() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07003481 if (mActivityRecord == null) {
3482 // Only windows with an ActivityRecord are letterboxed.
Adrian Roos865c70f2018-01-10 17:32:27 +01003483 return false;
3484 }
chaviwcdba9a42018-07-19 11:36:42 -07003485 if (!mWindowFrames.parentFrameWasClippedByDisplayCutout()) {
Adrian Roos5ed644f2018-03-19 17:01:05 +01003486 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003487 return false;
3488 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003489 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003490 // Layout in cutout, no letterbox.
3491 return false;
3492 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003493 if (!mAttrs.isFullscreen()) {
3494 // Not filling the parent frame, no letterbox
3495 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003496 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003497 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3498 // it to be.
3499 return !frameCoversEntireAppTokenBounds();
3500 }
3501
3502 /**
3503 * @return true if this window covers the entire bounds of its app window token
3504 * @throws NullPointerException if there is no app window token for this window
3505 */
3506 private boolean frameCoversEntireAppTokenBounds() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07003507 mTmpRect.set(mActivityRecord.getBounds());
chaviw492139a2018-07-16 16:07:35 -07003508 mTmpRect.intersectUnchecked(mWindowFrames.mFrame);
Garfield Tane8d84ab2019-10-11 09:49:40 -07003509 return mActivityRecord.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003510 }
3511
Adrian Roos23df3a32018-03-15 15:41:13 +01003512 @Override
3513 public boolean isLetterboxedOverlappingWith(Rect rect) {
Garfield Tane8d84ab2019-10-11 09:49:40 -07003514 return mActivityRecord != null && mActivityRecord.isLetterboxOverlappingWith(rect);
Adrian Roos23df3a32018-03-15 15:41:13 +01003515 }
3516
Chong Zhang3005e752015-09-18 18:46:28 -07003517 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003518 return mDragResizing != computeDragResizing();
3519 }
3520
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003521 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003522 void setWaitingForDrawnIfResizingChanged() {
3523 if (isDragResizeChanged()) {
Yunfan Chen87b5a242019-10-01 17:53:59 +09003524 mWmService.mRoot.mWaitingForDrawn.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003525 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003526 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003527 }
3528
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003529 /**
3530 * @return Whether we reported a drag resize change to the application or not already.
3531 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003532 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003533 return mDragResizingChangeReported;
3534 }
3535
3536 /**
3537 * Resets the state whether we reported a drag resize change to the app.
3538 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003539 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003540 void resetDragResizingChangeReported() {
3541 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003542 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003543 }
3544
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003545 int getResizeMode() {
3546 return mResizeMode;
3547 }
3548
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003549 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003550 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003551 if (task == null) {
3552 return false;
3553 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003554 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003555 return false;
3556 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003557 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003558 // Floating windows never enter drag resize mode.
3559 return false;
3560 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003561 if (task.isDragResizing()) {
3562 return true;
3563 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003564
3565 // If the bounds are currently frozen, it means that the layout size that the app sees
3566 // and the bounds we clip this window to might be different. In order to avoid holes, we
3567 // simulate that we are still resizing so the app fills the hole with the resizing
3568 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003569 return (getDisplayContent().mDividerControllerLocked.isResizing()
Garfield Tane8d84ab2019-10-11 09:49:40 -07003570 || mActivityRecord != null && !mActivityRecord.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003571 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003572
Chong Zhang3005e752015-09-18 18:46:28 -07003573 }
3574
3575 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003576 final boolean resizing = computeDragResizing();
3577 if (resizing == mDragResizing) {
3578 return;
3579 }
3580 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003581 final Task task = getTask();
3582 if (task != null && task.isDragResizing()) {
3583 mResizeMode = task.getDragResizeMode();
3584 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003585 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003586 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3587 : DRAG_RESIZE_MODE_FREEFORM;
3588 }
Chong Zhang3005e752015-09-18 18:46:28 -07003589 }
3590
3591 boolean isDragResizing() {
3592 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003593 }
3594
Robert Carr2487ce72016-04-07 15:18:45 -07003595 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003596 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3597 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003598 }
3599
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003600 @CallSuper
3601 @Override
Nataniel Borges023ecb52019-01-16 14:15:43 -08003602 public void writeToProto(ProtoOutputStream proto, long fieldId,
3603 @WindowTraceLogLevel int logLevel) {
3604 boolean isVisible = isVisible();
3605 if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible) {
3606 return;
3607 }
3608
Steven Timotiusaf03df62017-07-18 16:56:43 -07003609 final long token = proto.start(fieldId);
Nataniel Borges023ecb52019-01-16 14:15:43 -08003610 super.writeToProto(proto, WINDOW_CONTAINER, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003611 writeIdentifierToProto(proto, IDENTIFIER);
3612 proto.write(DISPLAY_ID, getDisplayId());
3613 proto.write(STACK_ID, getStackId());
3614 mAttrs.writeToProto(proto, ATTRIBUTES);
3615 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
chaviw553b0212018-07-12 13:37:01 -07003616 mWindowFrames.writeToProto(proto, WINDOW_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003617 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003618 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003619 mWinAnimator.writeToProto(proto, ANIMATOR);
3620 proto.write(ANIMATING_EXIT, mAnimatingExit);
3621 for (int i = 0; i < mChildren.size(); i++) {
Nataniel Borges023ecb52019-01-16 14:15:43 -08003622 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003623 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003624 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3625 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3626 proto.write(VIEW_VISIBILITY, mViewVisibility);
3627 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3628 proto.write(HAS_SURFACE, mHasSurface);
3629 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003630 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3631 proto.write(DESTROYING, mDestroying);
3632 proto.write(REMOVED, mRemoved);
3633 proto.write(IS_ON_SCREEN, isOnScreen());
Nataniel Borges023ecb52019-01-16 14:15:43 -08003634 proto.write(IS_VISIBLE, isVisible);
Vishnu Nairddd80742018-08-21 14:12:46 -07003635 proto.write(PENDING_SEAMLESS_ROTATION, mPendingSeamlessRotate != null);
3636 proto.write(FINISHED_SEAMLESS_ROTATION_FRAME, mFinishSeamlessRotateFrameNumber);
3637 proto.write(FORCE_SEAMLESS_ROTATION, mForceSeamlesslyRotate);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003638 proto.end(token);
3639 }
3640
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003641 @Override
3642 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003643 final long token = proto.start(fieldId);
3644 proto.write(HASH_CODE, System.identityHashCode(this));
3645 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3646 final CharSequence title = getWindowTag();
3647 if (title != null) {
3648 proto.write(TITLE, title.toString());
3649 }
3650 proto.end(token);
3651 }
3652
Jorim Jaggia5e10572017-11-15 14:36:26 +01003653 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003654 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Louis Changdc077272019-11-12 16:52:56 +08003655 final ActivityStack stack = getStack();
chaviwc65fa582018-08-09 15:33:13 -07003656 pw.print(prefix + "mDisplayId=" + getDisplayId());
3657 if (stack != null) {
3658 pw.print(" stackId=" + stack.mStackId);
3659 }
3660 pw.println(" mSession=" + mSession
3661 + " mClient=" + mClient.asBinder());
3662 pw.println(prefix + "mOwnerUid=" + mOwnerUid
3663 + " mShowToOwnerOnly=" + mShowToOwnerOnly
3664 + " package=" + mAttrs.packageName
3665 + " appop=" + AppOpsManager.opToName(mAppOp));
3666 pw.println(prefix + "mAttrs=" + mAttrs.toString(prefix));
3667 pw.println(prefix + "Requested w=" + mRequestedWidth
3668 + " h=" + mRequestedHeight
3669 + " mLayoutSeq=" + mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003670 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
chaviwc65fa582018-08-09 15:33:13 -07003671 pw.println(prefix + "LastRequested w=" + mLastRequestedWidth
3672 + " h=" + mLastRequestedHeight);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003673 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003674 if (mIsChildWindow || mLayoutAttached) {
chaviwc65fa582018-08-09 15:33:13 -07003675 pw.println(prefix + "mParentWindow=" + getParentWindow()
3676 + " mLayoutAttached=" + mLayoutAttached);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003677 }
3678 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
chaviwc65fa582018-08-09 15:33:13 -07003679 pw.println(prefix + "mIsImWindow=" + mIsImWindow
3680 + " mIsWallpaper=" + mIsWallpaper
3681 + " mIsFloatingLayer=" + mIsFloatingLayer
3682 + " mWallpaperVisible=" + mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003683 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003684 if (dumpAll) {
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003685 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3686 pw.print(" mSubLayer="); pw.print(mSubLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003687 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003688 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003689 pw.println(prefix + "mToken=" + mToken);
Garfield Tane8d84ab2019-10-11 09:49:40 -07003690 if (mActivityRecord != null) {
3691 pw.println(prefix + "mActivityRecord=" + mActivityRecord);
chaviwc65fa582018-08-09 15:33:13 -07003692 pw.print(prefix + "mAppDied=" + mAppDied);
3693 pw.print(prefix + "drawnStateEvaluated=" + getDrawnStateEvaluated());
3694 pw.println(prefix + "mightAffectAllDrawn=" + mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003695 }
chaviwc65fa582018-08-09 15:33:13 -07003696 pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility)
3697 + " mHaveFrame=" + mHaveFrame
3698 + " mObscured=" + mObscured);
3699 pw.println(prefix + "mSeq=" + mSeq
3700 + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003701 }
chaviw15ad49f2019-04-24 15:05:39 -07003702 if (!isVisibleByPolicy() || !mLegacyPolicyVisibilityAfterAnim || !mAppOpVisibility
chaviwc65fa582018-08-09 15:33:13 -07003703 || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow
Suprabh Shukla69c71422018-04-02 18:39:01 -07003704 || mHiddenWhileSuspended) {
chaviw15ad49f2019-04-24 15:05:39 -07003705 pw.println(prefix + "mPolicyVisibility=" + isVisibleByPolicy()
3706 + " mLegacyPolicyVisibilityAfterAnim=" + mLegacyPolicyVisibilityAfterAnim
chaviwc65fa582018-08-09 15:33:13 -07003707 + " mAppOpVisibility=" + mAppOpVisibility
3708 + " parentHidden=" + isParentWindowHidden()
3709 + " mPermanentlyHidden=" + mPermanentlyHidden
3710 + " mHiddenWhileSuspended=" + mHiddenWhileSuspended
3711 + " mForceHideNonSystemOverlayWindow=" + mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003712 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003713 if (!mRelayoutCalled || mLayoutNeeded) {
chaviwc65fa582018-08-09 15:33:13 -07003714 pw.println(prefix + "mRelayoutCalled=" + mRelayoutCalled
3715 + " mLayoutNeeded=" + mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003716 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003717 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003718 pw.println(prefix + "mGivenContentInsets=" + mGivenContentInsets.toShortString(sTmpSB)
3719 + " mGivenVisibleInsets=" + mGivenVisibleInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003720 if (mTouchableInsets != 0 || mGivenInsetsPending) {
chaviwc65fa582018-08-09 15:33:13 -07003721 pw.println(prefix + "mTouchableInsets=" + mTouchableInsets
3722 + " mGivenInsetsPending=" + mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003723 Region region = new Region();
3724 getTouchableRegion(region);
chaviwc65fa582018-08-09 15:33:13 -07003725 pw.println(prefix + "touchable region=" + region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003726 }
chaviwc65fa582018-08-09 15:33:13 -07003727 pw.println(prefix + "mFullConfiguration=" + getConfiguration());
3728 pw.println(prefix + "mLastReportedConfiguration=" + getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003729 }
chaviwc65fa582018-08-09 15:33:13 -07003730 pw.println(prefix + "mHasSurface=" + mHasSurface
3731 + " isReadyForDisplay()=" + isReadyForDisplay()
3732 + " mWindowRemovalAllowed=" + mWindowRemovalAllowed);
Riddle Hsub398da32019-01-21 21:48:16 +08003733 if (inSizeCompatMode()) {
chaviw9c81e632018-07-31 11:17:52 -07003734 pw.println(prefix + "mCompatFrame=" + mWindowFrames.mCompatFrame.toShortString(sTmpSB));
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003735 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003736 if (dumpAll) {
chaviw553b0212018-07-12 13:37:01 -07003737 mWindowFrames.dump(pw, prefix);
chaviw9c81e632018-07-31 11:17:52 -07003738 pw.println(prefix + " surface=" + mAttrs.surfaceInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003739 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003740 super.dump(pw, prefix, dumpAll);
chaviwc65fa582018-08-09 15:33:13 -07003741 pw.println(prefix + mWinAnimator + ":");
Dianne Hackborn529e7442012-11-01 14:22:28 -07003742 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003743 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
chaviwc65fa582018-08-09 15:33:13 -07003744 pw.println(prefix + "mAnimatingExit=" + mAnimatingExit
3745 + " mRemoveOnExit=" + mRemoveOnExit
3746 + " mDestroying=" + mDestroying
3747 + " mRemoved=" + mRemoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003748 }
chaviw40234662018-02-07 09:37:16 -08003749 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
chaviwc65fa582018-08-09 15:33:13 -07003750 pw.println(prefix + "mOrientationChanging=" + mOrientationChanging
3751 + " configOrientationChanging="
3752 + (getLastReportedConfiguration().orientation != getConfiguration().orientation)
3753 + " mAppFreezing=" + mAppFreezing
3754 + " mReportOrientationChanged=" + mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003755 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003756 if (mLastFreezeDuration != 0) {
chaviwc65fa582018-08-09 15:33:13 -07003757 pw.print(prefix + "mLastFreezeDuration=");
3758 TimeUtils.formatDuration(mLastFreezeDuration, pw);
3759 pw.println();
Dianne Hackborna57c6952013-03-29 14:46:40 -07003760 }
chaviwc65fa582018-08-09 15:33:13 -07003761 pw.print(prefix + "mForceSeamlesslyRotate=" + mForceSeamlesslyRotate
3762 + " seamlesslyRotate: pending=");
Vishnu Nairddd80742018-08-21 14:12:46 -07003763 if (mPendingSeamlessRotate != null) {
3764 mPendingSeamlessRotate.dump(pw);
3765 } else {
3766 pw.print("null");
Adrian Roos27a90d22018-07-06 02:39:54 -07003767 }
chaviwc65fa582018-08-09 15:33:13 -07003768 pw.println(" finishedFrameNumber=" + mFinishSeamlessRotateFrameNumber);
Vishnu Nairddd80742018-08-21 14:12:46 -07003769
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003770 if (mHScale != 1 || mVScale != 1) {
chaviwc65fa582018-08-09 15:33:13 -07003771 pw.println(prefix + "mHScale=" + mHScale
3772 + " mVScale=" + mVScale);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003773 }
3774 if (mWallpaperX != -1 || mWallpaperY != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003775 pw.println(prefix + "mWallpaperX=" + mWallpaperX
3776 + " mWallpaperY=" + mWallpaperY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003777 }
3778 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003779 pw.println(prefix + "mWallpaperXStep=" + mWallpaperXStep
3780 + " mWallpaperYStep=" + mWallpaperYStep);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003781 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003782 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3783 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
chaviwc65fa582018-08-09 15:33:13 -07003784 pw.println(prefix + "mWallpaperDisplayOffsetX=" + mWallpaperDisplayOffsetX
3785 + " mWallpaperDisplayOffsetY=" + mWallpaperDisplayOffsetY);
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003786 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003787 if (mDrawLock != null) {
chaviwc65fa582018-08-09 15:33:13 -07003788 pw.println(prefix + "mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003789 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003790 if (isDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003791 pw.println(prefix + "isDragResizing=" + isDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003792 }
3793 if (computeDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003794 pw.println(prefix + "computeDragResizing=" + computeDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003795 }
chaviwc65fa582018-08-09 15:33:13 -07003796 pw.println(prefix + "isOnScreen=" + isOnScreen());
3797 pw.println(prefix + "isVisible=" + isVisible());
Jackal Guoc43a0a62019-04-23 09:15:14 +08003798 pw.println(prefix + "mEmbeddedDisplayContents=" + mEmbeddedDisplayContents);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003799 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003800
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003801 @Override
3802 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003803 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003804 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003805 }
3806
Robert Carra1eb4392015-12-10 12:43:51 -08003807 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003808 CharSequence tag = mAttrs.getTitle();
3809 if (tag == null || tag.length() <= 0) {
3810 tag = mAttrs.packageName;
3811 }
3812 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003813 }
3814
3815 @Override
3816 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003817 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003818 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003819 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003820 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003821 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003822 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003823 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003824 }
3825 return mStringNameCache;
3826 }
Robert Carr58f29132015-10-29 14:19:05 -07003827
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003828 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Jorim Jaggi4981f152019-03-26 18:58:45 +01003829 if (mHScale == 1 && mVScale == 1) {
3830 return;
3831 }
3832 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003833 clipRect.left = (int) (clipRect.left / mHScale);
3834 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003835 }
3836 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003837 clipRect.top = (int) (clipRect.top / mVScale);
3838 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003839 }
3840 }
Robert Carr31e28482015-12-02 16:53:18 -08003841
chaviw9c81e632018-07-31 11:17:52 -07003842 private void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003843 final int pw = containingFrame.width();
3844 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003845 final Task task = getTask();
Evan Rosky4fb1e912019-03-06 13:54:43 -08003846 final boolean inNonFullscreenContainer = !inAppWindowThatMatchesParentBounds();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003847 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3848
3849 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003850 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3851 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003852 // 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 -07003853 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3854 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3855 // the display.
3856 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003857 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003858 float x, y;
3859 int w,h;
3860
Riddle Hsub398da32019-01-21 21:48:16 +08003861 final boolean inSizeCompatMode = inSizeCompatMode();
Robert Carr31e28482015-12-02 16:53:18 -08003862 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3863 if (mAttrs.width < 0) {
3864 w = pw;
Riddle Hsub398da32019-01-21 21:48:16 +08003865 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003866 w = (int)(mAttrs.width * mGlobalScale + .5f);
3867 } else {
3868 w = mAttrs.width;
3869 }
3870 if (mAttrs.height < 0) {
3871 h = ph;
Riddle Hsub398da32019-01-21 21:48:16 +08003872 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003873 h = (int)(mAttrs.height * mGlobalScale + .5f);
3874 } else {
3875 h = mAttrs.height;
3876 }
3877 } else {
3878 if (mAttrs.width == MATCH_PARENT) {
3879 w = pw;
Riddle Hsub398da32019-01-21 21:48:16 +08003880 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003881 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3882 } else {
3883 w = mRequestedWidth;
3884 }
3885 if (mAttrs.height == MATCH_PARENT) {
3886 h = ph;
Riddle Hsub398da32019-01-21 21:48:16 +08003887 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003888 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3889 } else {
3890 h = mRequestedHeight;
3891 }
3892 }
3893
Riddle Hsub398da32019-01-21 21:48:16 +08003894 if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003895 x = mAttrs.x * mGlobalScale;
3896 y = mAttrs.y * mGlobalScale;
3897 } else {
3898 x = mAttrs.x;
3899 y = mAttrs.y;
3900 }
3901
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003902 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003903 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003904 // required by {@link Gravity#apply} call.
3905 w = Math.min(w, pw);
3906 h = Math.min(h, ph);
3907 }
3908
3909 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003910 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003911 (int) (x + mAttrs.horizontalMargin * pw),
chaviw492139a2018-07-16 16:07:35 -07003912 (int) (y + mAttrs.verticalMargin * ph), mWindowFrames.mFrame);
Robert Carr31e28482015-12-02 16:53:18 -08003913
3914 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003915 if (fitToDisplay) {
chaviw492139a2018-07-16 16:07:35 -07003916 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mWindowFrames.mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003917 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003918
3919 // We need to make sure we update the CompatFrame as it is used for
3920 // cropping decisions, etc, on systems where we lack a decor layer.
chaviw9c81e632018-07-31 11:17:52 -07003921 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Riddle Hsub398da32019-01-21 21:48:16 +08003922 if (inSizeCompatMode) {
Robert Carr6e18c5e2016-02-29 15:57:13 -08003923 // See comparable block in computeFrameLw.
chaviw9c81e632018-07-31 11:17:52 -07003924 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Robert Carr6e18c5e2016-02-29 15:57:13 -08003925 }
Robert Carr31e28482015-12-02 16:53:18 -08003926 }
Robert Carr51a1b872015-12-08 14:03:13 -08003927
3928 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003929 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003930 }
3931
Robert Carrf3b72c72016-03-21 18:16:39 -07003932 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003933 return mIsChildWindow
3934 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003935 }
3936
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003937 /**
3938 * Returns true if any window added by an application process that if of type
3939 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3940 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3941 * this window is visible.
3942 */
3943 boolean hideNonSystemOverlayWindowsWhenVisible() {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -07003944 return (mAttrs.privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003945 && mSession.mCanHideNonSystemOverlayWindows;
3946 }
3947
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003948 /** Returns the parent window if this is a child of another window, else null. */
3949 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003950 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3951 // WindowContainer that isn't a WindowState.
3952 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003953 }
3954
3955 /** Returns the topmost parent window if this is a child of another window, else this. */
3956 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003957 WindowState current = this;
3958 WindowState topParent = current;
3959 while (current != null && current.mIsChildWindow) {
3960 current = current.getParentWindow();
3961 // Parent window can be null if the child is detached from it's parent already, but
3962 // someone still has a reference to access it. So, we return the top parent value we
3963 // already have instead of null.
3964 if (current != null) {
3965 topParent = current;
3966 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003967 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003968 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003969 }
3970
Wale Ogunwale9d147902016-07-16 11:58:55 -07003971 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003972 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003973 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003974 }
3975
Jorim Jaggib52b0452019-07-16 17:43:15 +02003976 private boolean isParentWindowGoneForLayout() {
3977 final WindowState parent = getParentWindow();
3978 return parent != null && parent.isGoneForLayoutLw();
3979 }
3980
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003981 void setWillReplaceWindow(boolean animate) {
3982 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003983 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003984 c.setWillReplaceWindow(animate);
3985 }
3986
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003987 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3988 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3989 // We don't set replacing on starting windows since they are added by window manager and
3990 // not the client so won't be replaced by the client.
3991 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003992 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003993
3994 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003995 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003996 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003997 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003998
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003999 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08004000 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004001 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08004002 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004003
4004 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004005 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004006 c.clearWillReplaceWindow();
4007 }
4008 }
4009
4010 boolean waitingForReplacement() {
4011 if (mWillReplaceWindow) {
4012 return true;
4013 }
4014
4015 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004016 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004017 if (c.waitingForReplacement()) {
4018 return true;
4019 }
4020 }
4021 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08004022 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08004023
Chong Zhang4d7369a2016-04-25 16:09:14 -07004024 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07004025 final DisplayContent dc = getDisplayContent();
4026 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
4027 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4028 dc.setLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004029 mWmService.mWindowPlacerLocked.requestTraversal();
Chong Zhang4d7369a2016-04-25 16:09:14 -07004030 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004031
4032 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004033 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004034 c.requestUpdateWallpaperIfNeeded();
4035 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07004036 }
4037
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08004038 float translateToWindowX(float x) {
chaviw492139a2018-07-16 16:07:35 -07004039 float winX = x - mWindowFrames.mFrame.left;
Riddle Hsub398da32019-01-21 21:48:16 +08004040 if (inSizeCompatMode()) {
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08004041 winX *= mGlobalScale;
4042 }
4043 return winX;
4044 }
4045
4046 float translateToWindowY(float y) {
chaviw492139a2018-07-16 16:07:35 -07004047 float winY = y - mWindowFrames.mFrame.top;
Riddle Hsub398da32019-01-21 21:48:16 +08004048 if (inSizeCompatMode()) {
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08004049 winY *= mGlobalScale;
4050 }
4051 return winY;
4052 }
Robert Carrd1a010f2016-04-07 22:36:22 -07004053
4054 // During activity relaunch due to resize, we sometimes use window replacement
4055 // for only child windows (as the main window is handled by window preservation)
4056 // and the big surface.
4057 //
Chong Zhangfea963e2016-08-15 17:14:16 -07004058 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
4059 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
4060 // we also want to replace them at such phases, as they won't be covered by window
4061 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07004062 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07004063 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07004064 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07004065 }
Robert Carrfd10cd12016-06-29 16:41:50 -07004066
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004067 void setWillReplaceChildWindows() {
4068 if (shouldBeReplacedWithChildren()) {
4069 setWillReplaceWindow(false /* animate */);
4070 }
4071 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004072 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004073 c.setWillReplaceChildWindows();
4074 }
4075 }
4076
4077 WindowState getReplacingWindow() {
4078 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
4079 return this;
4080 }
4081 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004082 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004083 final WindowState replacing = c.getReplacingWindow();
4084 if (replacing != null) {
4085 return replacing;
4086 }
4087 }
4088 return null;
4089 }
4090
Jorim Jaggife762342016-10-13 14:33:27 +02004091 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07004092 public int getRotationAnimationHint() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07004093 if (mActivityRecord != null) {
4094 return mActivityRecord.mRotationAnimationHint;
Robert Carrfd10cd12016-06-29 16:41:50 -07004095 } else {
4096 return -1;
4097 }
4098 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07004099
Jorim Jaggife762342016-10-13 14:33:27 +02004100 @Override
4101 public boolean isInputMethodWindow() {
4102 return mIsImWindow;
4103 }
4104
Wale Ogunwale9d147902016-07-16 11:58:55 -07004105 // This must be called while inside a transaction.
4106 boolean performShowLocked() {
4107 if (isHiddenFromUserLocked()) {
4108 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
chaviwbb6bd8a2019-05-28 17:05:28 -07004109 clearPolicyVisibilityFlag(VISIBLE_FOR_USER);
Wale Ogunwale9d147902016-07-16 11:58:55 -07004110 return false;
4111 }
4112
4113 logPerformShow("performShow on ");
4114
Jorim Jaggia50da602016-12-29 11:51:42 +01004115 final int drawState = mWinAnimator.mDrawState;
4116 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
Garfield Tane8d84ab2019-10-11 09:49:40 -07004117 && mAttrs.type != TYPE_APPLICATION_STARTING && mActivityRecord != null) {
4118 mActivityRecord.onFirstWindowDrawn(this, mWinAnimator);
Jorim Jaggia50da602016-12-29 11:51:42 +01004119 }
4120
Jorim Jaggib0d27342016-11-01 16:10:42 -07004121 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07004122 return false;
4123 }
4124
4125 logPerformShow("Showing ");
4126
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004127 mWmService.enableScreenIfNeededLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07004128 mWinAnimator.applyEnterAnimationLocked();
4129
4130 // Force the show in the next prepareSurfaceLocked() call.
4131 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07004132 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07004133 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
4134 mWinAnimator.mDrawState = HAS_DRAWN;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004135 mWmService.scheduleAnimationLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07004136
4137 if (mHidden) {
4138 mHidden = false;
4139 final DisplayContent displayContent = getDisplayContent();
4140
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004141 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004142 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07004143 if (c.mWinAnimator.mSurfaceController != null) {
4144 c.performShowLocked();
4145 // It hadn't been shown, which means layout not performed on it, so now we
4146 // want to make sure to do a layout. If called from within the transaction
4147 // loop, this will cause it to restart with a new layout.
4148 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07004149 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07004150 }
4151 }
4152 }
4153 }
4154
Wale Ogunwale9d147902016-07-16 11:58:55 -07004155 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07004156 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07004157 }
4158
4159 return true;
4160 }
4161
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07004162 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07004163 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02004164 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07004165 Slog.v(TAG, prefix + this
4166 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07004167 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07004168 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
chaviw15ad49f2019-04-24 15:05:39 -07004169 + " during animation: policyVis=" + isVisibleByPolicy()
Wale Ogunwale9d147902016-07-16 11:58:55 -07004170 + " parentHidden=" + isParentWindowHidden()
Issei Suzuki1669ea42019-11-06 14:20:59 +01004171 + " tok.visibleRequested="
4172 + (mActivityRecord != null && mActivityRecord.mVisibleRequested)
Issei Suzuki7b9e2572019-11-14 16:19:54 +01004173 + " tok.hidden=" + (mActivityRecord != null && mActivityRecord.isHidden())
lumark9bca6b42019-10-17 18:35:22 +08004174 + " animating=" + isAnimating(TRANSITION | PARENTS)
Wale Ogunwale9d147902016-07-16 11:58:55 -07004175 + " tok animating="
lumark9bca6b42019-10-17 18:35:22 +08004176 + (mActivityRecord != null && mActivityRecord.isAnimating(TRANSITION))
Wale Ogunwale9d147902016-07-16 11:58:55 -07004177 + " Callers=" + Debug.getCallers(4));
4178 }
4179 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004180
4181 WindowInfo getWindowInfo() {
4182 WindowInfo windowInfo = WindowInfo.obtain();
RyanlwLin25a36512019-05-28 21:01:52 +08004183 windowInfo.displayId = getDisplayId();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004184 windowInfo.type = mAttrs.type;
4185 windowInfo.layer = mLayer;
4186 windowInfo.token = mClient.asBinder();
Garfield Tane8d84ab2019-10-11 09:49:40 -07004187 if (mActivityRecord != null) {
4188 windowInfo.activityToken = mActivityRecord.appToken.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07004189 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004190 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08004191 // Panel windows have no public way to set the a11y title directly. Use the
4192 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07004193 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
4194 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
4195 // Accessibility overlays should have titles that work for accessibility, and can't set
4196 // the a11y title themselves.
4197 final boolean isAccessibilityOverlay =
4198 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
4199 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Jackal Guo25a33cbd2018-08-01 16:08:45 +08004200 final CharSequence title = mAttrs.getTitle();
4201 windowInfo.title = TextUtils.isEmpty(title) ? null : title;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08004202 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004203 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
4204 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08004205 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004206 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Jackal Guoac2b62e2018-08-22 18:28:46 +08004207 windowInfo.hasFlagWatchOutsideTouch =
4208 (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004209
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004210 if (mIsChildWindow) {
4211 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004212 }
4213
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004214 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004215 if (childCount > 0) {
4216 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004217 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004218 }
4219 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004220 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004221 windowInfo.childTokens.add(child.mClient.asBinder());
4222 }
4223 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004224 return windowInfo;
4225 }
4226
Wale Ogunwale9adfe572016-09-08 20:43:58 -07004227 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004228 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004229 if (mChildren.isEmpty()) {
4230 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004231 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004232 }
4233
4234 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004235 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004236 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004237 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004238 }
4239 }
4240
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004241 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004242 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004243 // below the parent, then this window (the parent), and then the positive sublayer children
4244 // because they need to appear above the parent.
4245 int i = 0;
4246 final int count = mChildren.size();
4247 WindowState child = mChildren.get(i);
4248
4249 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004250 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004251 return true;
4252 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004253 i++;
4254 if (i >= count) {
4255 break;
4256 }
4257 child = mChildren.get(i);
4258 }
4259
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004260 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004261 return true;
4262 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004263
4264 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004265 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004266 return true;
4267 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004268 i++;
4269 if (i >= count) {
4270 break;
4271 }
4272 child = mChildren.get(i);
4273 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004274
4275 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004276 }
4277
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004278 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004279 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004280 // above the parent, then this window (the parent), and then the negative sublayer children
4281 // because they need to appear above the parent.
4282 int i = mChildren.size() - 1;
4283 WindowState child = mChildren.get(i);
4284
4285 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004286 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004287 return true;
4288 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004289 --i;
4290 if (i < 0) {
4291 break;
4292 }
4293 child = mChildren.get(i);
4294 }
4295
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004296 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004297 return true;
4298 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004299
4300 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004301 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004302 return true;
4303 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004304 --i;
4305 if (i < 0) {
4306 break;
4307 }
4308 child = mChildren.get(i);
4309 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004310
4311 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004312 }
4313
Robert Carr9785cf32018-04-25 15:06:07 -07004314 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
4315 boolean traverseTopToBottom) {
4316 // If this window is the current IME target, so we need to process the IME windows
4317 // directly above it. The exception is if we are in split screen
4318 // in which case we process the IME at the DisplayContent level to
4319 // ensure it is above the docked divider.
4320 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
4321 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4322 return true;
4323 }
4324 }
4325 return false;
4326 }
4327
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004328 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4329 boolean traverseTopToBottom) {
4330 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07004331 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
4332 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004333 return true;
4334 }
4335 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07004336 if (callback.apply(this)
4337 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004338 return true;
4339 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004340 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004341 return false;
4342 }
4343
Wale Ogunwaled1880962016-11-08 10:31:59 -08004344 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004345 if (mChildren.isEmpty()) {
4346 return callback.test(this) ? this : null;
4347 }
4348
4349 // We want to consume the positive sublayer children first because they need to appear
4350 // above the parent, then this window (the parent), and then the negative sublayer children
4351 // because they need to appear above the parent.
4352 int i = mChildren.size() - 1;
4353 WindowState child = mChildren.get(i);
4354
4355 while (i >= 0 && child.mSubLayer >= 0) {
4356 if (callback.test(child)) {
4357 return child;
4358 }
4359 --i;
4360 if (i < 0) {
4361 break;
4362 }
4363 child = mChildren.get(i);
4364 }
4365
Wale Ogunwaled1880962016-11-08 10:31:59 -08004366 if (callback.test(this)) {
4367 return this;
4368 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004369
4370 while (i >= 0) {
4371 if (callback.test(child)) {
4372 return child;
4373 }
4374 --i;
4375 if (i < 0) {
4376 break;
4377 }
4378 child = mChildren.get(i);
4379 }
4380
4381 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004382 }
4383
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004384 /**
4385 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
4386 * otherwise.
4387 */
4388 @VisibleForTesting
4389 boolean isSelfOrAncestorWindowAnimatingExit() {
4390 WindowState window = this;
4391 do {
4392 if (window.mAnimatingExit) {
4393 return true;
4394 }
4395 window = window.getParentWindow();
4396 } while (window != null);
4397 return false;
4398 }
4399
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004400 void onExitAnimationDone() {
4401 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4402 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
lumark9bca6b42019-10-17 18:35:22 +08004403 + " selfAnimating=" + isAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004404
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004405 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004406 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01004407 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004408 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004409 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004410 }
4411 }
4412
4413 if (mWinAnimator.mEnteringAnimation) {
4414 mWinAnimator.mEnteringAnimation = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004415 mWmService.requestTraversal();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004416 // System windows don't have an activity and an app token as a result, but need a way
4417 // to be informed about their entrance animation end.
Garfield Tane8d84ab2019-10-11 09:49:40 -07004418 if (mActivityRecord == null) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004419 try {
4420 mClient.dispatchWindowShown();
4421 } catch (RemoteException e) {
4422 }
4423 }
4424 }
4425
lumark9bca6b42019-10-17 18:35:22 +08004426 if (isAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004427 return;
4428 }
Jacky Kaof93252b2019-07-18 15:19:52 +08004429 if (mWmService.mAccessibilityController != null) {
4430 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(getDisplayId());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004431 }
4432
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004433 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004434 return;
4435 }
4436
Adrian Roosb125e0b2019-10-02 14:55:14 +02004437 ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Exit animation finished in %s: remove=%b",
4438 this, mRemoveOnExit);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004439
4440 mDestroying = true;
4441
4442 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004443
4444 // Use pendingTransaction here so hide is done the same transaction as the other
4445 // animations when exiting
4446 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004447
4448 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4449 // care to ensure the activity has actually stopped and the surface is not still in use.
4450 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4451 // transaction.
Garfield Tane8d84ab2019-10-11 09:49:40 -07004452 if (mActivityRecord != null) {
4453 mActivityRecord.destroySurfaces();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004454 } else {
4455 if (hasSurface) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004456 mWmService.mDestroySurface.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004457 }
4458 if (mRemoveOnExit) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004459 mWmService.mPendingRemove.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004460 mRemoveOnExit = false;
4461 }
4462 }
4463 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004464 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004465 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004466
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004467 boolean clearAnimatingFlags() {
4468 boolean didSomething = false;
4469 // We don't want to clear it out for windows that get replaced, because the
4470 // animation depends on the flag to remove the replaced window.
4471 //
4472 // We also don't clear the mAnimatingExit flag for windows which have the
4473 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4474 // by the client. We should let animation proceed and not clear this flag or
4475 // they won't eventually be removed by WindowStateAnimator#finishExit.
4476 if (!mWillReplaceWindow && !mRemoveOnExit) {
4477 // Clear mAnimating flag together with mAnimatingExit. When animation
4478 // changes from exiting to entering, we need to clear this flag until the
4479 // new animation gets applied, so that isAnimationStarting() becomes true
4480 // until then.
4481 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4482 // placement for this window during this period, one or more frame will
4483 // show up with wrong position or scale.
4484 if (mAnimatingExit) {
4485 mAnimatingExit = false;
4486 didSomething = true;
4487 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004488 if (mDestroying) {
4489 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004490 mWmService.mDestroySurface.remove(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004491 didSomething = true;
4492 }
4493 }
4494
4495 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004496 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004497 }
4498
4499 return didSomething;
4500 }
4501
Winson4b4ba902016-07-27 19:45:52 -07004502 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004503 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004504 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004505
4506 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004507 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004508 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004509 c.hideWallpaperWindow(wasDeferred, reason);
4510 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004511 if (!mWinAnimator.mLastHidden || wasDeferred) {
4512 mWinAnimator.hide(reason);
Tiger Huang50d45462018-05-25 22:57:52 +08004513 getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004514 dispatchWallpaperVisibility(false);
4515 final DisplayContent displayContent = getDisplayContent();
4516 if (displayContent != null) {
4517 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Tiger Huang50d45462018-05-25 22:57:52 +08004518 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004519 mWmService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this,
Tiger Huang50d45462018-05-25 22:57:52 +08004520 displayContent.pendingLayoutChanges);
4521 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004522 }
4523 }
4524 }
4525
4526 /**
4527 * Check wallpaper window for visibility change and notify window if so.
4528 * @param visible Current visibility.
4529 */
4530 void dispatchWallpaperVisibility(final boolean visible) {
4531 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004532 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004533
4534 // Only send notification if the visibility actually changed and we are not trying to hide
4535 // the wallpaper when we are deferring hiding of the wallpaper.
4536 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4537 mWallpaperVisible = visible;
4538 try {
4539 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4540 "Updating vis of wallpaper " + this
4541 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4542 mClient.dispatchAppVisibility(visible);
4543 } catch (RemoteException e) {
4544 }
4545 }
4546 }
4547
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004548 boolean hasVisibleNotDrawnWallpaper() {
4549 if (mWallpaperVisible && !isDrawnLw()) {
4550 return true;
4551 }
4552 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004553 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004554 if (c.hasVisibleNotDrawnWallpaper()) {
4555 return true;
4556 }
4557 }
4558 return false;
4559 }
4560
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004561 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4562 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004563 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004564 c.updateReportedVisibility(results);
4565 }
4566
4567 if (mAppFreezing || mViewVisibility != View.VISIBLE
4568 || mAttrs.type == TYPE_APPLICATION_STARTING
4569 || mDestroying) {
4570 return;
4571 }
4572 if (DEBUG_VISIBILITY) {
4573 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
lumark9bca6b42019-10-17 18:35:22 +08004574 + ", animating=" + isAnimating(TRANSITION | PARENTS));
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004575 if (!isDrawnLw()) {
4576 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
chaviw15ad49f2019-04-24 15:05:39 -07004577 + " pv=" + isVisibleByPolicy()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004578 + " mDrawState=" + mWinAnimator.mDrawState
4579 + " ph=" + isParentWindowHidden()
Issei Suzuki1669ea42019-11-06 14:20:59 +01004580 + " th=" + (mActivityRecord != null && mActivityRecord.mVisibleRequested)
lumark9bca6b42019-10-17 18:35:22 +08004581 + " a=" + isAnimating(TRANSITION | PARENTS));
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004582 }
4583 }
4584
4585 results.numInteresting++;
4586 if (isDrawnLw()) {
4587 results.numDrawn++;
lumark9bca6b42019-10-17 18:35:22 +08004588 if (!isAnimating(TRANSITION | PARENTS)) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004589 results.numVisible++;
4590 }
4591 results.nowGone = false;
lumark9bca6b42019-10-17 18:35:22 +08004592 } else if (isAnimating(TRANSITION | PARENTS)) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004593 results.nowGone = false;
4594 }
4595 }
4596
Robert Carr683e05d2018-04-18 15:11:04 -07004597 private boolean skipDecorCrop() {
4598 // The decor frame is used to specify the region not covered by the system
4599 // decorations (nav bar, status bar). In case this is empty, for example with
4600 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
chaviw553b0212018-07-12 13:37:01 -07004601 if (mWindowFrames.mDecorFrame.isEmpty()) {
Robert Carr683e05d2018-04-18 15:11:04 -07004602 return true;
4603 }
4604
4605 // But if we have a frame, and are an application window, then we must be cropped.
Garfield Tane8d84ab2019-10-11 09:49:40 -07004606 if (mActivityRecord != null) {
Robert Carr683e05d2018-04-18 15:11:04 -07004607 return false;
4608 }
4609
4610 // For non application windows, we may be allowed to extend over the decor bars
4611 // depending on our type and permissions assosciated with our token.
4612 return mToken.canLayerAboveSystemBars();
4613 }
4614
Robert Carrfbbde852016-10-18 11:02:28 -07004615 /**
4616 * Calculate the window crop according to system decor policy. In general this is
4617 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4618 * special cases. This rectangle is in screen space.
4619 */
4620 void calculatePolicyCrop(Rect policyCrop) {
4621 final DisplayContent displayContent = getDisplayContent();
Robert Carrfbbde852016-10-18 11:02:28 -07004622
Riddle Hsub398da32019-01-21 21:48:16 +08004623 if (!displayContent.isDefaultDisplay && !displayContent.supportsSystemDecorations()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004624 // On a different display there is no system decor. Crop the window
4625 // by the screen boundaries.
Riddle Hsub398da32019-01-21 21:48:16 +08004626 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw9c81e632018-07-31 11:17:52 -07004627 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4628 mWindowFrames.mCompatFrame.height());
4629 policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top,
4630 displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left,
4631 displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004632 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004633 // Windows without policy decor aren't cropped.
chaviw9c81e632018-07-31 11:17:52 -07004634 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4635 mWindowFrames.mCompatFrame.height());
Robert Carrfbbde852016-10-18 11:02:28 -07004636 } else {
4637 // Crop to the system decor specified by policy.
4638 calculateSystemDecorRect(policyCrop);
4639 }
4640 }
4641
4642 /**
4643 * The system decor rect is the region of the window which is not covered
4644 * by system decorations.
4645 */
4646 private void calculateSystemDecorRect(Rect systemDecorRect) {
chaviw553b0212018-07-12 13:37:01 -07004647 final Rect decorRect = mWindowFrames.mDecorFrame;
chaviw492139a2018-07-16 16:07:35 -07004648 final int width = mWindowFrames.mFrame.width();
4649 final int height = mWindowFrames.mFrame.height();
Robert Carrfbbde852016-10-18 11:02:28 -07004650
chaviw492139a2018-07-16 16:07:35 -07004651 final int left = mWindowFrames.mFrame.left;
4652 final int top = mWindowFrames.mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004653
4654 // Initialize the decor rect to the entire frame.
4655 if (isDockedResizing()) {
4656 // If we are resizing with the divider, the task bounds might be smaller than the
4657 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4658 // want in this case in order to avoid holes.
4659 //
4660 // We take care to not shrink the width, for surfaces which are larger than
4661 // the display region. Of course this area will not eventually be visible
4662 // but if we truncate the width now, we will calculate incorrectly
4663 // when adjusting to the stack bounds.
4664 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4665 systemDecorRect.set(0, 0,
4666 Math.max(width, displayInfo.logicalWidth),
4667 Math.max(height, displayInfo.logicalHeight));
4668 } else {
4669 systemDecorRect.set(0, 0, width, height);
4670 }
4671
4672 // If a freeform window is animating from a position where it would be cutoff, it would be
4673 // cutoff during the animation. We don't want that, so for the duration of the animation
4674 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004675
4676 // We also ignore cropping when the window is currently being drag resized in split screen
4677 // to prevent issues with the crop for screenshot.
4678 final boolean cropToDecor =
4679 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004680 if (cropToDecor) {
4681 // Intersect with the decor rect, offsetted by window position.
4682 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4683 decorRect.right - left, decorRect.bottom - top);
4684 }
4685
4686 // If size compatibility is being applied to the window, the
4687 // surface is scaled relative to the screen. Also apply this
4688 // scaling to the crop rect. We aren't using the standard rect
4689 // scale function because we want to round things to make the crop
4690 // always round to a larger rect to ensure we don't crop too
4691 // much and hide part of the window that should be seen.
Jorim Jaggi4981f152019-03-26 18:58:45 +01004692 if (mInvGlobalScale != 1.0f && inSizeCompatMode()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004693 final float scale = mInvGlobalScale;
4694 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4695 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4696 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4697 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4698 }
4699
4700 }
4701
4702 /**
4703 * Expand the given rectangle by this windows surface insets. This
4704 * takes you from the 'window size' to the 'surface size'.
4705 * The surface insets are positive in each direction, so we inset by
4706 * the inverse.
4707 */
4708 void expandForSurfaceInsets(Rect r) {
4709 r.inset(-mAttrs.surfaceInsets.left,
4710 -mAttrs.surfaceInsets.top,
4711 -mAttrs.surfaceInsets.right,
4712 -mAttrs.surfaceInsets.bottom);
4713 }
4714
Robert Carrc91d1c32017-02-15 19:37:46 -08004715 boolean surfaceInsetsChanging() {
4716 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4717 }
4718
Tiger Huang1ffefc22019-04-08 15:49:18 +08004719 int relayoutVisibleWindow(int result, int attrChanges) {
Robert Carrecc06b32017-04-18 14:25:10 -07004720 final boolean wasVisible = isVisibleLw();
4721
4722 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004723
Robert Carrc91d1c32017-02-15 19:37:46 -08004724 if (mAnimatingExit) {
4725 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4726 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4727
Riddle Hsub8d704b2019-02-22 12:44:12 +08004728 // Cancel the existing exit animation for the next enter animation.
lumark9bca6b42019-10-17 18:35:22 +08004729 if (isAnimating()) {
Riddle Hsub8d704b2019-02-22 12:44:12 +08004730 cancelAnimation();
4731 destroySurfaceUnchecked();
4732 }
Robert Carrc91d1c32017-02-15 19:37:46 -08004733 mAnimatingExit = false;
4734 }
4735 if (mDestroying) {
4736 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004737 mWmService.mDestroySurface.remove(this);
Robert Carrc91d1c32017-02-15 19:37:46 -08004738 }
Tiger Huang1ffefc22019-04-08 15:49:18 +08004739 if (!wasVisible) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004740 mWinAnimator.mEnterAnimationPending = true;
4741 }
4742
Andrii Kulian8ee72852017-03-10 10:36:45 -08004743 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004744
4745 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004746
Jorim Jaggi4981f152019-03-26 18:58:45 +01004747 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "prepareToDisplay");
4748 try {
4749 prepareWindowToDisplayDuringRelayout(wasVisible);
4750 } finally {
4751 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
4752 }
Bryce Leeae73ba42017-05-05 09:58:25 -07004753
Robert Carrc91d1c32017-02-15 19:37:46 -08004754 if ((attrChanges & FORMAT_CHANGED) != 0) {
4755 // If the format can't be changed in place, preserve the old surface until the app draws
4756 // on the new one. This prevents blinking when we change elevation of freeform and
4757 // pinned windows.
4758 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4759 mWinAnimator.preserveSurfaceLocked();
4760 result |= RELAYOUT_RES_SURFACE_CHANGED
4761 | RELAYOUT_RES_FIRST_TIME;
4762 }
4763 }
4764
4765 // When we change the Surface size, in scenarios which may require changing
4766 // the surface position in sync with the resize, we use a preserved surface
4767 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004768 // sized surface. At the moment this logic is only in place for switching
4769 // in and out of the big surface for split screen resize.
4770 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004771 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004772 // We can only change top level windows to the full-screen surface when
4773 // resizing (as we only have one full-screen surface). So there is no need
4774 // to preserve and destroy windows which are attached to another, they
4775 // will keep their surface and its size may change over time.
4776 if (mHasSurface && !isChildWindow()) {
4777 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004778 result |= RELAYOUT_RES_SURFACE_CHANGED |
4779 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004780 }
4781 }
4782 final boolean freeformResizing = isDragResizing()
4783 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4784 final boolean dockedResizing = isDragResizing()
4785 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4786 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4787 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004788 return result;
4789 }
4790
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004791 /**
4792 * @return True if this window has been laid out at least once; false otherwise.
4793 */
4794 boolean isLaidOut() {
4795 return mLayoutSeq != -1;
4796 }
4797
4798 /**
Jackal Guoc43a0a62019-04-23 09:15:14 +08004799 * Add the DisplayContent of the embedded display which is re-parented to this window to
4800 * the list of embedded displays.
4801 *
4802 * @param dc DisplayContent of the re-parented embedded display.
4803 * @return {@code true} if the giving DisplayContent is added, {@code false} otherwise.
4804 */
4805 boolean addEmbeddedDisplayContent(DisplayContent dc) {
4806 return mEmbeddedDisplayContents.add(dc);
4807 }
4808
4809 /**
4810 * Remove the DisplayContent of the embedded display which is re-parented to this window from
4811 * the list of embedded displays.
4812 *
4813 * @param dc DisplayContent of the re-parented embedded display.
4814 * @return {@code true} if the giving DisplayContent is removed, {@code false} otherwise.
4815 */
4816 boolean removeEmbeddedDisplayContent(DisplayContent dc) {
4817 return mEmbeddedDisplayContents.remove(dc);
4818 }
4819
4820 /**
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004821 * Updates the last inset values to the current ones.
4822 */
4823 void updateLastInsetValues() {
chaviw9c81e632018-07-31 11:17:52 -07004824 mWindowFrames.updateLastInsetValues();
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004825 }
4826
Jorim Jaggia5e10572017-11-15 14:36:26 +01004827 void startAnimation(Animation anim) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01004828
4829 // If we are an inset provider, all our animations are driven by the inset client.
Jorim Jaggi956ca412019-01-07 14:49:14 +01004830 if (mControllableInsetProvider != null) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01004831 return;
4832 }
4833
Jorim Jaggia5e10572017-11-15 14:36:26 +01004834 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07004835 anim.initialize(mWindowFrames.mFrame.width(), mWindowFrames.mFrame.height(),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004836 displayInfo.appWidth, displayInfo.appHeight);
4837 anim.restrictDuration(MAX_ANIMATION_DURATION);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004838 anim.scaleCurrentDuration(mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004839 final AnimationAdapter adapter = new LocalAnimationAdapter(
Lucas Dupin3e1dc202018-12-02 15:14:20 -08004840 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */,
Lucas Dupin95acf432019-04-29 17:55:38 -07004841 0 /* windowCornerRadius */),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004842 mWmService.mSurfaceAnimationRunner);
Tiger Huanged6794e2019-05-07 20:07:59 +08004843 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004844 commitPendingTransaction();
4845 }
4846
chaviw161ea3e2018-01-31 12:01:12 -08004847 private void startMoveAnimation(int left, int top) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01004848
4849 // If we are an inset provider, all our animations are driven by the inset client.
Jorim Jaggi956ca412019-01-07 14:49:14 +01004850 if (mControllableInsetProvider != null) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01004851 return;
4852 }
4853
Jorim Jaggia5e10572017-11-15 14:36:26 +01004854 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004855 final Point oldPosition = new Point();
4856 final Point newPosition = new Point();
chaviw492139a2018-07-16 16:07:35 -07004857 transformFrameToSurfacePosition(mWindowFrames.mLastFrame.left, mWindowFrames.mLastFrame.top,
4858 oldPosition);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004859 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004860 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004861 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004862 mWmService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004863 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004864 }
4865
4866 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4867 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4868 }
4869
4870 @Override
4871 protected void onAnimationFinished() {
chaviwccd5d502019-02-22 13:30:31 -08004872 super.onAnimationFinished();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004873 mWinAnimator.onAnimationFinished();
4874 }
4875
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004876 /**
4877 * Retrieves the current transformation matrix of the window, relative to the display.
4878 *
4879 * @param float9 A temporary array of 9 floats.
4880 * @param outMatrix Matrix to fill in the transformation.
4881 */
4882 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4883 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4884 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4885 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4886 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004887 int x = mSurfacePosition.x;
4888 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004889
Tiger Huangd8ec9382019-04-18 14:35:09 -07004890 // We might be on a display which has been re-parented to a view in another window, so here
4891 // computes the global location of our display.
4892 DisplayContent dc = getDisplayContent();
4893 while (dc != null && dc.getParentWindow() != null) {
4894 final WindowState displayParent = dc.getParentWindow();
4895 x += displayParent.mWindowFrames.mFrame.left - displayParent.mAttrs.surfaceInsets.left
4896 + (dc.getLocationInParentWindow().x * displayParent.mGlobalScale + 0.5f);
4897 y += displayParent.mWindowFrames.mFrame.top - displayParent.mAttrs.surfaceInsets.top
4898 + (dc.getLocationInParentWindow().y * displayParent.mGlobalScale + 0.5f);
4899 dc = displayParent.getDisplayContent();
4900 }
4901
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004902 // If changed, also adjust transformFrameToSurfacePosition
4903 final WindowContainer parent = getParent();
4904 if (isChildWindow()) {
4905 final WindowState parentWindow = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07004906 x += parentWindow.mWindowFrames.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4907 y += parentWindow.mWindowFrames.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004908 } else if (parent != null) {
4909 final Rect parentBounds = parent.getBounds();
4910 x += parentBounds.left;
4911 y += parentBounds.top;
4912 }
4913 float9[Matrix.MTRANS_X] = x;
4914 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004915 float9[Matrix.MPERSP_0] = 0;
4916 float9[Matrix.MPERSP_1] = 0;
4917 float9[Matrix.MPERSP_2] = 1;
4918 outMatrix.setValues(float9);
4919 }
4920
Garfield Tane8d84ab2019-10-11 09:49:40 -07004921 // TODO: Hack to work around the number of states ActivityRecord needs to access without having
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004922 // access to its windows children. Need to investigate re-writing
Garfield Tane8d84ab2019-10-11 09:49:40 -07004923 // {@link ActivityRecord#updateReportedVisibilityLocked} so this can be removed.
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004924 static final class UpdateReportedVisibilityResults {
4925 int numInteresting;
4926 int numVisible;
4927 int numDrawn;
4928 boolean nowGone = true;
4929
4930 void reset() {
4931 numInteresting = 0;
4932 numVisible = 0;
4933 numDrawn = 0;
4934 nowGone = true;
4935 }
4936 }
Robert Carraf422a82017-04-10 18:34:33 -07004937
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004938 private static final class WindowId extends IWindowId.Stub {
4939 private final WeakReference<WindowState> mOuter;
4940
4941 private WindowId(WindowState outer) {
4942
4943 // Use a weak reference for the outer class. This is important to prevent the following
4944 // leak: Since we send this class to the client process, binder will keep it alive as
4945 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4946 // out our reference so even though this class is kept alive we don't leak WindowState,
4947 // which can keep a whole lot of classes alive.
4948 mOuter = new WeakReference<>(outer);
4949 }
4950
4951 @Override
4952 public void registerFocusObserver(IWindowFocusObserver observer) {
4953 final WindowState outer = mOuter.get();
4954 if (outer != null) {
4955 outer.registerFocusObserver(observer);
4956 }
4957 }
4958 @Override
4959 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4960 final WindowState outer = mOuter.get();
4961 if (outer != null) {
4962 outer.unregisterFocusObserver(observer);
4963 }
4964 }
4965 @Override
4966 public boolean isFocused() {
4967 final WindowState outer = mOuter.get();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004968 if (outer != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004969 synchronized (outer.mWmService.mGlobalLock) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004970 return outer.isFocused();
4971 }
4972 }
4973 return false;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004974 }
4975 }
4976
Robert Carrb1579c82017-09-05 14:54:47 -07004977
4978 @Override
4979 boolean shouldMagnify() {
4980 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004981 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4982 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4983 mAttrs.type == TYPE_NAVIGATION_BAR ||
4984 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4985 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla9552b262018-03-13 12:24:50 -07004986 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004987 return false;
4988 }
4989 return true;
4990 }
4991
4992 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004993 SurfaceSession getSession() {
4994 if (mSession.mSurfaceSession != null) {
4995 return mSession.mSurfaceSession;
4996 } else {
4997 return getParent().getSession();
4998 }
4999 }
5000
5001 @Override
5002 boolean needsZBoost() {
lumarkff0ab692018-11-05 20:32:30 +08005003 final WindowState inputMethodTarget = getDisplayContent().mInputMethodTarget;
5004 if (mIsImWindow && inputMethodTarget != null) {
Garfield Tane8d84ab2019-10-11 09:49:40 -07005005 final ActivityRecord activity = inputMethodTarget.mActivityRecord;
5006 if (activity != null) {
5007 return activity.needsZBoost();
Jorim Jaggib0fc8172017-11-23 17:04:08 +00005008 }
5009 }
5010 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07005011 }
5012
Robert Carrf07ef9e2017-11-21 12:12:49 -08005013 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07005014 if (!mAnimatingExit && mAppDied) {
5015 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08005016 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08005017 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08005018 // Only show a dim behind when the following is satisfied:
5019 // 1. The window has the flag FLAG_DIM_BEHIND
5020 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
5021 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08005022 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07005023 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08005024 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07005025 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08005026 }
5027
5028 @Override
5029 void prepareSurfaces() {
5030 final Dimmer dimmer = getDimmer();
5031 mIsDimming = false;
5032 if (dimmer != null) {
5033 applyDims(dimmer);
5034 }
chaviw2f0567b2018-01-29 16:22:02 -08005035 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01005036
Robert Carrb1579c82017-09-05 14:54:47 -07005037 mWinAnimator.prepareSurfaceLocked(true);
5038 super.prepareSurfaces();
5039 }
5040
5041 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01005042 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
5043 super.onAnimationLeashCreated(t, leash);
5044
5045 // Leash is now responsible for position, so set our position to 0.
5046 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08005047 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005048 }
5049
5050 @Override
lumarkf6f34942019-04-29 16:56:50 +08005051 public void onAnimationLeashLost(Transaction t) {
5052 super.onAnimationLeashLost(t);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005053 updateSurfacePosition(t);
5054 }
5055
chaviwe07246a2017-12-12 16:18:29 -08005056 @Override
chaviw2f0567b2018-01-29 16:22:02 -08005057 void updateSurfacePosition() {
5058 updateSurfacePosition(getPendingTransaction());
5059 }
5060
Vishnu Naird8c664b2018-09-24 12:52:35 -07005061 @VisibleForTesting
5062 void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01005063 if (mSurfaceControl == null) {
5064 return;
5065 }
5066
chaviw492139a2018-07-16 16:07:35 -07005067 transformFrameToSurfacePosition(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top,
5068 mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08005069
Vishnu Nair83537a72018-07-19 21:27:48 -07005070 // Freeze position while we're unrotated, so the surface remains at the position it was
5071 // prior to the rotation.
Vishnu Nairddd80742018-08-21 14:12:46 -07005072 if (!mSurfaceAnimator.hasLeash() && mPendingSeamlessRotate == null
5073 && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01005074 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08005075 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08005076 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
5077 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
5078 t.deferTransactionUntil(mSurfaceControl,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07005079 mWinAnimator.mSurfaceController.mSurfaceControl,
chaviwbe43ac82018-04-04 15:14:49 -07005080 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08005081 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01005082 }
5083 }
5084
5085 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
5086 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01005087
5088 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08005089 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01005090 if (isChildWindow()) {
5091 // TODO: This probably falls apart at some point and we should
5092 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01005093
5094 // Since the parent was outset by its surface insets, we need to undo the outsetting
5095 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01005096 final WindowState parent = getParentWindow();
Riddle Hsub398da32019-01-21 21:48:16 +08005097 transformSurfaceInsetsPosition(mTmpPoint, parent.mAttrs.surfaceInsets);
5098 outPoint.offset(-parent.mWindowFrames.mFrame.left + mTmpPoint.x,
5099 -parent.mWindowFrames.mFrame.top + mTmpPoint.y);
chaviwe07246a2017-12-12 16:18:29 -08005100 } else if (parentWindowContainer != null) {
Evan Roskyed6767f2018-10-26 17:21:06 -07005101 final Rect parentBounds = parentWindowContainer.getDisplayedBounds();
chaviwe07246a2017-12-12 16:18:29 -08005102 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005103 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01005104
Louis Changdc077272019-11-12 16:52:56 +08005105 ActivityStack stack = getStack();
Robert Carr32bcb102018-01-29 15:03:23 -08005106
5107 // If we have stack outsets, that means the top-left
5108 // will be outset, and we need to inset ourselves
5109 // to account for it. If we actually have shadows we will
5110 // then un-inset ourselves by the surfaceInsets.
5111 if (stack != null) {
5112 final int outset = stack.getStackOutset();
5113 outPoint.offset(outset, outset);
5114 }
5115
Jorim Jaggi9af095b2017-12-12 17:18:57 +01005116 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Riddle Hsub398da32019-01-21 21:48:16 +08005117 transformSurfaceInsetsPosition(mTmpPoint, mAttrs.surfaceInsets);
5118 outPoint.offset(-mTmpPoint.x, -mTmpPoint.y);
5119 }
5120
5121 /**
5122 * The surface insets from layout parameter are in application coordinate. If the window is
5123 * scaled, the insets also need to be scaled for surface position in global coordinate.
5124 */
5125 private void transformSurfaceInsetsPosition(Point outPos, Rect surfaceInsets) {
5126 if (!inSizeCompatMode()) {
5127 outPos.x = surfaceInsets.left;
5128 outPos.y = surfaceInsets.top;
5129 return;
5130 }
5131 outPos.x = (int) (surfaceInsets.left * mGlobalScale + 0.5f);
5132 outPos.y = (int) (surfaceInsets.top * mGlobalScale + 0.5f);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005133 }
5134
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005135 boolean needsRelativeLayeringToIme() {
5136 // We only use the relative layering mode in split screen, as part of elevating the IME
5137 // and windows above it's target above the docked divider.
5138 if (!inSplitScreenWindowingMode()) {
5139 return false;
5140 }
5141
5142 if (isChildWindow()) {
5143 // If we are a child of the input method target we need this promotion.
5144 if (getParentWindow().isInputMethodTarget()) {
5145 return true;
5146 }
Garfield Tane8d84ab2019-10-11 09:49:40 -07005147 } else if (mActivityRecord != null) {
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005148 // Likewise if we share a token with the Input method target and are ordered
5149 // above it but not necessarily a child (e.g. a Dialog) then we also need
5150 // this promotion.
lumarkff0ab692018-11-05 20:32:30 +08005151 final WindowState imeTarget = getDisplayContent().mInputMethodTarget;
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005152 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
5153 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
5154 return inTokenWithAndAboveImeTarget;
5155 }
5156 return false;
5157 }
5158
Jorim Jaggia5e10572017-11-15 14:36:26 +01005159 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07005160 void assignLayer(Transaction t, int layer) {
5161 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005162 if (needsRelativeLayeringToIme()) {
5163 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07005164 return;
5165 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005166 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07005167 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07005168
5169 @Override
5170 public boolean isDimming() {
5171 return mIsDimming;
5172 }
Robert Carr0eff1872017-12-01 14:27:04 -08005173
5174 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
5175 // then we can drop all negative layering on the windowing side and simply inherit
5176 // the default implementation here.
5177 public void assignChildLayers(Transaction t) {
Tiger Huang9c8ee262019-02-19 20:44:27 +08005178 // The surface of the main window might be preserved. So the child window on top of the main
5179 // window should be also on top of the preserved surface.
5180 int layer = PRESERVED_SURFACE_LAYER + 1;
Robert Carr0eff1872017-12-01 14:27:04 -08005181 for (int i = 0; i < mChildren.size(); i++) {
5182 final WindowState w = mChildren.get(i);
5183
5184 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
5185 // while they both need to go below the main window. However the
5186 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
5187 // been defined and so we can use static layers and leave it that way.
5188 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
shubangcdc23b52019-06-19 11:08:10 -07005189 if (mWinAnimator.hasSurface()) {
5190 w.assignRelativeLayer(t, mWinAnimator.mSurfaceController.mSurfaceControl, -2);
5191 } else {
5192 w.assignLayer(t, -2);
5193 }
Robert Carr0eff1872017-12-01 14:27:04 -08005194 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
shubangcdc23b52019-06-19 11:08:10 -07005195 if (mWinAnimator.hasSurface()) {
5196 w.assignRelativeLayer(t, mWinAnimator.mSurfaceController.mSurfaceControl, -1);
5197 } else {
5198 w.assignLayer(t, -1);
5199 }
Robert Carr0eff1872017-12-01 14:27:04 -08005200 } else {
5201 w.assignLayer(t, layer);
5202 }
5203 w.assignChildLayers(t);
5204 layer++;
5205 }
5206 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01005207
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005208 /**
Tiger Huang2b210c22019-03-18 21:21:26 +08005209 * Update a tap exclude region identified by provided id. The requested area will be clipped to
5210 * the window bounds.
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005211 */
Tiger Huang2b210c22019-03-18 21:21:26 +08005212 void updateTapExcludeRegion(int regionId, Region region) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005213 final DisplayContent currentDisplay = getDisplayContent();
5214 if (currentDisplay == null) {
5215 throw new IllegalStateException("Trying to update window not attached to any display.");
5216 }
5217
5218 if (mTapExcludeRegionHolder == null) {
5219 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
5220
5221 // Make sure that this window is registered as one that provides a tap exclude region
5222 // for its containing display.
5223 currentDisplay.mTapExcludeProvidingWindows.add(this);
5224 }
5225
Tiger Huang2b210c22019-03-18 21:21:26 +08005226 mTapExcludeRegionHolder.updateRegion(regionId, region);
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005227 // Trigger touch exclude region update on current display.
Tiger Huang1e5b10a2018-07-30 20:19:51 +08005228 currentDisplay.updateTouchExcludeRegion();
Tiger Huang04dc4cc2019-01-17 18:41:41 +08005229 // Trigger touchable region update for this window.
5230 currentDisplay.getInputMonitor().updateInputWindowsLw(true /* force */);
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005231 }
5232
Tiger Huang04dc4cc2019-01-17 18:41:41 +08005233 /**
5234 * Union the region with current tap exclude region that this window provides.
5235 *
5236 * @param region The region to be amended. It is on the screen coordinates.
5237 */
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005238 void amendTapExcludeRegion(Region region) {
Tiger Huang04dc4cc2019-01-17 18:41:41 +08005239 final Region tempRegion = Region.obtain();
5240 mTmpRect.set(mWindowFrames.mFrame);
5241 mTmpRect.offsetTo(0, 0);
5242 mTapExcludeRegionHolder.amendRegion(tempRegion, mTmpRect);
5243 // The region held by the holder is on the window coordinates. We need to translate it to
5244 // the screen coordinates.
5245 tempRegion.translate(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top);
5246 region.op(tempRegion, Region.Op.UNION);
5247 tempRegion.recycle();
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005248 }
5249
Jackal Guoc43a0a62019-04-23 09:15:14 +08005250 boolean hasTapExcludeRegion() {
5251 return mTapExcludeRegionHolder != null && !mTapExcludeRegionHolder.isEmpty();
5252 }
5253
Robert Carr825581a2018-03-30 14:00:53 -07005254 @Override
5255 public boolean isInputMethodTarget() {
lumarkff0ab692018-11-05 20:32:30 +08005256 return getDisplayContent().mInputMethodTarget == this;
Robert Carr825581a2018-03-30 14:00:53 -07005257 }
5258
chaviwbe43ac82018-04-04 15:14:49 -07005259 long getFrameNumber() {
5260 return mFrameNumber;
5261 }
5262
5263 void setFrameNumber(long frameNumber) {
5264 mFrameNumber = frameNumber;
5265 }
5266
chaviw553b0212018-07-12 13:37:01 -07005267 public void getMaxVisibleBounds(Rect out) {
5268 if (out.isEmpty()) {
5269 out.set(mWindowFrames.mVisibleFrame);
5270 return;
5271 }
5272
5273 if (mWindowFrames.mVisibleFrame.left < out.left) {
5274 out.left = mWindowFrames.mVisibleFrame.left;
5275 }
5276 if (mWindowFrames.mVisibleFrame.top < out.top) {
5277 out.top = mWindowFrames.mVisibleFrame.top;
5278 }
5279 if (mWindowFrames.mVisibleFrame.right > out.right) {
5280 out.right = mWindowFrames.mVisibleFrame.right;
5281 }
5282 if (mWindowFrames.mVisibleFrame.bottom > out.bottom) {
5283 out.bottom = mWindowFrames.mVisibleFrame.bottom;
5284 }
5285 }
5286
chaviw9c81e632018-07-31 11:17:52 -07005287 /**
5288 * Copy the inset values over so they can be sent back to the client when a relayout occurs.
5289 */
Jorim Jaggif081f062019-10-24 16:24:54 +02005290 void getInsetsForRelayout(Rect outContentInsets, Rect outVisibleInsets,
5291 Rect outStableInsets) {
chaviw9c81e632018-07-31 11:17:52 -07005292 outContentInsets.set(mWindowFrames.mContentInsets);
5293 outVisibleInsets.set(mWindowFrames.mVisibleInsets);
5294 outStableInsets.set(mWindowFrames.mStableInsets);
chaviw9c81e632018-07-31 11:17:52 -07005295
5296 mLastRelayoutContentInsets.set(mWindowFrames.mContentInsets);
5297 }
5298
5299 void getContentInsets(Rect outContentInsets) {
5300 outContentInsets.set(mWindowFrames.mContentInsets);
5301 }
5302
5303 Rect getContentInsets() {
5304 return mWindowFrames.mContentInsets;
5305 }
5306
5307 void getStableInsets(Rect outStableInsets) {
5308 outStableInsets.set(mWindowFrames.mStableInsets);
5309 }
5310
5311 Rect getStableInsets() {
5312 return mWindowFrames.mStableInsets;
5313 }
5314
5315 void resetLastContentInsets() {
5316 mWindowFrames.resetLastContentInsets();
5317 }
5318
5319 Rect getVisibleInsets() {
5320 return mWindowFrames.mVisibleInsets;
5321 }
5322
chaviw1454b392018-08-06 09:54:04 -07005323 @Override
5324 public WindowFrames getWindowFrames() {
5325 return mWindowFrames;
5326 }
5327
5328 void resetContentChanged() {
5329 mWindowFrames.setContentChanged(false);
5330 }
5331
Jorim Jaggi956ca412019-01-07 14:49:14 +01005332 /**
5333 * Set's an {@link InsetsSourceProvider} to be associated with this window, but only if the
5334 * provider itself is controllable, as one window can be the provider of more than one inset
5335 * type (i.e. gesture insets). If this window is controllable, all its animations must be
5336 * controlled by its control target, and the visibility of this window should be taken account
5337 * into the state of the control target.
5338 *
5339 * @param insetProvider the provider which should not be visible to the client.
5340 * @see InsetsStateController#getInsetsForDispatch(WindowState)
5341 */
5342 void setControllableInsetProvider(InsetsSourceProvider insetProvider) {
5343 mControllableInsetProvider = insetProvider;
Jorim Jaggif96c90a2018-09-26 16:55:15 +02005344 }
5345
Jorim Jaggi956ca412019-01-07 14:49:14 +01005346 InsetsSourceProvider getControllableInsetProvider() {
5347 return mControllableInsetProvider;
Jorim Jaggif96c90a2018-09-26 16:55:15 +02005348 }
5349
Jorim Jaggia5e10572017-11-15 14:36:26 +01005350 private final class MoveAnimationSpec implements AnimationSpec {
5351
5352 private final long mDuration;
5353 private Interpolator mInterpolator;
5354 private Point mFrom = new Point();
5355 private Point mTo = new Point();
5356
5357 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
5358 final Animation anim = AnimationUtils.loadAnimation(mContext,
5359 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01005360 mDuration = (long)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08005361 (anim.computeDurationHint() * mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01005362 mInterpolator = anim.getInterpolator();
5363 mFrom.set(fromX, fromY);
5364 mTo.set(toX, toY);
5365 }
5366
5367 @Override
5368 public long getDuration() {
5369 return mDuration;
5370 }
5371
5372 @Override
5373 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
5374 final float fraction = (float) currentPlayTime / getDuration();
5375 final float v = mInterpolator.getInterpolation(fraction);
5376 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
5377 mFrom.y + (mTo.y - mFrom.y) * v);
5378 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01005379
5380 @Override
5381 public void dump(PrintWriter pw, String prefix) {
chaviwc65fa582018-08-09 15:33:13 -07005382 pw.println(prefix + "from=" + mFrom
5383 + " to=" + mTo
5384 + " duration=" + mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01005385 }
5386
5387 @Override
5388 public void writeToProtoInner(ProtoOutputStream proto) {
5389 final long token = proto.start(MOVE);
5390 mFrom.writeToProto(proto, FROM);
5391 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07005392 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01005393 proto.end(token);
5394 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01005395 }
Vishnu Nair539334a2019-09-20 10:46:21 -07005396
5397 KeyInterceptionInfo getKeyInterceptionInfo() {
5398 if (mKeyInterceptionInfo == null
5399 || mKeyInterceptionInfo.layoutParamsPrivateFlags != getAttrs().privateFlags
5400 || mKeyInterceptionInfo.layoutParamsType != getAttrs().type
5401 || mKeyInterceptionInfo.windowTitle != getWindowTag()) {
5402 mKeyInterceptionInfo = new KeyInterceptionInfo(getAttrs().type, getAttrs().privateFlags,
5403 getWindowTag().toString());
5404 }
5405 return mKeyInterceptionInfo;
5406 }
lumark19a5d2e2019-10-11 16:19:30 +08005407
5408 @Override
5409 void getAnimationFrames(Rect outFrame, Rect outInsets, Rect outStableInsets,
5410 Rect outSurfaceInsets) {
5411 // Containing frame will usually cover the whole screen, including dialog windows.
5412 // For freeform workspace windows it will not cover the whole screen and it also
5413 // won't exactly match the final freeform window frame (e.g. when overlapping with
5414 // the status bar). In that case we need to use the final frame.
5415 if (inFreeformWindowingMode()) {
5416 outFrame.set(getFrameLw());
5417 } else if (isLetterboxedAppWindow()) {
5418 outFrame.set(getTask().getBounds());
5419 } else if (isDockedResizing()) {
5420 // If we are animating while docked resizing, then use the stack bounds as the
5421 // animation target (which will be different than the task bounds)
5422 outFrame.set(getTask().getParent().getBounds());
5423 } else {
5424 outFrame.set(getContainingFrame());
5425 }
5426 outSurfaceInsets.set(getAttrs().surfaceInsets);
5427 // TODO(b/72757033): These are insets relative to the window frame, but we're really
5428 // interested in the insets relative to the frame we chose in the if-blocks above.
5429 getContentInsets(outInsets);
5430 getStableInsets(outStableInsets);
5431 }
satokcef37fb2011-10-24 21:49:38 +09005432}