blob: faa483a48ea4f2d26dec89c8654ca8d773d51cab [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 Ogunwale1ebcd8e2020-01-21 11:27:03 -080019import static android.app.ActivityTaskManager.INVALID_TASK_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;
Galia Peycheva70b55712020-03-16 18:31:34 +010023import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM;
Evan Rosky36138542020-05-01 18:02:11 -070024import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Adrian Roos5f2c9a12019-07-03 18:31:46 +020025import static android.app.WindowConfiguration.isSplitScreenWindowingMode;
26import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
chaviw40234662018-02-07 09:37:16 -080027import static android.os.PowerManager.DRAW_WAKE_LOCK;
Jorim Jaggi02886a82016-12-06 09:10:06 -080028import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Ming-Shin Lu35ff45d2020-07-02 15:40:31 +080029import static android.view.InsetsState.ITYPE_IME;
Jorim Jaggia5e10572017-11-15 14:36:26 +010030import static android.view.SurfaceControl.Transaction;
Adrian Roos019a52b2019-07-02 16:47:44 +020031import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
32import static android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080033import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
34import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
35import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
36import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Jorim Jaggi956ca412019-01-07 14:49:14 +010037import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080038import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
39import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
40import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Andrew Chant17c896e2019-12-05 22:39:02 +000041import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jorim Jaggi02886a82016-12-06 09:10:06 -080042import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
43import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
44import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
45import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
46import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
47import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080048import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
49import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
50import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080051import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080052import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Adrian Roosfa02da62018-01-15 16:01:18 +010053import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080054import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
55import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
56import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
57import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
58import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
59import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
60import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Philip P. Moltmann66ce2382018-10-09 13:46:11 -070061import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -080062import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080063import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carr0eff1872017-12-01 14:27:04 -080064import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Vishnu Nair1d0fa072018-01-04 07:53:00 -080065import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080066import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
67import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -080068import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
69import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080070import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
71import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -080072import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
Jorim Jaggi02886a82016-12-06 09:10:06 -080073import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
74import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -080075import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Robert Carrb1579c82017-09-05 14:54:47 -070076import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
77import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Robert Carree4d4b92017-11-22 12:21:46 -080078import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
wilsonshihe8321942019-10-18 18:39:46 +080079import static android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE;
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -080080import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
81import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
82import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
83import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
84import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
Winson Chung8ae977d2020-06-25 13:05:19 -070085import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -080086import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
87import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Heemin Seog2cf45dd2020-02-24 15:43:29 -080088import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL;
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -080089import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
90import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070091import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -080092import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080093import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070094import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080095import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
96import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
97import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
98import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Vishnu Nairddd80742018-08-21 14:12:46 -070099
Yunfan Chenb4fe58c2019-03-27 18:35:06 +0900100import static com.android.server.am.ActivityManagerService.MY_PID;
Adrian Roose99bc052017-11-20 17:55:31 +0100101import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
102import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
103import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
104import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Vishnu Nairddd80742018-08-21 14:12:46 -0700105import static com.android.server.wm.AnimationSpecProto.MOVE;
Adrian Roos5f2c9a12019-07-03 18:31:46 +0200106import static com.android.server.wm.DisplayContent.logsGestureExclusionRestrictions;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800107import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
108import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Vishnu Nairddd80742018-08-21 14:12:46 -0700109import static com.android.server.wm.IdentifierProto.HASH_CODE;
110import static com.android.server.wm.IdentifierProto.TITLE;
111import static com.android.server.wm.IdentifierProto.USER_ID;
112import static com.android.server.wm.MoveAnimationSpecProto.DURATION_MS;
113import static com.android.server.wm.MoveAnimationSpecProto.FROM;
114import static com.android.server.wm.MoveAnimationSpecProto.TO;
Adrian Roosb125e0b2019-10-02 14:55:14 +0200115import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ADD_REMOVE;
116import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS;
117import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS;
118import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT;
Taran Singh85661e32020-05-07 14:45:34 -0700119import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_IME;
Adrian Roosb125e0b2019-10-02 14:55:14 +0200120import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION;
121import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_RESIZE;
122import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_STARTING_WINDOW;
Issei Suzuki8b995df2020-01-08 12:23:04 +0100123import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_WINDOW_ANIMATION;
lumark9bca6b42019-10-17 18:35:22 +0800124import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS;
125import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION;
Vishnu Nairdddc9f52020-03-09 09:37:27 -0700126import static com.android.server.wm.WindowContainerChildProto.WINDOW;
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200127import static com.android.server.wm.WindowManagerDebugConfig.DEBUG;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800128import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800129import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800130import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800131import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Tiger Huang50d45462018-05-25 22:57:52 +0800132import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800133import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200134import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800135import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800136import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
137import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
138import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Louis Changa009c762020-02-26 11:21:31 +0800139import static com.android.server.wm.WindowManagerService.H.WINDOW_STATE_BLAST_SYNC_TIMEOUT;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100140import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800141import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
142import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
143import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Tiger Huang8af6ba42018-06-07 19:24:09 +0800144import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800145import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
146import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800147import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
148import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
149import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
Tiger Huang9c8ee262019-02-19 20:44:27 +0800150import static com.android.server.wm.WindowStateAnimator.PRESERVED_SURFACE_LAYER;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800151import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700152import static com.android.server.wm.WindowStateProto.ANIMATING_EXIT;
153import static com.android.server.wm.WindowStateProto.ANIMATOR;
154import static com.android.server.wm.WindowStateProto.ATTRIBUTES;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700155import static com.android.server.wm.WindowStateProto.DESTROYING;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700156import static com.android.server.wm.WindowStateProto.DISPLAY_ID;
Vishnu Nairddd80742018-08-21 14:12:46 -0700157import static com.android.server.wm.WindowStateProto.FINISHED_SEAMLESS_ROTATION_FRAME;
158import static com.android.server.wm.WindowStateProto.FORCE_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700159import static com.android.server.wm.WindowStateProto.GIVEN_CONTENT_INSETS;
160import static com.android.server.wm.WindowStateProto.HAS_SURFACE;
161import static com.android.server.wm.WindowStateProto.IDENTIFIER;
162import static com.android.server.wm.WindowStateProto.IS_ON_SCREEN;
163import static com.android.server.wm.WindowStateProto.IS_READY_FOR_DISPLAY;
164import static com.android.server.wm.WindowStateProto.IS_VISIBLE;
Vishnu Nairddd80742018-08-21 14:12:46 -0700165import static com.android.server.wm.WindowStateProto.PENDING_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700166import static com.android.server.wm.WindowStateProto.REMOVED;
167import static com.android.server.wm.WindowStateProto.REMOVE_ON_EXIT;
168import static com.android.server.wm.WindowStateProto.REQUESTED_HEIGHT;
169import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700170import static com.android.server.wm.WindowStateProto.STACK_ID;
171import static com.android.server.wm.WindowStateProto.SURFACE_INSETS;
172import static com.android.server.wm.WindowStateProto.SURFACE_POSITION;
173import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY;
174import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700175import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER;
chaviw553b0212018-07-12 13:37:01 -0700176import static com.android.server.wm.WindowStateProto.WINDOW_FRAMES;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800177
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700178import android.annotation.CallSuper;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200179import android.annotation.Nullable;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800180import android.app.AppOpsManager;
Alex Johnston302c1fe2020-06-18 20:00:51 +0100181import android.app.admin.DevicePolicyCache;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800182import android.content.Context;
183import android.content.res.Configuration;
184import android.graphics.Matrix;
185import android.graphics.PixelFormat;
186import android.graphics.Point;
187import android.graphics.Rect;
188import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700189import android.os.Binder;
Adrian Roos019a52b2019-07-02 16:47:44 +0200190import android.os.Build;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700191import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800192import android.os.IBinder;
193import android.os.PowerManager;
Michael Wrighte3001042019-02-05 00:13:14 +0000194import android.os.PowerManager.WakeReason;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800195import android.os.RemoteCallbackList;
196import android.os.RemoteException;
197import android.os.SystemClock;
198import android.os.Trace;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800199import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800200import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800201import android.text.TextUtils;
Jackal Guoc43a0a62019-04-23 09:15:14 +0800202import android.util.ArraySet;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800203import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200204import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800205import android.util.Slog;
206import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700207import android.util.proto.ProtoOutputStream;
Brad Stenningaf596412018-04-02 12:03:19 -0700208import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100209import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800210import android.view.DisplayInfo;
211import android.view.Gravity;
212import android.view.IApplicationToken;
213import android.view.IWindow;
214import android.view.IWindowFocusObserver;
215import android.view.IWindowId;
216import android.view.InputChannel;
217import android.view.InputEvent;
218import android.view.InputEventReceiver;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800219import android.view.InputWindowHandle;
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100220import android.view.InsetsSource;
Jorim Jaggi956ca412019-01-07 14:49:14 +0100221import android.view.InsetsState;
Vishnu Nairba183352018-11-21 11:16:49 -0800222import android.view.Surface.Rotation;
Robert Carrb1579c82017-09-05 14:54:47 -0700223import android.view.SurfaceControl;
224import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800225import android.view.View;
226import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700227import android.view.WindowInfo;
Tiger Huang332793b2019-10-29 23:21:27 +0800228import android.view.WindowInsets.Type.InsetsType;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800229import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100230import android.view.animation.Animation;
231import android.view.animation.AnimationUtils;
232import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800233
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100234import com.android.internal.annotations.VisibleForTesting;
Vishnu Nair539334a2019-09-20 10:46:21 -0700235import com.android.internal.policy.KeyInterceptionInfo;
Muhammad Qureshi759f92f2020-01-28 10:41:55 -0800236import com.android.internal.util.FrameworkStatsLog;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800237import com.android.internal.util.ToBooleanFunction;
Adrian Roose99bc052017-11-20 17:55:31 +0100238import com.android.server.policy.WindowManagerPolicy;
Adrian Roosb125e0b2019-10-02 14:55:14 +0200239import com.android.server.protolog.common.ProtoLog;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100240import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
Issei Suzuki8b995df2020-01-08 12:23:04 +0100241import com.android.server.wm.SurfaceAnimator.AnimationType;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100242import com.android.server.wm.utils.WmDisplayCutout;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800243
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800244import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200245import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800246import java.util.ArrayList;
chaviw54521692020-06-12 14:34:30 -0700247import java.util.Collections;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700248import java.util.Comparator;
Adrian Roos4ffc8972019-02-07 20:45:11 +0100249import java.util.List;
chaviw54521692020-06-12 14:34:30 -0700250import java.util.Set;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800251import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800252
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700253/** A window in the window manager. */
Jorim Jaggi28620472019-01-02 23:21:49 +0100254class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState,
255 InsetsControlTarget {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800256 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800257
Skuhne81c524a2015-08-12 13:34:14 -0700258 // The minimal size of a window within the usable area of the freeform stack.
Vishnu Nair93d68c22019-03-22 13:45:31 -0700259 // TODO(multi-window): fix the min sizes when we have minimum width/height support,
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700260 // use hard-coded min sizes for now.
261 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
262 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700263
264 // The thickness of a window resize handle outside the window bounds on the free form workspace
265 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700266 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700267
Adrian Roos5f2c9a12019-07-03 18:31:46 +0200268 static final int EXCLUSION_LEFT = 0;
269 static final int EXCLUSION_RIGHT = 1;
270
Craig Mautnere7ae2502012-03-26 17:11:19 -0700271 final WindowManagerPolicy mPolicy;
272 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800273 final Session mSession;
274 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800275 final int mAppOp;
276 // UserId and appId of the owner. Don't display windows of non-current user.
277 final int mOwnerUid;
wilsonshihd0fc2ca2020-03-18 22:41:55 +0800278 /**
279 * Requested userId, if this is not equals with the userId from mOwnerUid, then this window is
280 * created for secondary user.
281 * Use this member instead of get userId from mOwnerUid while query for visibility.
282 */
283 final int mShowUserId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800284 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
285 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200286 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700288 // The same object as mToken if this is an app window and null for non-app windows.
Garfield Tane8d84ab2019-10-11 09:49:40 -0700289 ActivityRecord mActivityRecord;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700290
291 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
292 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
294 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700295 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 final int mBaseLayer;
297 final int mSubLayer;
298 final boolean mLayoutAttached;
299 final boolean mIsImWindow;
300 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700301 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700302 int mSeq;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700304 int mSystemUiVisibility;
chaviw15ad49f2019-04-24 15:05:39 -0700305
Wale Ogunwale571771c2016-08-26 13:18:50 -0700306 /**
chaviw15ad49f2019-04-24 15:05:39 -0700307 * The visibility flag of the window based on policy like {@link WindowManagerPolicy}.
Wale Ogunwale571771c2016-08-26 13:18:50 -0700308 * Normally set by calling {@link #showLw} and {@link #hideLw}.
chaviw15ad49f2019-04-24 15:05:39 -0700309 *
310 * TODO: b/131253938 This will eventually be split into individual visibility policy flags.
Wale Ogunwale571771c2016-08-26 13:18:50 -0700311 */
chaviw15ad49f2019-04-24 15:05:39 -0700312 static final int LEGACY_POLICY_VISIBILITY = 1;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700313 /**
chaviw15ad49f2019-04-24 15:05:39 -0700314 * The visibility flag that determines whether this window is visible for the current user.
Wale Ogunwale571771c2016-08-26 13:18:50 -0700315 */
chaviw15ad49f2019-04-24 15:05:39 -0700316 private static final int VISIBLE_FOR_USER = 1 << 1;
317 private static final int POLICY_VISIBILITY_ALL = VISIBLE_FOR_USER | LEGACY_POLICY_VISIBILITY;
318 /**
319 * The Bitwise-or of flags that contribute to visibility of the WindowState
320 */
321 private int mPolicyVisibility = POLICY_VISIBILITY_ALL;
322
323 /**
324 * Whether {@link #LEGACY_POLICY_VISIBILITY} flag should be set after a transition animation.
325 * For example, {@link #LEGACY_POLICY_VISIBILITY} might be set during an exit animation to hide
326 * it and then unset when the value of {@link #mLegacyPolicyVisibilityAfterAnim} is false
327 * after the exit animation is done.
328 *
329 * TODO: b/131253938 Determine whether this can be changed to use a visibility flag instead.
330 */
331 boolean mLegacyPolicyVisibilityAfterAnim = true;
Suprabh Shukla69c71422018-04-02 18:39:01 -0700332 // overlay window is hidden because the owning app is suspended
333 private boolean mHiddenWhileSuspended;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700334 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700335 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700336 // This is a non-system overlay window that is currently force hidden.
337 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800338 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800339 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700341 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200342 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700343 private int mResizeMode;
Robert Carr52385c32020-06-23 15:56:28 -0700344 private boolean mRedrawForSyncReported;
chaviw73abde92020-05-18 17:56:35 -0700345
Vishnu Nair83537a72018-07-19 21:27:48 -0700346 /**
347 * Special mode that is intended only for the rounded corner overlay: during rotation
348 * transition, we un-rotate the window token such that the window appears as it did before the
349 * rotation.
Vishnu Nair83537a72018-07-19 21:27:48 -0700350 */
351 final boolean mForceSeamlesslyRotate;
Vishnu Nairddd80742018-08-21 14:12:46 -0700352 SeamlessRotator mPendingSeamlessRotate;
353 long mFinishSeamlessRotateFrameNumber;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700354
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700355 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800356
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700357 /**
358 * The window size that was requested by the application. These are in
359 * the application's coordinate space (without compatibility scale applied).
360 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800361 int mRequestedWidth;
362 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700363 private int mLastRequestedWidth;
364 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700365
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800366 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 boolean mHaveFrame;
368 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800369
370 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700371
Jackal Guoc43a0a62019-04-23 09:15:14 +0800372 /** @see #addEmbeddedDisplayContent(DisplayContent dc) */
373 private final ArraySet<DisplayContent> mEmbeddedDisplayContents = new ArraySet<>();
374
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700375 /**
376 * Used to store last reported to client configuration and check if we have newer available.
377 * We'll send configuration to client only if it is different from the last applied one and
378 * client won't perform unnecessary updates.
379 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700380 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700381
Jorim Jaggi381cd722019-03-27 17:33:02 +0100382 /** @see #isLastConfigReportedToClient() */
383 private boolean mLastConfigReportedToClient;
384
Yunfan Chen75157d72018-07-27 14:47:21 +0900385 private final Configuration mTempConfiguration = new Configuration();
386
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700387 /**
Robert Carr18f622f2017-05-08 11:20:43 -0700388 * The last content insets returned to the client in relayout. We use
389 * these in the bounds animation to ensure we only observe inset changes
390 * at the same time that a client resizes it's surface so that we may use
391 * the geometryAppliesWithResize synchronization mechanism to keep
392 * the contents in place.
393 */
394 final Rect mLastRelayoutContentInsets = new Rect();
395
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700396 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800397 * Set to true if we are waiting for this window to receive its
398 * given internal insets before laying out other windows based on it.
399 */
400 boolean mGivenInsetsPending;
401
402 /**
403 * These are the content insets that were given during layout for
404 * this window, to be applied to windows behind it.
405 */
406 final Rect mGivenContentInsets = new Rect();
407
408 /**
409 * These are the visible insets that were given during layout for
410 * this window, to be applied to windows behind it.
411 */
412 final Rect mGivenVisibleInsets = new Rect();
413
414 /**
415 * This is the given touchable area relative to the window frame, or null if none.
416 */
417 final Region mGivenTouchableRegion = new Region();
418
419 /**
420 * Flag indicating whether the touchable region should be adjusted by
421 * the visible insets; if false the area outside the visible insets is
422 * NOT touchable, so we must use those to adjust the frame during hit
423 * tests.
424 */
425 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
426
427 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400428 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700429 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800430 float mHScale=1, mVScale=1;
431 float mLastHScale=1, mLastVScale=1;
432 final Matrix mTmpMatrix = new Matrix();
Lucas Dupin13f4b8a2020-02-19 13:41:52 -0800433 final float[] mTmpMatrixArray = new float[9];
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800434
chaviw553b0212018-07-12 13:37:01 -0700435 private final WindowFrames mWindowFrames = new WindowFrames();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700436
Riddle Hsuc7175762020-01-10 21:03:48 +0800437 /** The frames used to compute a temporal layout appearance. */
438 private WindowFrames mSimulatedWindowFrames;
439
Jorim Jaggidc249c42015-12-15 14:57:31 -0800440 /**
441 * Usually empty. Set to the task's tempInsetFrame. See
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700442 *{@link android.app.IActivityTaskManager#resizeDockedStack}.
Jorim Jaggidc249c42015-12-15 14:57:31 -0800443 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700444 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800445
Adrian Roos4ffc8972019-02-07 20:45:11 +0100446 /**
447 * List of rects where system gestures should be ignored.
448 *
449 * Coordinates are relative to the window's position.
450 */
451 private final List<Rect> mExclusionRects = new ArrayList<>();
452
Adrian Roos5f2c9a12019-07-03 18:31:46 +0200453 // 0 = left, 1 = right
454 private final int[] mLastRequestedExclusionHeight = {0, 0};
455 private final int[] mLastGrantedExclusionHeight = {0, 0};
456 private final long[] mLastExclusionLogUptimeMillis = {0, 0};
457
458 private boolean mLastShownChangedReported;
459
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800460 // If a window showing a wallpaper: the requested offset for the
461 // wallpaper; if a wallpaper window: the currently applied offset.
462 float mWallpaperX = -1;
463 float mWallpaperY = -1;
464
Lucas Dupin13f4b8a2020-02-19 13:41:52 -0800465 // If a window showing a wallpaper: the requested zoom out for the
466 // wallpaper; if a wallpaper window: the currently applied zoom.
467 float mWallpaperZoomOut = -1;
468
469 // If a wallpaper window: whether the wallpaper should be scaled when zoomed, if set
470 // to false, mWallpaperZoom will be ignored here and just passed to the WallpaperService.
471 boolean mShouldScaleWallpaper;
472
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473 // If a window showing a wallpaper: what fraction of the offset
474 // range corresponds to a full virtual screen.
475 float mWallpaperXStep = -1;
476 float mWallpaperYStep = -1;
477
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700478 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
479 // to its window; if a wallpaper window: not used.
480 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
481 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
482
Craig Mautner2268e7e2012-12-13 15:40:00 -0800483 /**
484 * This is set after IWindowSession.relayout() has been called at
485 * least once for the window. It allows us to detect the situation
486 * where we don't yet have a surface, but should have one soon, so
487 * we can give the window focus before waiting for the relayout.
488 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 boolean mRelayoutCalled;
490
Robert Carrfed10072016-05-26 11:48:49 -0700491 boolean mInRelayout;
492
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800493 /**
494 * If the application has called relayout() with changes that can
495 * impact its window's size, we need to perform a layout pass on it
496 * even if it is not currently visible for layout. This is set
497 * when in that case until the layout is done.
498 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800499 boolean mLayoutNeeded;
500
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800501 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800502 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800503
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800504 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800505 boolean mDestroying;
506
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800507 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800508 boolean mRemoveOnExit;
509
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800510 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800511 * Whether the app died while it was visible, if true we might need
512 * to continue to show it until it's restarted.
513 */
514 boolean mAppDied;
515
516 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800517 * Set when the orientation is changing and this window has not yet
518 * been updated for the new orientation.
519 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700520 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800521
Dianne Hackborna57c6952013-03-29 14:46:40 -0700522 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700523 * Sometimes in addition to the mOrientationChanging
524 * flag we report that the orientation is changing
525 * due to a mismatch in current and reported configuration.
526 *
527 * In the case of timeout we still need to make sure we
528 * leave the orientation changing state though, so we
529 * use this as a special time out escape hatch.
530 */
531 private boolean mOrientationChangeTimedOut;
532
533 /**
Robert Carr237028a2016-07-26 10:39:45 -0700534 * The orientation during the last visible call to relayout. If our
535 * current orientation is different, the window can't be ready
536 * to be shown.
537 */
538 int mLastVisibleLayoutRotation = -1;
539
540 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800541 * Set when we need to report the orientation change to client to trigger a relayout.
542 */
543 boolean mReportOrientationChanged;
544
545 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700546 * How long we last kept the screen frozen.
547 */
548 int mLastFreezeDuration;
549
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800550 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800551 boolean mRemoved;
552
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800553 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800554 * It is save to remove the window and destroy the surface because the client requested removal
555 * or some other higher level component said so (e.g. activity manager).
556 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800557 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700558 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800559
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800560 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700561 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800562 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700563 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800564
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800565 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700566 private String mStringNameCache;
567 private CharSequence mLastTitle;
568 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800569
Craig Mautnera2c77052012-03-26 12:14:43 -0700570 final WindowStateAnimator mWinAnimator;
571
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700572 boolean mHasSurface = false;
573
Robert Carra1eb4392015-12-10 12:43:51 -0800574 // This window will be replaced due to relaunch. This allows window manager
575 // to differentiate between simple removal of a window and replacement. In the latter case it
576 // will preserve the old window until the new one is drawn.
577 boolean mWillReplaceWindow = false;
578 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700579 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800580 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700581 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800582 // If not null, the window that will be used to replace the old one. This is being set when
583 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700584 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700585 // For the new window in the replacement transition, if we have
586 // requested to replace without animation, then we should
587 // make sure we also don't apply an enter animation for
588 // the new window.
589 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800590 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700591 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800592
Jeff Brownc2932a12014-11-20 18:04:05 -0800593 /**
594 * Wake lock for drawing.
595 * Even though it's slightly more expensive to do so, we will use a separate wake lock
596 * for each app that is requesting to draw while dozing so that we can accurately track
597 * who is preventing the system from suspending.
598 * This lock is only acquired on first use.
599 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700600 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800601
Riddle Hsub398da32019-01-21 21:48:16 +0800602 private final Rect mTmpRect = new Rect();
603 private final Point mTmpPoint = new Point();
Wale Ogunwale2b19b6042015-09-18 15:14:59 -0700604
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800605 /**
Jackal Guoc43a0a62019-04-23 09:15:14 +0800606 * If a window is on a display which has been re-parented to a view in another window,
607 * use this offset to indicate the correct location.
608 */
609 private final Point mLastReportedDisplayOffset = new Point();
610
611 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800612 * Whether the window was resized by us while it was gone for layout.
613 */
614 boolean mResizedWhileGone = false;
615
Robert Carr6da3cc02016-06-16 15:17:07 -0700616 /**
617 * During seamless rotation we have two phases, first the old window contents
618 * are rotated to look as if they didn't move in the new coordinate system. Then we
619 * have to freeze updates to this layer (to preserve the transformation) until
620 * the resize actually occurs. This is true from when the transformation is set
621 * and false until the transaction to resize is sent.
622 */
623 boolean mSeamlesslyRotated = false;
624
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700625 /**
Tiger Huang57e2e1c2020-03-13 22:54:36 +0800626 * Indicates if this window is behind IME. Only windows behind IME can get insets from IME.
627 */
628 boolean mBehindIme = false;
629
630 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800631 * Surface insets from the previous call to relayout(), used to track
632 * if we are changing the Surface insets.
633 */
634 final Rect mLastSurfaceInsets = new Rect();
635
636 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700637 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
638 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
639 * make sure all children have been considered.
640 */
641 private boolean mDrawnStateEvaluated;
642
Jorim Jaggia5e10572017-11-15 14:36:26 +0100643 private final Point mSurfacePosition = new Point();
644
Bryce Leed390deb2017-06-22 13:14:28 -0700645 /**
Tiger Huang04dc4cc2019-01-17 18:41:41 +0800646 * A region inside of this window to be excluded from touch.
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800647 */
chaviwaa0d74e2019-12-26 14:13:40 -0800648 private final Region mTapExcludeRegion = new Region();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800649
650 /**
chaviw40234662018-02-07 09:37:16 -0800651 * Used for testing because the real PowerManager is final.
652 */
653 private PowerManagerWrapper mPowerManagerWrapper;
654
655 /**
chaviwbe43ac82018-04-04 15:14:49 -0700656 * A frame number in which changes requested in this layout will be rendered.
657 */
658 private long mFrameNumber = -1;
659
chaviwc65fa582018-08-09 15:33:13 -0700660 private static final StringBuilder sTmpSB = new StringBuilder();
661
chaviwbe43ac82018-04-04 15:14:49 -0700662 /**
chaviw54521692020-06-12 14:34:30 -0700663 * Whether the next surfacePlacement call should notify that the blast sync is ready.
664 * This is set to true when {@link #finishDrawing(Transaction)} is called so
665 * {@link #onTransactionReady(int, Set)} is called after the next surfacePlacement. This allows
666 * Transactions to get flushed into the syncTransaction before notifying {@link BLASTSyncEngine}
667 * that this WindowState is ready.
668 */
669 private boolean mNotifyBlastOnSurfacePlacement;
670
671 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700672 * 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 -0700673 * of z-order and 1 otherwise.
674 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800675 private static final Comparator<WindowState> sWindowSubLayerComparator =
676 new Comparator<WindowState>() {
677 @Override
678 public int compare(WindowState w1, WindowState w2) {
679 final int layer1 = w1.mSubLayer;
680 final int layer2 = w2.mSubLayer;
681 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
682 // We insert the child window into the list ordered by
683 // the sub-layer. For same sub-layers, the negative one
684 // should go below others; the positive one should go
685 // above others.
686 return -1;
687 }
688 return 1;
689 };
690 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700691
Robert Carrf59b8dd2017-10-02 18:58:36 -0700692 /**
693 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
694 * container.
695 */
696 private boolean mIsDimming = false;
697
Jorim Jaggi956ca412019-01-07 14:49:14 +0100698 private @Nullable InsetsSourceProvider mControllableInsetProvider;
Tiger Huang8734d472020-03-05 16:29:40 +0800699 private final InsetsState mRequestedInsetsState = new InsetsState();
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200700
Robert Carrf59b8dd2017-10-02 18:58:36 -0700701 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
Vishnu Nair539334a2019-09-20 10:46:21 -0700702 private KeyInterceptionInfo mKeyInterceptionInfo;
Robert Carrf59b8dd2017-10-02 18:58:36 -0700703
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100704 /**
Ana Krulecfea97172019-11-02 23:11:02 +0100705 * This information is passed to SurfaceFlinger to decide which window should have a priority
706 * when deciding about the refresh rate of the display. All windows have the lowest priority by
707 * default. The variable is cached, so we do not send too many updates to SF.
708 */
709 int mFrameRateSelectionPriority = RefreshRatePolicy.LAYER_PRIORITY_UNSET;
710
Rob Carr25376512020-03-09 15:23:19 -0700711 /**
712 * BLASTSyncEngine ID corresponding to a sync-set for all
713 * our children. We add our children to this set in Sync,
714 * but we save it and don't mark it as ready until finishDrawing
715 * this way we have a two way latch between all our children finishing
716 * and drawing ourselves.
717 */
718 private int mLocalSyncId = -1;
719
Rob Carrae0100b2020-03-09 14:46:19 -0700720 static final int BLAST_TIMEOUT_DURATION = 5000; /* milliseconds */
721
Jorim Jaggi268bf6882020-06-18 23:44:02 +0200722 private final WindowProcessController mWpcForDisplayConfigChanges;
723
Ana Krulecfea97172019-11-02 23:11:02 +0100724 /**
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100725 * @return The insets state as requested by the client, i.e. the dispatched insets state
726 * for which the visibilities are overridden with what the client requested.
727 */
Tiger Huang533682e2020-08-07 20:13:55 +0800728 @Override
729 public InsetsState getRequestedInsetsState() {
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100730 return mRequestedInsetsState;
Jorim Jaggi956ca412019-01-07 14:49:14 +0100731 }
732
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100733 /**
734 * @see #getRequestedInsetsState()
735 */
736 void updateRequestedInsetsState(InsetsState state) {
737
738 // Only update the sources the client is actually controlling.
Jorim Jaggibfa95a72020-06-18 22:51:49 +0200739 for (int i = 0; i < InsetsState.SIZE; i++) {
740 final InsetsSource source = state.peekSource(i);
741 if (source == null) continue;
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100742 mRequestedInsetsState.addSource(source);
743 }
Jorim Jaggi956ca412019-01-07 14:49:14 +0100744 }
745
Vishnu Nairba183352018-11-21 11:16:49 -0800746 void seamlesslyRotateIfAllowed(Transaction transaction, @Rotation int oldRotation,
747 @Rotation int rotation, boolean requested) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700748 // Invisible windows and the wallpaper do not participate in the seamless rotation animation
749 if (!isVisibleNow() || mIsWallpaper) {
750 return;
751 }
Adrian Roosfaa102f2018-08-02 15:56:15 +0200752
Riddle Hsu6f548e92020-01-13 13:34:09 +0800753 if (mToken.hasFixedRotationTransform()) {
754 // The transform of its surface is handled by fixed rotation.
755 return;
756 }
757
Vishnu Nairddd80742018-08-21 14:12:46 -0700758 if (mPendingSeamlessRotate != null) {
759 oldRotation = mPendingSeamlessRotate.getOldRotation();
760 }
761
Ming-Shin Lu35ff45d2020-07-02 15:40:31 +0800762 // Skip performing seamless rotation when the controlled insets is IME with visible state.
763 if (mControllableInsetProvider != null
764 && mControllableInsetProvider.getSource().getType() == ITYPE_IME) {
765 return;
766 }
767
Vishnu Nairddd80742018-08-21 14:12:46 -0700768 if (mForceSeamlesslyRotate || requested) {
Tiger Huang969c6082019-12-24 20:08:57 +0800769 if (mControllableInsetProvider != null) {
770 mControllableInsetProvider.startSeamlessRotation();
771 }
Vishnu Naireb53e522020-05-08 18:03:12 -0700772 mPendingSeamlessRotate = new SeamlessRotator(oldRotation, rotation, getDisplayInfo(),
773 false /* applyFixedTransformationHint */);
Vishnu Nairec634062018-09-20 20:16:18 -0700774 mPendingSeamlessRotate.unrotate(transaction, this);
Riddle Hsuccf09402019-08-13 00:33:06 +0800775 getDisplayContent().getDisplayRotation().markForSeamlessRotation(this,
776 true /* seamlesslyRotated */);
Vishnu Nairddd80742018-08-21 14:12:46 -0700777 }
778 }
779
Vishnu Nairba183352018-11-21 11:16:49 -0800780 void finishSeamlessRotation(boolean timeout) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700781 if (mPendingSeamlessRotate != null) {
Vishnu Nairba183352018-11-21 11:16:49 -0800782 mPendingSeamlessRotate.finish(this, timeout);
Vishnu Nairddd80742018-08-21 14:12:46 -0700783 mFinishSeamlessRotateFrameNumber = getFrameNumber();
784 mPendingSeamlessRotate = null;
Riddle Hsuccf09402019-08-13 00:33:06 +0800785 getDisplayContent().getDisplayRotation().markForSeamlessRotation(this,
786 false /* seamlesslyRotated */);
Tiger Huang969c6082019-12-24 20:08:57 +0800787 if (mControllableInsetProvider != null) {
788 mControllableInsetProvider.finishSeamlessRotation(timeout);
789 }
Vishnu Nair83537a72018-07-19 21:27:48 -0700790 }
791 }
792
Adrian Roos4ffc8972019-02-07 20:45:11 +0100793 List<Rect> getSystemGestureExclusion() {
794 return mExclusionRects;
795 }
796
797 /**
798 * Sets the system gesture exclusion rects.
799 *
800 * @return {@code true} if anything changed
801 */
802 boolean setSystemGestureExclusion(List<Rect> exclusionRects) {
803 if (mExclusionRects.equals(exclusionRects)) {
804 return false;
805 }
806 mExclusionRects.clear();
807 mExclusionRects.addAll(exclusionRects);
808 return true;
809 }
810
Adrian Roos019a52b2019-07-02 16:47:44 +0200811 boolean isImplicitlyExcludingAllSystemGestures() {
812 final int immersiveStickyFlags =
813 SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
814 final boolean immersiveSticky =
815 (mSystemUiVisibility & immersiveStickyFlags) == immersiveStickyFlags;
Adrian Roos1c2e9a12019-08-20 18:23:47 +0200816 return immersiveSticky && mWmService.mConstants.mSystemGestureExcludedByPreQStickyImmersive
Garfield Tane8d84ab2019-10-11 09:49:40 -0700817 && mActivityRecord != null && mActivityRecord.mTargetSdk < Build.VERSION_CODES.Q;
Adrian Roos019a52b2019-07-02 16:47:44 +0200818 }
819
Adrian Roos5f2c9a12019-07-03 18:31:46 +0200820 void setLastExclusionHeights(int side, int requested, int granted) {
821 boolean changed = mLastGrantedExclusionHeight[side] != granted
822 || mLastRequestedExclusionHeight[side] != requested;
823
824 if (changed) {
825 if (mLastShownChangedReported) {
826 logExclusionRestrictions(side);
827 }
828
829 mLastGrantedExclusionHeight[side] = granted;
830 mLastRequestedExclusionHeight[side] = requested;
831 }
832 }
833
chaviw40234662018-02-07 09:37:16 -0800834 interface PowerManagerWrapper {
Michael Wrighte3001042019-02-05 00:13:14 +0000835 void wakeUp(long time, @WakeReason int reason, String details);
chaviw40234662018-02-07 09:37:16 -0800836
837 boolean isInteractive();
838
839 }
840
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800841 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800842 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
wilsonshihd0fc2ca2020-03-18 22:41:55 +0800843 int viewVisibility, int ownerId, int showUserId,
844 boolean ownerCanAddInternalSystemWindow) {
845 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId, showUserId,
chaviw40234662018-02-07 09:37:16 -0800846 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
847 @Override
Michael Wrighte3001042019-02-05 00:13:14 +0000848 public void wakeUp(long time, @WakeReason int reason, String details) {
849 service.mPowerManager.wakeUp(time, reason, details);
chaviw40234662018-02-07 09:37:16 -0800850 }
851
852 @Override
853 public boolean isInteractive() {
854 return service.mPowerManager.isInteractive();
855 }
856 });
857 }
858
859 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
860 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
wilsonshihd0fc2ca2020-03-18 22:41:55 +0800861 int viewVisibility, int ownerId, int showUserId,
862 boolean ownerCanAddInternalSystemWindow, PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100863 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800864 mSession = s;
865 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800866 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800867 mToken = token;
Garfield Tane8d84ab2019-10-11 09:49:40 -0700868 mActivityRecord = mToken.asActivityRecord();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700869 mOwnerUid = ownerId;
wilsonshihd0fc2ca2020-03-18 22:41:55 +0800870 mShowUserId = showUserId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800871 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200872 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800873 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700874 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800875 mViewVisibility = viewVisibility;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800876 mPolicy = mWmService.mPolicy;
877 mContext = mWmService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800878 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700879 mSeq = seq;
chaviw40234662018-02-07 09:37:16 -0800880 mPowerManagerWrapper = powerManagerWrapper;
Vishnu Nair83537a72018-07-19 21:27:48 -0700881 mForceSeamlesslyRotate = token.mRoundedCornerOverlay;
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200882 if (DEBUG) {
883 Slog.v(TAG, "Window " + this + " client=" + c.asBinder()
884 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
885 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800886 try {
887 c.asBinder().linkToDeath(deathRecipient, 0);
888 } catch (RemoteException e) {
889 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700890 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800891 mLayoutAttached = false;
892 mIsImWindow = false;
893 mIsWallpaper = false;
894 mIsFloatingLayer = false;
895 mBaseLayer = 0;
896 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700897 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700898 mWinAnimator = null;
Jorim Jaggi268bf6882020-06-18 23:44:02 +0200899 mWpcForDisplayConfigChanges = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800900 return;
901 }
902 mDeathRecipient = deathRecipient;
903
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700904 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800905 // The multiplier here is to reserve space for multiple
906 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800907 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700908 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800909 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700910 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900911
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800912 mLayoutAttached = mAttrs.type !=
913 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700914 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
915 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
916 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800917 } else {
918 // The multiplier here is to reserve space for multiple
919 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800920 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700921 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800922 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700923 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800924 mLayoutAttached = false;
925 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
926 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
927 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800928 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700929 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800930
Garfield Tane8d84ab2019-10-11 09:49:40 -0700931 if (mActivityRecord != null && mActivityRecord.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700932 // Windows for apps that can show for all users should also show when the device is
933 // locked.
934 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700935 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800936
Craig Mautner322e4032012-07-13 13:35:20 -0700937 mWinAnimator = new WindowStateAnimator(this);
938 mWinAnimator.mAlpha = a.alpha;
939
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800940 mRequestedWidth = 0;
941 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700942 mLastRequestedWidth = 0;
943 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800944 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800945 mInputWindowHandle = new InputWindowHandle(
Riddle Hsua5eb0102020-12-03 15:57:36 +0800946 mActivityRecord != null
947 ? mActivityRecord.getInputApplicationHandle(false /* update */) : null,
Garfield Tane8d84ab2019-10-11 09:49:40 -0700948 getDisplayId());
lumarkbde15132019-12-18 22:29:43 +0800949
950 // Make sure we initial all fields before adding to parentWindow, to prevent exception
951 // during onDisplayChanged.
952 if (mIsChildWindow) {
953 ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Adding %s to %s", this, parentWindow);
954 parentWindow.addChild(this, sWindowSubLayerComparator);
955 }
Jorim Jaggi268bf6882020-06-18 23:44:02 +0200956
957 // System process or invalid process cannot register to display config change.
958 mWpcForDisplayConfigChanges = (s.mPid == MY_PID || s.mPid < 0)
959 ? null
960 : service.mAtmService.getProcessController(s.mPid, s.mUid);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800961 }
962
963 void attach() {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200964 if (DEBUG) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800965 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800966 }
967
Bryce Leed390deb2017-06-22 13:14:28 -0700968 /**
Riddle Hsub398da32019-01-21 21:48:16 +0800969 * @return {@code true} if the application runs in size compatibility mode.
970 * @see android.content.res.CompatibilityInfo#supportsScreen
971 * @see ActivityRecord#inSizeCompatMode
972 */
973 boolean inSizeCompatMode() {
974 return (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0
Garfield Tane8d84ab2019-10-11 09:49:40 -0700975 || (mActivityRecord != null && mActivityRecord.hasSizeCompatBounds()
Riddle Hsub398da32019-01-21 21:48:16 +0800976 // Exclude starting window because it is not displayed by the application.
977 && mAttrs.type != TYPE_APPLICATION_STARTING);
978 }
979
980 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700981 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
982 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700983 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700984 return mDrawnStateEvaluated;
985 }
986
987 /**
988 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
989 * be cleared when detached from parent.
990 */
991 void setDrawnStateEvaluated(boolean evaluated) {
992 mDrawnStateEvaluated = evaluated;
993 }
994
995 @Override
Wale Ogunwalec17418e2019-10-13 23:00:40 +0200996 void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) {
997 super.onParentChanged(newParent, oldParent);
Bryce Leed390deb2017-06-22 13:14:28 -0700998 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700999
1000 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -07001001 }
1002
Craig Mautnera2c77052012-03-26 12:14:43 -07001003 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001004 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001005 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001006 }
1007
1008 @Override
1009 public String getOwningPackage() {
1010 return mAttrs.packageName;
1011 }
1012
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08001013 @Override
1014 public boolean canAddInternalSystemWindow() {
1015 return mOwnerCanAddInternalSystemWindow;
1016 }
1017
Jorim Jaggif12ec0f2017-08-23 16:14:10 +02001018 @Override
1019 public boolean canAcquireSleepToken() {
1020 return mSession.mCanAcquireSleepToken;
1021 }
1022
Jorim Jaggif5834272016-04-04 20:25:41 -07001023 /**
1024 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
1025 * from {@param frame}. In other words, it applies the insets that would result if
1026 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -07001027 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
1028 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -07001029 */
Andrii Kuliandaea3572016-04-08 13:20:51 -07001030 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
1031 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
1032 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
1033 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
1034 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -07001035 frame.inset(left, top, right, bottom);
1036 }
1037
Riddle Hsuc7175762020-01-10 21:03:48 +08001038 void computeFrame(DisplayFrames displayFrames) {
1039 getLayoutingWindowFrames().setDisplayCutout(displayFrames.mDisplayCutout);
1040 computeFrameLw();
1041 // Update the source frame to provide insets to other windows during layout. If the
1042 // simulated frames exist, then this is not computing a stable result so just skip.
1043 if (mControllableInsetProvider != null && mSimulatedWindowFrames == null) {
1044 mControllableInsetProvider.updateSourceFrame();
1045 }
1046 }
1047
Evan Roskyed6767f2018-10-26 17:21:06 -07001048 @Override
chaviw1454b392018-08-06 09:54:04 -07001049 public void computeFrameLw() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001050 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001051 // This window is being replaced and either already got information that it's being
1052 // removed or we are still waiting for some information. Because of this we don't
1053 // want to apply any more changes to it, so it remains in this state until new window
1054 // appears.
1055 return;
1056 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001057 mHaveFrame = true;
1058
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001059 final Task task = getTask();
Evan Rosky4fb1e912019-03-06 13:54:43 -08001060 final boolean isFullscreenAndFillsDisplay = !inMultiWindowMode() && matchesDisplayBounds();
Robert Carre6275582016-02-29 15:45:45 -08001061 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001062 final DisplayContent dc = getDisplayContent();
Riddle Hsu6f548e92020-01-13 13:34:09 +08001063 final DisplayInfo displayInfo = getDisplayInfo();
Riddle Hsuc7175762020-01-10 21:03:48 +08001064 final WindowFrames windowFrames = getLayoutingWindowFrames();
Wale Ogunwale79f268d2015-12-18 08:25:47 -08001065
Evan Roskyed6767f2018-10-26 17:21:06 -07001066 mInsetFrame.set(getBounds());
Chong Zhangae35fef2016-03-16 15:56:55 -07001067
Jorim Jaggif5834272016-04-04 20:25:41 -07001068 // Denotes the actual frame used to calculate the insets and to perform the layout. When
1069 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
1070 // insets temporarily. By the notion of a task having a different layout frame, we can
1071 // achieve that while still moving the task around.
1072 final Rect layoutContainingFrame;
1073 final Rect layoutDisplayFrame;
1074
1075 // The offset from the layout containing frame to the actual containing frame.
1076 final int layoutXDiff;
1077 final int layoutYDiff;
Evan Rosky0d654cb2019-02-26 10:59:10 -08001078 final WindowState imeWin = mWmService.mRoot.getCurrentInputMethodWindow();
HEO SEUNGe10f4192019-11-21 10:21:04 +09001079 final boolean isInputMethodAdjustTarget = windowsAreFloating
1080 ? dc.mInputMethodTarget != null && task == dc.mInputMethodTarget.getTask()
1081 : isInputMethodTarget();
Evan Rosky0d654cb2019-02-26 10:59:10 -08001082 final boolean isImeTarget =
HEO SEUNGe10f4192019-11-21 10:21:04 +09001083 imeWin != null && imeWin.isVisibleNow() && isInputMethodAdjustTarget;
Evan Rosky4fb1e912019-03-06 13:54:43 -08001084 if (isFullscreenAndFillsDisplay || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08001085 // We use the parent frame as the containing frame for fullscreen and child windows
Riddle Hsuc7175762020-01-10 21:03:48 +08001086 windowFrames.mContainingFrame.set(windowFrames.mParentFrame);
1087 layoutDisplayFrame = windowFrames.mDisplayFrame;
1088 layoutContainingFrame = windowFrames.mParentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -07001089 layoutXDiff = 0;
1090 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -08001091 } else {
Evan Rosky6ecd67c2020-04-14 11:50:43 -07001092 windowFrames.mContainingFrame.set(getBounds());
Garfield Tane8d84ab2019-10-11 09:49:40 -07001093 if (mActivityRecord != null && !mActivityRecord.mFrozenBounds.isEmpty()) {
Jorim Jaggi0429f3522015-12-22 16:29:16 +01001094
1095 // If the bounds are frozen, we still want to translate the window freely and only
1096 // freeze the size.
Garfield Tane8d84ab2019-10-11 09:49:40 -07001097 Rect frozen = mActivityRecord.mFrozenBounds.peek();
Riddle Hsuc7175762020-01-10 21:03:48 +08001098 windowFrames.mContainingFrame.right =
1099 windowFrames.mContainingFrame.left + frozen.width();
1100 windowFrames.mContainingFrame.bottom =
1101 windowFrames.mContainingFrame.top + frozen.height();
Jorim Jaggi0429f3522015-12-22 16:29:16 +01001102 }
Robert Carrfc03b2b2016-03-31 15:22:02 -07001103 // IME is up and obscuring this window. Adjust the window position so it is visible.
Evan Rosky0d654cb2019-02-26 10:59:10 -08001104 if (isImeTarget) {
1105 if (inFreeformWindowingMode()) {
1106 // Push the freeform window up to make room for the IME. However, don't push
1107 // it up past the top of the screen.
Riddle Hsuc7175762020-01-10 21:03:48 +08001108 final int bottomOverlap = windowFrames.mContainingFrame.bottom
1109 - windowFrames.mVisibleFrame.bottom;
Evan Rosky0d654cb2019-02-26 10:59:10 -08001110 if (bottomOverlap > 0) {
Riddle Hsuc7175762020-01-10 21:03:48 +08001111 final int distanceToTop = Math.max(windowFrames.mContainingFrame.top
1112 - windowFrames.mContentFrame.top, 0);
Evan Rosky0d654cb2019-02-26 10:59:10 -08001113 int offs = Math.min(bottomOverlap, distanceToTop);
Riddle Hsuc7175762020-01-10 21:03:48 +08001114 windowFrames.mContainingFrame.offset(0, -offs);
HEO SEUNGe10f4192019-11-21 10:21:04 +09001115 mInsetFrame.offset(0, -offs);
Evan Rosky0d654cb2019-02-26 10:59:10 -08001116 }
Riddle Hsuc7175762020-01-10 21:03:48 +08001117 } else if (!inPinnedWindowingMode() && windowFrames.mContainingFrame.bottom
1118 > windowFrames.mParentFrame.bottom) {
Winson Chungd73e94b52017-05-31 16:25:30 -07001119 // But in docked we want to behave like fullscreen and behave as if the task
1120 // were given smaller bounds for the purposes of layout. Skip adjustments for
1121 // the pinned stack, they are handled separately in the PinnedStackController.
Riddle Hsuc7175762020-01-10 21:03:48 +08001122 windowFrames.mContainingFrame.bottom = windowFrames.mParentFrame.bottom;
Winson Chungd73e94b52017-05-31 16:25:30 -07001123 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -07001124 }
Skuhne81c524a2015-08-12 13:34:14 -07001125
Robert Carre6275582016-02-29 15:45:45 -08001126 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -07001127 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
1128 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -08001129 // "content frame" since it is allowed to be outside the visible desktop.
Riddle Hsuc7175762020-01-10 21:03:48 +08001130 if (windowFrames.mContainingFrame.isEmpty()) {
1131 windowFrames.mContainingFrame.set(windowFrames.mContentFrame);
Skuhne81c524a2015-08-12 13:34:14 -07001132 }
Doris Liu06d582d2015-06-01 13:18:43 -07001133 }
Adrian Roos604ef952018-05-15 20:13:13 +02001134
Riddle Hsuc7175762020-01-10 21:03:48 +08001135 layoutDisplayFrame = new Rect(windowFrames.mDisplayFrame);
1136 windowFrames.mDisplayFrame.set(windowFrames.mContainingFrame);
1137 layoutXDiff = mInsetFrame.left - windowFrames.mContainingFrame.left;
1138 layoutYDiff = mInsetFrame.top - windowFrames.mContainingFrame.top;
Evan Roskyed6767f2018-10-26 17:21:06 -07001139 layoutContainingFrame = mInsetFrame;
Riddle Hsu6f548e92020-01-13 13:34:09 +08001140 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Riddle Hsuc7175762020-01-10 21:03:48 +08001141 subtractInsets(windowFrames.mDisplayFrame, layoutContainingFrame, layoutDisplayFrame,
chaviw1454b392018-08-06 09:54:04 -07001142 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -07001143 if (!layoutInParentFrame()) {
Riddle Hsuc7175762020-01-10 21:03:48 +08001144 subtractInsets(windowFrames.mContainingFrame, layoutContainingFrame,
1145 windowFrames.mParentFrame, mTmpRect);
1146 subtractInsets(mInsetFrame, layoutContainingFrame, windowFrames.mParentFrame,
chaviw553b0212018-07-12 13:37:01 -07001147 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -07001148 }
Jorim Jaggif5834272016-04-04 20:25:41 -07001149 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -07001150 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001151
Riddle Hsuc7175762020-01-10 21:03:48 +08001152 final int pw = windowFrames.mContainingFrame.width();
1153 final int ph = windowFrames.mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001154
Dianne Hackborn1743b642012-03-12 17:04:43 -07001155 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1156 mLastRequestedWidth = mRequestedWidth;
1157 mLastRequestedHeight = mRequestedHeight;
Riddle Hsuc7175762020-01-10 21:03:48 +08001158 windowFrames.setContentChanged(true);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001159 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001160
Riddle Hsuc7175762020-01-10 21:03:48 +08001161 final int fw = windowFrames.mFrame.width();
1162 final int fh = windowFrames.mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001163
Riddle Hsuc7175762020-01-10 21:03:48 +08001164 applyGravityAndUpdateFrame(windowFrames, layoutContainingFrame, layoutDisplayFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -07001165
Craig Mautnera248eee2013-05-07 11:41:27 -07001166 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001167 // final window frame.
Riddle Hsuc7175762020-01-10 21:03:48 +08001168 if (windowsAreFloating && !windowFrames.mFrame.isEmpty()) {
1169 final int visBottom = windowFrames.mVisibleFrame.bottom;
1170 final int contentBottom = windowFrames.mContentFrame.bottom;
1171 windowFrames.mContentFrame.set(windowFrames.mFrame);
1172 windowFrames.mVisibleFrame.set(windowFrames.mContentFrame);
1173 windowFrames.mStableFrame.set(windowFrames.mContentFrame);
Evan Rosky0d654cb2019-02-26 10:59:10 -08001174 if (isImeTarget && inFreeformWindowingMode()) {
1175 // After displacing a freeform window to make room for the ime, any part of
1176 // the window still covered by IME should be inset.
Riddle Hsuc7175762020-01-10 21:03:48 +08001177 if (contentBottom + layoutYDiff < windowFrames.mContentFrame.bottom) {
1178 windowFrames.mContentFrame.bottom = contentBottom + layoutYDiff;
Evan Rosky0d654cb2019-02-26 10:59:10 -08001179 }
Riddle Hsuc7175762020-01-10 21:03:48 +08001180 if (visBottom + layoutYDiff < windowFrames.mVisibleFrame.bottom) {
1181 windowFrames.mVisibleFrame.bottom = visBottom + layoutYDiff;
Evan Rosky0d654cb2019-02-26 10:59:10 -08001182 }
1183 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001184 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Riddle Hsuc7175762020-01-10 21:03:48 +08001185 windowFrames.mContentFrame.set(windowFrames.mFrame);
1186 if (!windowFrames.mFrame.equals(windowFrames.mLastFrame)) {
Jorim Jaggi192086e2016-03-11 17:17:03 +01001187 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -08001188 }
Skuhne81c524a2015-08-12 13:34:14 -07001189 } else {
Riddle Hsuc7175762020-01-10 21:03:48 +08001190 windowFrames.mContentFrame.set(
1191 Math.max(windowFrames.mContentFrame.left, windowFrames.mFrame.left),
1192 Math.max(windowFrames.mContentFrame.top, windowFrames.mFrame.top),
1193 Math.min(windowFrames.mContentFrame.right, windowFrames.mFrame.right),
1194 Math.min(windowFrames.mContentFrame.bottom, windowFrames.mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001195
Riddle Hsuc7175762020-01-10 21:03:48 +08001196 windowFrames.mVisibleFrame.set(
1197 Math.max(windowFrames.mVisibleFrame.left, windowFrames.mFrame.left),
1198 Math.max(windowFrames.mVisibleFrame.top, windowFrames.mFrame.top),
1199 Math.min(windowFrames.mVisibleFrame.right, windowFrames.mFrame.right),
1200 Math.min(windowFrames.mVisibleFrame.bottom, windowFrames.mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001201
Riddle Hsuc7175762020-01-10 21:03:48 +08001202 windowFrames.mStableFrame.set(
1203 Math.max(windowFrames.mStableFrame.left, windowFrames.mFrame.left),
1204 Math.max(windowFrames.mStableFrame.top, windowFrames.mFrame.top),
1205 Math.min(windowFrames.mStableFrame.right, windowFrames.mFrame.right),
1206 Math.min(windowFrames.mStableFrame.bottom, windowFrames.mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -07001207 }
Adrian Roosfa104232014-06-20 16:10:14 -07001208
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001209 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Riddle Hsuc7175762020-01-10 21:03:48 +08001210 final WmDisplayCutout c = windowFrames.mDisplayCutout.calculateRelativeTo(
1211 windowFrames.mDisplayFrame);
1212 windowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets());
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001213 } else {
Riddle Hsu6f548e92020-01-13 13:34:09 +08001214 windowFrames.calculateInsets(windowsAreFloating, isFullscreenAndFillsDisplay,
1215 getDisplayFrames(dc.mDisplayFrames).mUnrestricted);
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001216 }
Adrian Roosfa104232014-06-20 16:10:14 -07001217
Riddle Hsuc7175762020-01-10 21:03:48 +08001218 windowFrames.setDisplayCutout(
1219 windowFrames.mDisplayCutout.calculateRelativeTo(windowFrames.mFrame));
Jorim Jaggibae2b152018-04-18 17:27:27 +02001220
Jorim Jaggi656f6502016-04-11 21:08:17 -07001221 // Offset the actual frame by the amount layout frame is off.
Riddle Hsuc7175762020-01-10 21:03:48 +08001222 windowFrames.offsetFrames(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001223
Riddle Hsuc7175762020-01-10 21:03:48 +08001224 windowFrames.mCompatFrame.set(windowFrames.mFrame);
Riddle Hsub398da32019-01-21 21:48:16 +08001225 if (inSizeCompatMode()) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001226 // If there is a size compatibility scale being applied to the
1227 // window, we need to apply this to its insets so that they are
1228 // reported to the app in its coordinate space.
Riddle Hsuc7175762020-01-10 21:03:48 +08001229 windowFrames.scaleInsets(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001230
1231 // Also the scaled frame that we report to the app needs to be
1232 // adjusted to be in its coordinate space.
Riddle Hsuc7175762020-01-10 21:03:48 +08001233 windowFrames.mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001234 }
1235
Riddle Hsuc7175762020-01-10 21:03:48 +08001236 if (mIsWallpaper && (fw != windowFrames.mFrame.width()
1237 || fh != windowFrames.mFrame.height())) {
Riddle Hsu6da58ac2020-04-02 01:04:40 +08001238 dc.mWallpaperController.updateWallpaperOffset(this, false /* sync */);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001239 }
1240
Evan Rosky70213702019-11-05 10:26:24 -08001241 // Calculate relative frame
Riddle Hsuc7175762020-01-10 21:03:48 +08001242 windowFrames.mRelFrame.set(windowFrames.mFrame);
Evan Rosky70213702019-11-05 10:26:24 -08001243 WindowContainer parent = getParent();
1244 int parentLeft = 0;
1245 int parentTop = 0;
1246 if (mIsChildWindow) {
1247 parentLeft = ((WindowState) parent).mWindowFrames.mFrame.left;
1248 parentTop = ((WindowState) parent).mWindowFrames.mFrame.top;
1249 } else if (parent != null) {
Evan Rosky6ecd67c2020-04-14 11:50:43 -07001250 final Rect parentBounds = parent.getBounds();
Evan Rosky70213702019-11-05 10:26:24 -08001251 parentLeft = parentBounds.left;
1252 parentTop = parentBounds.top;
1253 }
Riddle Hsuc7175762020-01-10 21:03:48 +08001254 windowFrames.mRelFrame.offsetTo(windowFrames.mFrame.left - parentLeft,
1255 windowFrames.mFrame.top - parentTop);
Evan Rosky70213702019-11-05 10:26:24 -08001256
Adam Pardyl8c2d19c2019-09-16 17:15:38 +02001257 if (DEBUG_LAYOUT || DEBUG) {
1258 Slog.v(TAG, "Resolving (mRequestedWidth="
1259 + mRequestedWidth + ", mRequestedheight="
1260 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
Riddle Hsuc7175762020-01-10 21:03:48 +08001261 + "): frame=" + windowFrames.mFrame.toShortString()
1262 + " " + windowFrames.getInsetsInfo()
Adam Pardyl8c2d19c2019-09-16 17:15:38 +02001263 + " " + mAttrs.getTitle());
1264 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001265 }
1266
Bryce Leef3c6a472017-11-14 14:53:06 -08001267 // TODO: Look into whether this override is still necessary.
1268 @Override
1269 public Rect getBounds() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001270 if (mActivityRecord != null) {
1271 return mActivityRecord.getBounds();
Bryce Leef3c6a472017-11-14 14:53:06 -08001272 } else {
1273 return super.getBounds();
1274 }
1275 }
1276
Craig Mautnera2c77052012-03-26 12:14:43 -07001277 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001278 public Rect getFrameLw() {
chaviw492139a2018-07-16 16:07:35 -07001279 return mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001280 }
1281
Evan Rosky70213702019-11-05 10:26:24 -08001282 /** Accessor for testing */
1283 Rect getRelativeFrameLw() {
1284 return mWindowFrames.mRelFrame;
1285 }
1286
Craig Mautnera2c77052012-03-26 12:14:43 -07001287 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001288 public Rect getDisplayFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001289 return mWindowFrames.mDisplayFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001290 }
1291
Craig Mautnera2c77052012-03-26 12:14:43 -07001292 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001293 public Rect getContentFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001294 return mWindowFrames.mContentFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001295 }
1296
Craig Mautnera2c77052012-03-26 12:14:43 -07001297 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001298 public Rect getVisibleFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001299 return mWindowFrames.mVisibleFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001300 }
1301
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001302 Rect getStableFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001303 return mWindowFrames.mStableFrame;
1304 }
1305
1306 Rect getDecorFrame() {
1307 return mWindowFrames.mDecorFrame;
1308 }
1309
1310 Rect getParentFrame() {
1311 return mWindowFrames.mParentFrame;
1312 }
1313
1314 Rect getContainingFrame() {
1315 return mWindowFrames.mContainingFrame;
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001316 }
1317
chaviwcdba9a42018-07-19 11:36:42 -07001318 WmDisplayCutout getWmDisplayCutout() {
1319 return mWindowFrames.mDisplayCutout;
1320 }
1321
chaviw9c81e632018-07-31 11:17:52 -07001322 void getCompatFrame(Rect outFrame) {
1323 outFrame.set(mWindowFrames.mCompatFrame);
1324 }
1325
1326 void getCompatFrameSize(Rect outFrame) {
1327 outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height());
1328 }
1329
Craig Mautnera2c77052012-03-26 12:14:43 -07001330 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001331 public boolean getGivenInsetsPendingLw() {
1332 return mGivenInsetsPending;
1333 }
1334
Craig Mautnera2c77052012-03-26 12:14:43 -07001335 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001336 public Rect getGivenContentInsetsLw() {
1337 return mGivenContentInsets;
1338 }
1339
Craig Mautnera2c77052012-03-26 12:14:43 -07001340 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 public Rect getGivenVisibleInsetsLw() {
1342 return mGivenVisibleInsets;
1343 }
1344
Craig Mautnera2c77052012-03-26 12:14:43 -07001345 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001346 public WindowManager.LayoutParams getAttrs() {
1347 return mAttrs;
1348 }
1349
Craig Mautner812d2ca2012-09-27 15:35:34 -07001350 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001351 public int getSystemUiVisibility() {
1352 return mSystemUiVisibility;
1353 }
1354
Craig Mautner19d59bc2012-09-04 11:15:56 -07001355 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001356 public int getSurfaceLayer() {
1357 return mLayer;
1358 }
1359
Craig Mautner812d2ca2012-09-27 15:35:34 -07001360 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001361 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001362 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001363 }
1364
1365 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001366 public IApplicationToken getAppToken() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001367 return mActivityRecord != null ? mActivityRecord.appToken : null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001368 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001369
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001370 @Override
1371 public boolean isVoiceInteraction() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001372 return mActivityRecord != null && mActivityRecord.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001373 }
1374
Robert Carr31aa98b2016-07-20 15:29:03 -07001375 boolean setReportResizeHints() {
chaviw9c81e632018-07-31 11:17:52 -07001376 return mWindowFrames.setReportResizeHints();
Craig Mautner4c5eb222013-11-18 12:59:05 -08001377 }
1378
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001379 /**
1380 * Adds the window to the resizing list if any of the parameters we use to track the window
1381 * dimensions or insets have changed.
1382 */
1383 void updateResizingWindowIfNeeded() {
1384 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001385 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001386 return;
1387 }
1388
chaviw9c81e632018-07-31 11:17:52 -07001389 boolean didFrameInsetsChange = setReportResizeHints();
Jorim Jaggi381cd722019-03-27 17:33:02 +01001390 boolean configChanged = !isLastConfigReportedToClient();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001391 if (DEBUG_CONFIGURATION && configChanged) {
1392 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1393 }
1394
1395 final boolean dragResizingChanged = isDragResizeChanged()
1396 && !isDragResizingChangeReported();
1397
Adam Pardyl8c2d19c2019-09-16 17:15:38 +02001398 if (DEBUG) {
1399 Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1400 + " dragResizingChanged=" + dragResizingChanged
1401 + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame);
1402 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001403
1404 // We update mLastFrame always rather than in the conditional with the last inset
1405 // variables, because mFrameSizeChanged only tracks the width and height changing.
Riddle Hsu2652da82019-11-29 18:08:26 +08001406 updateLastFrames();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001407
chaviw73abde92020-05-18 17:56:35 -07001408 // Add a window that is using blastSync to the resizing list if it hasn't been reported
1409 // already. This because the window is waiting on a finishDrawing from the client.
chaviw9c81e632018-07-31 11:17:52 -07001410 if (didFrameInsetsChange
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001411 || winAnimator.mSurfaceResized
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001412 || configChanged
1413 || dragResizingChanged
chaviw73abde92020-05-18 17:56:35 -07001414 || mReportOrientationChanged
Robert Carr52385c32020-06-23 15:56:28 -07001415 || shouldSendRedrawForSync()) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001416 ProtoLog.v(WM_DEBUG_RESIZE,
1417 "Resize reasons for w=%s: %s surfaceResized=%b configChanged=%b "
1418 + "dragResizingChanged=%b reportOrientationChanged=%b",
1419 this, mWindowFrames.getInsetsChangedInfo(), winAnimator.mSurfaceResized,
1420 configChanged, dragResizingChanged, mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001421
1422 // If it's a dead window left on screen, and the configuration changed, there is nothing
1423 // we can do about it. Remove the window now.
Garfield Tane8d84ab2019-10-11 09:49:40 -07001424 if (mActivityRecord != null && mAppDied) {
1425 mActivityRecord.removeDeadWindows();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001426 return;
1427 }
1428
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001429 updateLastInsetValues();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001430 mWmService.makeWindowFreezingScreenIfNeededLocked(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001431
1432 // If the orientation is changing, or we're starting or ending a drag resizing action,
1433 // then we need to hold off on unfreezing the display until this window has been
1434 // redrawn; to do that, we need to go through the process of getting informed by the
1435 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001436 if (getOrientationChanging() || dragResizingChanged) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001437 if (getOrientationChanging()) {
1438 Slog.v(TAG_WM, "Orientation start waiting for draw"
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001439 + ", mDrawState=DRAW_PENDING in " + this
1440 + ", surfaceController " + winAnimator.mSurfaceController);
1441 }
Adrian Roosb125e0b2019-10-02 14:55:14 +02001442 if (dragResizingChanged) {
1443 ProtoLog.v(WM_DEBUG_RESIZE,
1444 "Resize start waiting for draw, "
1445 + "mDrawState=DRAW_PENDING in %s, surfaceController %s",
1446 this, winAnimator.mSurfaceController);
1447 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001448 winAnimator.mDrawState = DRAW_PENDING;
Garfield Tane8d84ab2019-10-11 09:49:40 -07001449 if (mActivityRecord != null) {
1450 mActivityRecord.clearAllDrawn();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001451 }
1452 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001453 if (!mWmService.mResizingWindows.contains(this)) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001454 ProtoLog.v(WM_DEBUG_RESIZE, "Resizing window %s", this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001455 mWmService.mResizingWindows.add(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001456 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001457 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001458 if (isDrawnLw()) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001459 ProtoLog.v(WM_DEBUG_ORIENTATION,
1460 "Orientation not waiting for draw in %s, surfaceController %s", this,
1461 winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001462 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001463 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001464 - mWmService.mDisplayFreezeTime);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001465 }
1466 }
1467 }
1468
Bryce Lee8c3cf382017-07-06 19:47:10 -07001469 boolean getOrientationChanging() {
1470 // In addition to the local state flag, we must also consider the difference in the last
1471 // reported configuration vs. the current state. If the client code has not been informed of
1472 // the change, logic dependent on having finished processing the orientation, such as
1473 // unfreezing, could be improperly triggered.
1474 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1475 // this is not necessarily what the client has processed yet. Find a
1476 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001477 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001478 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001479 && !mSeamlesslyRotated
1480 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001481 }
1482
1483 void setOrientationChanging(boolean changing) {
1484 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001485 mOrientationChangeTimedOut = false;
1486 }
1487
1488 void orientationChangeTimedOut() {
1489 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001490 }
1491
Tiger Huanged6794e2019-05-07 20:07:59 +08001492 @Override
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001493 DisplayContent getDisplayContent() {
1494 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001495 }
1496
Adrian Roos5251b1d2018-03-23 18:57:43 +01001497 @Override
1498 void onDisplayChanged(DisplayContent dc) {
Tiger Huang2a8931a2020-04-16 19:25:11 +08001499 if (dc != null && mDisplayContent != null && dc != mDisplayContent
Tiger Huangfdec32c2020-04-10 02:07:30 +08001500 && mDisplayContent.mInputMethodInputTarget == this) {
1501 dc.setInputMethodInputTarget(mDisplayContent.mInputMethodInputTarget);
1502 mDisplayContent.mInputMethodInputTarget = null;
1503 }
Adrian Roos5251b1d2018-03-23 18:57:43 +01001504 super.onDisplayChanged(dc);
1505 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
Garfield Tane223e682019-04-15 09:59:25 -07001506 if (dc != null && mInputWindowHandle.displayId != dc.getDisplayId()) {
Adrian Roos5251b1d2018-03-23 18:57:43 +01001507 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001508 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001509 }
1510 }
1511
Riddle Hsu55d7c402020-02-26 22:49:29 +08001512 /** @return The display frames in use by this window. */
Riddle Hsu6f548e92020-01-13 13:34:09 +08001513 DisplayFrames getDisplayFrames(DisplayFrames originalFrames) {
1514 final DisplayFrames diplayFrames = mToken.getFixedRotationTransformDisplayFrames();
1515 if (diplayFrames != null) {
1516 return diplayFrames;
1517 }
1518 return originalFrames;
1519 }
1520
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001521 DisplayInfo getDisplayInfo() {
Riddle Hsu6f548e92020-01-13 13:34:09 +08001522 final DisplayInfo displayInfo = mToken.getFixedRotationTransformDisplayInfo();
1523 if (displayInfo != null) {
1524 return displayInfo;
1525 }
1526 return getDisplayContent().getDisplayInfo();
1527 }
1528
Riddle Hsu0c713fd2020-09-08 23:34:15 +08001529 /**
1530 * Returns the insets state for the client. Its sources may be the copies with visibility
1531 * modification according to the state of transient bars.
1532 */
Riddle Hsu6f548e92020-01-13 13:34:09 +08001533 InsetsState getInsetsState() {
Riddle Hsu6f548e92020-01-13 13:34:09 +08001534 return getDisplayContent().getInsetsPolicy().getInsetsForDispatch(this);
Chong Zhang09b21ef2015-09-14 10:20:21 -07001535 }
1536
Jorim Jaggife762342016-10-13 14:33:27 +02001537 @Override
1538 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001539 final DisplayContent displayContent = getDisplayContent();
1540 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001541 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001542 }
1543 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001544 }
1545
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001546 Task getTask() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001547 return mActivityRecord != null ? mActivityRecord.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001548 }
1549
Charles Chen7d550c42020-05-15 17:32:03 +08001550 @Nullable ActivityStack getRootTask() {
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08001551 final Task task = getTask();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001552 if (task != null) {
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08001553 return (ActivityStack) task.getRootTask();
Craig Mautnerd9a22882013-03-16 15:00:36 -07001554 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001555 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1556 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001557 final DisplayContent dc = getDisplayContent();
Andrii Kulian4c0fd0d2020-03-29 13:32:14 -07001558 return mAttrs.type >= FIRST_SYSTEM_WINDOW
1559 && dc != null ? dc.getDefaultTaskDisplayArea().getRootHomeTask() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001560 }
1561
Skuhnef932e562015-08-20 12:07:30 -07001562 /**
Evan Rosky364c9122020-06-04 16:09:31 -07001563 * This is a form of rectangle "difference". It cut off each dimension of rect by the amount
1564 * that toRemove is "pushing into" it from the outside. Any dimension that fully contains
1565 * toRemove won't change.
1566 */
1567 private void cutRect(Rect rect, Rect toRemove) {
1568 if (toRemove.isEmpty()) return;
1569 if (toRemove.top < rect.bottom && toRemove.bottom > rect.top) {
1570 if (toRemove.right >= rect.right && toRemove.left >= rect.left) {
1571 rect.right = toRemove.left;
1572 } else if (toRemove.left <= rect.left && toRemove.right <= rect.right) {
1573 rect.left = toRemove.right;
1574 }
1575 }
1576 if (toRemove.left < rect.right && toRemove.right > rect.left) {
1577 if (toRemove.bottom >= rect.bottom && toRemove.top >= rect.top) {
1578 rect.bottom = toRemove.top;
1579 } else if (toRemove.top <= rect.top && toRemove.bottom <= rect.bottom) {
1580 rect.top = toRemove.bottom;
1581 }
1582 }
1583 }
1584
1585 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001586 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001587 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001588 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001589 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001590 final Task task = getTask();
1591 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001592 bounds.setEmpty();
Wale Ogunwale2b19b6042015-09-18 15:14:59 -07001593 mTmpRect.setEmpty();
1594 if (intersectWithStackBounds) {
Wale Ogunwale0b3d2922019-12-30 08:55:07 -08001595 final ActivityStack stack = task.getStack();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001596 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001597 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b6042015-09-18 15:14:59 -07001598 } else {
1599 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001600 }
Evan Rosky364c9122020-06-04 16:09:31 -07001601 if (inSplitScreenPrimaryWindowingMode()) {
1602 // If this is in the primary split and the home stack is the top visible task in
1603 // the secondary split, it means this is "minimized" and thus must prevent
1604 // overlapping with home.
1605 // TODO(b/158242495): get rid of this when drag/drop can use surface bounds.
1606 final ActivityStack rootSecondary =
1607 task.getDisplayArea().getRootSplitScreenSecondaryTask();
1608 if (rootSecondary.isActivityTypeHome() || rootSecondary.isActivityTypeRecents()) {
1609 final WindowContainer topTask = rootSecondary.getTopChild();
1610 if (topTask.isVisible()) {
1611 cutRect(mTmpRect, topTask.getBounds());
1612 }
1613 }
1614 }
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001615 }
Wale Ogunwale2b19b6042015-09-18 15:14:59 -07001616
chaviw553b0212018-07-12 13:37:01 -07001617 bounds.set(mWindowFrames.mVisibleFrame);
Chong Zhang9184ec62015-09-24 12:32:21 -07001618 if (intersectWithStackBounds) {
1619 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b6042015-09-18 15:14:59 -07001620 }
1621
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001622 if (bounds.isEmpty()) {
chaviw492139a2018-07-16 16:07:35 -07001623 bounds.set(mWindowFrames.mFrame);
Wale Ogunwale2b19b6042015-09-18 15:14:59 -07001624 if (intersectWithStackBounds) {
1625 bounds.intersect(mTmpRect);
1626 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001627 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001628 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001629 }
1630
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001631 public long getInputDispatchingTimeoutNanos() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001632 return mActivityRecord != null
1633 ? mActivityRecord.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001634 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1635 }
1636
Craig Mautnere8552142012-11-07 13:55:47 -08001637 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001638 public boolean hasAppShownWindows() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001639 return mActivityRecord != null && (mActivityRecord.firstWindowDrawn || mActivityRecord.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001640 }
1641
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001642 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1643 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1644 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1645 if (dtdx < -.000001f || dtdx > .000001f) return false;
1646 if (dsdy < -.000001f || dsdy > .000001f) return false;
1647 return true;
1648 }
1649
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001650 void prelayout() {
Riddle Hsub398da32019-01-21 21:48:16 +08001651 if (inSizeCompatMode()) {
1652 mGlobalScale = mToken.getSizeCompatScale();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001653 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001654 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001655 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001656 }
1657 }
1658
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001659 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001660 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001661 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
lumark9bca6b42019-10-17 18:35:22 +08001662 || (isAnimating(TRANSITION | PARENTS)
1663 && !getDisplayContent().mAppTransition.isTransitionSet()))) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001664 return true;
1665 }
1666
Wale Ogunwale44f21802016-09-02 12:49:48 -07001667 return super.hasContentToDisplay();
1668 }
1669
1670 @Override
1671 boolean isVisible() {
chaviw15ad49f2019-04-24 15:05:39 -07001672 return wouldBeVisibleIfPolicyIgnored() && isVisibleByPolicy()
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001673 // If we don't have a provider, this window isn't used as a window generating
1674 // insets, so nobody can hide it over the inset APIs.
Jorim Jaggi956ca412019-01-07 14:49:14 +01001675 && (mControllableInsetProvider == null
1676 || mControllableInsetProvider.isClientVisible());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001677 }
1678
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001679 /**
chaviw15ad49f2019-04-24 15:05:39 -07001680 * Ensures that all the policy visibility bits are set.
1681 * @return {@code true} if all flags about visiblity are set
1682 */
1683 boolean isVisibleByPolicy() {
1684 return (mPolicyVisibility & POLICY_VISIBILITY_ALL) == POLICY_VISIBILITY_ALL;
1685 }
1686
1687 void clearPolicyVisibilityFlag(int policyVisibilityFlag) {
1688 mPolicyVisibility &= ~policyVisibilityFlag;
chaviwbb6bd8a2019-05-28 17:05:28 -07001689 mWmService.scheduleAnimationLocked();
chaviw15ad49f2019-04-24 15:05:39 -07001690 }
1691
1692 void setPolicyVisibilityFlag(int policyVisibilityFlag) {
1693 mPolicyVisibility |= policyVisibilityFlag;
chaviwbb6bd8a2019-05-28 17:05:28 -07001694 mWmService.scheduleAnimationLocked();
chaviw15ad49f2019-04-24 15:05:39 -07001695 }
1696
1697 private boolean isLegacyPolicyVisibility() {
1698 return (mPolicyVisibility & LEGACY_POLICY_VISIBILITY) != 0;
1699 }
1700
1701 /**
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001702 * @return {@code true} if the window would be visible if we'd ignore policy visibility,
1703 * {@code false} otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001704 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001705 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001706 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001707 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001708 }
1709
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001710 @Override
1711 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001712 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001713 }
1714
1715 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001716 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1717 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001718 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001719 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1720 boolean isWinVisibleLw() {
Issei Suzuki1669ea42019-11-06 14:20:59 +01001721 return (mActivityRecord == null || mActivityRecord.mVisibleRequested
lumark5bd11af2019-12-21 01:52:28 +08001722 || mActivityRecord.isAnimating(TRANSITION | PARENTS)) && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001723 }
1724
1725 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001726 * The same as isVisible(), but follows the current hidden state of the associated app token,
1727 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001728 */
1729 boolean isVisibleNow() {
Issei Suzukif2f6c912019-11-08 11:24:18 +01001730 return (mToken.isVisible() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001731 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001732 }
1733
1734 /**
1735 * Can this window possibly be a drag/drop target? The test here is
1736 * a combination of the above "visible now" with the check that the
1737 * Input Manager uses when discarding windows from input consideration.
1738 */
1739 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001740 return isVisibleNow() && !mRemoved
1741 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001742 }
1743
1744 /**
1745 * Same as isVisible(), but we also count it as visible between the
1746 * call to IWindowSession.add() and the first relayout().
1747 */
1748 boolean isVisibleOrAdding() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001749 final ActivityRecord atoken = mActivityRecord;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001750 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
chaviw15ad49f2019-04-24 15:05:39 -07001751 && isVisibleByPolicy() && !isParentWindowHidden()
Issei Suzuki1669ea42019-11-06 14:20:59 +01001752 && (atoken == null || atoken.mVisibleRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001753 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001754 }
1755
1756 /**
1757 * Is this window currently on-screen? It is on-screen either if it
1758 * is visible or it is currently running an animation before no longer
1759 * being visible.
1760 */
1761 boolean isOnScreen() {
chaviw15ad49f2019-04-24 15:05:39 -07001762 if (!mHasSurface || mDestroying || !isVisibleByPolicy()) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001763 return false;
1764 }
Garfield Tane8d84ab2019-10-11 09:49:40 -07001765 final ActivityRecord atoken = mActivityRecord;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001766 if (atoken != null) {
Issei Suzuki1669ea42019-11-06 14:20:59 +01001767 return ((!isParentWindowHidden() && atoken.mVisibleRequested)
lumark9bca6b42019-10-17 18:35:22 +08001768 || isAnimating(TRANSITION | PARENTS));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001769 }
lumark9bca6b42019-10-17 18:35:22 +08001770 return !isParentWindowHidden() || isAnimating(TRANSITION | PARENTS);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001771 }
1772
Galia Peycheva70b55712020-03-16 18:31:34 +01001773 boolean isDreamWindow() {
1774 return mActivityRecord != null
1775 && mActivityRecord.getActivityType() == ACTIVITY_TYPE_DREAM;
1776 }
1777
Alex Johnston302c1fe2020-06-18 20:00:51 +01001778 boolean isSecureLocked() {
1779 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SECURE) != 0) {
1780 return true;
1781 }
1782 return !DevicePolicyCache.getInstance().isScreenCaptureAllowed(mShowUserId,
1783 mOwnerCanAddInternalSystemWindow);
1784 }
1785
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001786 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001787 * Whether this window's drawn state might affect the drawn states of the app token.
1788 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001789 * @return true if the window should be considered while evaluating allDrawn flags.
1790 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001791 boolean mightAffectAllDrawn() {
1792 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1793 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1794 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001795 }
1796
1797 /**
1798 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1799 * it must be drawn before allDrawn can become true.
1800 */
1801 boolean isInteresting() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001802 return mActivityRecord != null && !mAppDied
1803 && (!mActivityRecord.isFreezingScreen() || !mAppFreezing)
Jorim Jaggi995e1062019-06-06 14:03:41 +02001804 && mViewVisibility == View.VISIBLE;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001805 }
1806
1807 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001808 * Like isOnScreen(), but we don't return true if the window is part
1809 * of a transition that has not yet been started.
1810 */
1811 boolean isReadyForDisplay() {
lumark588a3e82018-07-20 18:53:54 +08001812 if (mToken.waitingToShow && getDisplayContent().mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001813 return false;
1814 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001815 final boolean parentAndClientVisible = !isParentWindowHidden()
Issei Suzukif2f6c912019-11-08 11:24:18 +01001816 && mViewVisibility == View.VISIBLE && mToken.isVisible();
chaviw15ad49f2019-04-24 15:05:39 -07001817 return mHasSurface && isVisibleByPolicy() && !mDestroying
lumark9bca6b42019-10-17 18:35:22 +08001818 && (parentAndClientVisible || isAnimating(TRANSITION | PARENTS));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001819 }
1820
Riddle Hsu84bc3d72019-12-19 19:24:07 +08001821 boolean isFullyTransparent() {
1822 return mAttrs.alpha == 0f;
1823 }
1824
1825 /**
1826 * @return Whether the window can affect SystemUI flags, meaning that SystemUI (system bars,
1827 * for example) will be affected by the flags specified in this window. This is the
1828 * case when the surface is on screen but not exiting.
1829 */
1830 boolean canAffectSystemUiFlags() {
1831 if (isFullyTransparent()) {
Jorim Jaggi72207752018-01-08 13:16:59 +01001832 return false;
1833 }
Garfield Tane8d84ab2019-10-11 09:49:40 -07001834 if (mActivityRecord == null) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001835 final boolean shown = mWinAnimator.getShown();
1836 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001837 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001838 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001839 final Task task = getTask();
1840 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
Issei Suzukif2f6c912019-11-08 11:24:18 +01001841 return canFromTask && mActivityRecord.isVisible();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001842 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001843 }
1844
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001845 /**
1846 * Like isOnScreen, but returns false if the surface hasn't yet
1847 * been drawn.
1848 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001849 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001850 public boolean isDisplayedLw() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001851 final ActivityRecord atoken = mActivityRecord;
chaviw15ad49f2019-04-24 15:05:39 -07001852 return isDrawnLw() && isVisibleByPolicy()
Issei Suzuki1669ea42019-11-06 14:20:59 +01001853 && ((!isParentWindowHidden() && (atoken == null || atoken.mVisibleRequested))
lumark9bca6b42019-10-17 18:35:22 +08001854 || isAnimating(TRANSITION | PARENTS));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001855 }
1856
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001857 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001858 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001859 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001860 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001861 public boolean isAnimatingLw() {
lumark9bca6b42019-10-17 18:35:22 +08001862 return isAnimating(TRANSITION | PARENTS);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001863 }
1864
Craig Mautner812d2ca2012-09-27 15:35:34 -07001865 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001866 public boolean isGoneForLayoutLw() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07001867 final ActivityRecord atoken = mActivityRecord;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001868 return mViewVisibility == View.GONE
1869 || !mRelayoutCalled
chaviw7aec2312020-05-27 15:57:07 -07001870 // We can't check isVisible here because it will also check the client visibility
1871 // for WindowTokens. Even if the client is not visible, we still need to perform
1872 // a layout since they can request relayout when client visibility is false.
1873 // TODO (b/157682066) investigate if we can clean up isVisible
1874 || (atoken == null && !(wouldBeVisibleIfPolicyIgnored() && isVisibleByPolicy()))
Issei Suzuki1669ea42019-11-06 14:20:59 +01001875 || (atoken != null && !atoken.mVisibleRequested)
Jorim Jaggib52b0452019-07-16 17:43:15 +02001876 || isParentWindowGoneForLayout()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001877 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001878 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001879 }
1880
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001881 /**
1882 * Returns true if the window has a surface that it has drawn a
1883 * complete UI in to.
1884 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001885 public boolean isDrawFinishedLw() {
1886 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001887 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1888 || mWinAnimator.mDrawState == READY_TO_SHOW
1889 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001890 }
1891
1892 /**
1893 * Returns true if the window has a surface that it has drawn a
1894 * complete UI in to.
1895 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001896 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001897 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001898 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001899 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001900 }
1901
1902 /**
1903 * Return true if the window is opaque and fully drawn. This indicates
1904 * it may obscure windows behind it.
1905 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001906 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001907 // When there is keyguard, wallpaper could be placed over the secure app
1908 // window but invisible. We need to check wallpaper visibility explicitly
1909 // to determine if it's occluding apps.
1910 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1911 || (mIsWallpaper && mWallpaperVisible))
lumark9bca6b42019-10-17 18:35:22 +08001912 && isDrawnLw() && !isAnimating(TRANSITION | PARENTS);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001913 }
1914
Riddle Hsu5df3b7522019-12-16 13:27:37 -06001915 /** @see WindowManagerInternal#waitForAllWindowsDrawn */
1916 void requestDrawIfNeeded(List<WindowState> outWaitingForDrawn) {
1917 if (!isVisible()) {
1918 return;
1919 }
1920 if (mActivityRecord != null) {
1921 if (mActivityRecord.allDrawn) {
1922 // The allDrawn of activity is reset when the visibility is changed to visible, so
1923 // the content should be ready if allDrawn is set.
1924 return;
1925 }
1926 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1927 if (isDrawnLw()) {
1928 // Unnecessary to redraw a drawn starting window.
1929 return;
1930 }
1931 } else if (mActivityRecord.startingWindow != null) {
1932 // If the activity has an active starting window, there is no need to wait for the
1933 // main window.
1934 return;
1935 }
1936 } else if (!mPolicy.isKeyguardHostWindow(mAttrs)) {
1937 return;
1938 // Always invalidate keyguard host window to make sure it shows the latest content
1939 // because its visibility may not be changed.
1940 }
1941
1942 mWinAnimator.mDrawState = DRAW_PENDING;
1943 // Force add to {@link WindowManagerService#mResizingWindows}.
1944 resetLastContentInsets();
1945 outWaitingForDrawn.add(this);
1946 }
1947
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001948 @Override
1949 void onMovedByResize() {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001950 ProtoLog.d(WM_DEBUG_RESIZE, "onMovedByResize: Moving %s", this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001951 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001952 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001953 }
1954
Issei Suzuki2bcbd682019-11-08 13:20:14 +01001955 void onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001956 for (int i = mChildren.size() - 1; i >= 0; --i) {
Issei Suzuki2bcbd682019-11-08 13:20:14 +01001957 mChildren.get(i).onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001958 }
1959
Issei Suzuki2bcbd682019-11-08 13:20:14 +01001960 final boolean isVisibleNow = isVisibleNow();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001961 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1962 // Starting window that's exiting will be removed when the animation finishes.
1963 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1964 // to actually remove it.
lumark5bd11af2019-12-21 01:52:28 +08001965 if (!visible && isVisibleNow && mActivityRecord.isAnimating(PARENTS | TRANSITION)) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001966 mAnimatingExit = true;
1967 mRemoveOnExit = true;
1968 mWindowRemovalAllowed = true;
1969 }
Issei Suzuki2bcbd682019-11-08 13:20:14 +01001970 } else if (visible != isVisibleNow) {
chaviwe390cbd2018-04-16 15:29:38 -07001971 // Run exit animation if:
1972 // 1. App visibility and WS visibility are different
1973 // 2. App is not running an animation
1974 // 3. WS is currently visible
1975 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001976 final AccessibilityController accessibilityController =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001977 mWmService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001978 final int winTransit = TRANSIT_EXIT;
1979 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Rhed Jao02655dc2018-10-30 20:44:52 +08001980 if (accessibilityController != null) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001981 accessibilityController.onWindowTransitionLocked(this, winTransit);
1982 }
1983 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001984 setDisplayLayoutNeeded();
1985 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001986 }
1987
1988 boolean onSetAppExiting() {
1989 final DisplayContent displayContent = getDisplayContent();
1990 boolean changed = false;
1991
1992 if (isVisibleNow()) {
1993 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Rhed Jao02655dc2018-10-30 20:44:52 +08001994 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001995 mWmService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001996 }
1997 changed = true;
1998 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001999 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002000 }
2001 }
2002
2003 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002004 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002005 changed |= c.onSetAppExiting();
2006 }
2007
2008 return changed;
2009 }
2010
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002011 @Override
2012 void onResize() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002013 final ArrayList<WindowState> resizingWindows = mWmService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07002014 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002015 ProtoLog.d(WM_DEBUG_RESIZE, "onResize: Resizing %s", this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002016 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002017 }
2018 if (isGoneForLayoutLw()) {
2019 mResizedWhileGone = true;
2020 }
2021
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002022 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002023 }
2024
2025 void onUnfreezeBounds() {
2026 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002027 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002028 c.onUnfreezeBounds();
2029 }
2030
2031 if (!mHasSurface) {
2032 return;
2033 }
2034
2035 mLayoutNeeded = true;
2036 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002037 if (!mWmService.mResizingWindows.contains(this)) {
2038 mWmService.mResizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002039 }
2040 }
2041
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002042 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002043 * If the window has moved due to its containing content frame changing, then notify the
2044 * listeners and optionally animate it. Simply checking a change of position is not enough,
2045 * because being move due to dock divider is not a trigger for animation.
2046 */
chaviw161ea3e2018-01-31 12:01:12 -08002047 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002048 if (!hasMoved()) {
2049 return;
2050 }
2051
2052 // Frame has moved, containing content frame has also moved, and we're not currently
2053 // animating... let's do something.
chaviw492139a2018-07-16 16:07:35 -07002054 final int left = mWindowFrames.mFrame.left;
2055 final int top = mWindowFrames.mFrame.top;
Hongwei Wang252f5172020-08-20 14:16:19 -07002056
2057 // During the transition from pip to fullscreen, the activity windowing mode is set to
2058 // fullscreen at the beginning while the task is kept in pinned mode. Skip the move
2059 // animation in such case since the transition is handled in SysUI.
2060 final boolean hasMovementAnimation = getTask() == null
2061 ? getWindowConfiguration().hasMovementAnimations()
2062 : getTask().getWindowConfiguration().hasMovementAnimations();
David Stevens9440dc82017-03-16 19:00:20 -07002063 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002064 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Evan Rosky73a7fe92019-11-18 18:28:01 -08002065 && !isDragResizing()
Hongwei Wang252f5172020-08-20 14:16:19 -07002066 && hasMovementAnimation
Adrian Roos0e7b70a2018-06-07 15:29:34 +02002067 && !mWinAnimator.mLastHidden
2068 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08002069 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002070 }
2071
Jacky Kaof93252b2019-07-18 15:19:52 +08002072 if (mWmService.mAccessibilityController != null) {
2073 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(getDisplayId());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002074 }
Jackal Guoc43a0a62019-04-23 09:15:14 +08002075 updateLocationInParentDisplayIfNeeded();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002076
2077 try {
2078 mClient.moved(left, top);
2079 } catch (RemoteException e) {
2080 }
2081 mMovedByResize = false;
2082 }
2083
2084 /**
Craig Mautner4557c082015-04-27 13:07:40 -07002085 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002086 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
2087 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002088 private boolean hasMoved() {
chaviw1454b392018-08-06 09:54:04 -07002089 return mHasSurface && (mWindowFrames.hasContentChanged() || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07002090 && !mAnimatingExit
Evan Rosky70213702019-11-05 10:26:24 -08002091 && (mWindowFrames.mRelFrame.top != mWindowFrames.mLastRelFrame.top
2092 || mWindowFrames.mRelFrame.left != mWindowFrames.mLastRelFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07002093 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002094 }
2095
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08002096 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08002097 Task task = getTask();
Wale Ogunwale0b3d2922019-12-30 08:55:07 -08002098 if (task != null && task.getStack() != null && !task.getStack().fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08002099 return false;
2100 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08002101 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08002102 }
2103
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08002104 boolean fillsDisplay() {
2105 final DisplayInfo displayInfo = getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07002106 return mWindowFrames.mFrame.left <= 0 && mWindowFrames.mFrame.top <= 0
2107 && mWindowFrames.mFrame.right >= displayInfo.appWidth
2108 && mWindowFrames.mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002109 }
2110
Evan Rosky4fb1e912019-03-06 13:54:43 -08002111 private boolean matchesDisplayBounds() {
Riddle Hsu6f548e92020-01-13 13:34:09 +08002112 final Rect displayBounds = mToken.getFixedRotationTransformDisplayBounds();
2113 if (displayBounds != null) {
2114 // If the rotated display bounds are available, the window bounds are also rotated.
2115 return displayBounds.equals(getBounds());
2116 }
Evan Rosky4fb1e912019-03-06 13:54:43 -08002117 return getDisplayContent().getBounds().equals(getBounds());
2118 }
2119
Jorim Jaggi381cd722019-03-27 17:33:02 +01002120 /**
2121 * @return {@code true} if last applied config was reported to the client already, {@code false}
2122 * otherwise.
2123 */
2124 boolean isLastConfigReportedToClient() {
2125 return mLastConfigReportedToClient;
2126 }
2127
2128 @Override
2129 void onMergedOverrideConfigurationChanged() {
2130 super.onMergedOverrideConfigurationChanged();
2131 mLastConfigReportedToClient = false;
Craig Mautner812d2ca2012-09-27 15:35:34 -07002132 }
2133
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002134 void onWindowReplacementTimeout() {
2135 if (mWillReplaceWindow) {
2136 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07002137 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002138 // delays removal on certain conditions, which will leave the stale window in the
2139 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
2140 //
2141 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07002142 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002143 } else {
2144 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002145 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002146 c.onWindowReplacementTimeout();
2147 }
2148 }
2149 }
2150
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002151 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002152 void forceWindowsScaleableInTransaction(boolean force) {
2153 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
2154 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
2155 }
2156
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002157 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002158 }
2159
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07002160 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07002161 void removeImmediately() {
2162 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07002163
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07002164 if (mRemoved) {
2165 // Nothing to do.
Adrian Roosb125e0b2019-10-02 14:55:14 +02002166 ProtoLog.v(WM_DEBUG_ADD_REMOVE,
2167 "WS.removeImmediately: %s Already removed...", this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07002168 return;
2169 }
2170
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07002171 mRemoved = true;
2172
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002173 mWillReplaceWindow = false;
2174 if (mReplacementWindow != null) {
2175 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
2176 }
2177
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002178 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07002179 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002180 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07002181 }
Adrian Roosa6beec82020-07-17 13:52:03 +02002182 if (dc.mInputMethodInputTarget == this) {
2183 dc.setInputMethodInputTarget(null);
2184 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07002185
2186 final int type = mAttrs.type;
2187 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002188 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07002189 }
chaviwaa0d74e2019-12-26 14:13:40 -08002190
2191 // Remove this window from mTapExcludeProvidingWindows. If it was not registered, this will
2192 // not do anything.
2193 dc.mTapExcludeProvidingWindows.remove(this);
Tiger Huang7c610aa2018-10-27 00:01:01 +08002194 dc.getDisplayPolicy().removeWindowLw(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07002195
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002196 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08002197
Craig Mautner96868332012-12-04 14:29:11 -08002198 mWinAnimator.destroyDeferredSurfaceLocked();
2199 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08002200 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002201 try {
2202 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
2203 } catch (RuntimeException e) {
2204 // Ignore if it has already been removed (usually because
2205 // we are doing this as part of processing a death note.)
2206 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07002207
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002208 mWmService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002209 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002210
Wale Ogunwale571771c2016-08-26 13:18:50 -07002211 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002212 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002213 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002214 removeIfPossible(false /*keepVisibleDeadWindow*/);
chaviw355befd2020-06-23 08:11:46 -07002215 immediatelyNotifyBlastSync();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002216 }
2217
Wale Ogunwale571771c2016-08-26 13:18:50 -07002218 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002219 mWindowRemovalAllowed = true;
Adrian Roosb125e0b2019-10-02 14:55:14 +02002220 ProtoLog.v(WM_DEBUG_ADD_REMOVE,
2221 "removeIfPossible: %s callers=%s", this, Debug.getCallers(5));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002222
2223 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
Adrian Roosb125e0b2019-10-02 14:55:14 +02002224 if (startingWindow) {
2225 ProtoLog.d(WM_DEBUG_STARTING_WINDOW, "Starting window removed %s", this);
Adam Pardyl8c2d19c2019-09-16 17:15:38 +02002226 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002227
Adrian Roosb125e0b2019-10-02 14:55:14 +02002228 ProtoLog.v(WM_DEBUG_FOCUS, "Remove client=%x, surfaceController=%s Callers=%s",
2229 System.identityHashCode(mClient.asBinder()),
2230 mWinAnimator.mSurfaceController,
2231 Debug.getCallers(5));
2232
2233
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002234 final long origId = Binder.clearCallingIdentity();
2235
Peter Visontay3556a3b2017-11-01 17:23:17 +00002236 try {
2237 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002238
Adrian Roosb125e0b2019-10-02 14:55:14 +02002239 ProtoLog.v(WM_DEBUG_APP_TRANSITIONS,
2240 "Remove %s: mSurfaceController=%s mAnimatingExit=%b mRemoveOnExit=%b "
2241 + "mHasSurface=%b surfaceShowing=%b animating=%b app-animation=%b "
Issei Suzuki860fbc02019-10-31 16:49:35 +01002242 + "mWillReplaceWindow=%b mDisplayFrozen=%b callers=%s",
Adrian Roosb125e0b2019-10-02 14:55:14 +02002243 this, mWinAnimator.mSurfaceController, mAnimatingExit, mRemoveOnExit,
lumark9bca6b42019-10-17 18:35:22 +08002244 mHasSurface, mWinAnimator.getShown(),
2245 isAnimating(TRANSITION | PARENTS),
lumark5bd11af2019-12-21 01:52:28 +08002246 mActivityRecord != null && mActivityRecord.isAnimating(PARENTS | TRANSITION),
lumark9bca6b42019-10-17 18:35:22 +08002247 mWillReplaceWindow,
Adrian Roosb125e0b2019-10-02 14:55:14 +02002248 mWmService.mDisplayFrozen, Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002249
Peter Visontay3556a3b2017-11-01 17:23:17 +00002250 // Visibility of the removed window. Will be used later to update orientation later on.
2251 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002252
Peter Visontay3556a3b2017-11-01 17:23:17 +00002253 // First, see if we need to run an animation. If we do, we have to hold off on removing the
2254 // window until the animation is done. If the display is frozen, just remove immediately,
2255 // since the animation wouldn't be seen.
2256 if (mHasSurface && mToken.okToAnimate()) {
2257 if (mWillReplaceWindow) {
2258 // This window is going to be replaced. We need to keep it around until the new one
2259 // gets added, then we will get rid of this one.
Adrian Roosb125e0b2019-10-02 14:55:14 +02002260 ProtoLog.v(WM_DEBUG_ADD_REMOVE,
2261 "Preserving %s until the new one is added", this);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002262 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
2263 // been removed. We probably need another flag to indicate that window removal
2264 // should be deffered vs. overloading the flag that says we are playing an exit
2265 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002266 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00002267 mReplacingRemoveRequested = true;
2268 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002269 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002270
Peter Visontay3556a3b2017-11-01 17:23:17 +00002271 // If we are not currently running the exit animation, we need to see about starting one
2272 wasVisible = isWinVisibleLw();
2273
2274 if (keepVisibleDeadWindow) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002275 ProtoLog.v(WM_DEBUG_ADD_REMOVE,
2276 "Not removing %s because app died while it's visible", this);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002277
2278 mAppDied = true;
2279 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002280 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Peter Visontay3556a3b2017-11-01 17:23:17 +00002281
2282 // Set up a replacement input channel since the app is now dead.
2283 // We need to catch tapping on the dead window to restart the app.
2284 openInputChannel(null);
Arthur Hung95b38a92018-07-20 18:56:12 +08002285 getDisplayContent().getInputMonitor().updateInputWindowsLw(true /*force*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002286 return;
2287 }
2288
2289 if (wasVisible) {
2290 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
Chavi Weingarten75902ee2020-05-15 17:48:34 +00002291
Peter Visontay3556a3b2017-11-01 17:23:17 +00002292 // Try starting an animation.
Chavi Weingarten75902ee2020-05-15 17:48:34 +00002293 if (mWinAnimator.applyAnimationLocked(transit, false)) {
Peter Visontay3556a3b2017-11-01 17:23:17 +00002294 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02002295
2296 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
2297 // any change from that is performed immediately.
2298 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002299 mWmService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00002300 }
Rhed Jao02655dc2018-10-30 20:44:52 +08002301 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002302 mWmService.mAccessibilityController.onWindowTransitionLocked(this, transit);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002303 }
2304 }
Chavi Weingarten75902ee2020-05-15 17:48:34 +00002305 final boolean isAnimating = isAnimating(TRANSITION | PARENTS)
Garfield Tane8d84ab2019-10-11 09:49:40 -07002306 && (mActivityRecord == null || !mActivityRecord.isWaitingForTransitionStart());
2307 final boolean lastWindowIsStartingWindow = startingWindow && mActivityRecord != null
2308 && mActivityRecord.isLastWindow(this);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002309 // We delay the removal of a window if it has a showing surface that can be used to run
2310 // exit animation and it is marked as exiting.
2311 // Also, If isn't the an animating starting window that is the last window in the app.
2312 // We allow the removal of the non-animating starting window now as there is no
2313 // additional window or animation that will trigger its removal.
2314 if (mWinAnimator.getShown() && mAnimatingExit
2315 && (!lastWindowIsStartingWindow || isAnimating)) {
2316 // The exit animation is running or should run... wait for it!
Adrian Roosb125e0b2019-10-02 14:55:14 +02002317 ProtoLog.v(WM_DEBUG_ADD_REMOVE,
2318 "Not removing %s due to exit animation", this);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002319 setupWindowForRemoveOnExit();
Garfield Tane8d84ab2019-10-11 09:49:40 -07002320 if (mActivityRecord != null) {
2321 mActivityRecord.updateReportedVisibilityLocked();
Peter Visontay3556a3b2017-11-01 17:23:17 +00002322 }
2323 return;
2324 }
2325 }
2326
2327 removeImmediately();
2328 // Removing a visible window will effect the computed orientation
2329 // So just update orientation if needed.
Riddle Hsu4e611772018-10-31 18:58:28 +08002330 if (wasVisible) {
2331 final DisplayContent displayContent = getDisplayContent();
Riddle Hsuccf09402019-08-13 00:33:06 +08002332 if (displayContent.updateOrientation()) {
Shivam Agrawal6472e0e2019-07-03 16:27:49 -07002333 displayContent.sendNewConfiguration();
Riddle Hsu4e611772018-10-31 18:58:28 +08002334 }
Peter Visontay3556a3b2017-11-01 17:23:17 +00002335 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002336 mWmService.updateFocusedWindowLocked(isFocused()
Tiger Huang8af6ba42018-06-07 19:24:09 +08002337 ? UPDATE_FOCUS_REMOVING_FOCUS
2338 : UPDATE_FOCUS_NORMAL,
2339 true /*updateInputWindows*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00002340 } finally {
2341 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002342 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002343 }
2344
2345 private void setupWindowForRemoveOnExit() {
2346 mRemoveOnExit = true;
2347 setDisplayLayoutNeeded();
2348 // Request a focus update as this window's input channel is already gone. Otherwise
2349 // we could have no focused window in input manager.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002350 final boolean focusChanged = mWmService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002351 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002352 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002353 if (focusChanged) {
Arthur Hung95b38a92018-07-20 18:56:12 +08002354 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002355 }
2356 }
2357
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002358 void setHasSurface(boolean hasSurface) {
2359 mHasSurface = hasSurface;
2360 }
2361
chaviw50dbc982020-05-19 13:57:43 -07002362 /**
2363 * Checks whether one of the Windows in a Display embedded in this Window can be an IME target.
2364 */
2365 private boolean canWindowInEmbeddedDisplayBeImeTarget() {
2366 final int embeddedDisplayContentsSize = mEmbeddedDisplayContents.size();
2367 for (int i = embeddedDisplayContentsSize - 1; i >= 0; i--) {
2368 final DisplayContent edc = mEmbeddedDisplayContents.valueAt(i);
2369 if (edc.forAllWindows(WindowState::canBeImeTarget, true)) {
2370 return true;
2371 }
2372 }
2373 return false;
2374 }
2375
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002376 boolean canBeImeTarget() {
chaviw50dbc982020-05-19 13:57:43 -07002377 // If any of the embedded windows can be the IME target, this window will be the final IME
2378 // target. This is because embedded windows are on a different display in WM so it would
2379 // cause confusion trying to set the IME to a window on a different display. Instead, just
2380 // make the host window the IME target.
2381 if (canWindowInEmbeddedDisplayBeImeTarget()) {
2382 return true;
2383 }
2384
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002385 if (mIsImWindow) {
2386 // IME windows can't be IME targets. IME targets are required to be below the IME
2387 // windows and that wouldn't be possible if the IME window is its own target...silly.
2388 return false;
2389 }
2390
Taran Singh6c240d12020-06-15 16:54:35 -07002391 if (inPinnedWindowingMode()) {
2392 return false;
2393 }
2394
Winson Chung8ae977d2020-06-25 13:05:19 -07002395 if (mAttrs.type == TYPE_SCREENSHOT) {
2396 // Disallow screenshot windows from being IME targets
2397 return false;
2398 }
2399
Garfield Tane8d84ab2019-10-11 09:49:40 -07002400 final boolean windowsAreFocusable = mActivityRecord == null || mActivityRecord.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002401 if (!windowsAreFocusable) {
2402 // This window can't be an IME target if the app's windows should not be focusable.
2403 return false;
2404 }
2405
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08002406 final ActivityStack stack = getRootTask();
Evan Roskye84ef9e2020-01-09 17:28:19 -08002407 if (stack != null && !stack.isFocusable()) {
lumarkf948afe2019-05-23 21:22:36 +08002408 // Ignore when the stack shouldn't receive input event.
2409 // (i.e. the minimized stack in split screen mode.)
2410 return false;
2411 }
2412
Adrian Roos417823d2020-06-25 16:27:35 +02002413 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2414 // Ignore mayUseInputMethod for starting window for now.
2415 // TODO(b/159911356): Remove this special casing (originally added in commit e75d872).
Adrian Roos69947c02020-07-01 16:23:05 +02002416 } else {
2417 // TODO(b/145812508): Clean this up in S, may depend on b/141738570
2418 // The current logic lets windows become the "ime target" even though they are
2419 // not-focusable and can thus never actually start input.
2420 // Ideally, this would reject windows where mayUseInputMethod() == false, but this
2421 // also impacts Z-ordering of and delivery of IME insets to child windows, which means
2422 // that simply disallowing non-focusable windows would break apps.
2423 // See b/159438771, b/144619551.
2424
Tarandeep Singhbcba88c2019-12-06 10:36:55 -08002425 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Andrew Chant17c896e2019-12-05 22:39:02 +00002426
Tarandeep Singhbcba88c2019-12-06 10:36:55 -08002427 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are
2428 // set or both are cleared...and not a starting window.
Adrian Roos417823d2020-06-25 16:27:35 +02002429 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)) {
Tarandeep Singhbcba88c2019-12-06 10:36:55 -08002430 return false;
2431 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002432 }
2433
2434 if (DEBUG_INPUT_METHOD) {
2435 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2436 if (!isVisibleOrAdding()) {
2437 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2438 + " relayoutCalled=" + mRelayoutCalled
2439 + " viewVis=" + mViewVisibility
chaviw15ad49f2019-04-24 15:05:39 -07002440 + " policyVis=" + isVisibleByPolicy()
2441 + " policyVisAfterAnim=" + mLegacyPolicyVisibilityAfterAnim
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002442 + " parentHidden=" + isParentWindowHidden()
2443 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
Garfield Tane8d84ab2019-10-11 09:49:40 -07002444 if (mActivityRecord != null) {
Issei Suzuki1669ea42019-11-06 14:20:59 +01002445 Slog.i(TAG_WM, " mActivityRecord.visibleRequested="
2446 + mActivityRecord.mVisibleRequested);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002447 }
2448 }
2449 }
2450 return isVisibleOrAdding();
2451 }
2452
Chong Zhangacf11402015-11-04 16:23:10 -08002453 private final class DeadWindowEventReceiver extends InputEventReceiver {
2454 DeadWindowEventReceiver(InputChannel inputChannel) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002455 super(inputChannel, mWmService.mH.getLooper());
Chong Zhangacf11402015-11-04 16:23:10 -08002456 }
2457 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002458 public void onInputEvent(InputEvent event) {
Chong Zhangacf11402015-11-04 16:23:10 -08002459 finishInputEvent(event, true);
2460 }
2461 }
2462 /**
2463 * Dummy event receiver for windows that died visible.
2464 */
2465 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2466
Chong Zhang112eb8c2015-11-02 11:17:00 -08002467 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002468 if (mInputChannel != null) {
2469 throw new IllegalStateException("Window already has an input channel.");
2470 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002471 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002472 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2473 mInputChannel = inputChannels[0];
2474 mClientChannel = inputChannels[1];
Vishnu Nair18782162019-10-08 14:57:16 -07002475 mWmService.mInputManager.registerInputChannel(mInputChannel);
Vishnu Nair18782162019-10-08 14:57:16 -07002476 mInputWindowHandle.token = mInputChannel.getToken();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002477 if (outInputChannel != null) {
2478 mClientChannel.transferTo(outInputChannel);
2479 mClientChannel.dispose();
2480 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002481 } else {
2482 // If the window died visible, we setup a dummy input channel, so that taps
2483 // can still detected by input monitor channel, and we can relaunch the app.
2484 // Create dummy event receiver that simply reports all events as handled.
2485 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002486 }
Vishnu Nair18782162019-10-08 14:57:16 -07002487 mWmService.mInputToWindowMap.put(mInputWindowHandle.token, this);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002488 }
2489
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002490 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002491 if (mDeadWindowEventReceiver != null) {
2492 mDeadWindowEventReceiver.dispose();
2493 mDeadWindowEventReceiver = null;
2494 }
2495
2496 // unregister server channel first otherwise it complains about broken channel
2497 if (mInputChannel != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002498 mWmService.mInputManager.unregisterInputChannel(mInputChannel);
Robert Carre0a353c2018-08-02 16:38:04 -07002499
Chong Zhangacf11402015-11-04 16:23:10 -08002500 mInputChannel.dispose();
2501 mInputChannel = null;
2502 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002503 if (mClientChannel != null) {
2504 mClientChannel.dispose();
2505 mClientChannel = null;
2506 }
Vishnu Nair539334a2019-09-20 10:46:21 -07002507 mWmService.mKeyInterceptionInfoForToken.remove(mInputWindowHandle.token);
Vishnu Nair18782162019-10-08 14:57:16 -07002508 mWmService.mInputToWindowMap.remove(mInputWindowHandle.token);
Robert Carreadae822018-10-11 19:07:03 -07002509 mInputWindowHandle.token = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002510 }
2511
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002512 /** Returns true if the replacement window was removed. */
2513 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2514 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2515 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2516 removeReplacedWindow();
2517 return true;
2518 }
2519
2520 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002521 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002522 if (c.removeReplacedWindowIfNeeded(replacement)) {
2523 return true;
2524 }
2525 }
2526 return false;
2527 }
2528
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002529 private void removeReplacedWindow() {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002530 ProtoLog.d(WM_DEBUG_ADD_REMOVE, "Removing replaced window: %s", this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002531 mWillReplaceWindow = false;
2532 mAnimateReplacingWindow = false;
2533 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002534 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002535 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002536 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002537 }
2538 }
2539
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002540 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2541 boolean replacementSet = false;
2542
2543 if (mWillReplaceWindow && mReplacementWindow == null
2544 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2545
2546 mReplacementWindow = replacementCandidate;
2547 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2548 replacementSet = true;
2549 }
2550
2551 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002552 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002553 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2554 }
2555
2556 return replacementSet;
2557 }
2558
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002559 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002560 final DisplayContent dc = getDisplayContent();
2561 if (dc != null) {
2562 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002563 }
2564 }
2565
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002566 @Override
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -07002567 void switchUser(int userId) {
2568 super.switchUser(userId);
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -08002569
2570 if (showToCurrentUser()) {
2571 setPolicyVisibilityFlag(VISIBLE_FOR_USER);
2572 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002573 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2574 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
chaviw15ad49f2019-04-24 15:05:39 -07002575 clearPolicyVisibilityFlag(VISIBLE_FOR_USER);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002576 }
2577 }
2578
Vishnu Nair93d68c22019-03-22 13:45:31 -07002579 int getSurfaceTouchableRegion(InputWindowHandle inputWindowHandle, int flags) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002580 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Vishnu Nair93d68c22019-03-22 13:45:31 -07002581 final Region region = inputWindowHandle.touchableRegion;
2582 setTouchableRegionCropIfNeeded(inputWindowHandle);
2583
chaviwf5827d12019-12-13 09:58:48 -08002584 if (modal) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002585 flags |= FLAG_NOT_TOUCH_MODAL;
chaviwf5827d12019-12-13 09:58:48 -08002586 if (mActivityRecord != null) {
2587 // Limit the outer touch to the activity stack region.
2588 updateRegionForModalActivityWindow(region);
2589 } else {
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002590 // Give it a large touchable region at first because it was touch modal. The window
2591 // might be moved on the display, so the touchable region should be large enough to
2592 // ensure it covers the whole display, no matter where it is moved.
2593 getDisplayContent().getBounds(mTmpRect);
2594 final int dw = mTmpRect.width();
2595 final int dh = mTmpRect.height();
2596 region.set(-dw, -dh, dw + dw, dh + dh);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002597 }
chaviwf5827d12019-12-13 09:58:48 -08002598 subtractTouchExcludeRegionIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002599 } else {
chaviwf5827d12019-12-13 09:58:48 -08002600 // Not modal
Riddle Hsub5e960f2018-12-07 14:51:26 +08002601 getTouchableRegion(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002602 }
chaviwf5827d12019-12-13 09:58:48 -08002603
Riddle Hsub5e960f2018-12-07 14:51:26 +08002604 // Translate to surface based coordinates.
2605 region.translate(-mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
Robert Carra80ad042018-08-14 12:54:20 -07002606
Shivam Agrawal780b5bb2019-07-17 10:17:11 -07002607 // TODO(b/139804591): sizecompat layout needs to be reworked. Currently mFrame is post-
2608 // scaling but the existing logic doesn't expect that. The result is that the already-
2609 // scaled region ends up getting sent to surfaceflinger which then applies the scale
2610 // (again). Until this is resolved, apply an inverse-scale here.
2611 if (mActivityRecord != null && mActivityRecord.hasSizeCompatBounds()
2612 && mGlobalScale != 1.f) {
2613 region.scale(mInvGlobalScale);
2614 }
2615
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002616 return flags;
2617 }
2618
chaviwf5827d12019-12-13 09:58:48 -08002619 /**
arthurhungda4c2d62020-04-21 14:38:54 +08002620 * Expands the given rectangle by the region of window resize handle for freeform window.
2621 * @param inOutRect The rectangle to update.
2622 */
2623 private void adjustRegionInFreefromWindowMode(Rect inOutRect) {
2624 if (!inFreeformWindowingMode()) {
2625 return;
2626 }
2627
2628 // For freeform windows, we need the touch region to include the whole
2629 // surface for the shadows.
2630 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2631 final int delta = WindowManagerService.dipToPixel(
2632 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2633 inOutRect.inset(-delta, -delta);
2634 }
2635
2636 /**
chaviwf5827d12019-12-13 09:58:48 -08002637 * Updates the region for a window in an Activity that was a touch modal. This will limit
2638 * the outer touch to the activity stack region.
2639 * @param outRegion The region to update.
2640 */
2641 private void updateRegionForModalActivityWindow(Region outRegion) {
2642 // If the inner bounds of letterbox is available, then it will be used as the
2643 // touchable region so it won't cover the touchable letterbox and the touch
2644 // events can slip to activity from letterbox.
2645 mActivityRecord.getLetterboxInnerBounds(mTmpRect);
2646 if (mTmpRect.isEmpty()) {
2647 // If this is a modal window we need to dismiss it if it's not full screen
2648 // and the touch happens outside of the frame that displays the content. This
2649 // means we need to intercept touches outside of that window. The dim layer
2650 // user associated with the window (task or stack) will give us the good
2651 // bounds, as they would be used to display the dim layer.
2652 final Task task = getTask();
2653 if (task != null) {
2654 task.getDimBounds(mTmpRect);
Charles Chen7d550c42020-05-15 17:32:03 +08002655 } else if (getRootTask() != null) {
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08002656 getRootTask().getDimBounds(mTmpRect);
chaviwf5827d12019-12-13 09:58:48 -08002657 }
2658 }
arthurhungda4c2d62020-04-21 14:38:54 +08002659 adjustRegionInFreefromWindowMode(mTmpRect);
chaviwf5827d12019-12-13 09:58:48 -08002660 outRegion.set(mTmpRect);
2661 cropRegionToStackBoundsIfNeeded(outRegion);
2662 }
2663
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002664 void checkPolicyVisibilityChange() {
chaviw15ad49f2019-04-24 15:05:39 -07002665 if (isLegacyPolicyVisibility() != mLegacyPolicyVisibilityAfterAnim) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002666 if (DEBUG_VISIBILITY) {
2667 Slog.v(TAG, "Policy visibility changing after anim in " +
chaviw15ad49f2019-04-24 15:05:39 -07002668 mWinAnimator + ": " + mLegacyPolicyVisibilityAfterAnim);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002669 }
chaviw15ad49f2019-04-24 15:05:39 -07002670 if (mLegacyPolicyVisibilityAfterAnim) {
2671 setPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
2672 } else {
2673 clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
2674 }
2675 if (!isVisibleByPolicy()) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002676 mWinAnimator.hide("checkPolicyVisibilityChange");
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002677 if (isFocused()) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02002678 ProtoLog.i(WM_DEBUG_FOCUS_LIGHT,
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002679 "setAnimationLocked: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002680 mWmService.mFocusMayChange = true;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002681 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002682 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002683 // Window is no longer visible -- make sure if we were waiting
2684 // for it to be displayed before enabling the display, that
2685 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002686 mWmService.enableScreenIfNeededLocked();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002687 }
2688 }
2689 }
2690
2691 void setRequestedSize(int requestedWidth, int requestedHeight) {
2692 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2693 mLayoutNeeded = true;
2694 mRequestedWidth = requestedWidth;
2695 mRequestedHeight = requestedHeight;
2696 }
2697 }
2698
Bryce Leef858b572017-06-29 14:03:33 -07002699 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002700 // We need to turn on screen regardless of visibility.
Riddle Hsu4bb06be2019-07-02 01:03:07 +08002701 final boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0
Garfield Tane8d84ab2019-10-11 09:49:40 -07002702 || (mActivityRecord != null && mActivityRecord.canTurnScreenOn());
chaviw40234662018-02-07 09:37:16 -08002703
2704 // The screen will turn on if the following conditions are met
Riddle Hsu4bb06be2019-07-02 01:03:07 +08002705 // 1. The window has the flag FLAG_TURN_SCREEN_ON or ActivityRecord#canTurnScreenOn.
chaviw40234662018-02-07 09:37:16 -08002706 // 2. The WMS allows theater mode.
2707 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2708 // per resume to prevent the screen getting getting turned on for each relayout. Set
Wale Ogunwaleda8b8272018-11-29 19:37:37 -08002709 // currentLaunchCanTurnScreenOn will be set to false so the window doesn't turn the screen
2710 // on again during this resume.
chaviw40234662018-02-07 09:37:16 -08002711 // 4. When the screen is not interactive. This is because when the screen is already
2712 // interactive, the value may persist until the next animation, which could potentially
2713 // be occurring while turning off the screen. This would lead to the screen incorrectly
2714 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002715 if (hasTurnScreenOnFlag) {
Jorim Jaggi4981f152019-03-26 18:58:45 +01002716 boolean allowTheaterMode = mWmService.mAllowTheaterModeWakeFromLayout
2717 || Settings.Global.getInt(mWmService.mContext.getContentResolver(),
2718 Settings.Global.THEATER_MODE_ON, 0) == 0;
Garfield Tane8d84ab2019-10-11 09:49:40 -07002719 boolean canTurnScreenOn = mActivityRecord == null || mActivityRecord.currentLaunchCanTurnScreenOn();
Jorim Jaggi4981f152019-03-26 18:58:45 +01002720
Robin Lee0e8e167e2020-06-16 01:14:50 +02002721 if (allowTheaterMode && canTurnScreenOn
2722 && (mWmService.mAtmInternal.isDreaming()
2723 || !mPowerManagerWrapper.isInteractive())) {
chaviw474093d2018-03-07 15:03:38 -08002724 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2725 Slog.v(TAG, "Relayout window turning screen on: " + this);
2726 }
2727 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
Michael Wrighte3001042019-02-05 00:13:14 +00002728 PowerManager.WAKE_REASON_APPLICATION, "android.server.wm:SCREEN_ON_FLAG");
chaviw40234662018-02-07 09:37:16 -08002729 }
chaviwb28de1f2018-03-02 10:42:36 -08002730
Garfield Tane8d84ab2019-10-11 09:49:40 -07002731 if (mActivityRecord != null) {
2732 mActivityRecord.setCurrentLaunchCanTurnScreenOn(false);
chaviwb28de1f2018-03-02 10:42:36 -08002733 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002734 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002735
2736 // If we were already visible, skip rest of preparation.
2737 if (wasVisible) {
2738 if (DEBUG_VISIBILITY) Slog.v(TAG,
2739 "Already visible and does not turn on screen, skip preparing: " + this);
2740 return;
2741 }
2742
2743 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2744 == SOFT_INPUT_ADJUST_RESIZE) {
2745 mLayoutNeeded = true;
2746 }
2747
David Stevens9440dc82017-03-16 19:00:20 -07002748 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002749 mWinAnimator.applyEnterAnimationLocked();
2750 }
Bryce Leef858b572017-06-29 14:03:33 -07002751 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002752
Yunfan Chen75157d72018-07-27 14:47:21 +09002753 private Configuration getProcessGlobalConfiguration() {
2754 // For child windows we want to use the pid for the parent window in case the the child
2755 // window was added from another process.
Yunfan Chenb4fe58c2019-03-27 18:35:06 +09002756 final WindowState parentWindow = getParentWindow();
2757 final int pid = parentWindow != null ? parentWindow.mSession.mPid : mSession.mPid;
Yunfan Chenc2ff6cf2018-12-04 16:56:21 -08002758 final Configuration processConfig =
2759 mWmService.mAtmService.getGlobalConfigurationForPid(pid);
Yunfan Chenb4fe58c2019-03-27 18:35:06 +09002760 return processConfig;
Yunfan Chen75157d72018-07-27 14:47:21 +09002761 }
2762
Bryce Leef858b572017-06-29 14:03:33 -07002763 void getMergedConfiguration(MergedConfiguration outConfiguration) {
Yunfan Chen75157d72018-07-27 14:47:21 +09002764 final Configuration globalConfig = getProcessGlobalConfiguration();
Bryce Leef858b572017-06-29 14:03:33 -07002765 final Configuration overrideConfig = getMergedOverrideConfiguration();
2766 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2767 }
2768
Bryce Lee2b17afd2017-09-21 10:38:20 -07002769 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2770 mLastReportedConfiguration.setTo(config);
Jorim Jaggi381cd722019-03-27 17:33:02 +01002771 mLastConfigReportedToClient = true;
Bryce Lee2b17afd2017-09-21 10:38:20 -07002772 }
2773
2774 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2775 config.setTo(mLastReportedConfiguration);
2776 }
2777
2778 private Configuration getLastReportedConfiguration() {
2779 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002780 }
2781
2782 void adjustStartingWindowFlags() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07002783 if (mAttrs.type == TYPE_BASE_APPLICATION && mActivityRecord != null
2784 && mActivityRecord.startingWindow != null) {
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002785 // Special handling of starting window over the base
2786 // window of the app: propagate lock screen flags to it,
2787 // to provide the correct semantics while starting.
2788 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2789 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Garfield Tane8d84ab2019-10-11 09:49:40 -07002790 WindowManager.LayoutParams sa = mActivityRecord.startingWindow.mAttrs;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002791 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2792 }
2793 }
2794
2795 void setWindowScale(int requestedWidth, int requestedHeight) {
2796 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2797
2798 if (scaledWindow) {
2799 // requested{Width|Height} Surface's physical size
2800 // attrs.{width|height} Size on screen
2801 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2802 mHScale = (mAttrs.width != requestedWidth) ?
2803 (mAttrs.width / (float)requestedWidth) : 1.0f;
2804 mVScale = (mAttrs.height != requestedHeight) ?
2805 (mAttrs.height / (float)requestedHeight) : 1.0f;
2806 } else {
2807 mHScale = mVScale = 1;
2808 }
2809 }
2810
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002811 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002812 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002813 public void binderDied() {
2814 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002815 boolean resetSplitScreenResizing = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002816 synchronized (mWmService.mGlobalLock) {
2817 final WindowState win = mWmService
2818 .windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002819 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002820 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002821 final DisplayContent dc = getDisplayContent();
Garfield Tane8d84ab2019-10-11 09:49:40 -07002822 if (win.mActivityRecord != null && win.mActivityRecord.findMainWindow() == win) {
2823 mWmService.mTaskSnapshotController.onAppDied(win.mActivityRecord);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002824 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002825 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002826 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002827 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002828 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002829 }
2830 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002831 if (resetSplitScreenResizing) {
2832 try {
2833 // Note: this calls into ActivityManager, so we must *not* hold the window
2834 // manager lock while calling this.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002835 mWmService.mActivityTaskManager.setSplitScreenResizing(false);
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002836 } catch (RemoteException e) {
2837 // Local call, shouldn't return RemoteException.
2838 throw e.rethrowAsRuntimeException();
2839 }
2840 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002841 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002842 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002843 }
2844 }
2845 }
2846
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002847 /**
2848 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2849 * because we want to preserve its location on screen to be re-activated later when the user
2850 * interacts with it.
2851 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002852 private boolean shouldKeepVisibleDeadAppWindow() {
Issei Suzukid4ee1cc2019-11-08 13:20:14 +01002853 if (!isWinVisibleLw() || mActivityRecord == null || !mActivityRecord.isClientVisible()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002854 // Not a visible app window or the app isn't dead.
2855 return false;
2856 }
2857
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002858 if (mAttrs.token != mClient.asBinder()) {
2859 // The window was add by a client using another client's app token. We don't want to
2860 // keep the dead window around for this case since this is meant for 'real' apps.
2861 return false;
2862 }
2863
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002864 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2865 // We don't keep starting windows since they were added by the window manager before
2866 // the app even launched.
2867 return false;
2868 }
2869
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002870 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002871 }
2872
Tiger Huang513d5e12018-07-16 21:49:50 +08002873 @Override
2874 public boolean canReceiveKeys() {
lumarkd0b5c8f2019-09-29 11:30:37 +08002875 return canReceiveKeys(false /* fromUserTouch */);
2876 }
2877
2878 public boolean canReceiveKeys(boolean fromUserTouch) {
2879 final boolean canReceiveKeys = isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002880 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002881 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Louis Chang2104fd92019-11-04 15:43:53 +08002882 && (mActivityRecord == null || mActivityRecord.windowsAreFocusable(fromUserTouch))
Robert Carrebdf8582018-09-04 14:50:15 -07002883 && !cantReceiveTouchInput();
lumarkd0b5c8f2019-09-29 11:30:37 +08002884 if (!canReceiveKeys) {
2885 return false;
2886 }
2887 // Do not allow untrusted virtual display to receive keys unless user intentionally
2888 // touches the display.
2889 return fromUserTouch || getDisplayContent().isOnTop()
Charles Chenb28fb722020-05-21 17:19:32 +08002890 || getDisplayContent().isTrusted();
Matthew Nge15352e2016-12-20 15:36:29 -08002891 }
2892
lumark31e4f8e2019-01-10 20:48:18 +08002893 @Override
2894 public boolean canShowWhenLocked() {
2895 final boolean showBecauseOfActivity =
Garfield Tane8d84ab2019-10-11 09:49:40 -07002896 mActivityRecord != null && mActivityRecord.canShowWhenLocked();
lumark31e4f8e2019-01-10 20:48:18 +08002897 final boolean showBecauseOfWindow = (getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0;
2898 return showBecauseOfActivity || showBecauseOfWindow;
2899 }
2900
Issei Suzuki1669ea42019-11-06 14:20:59 +01002901 /** @return {@code false} if this window desires touch events. */
Robert Carrebdf8582018-09-04 14:50:15 -07002902 boolean cantReceiveTouchInput() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07002903 if (mActivityRecord == null || mActivityRecord.getTask() == null) {
Vinit Nayak8009e922019-09-05 11:49:53 -07002904 return false;
2905 }
2906
Wale Ogunwale0b3d2922019-12-30 08:55:07 -08002907 return mActivityRecord.getTask().getStack().shouldIgnoreInput()
Issei Suzuki1669ea42019-11-06 14:20:59 +01002908 || !mActivityRecord.mVisibleRequested
Winson Chungdc4edb82019-12-16 16:31:04 -08002909 || isRecentsAnimationConsumingAppInput();
Vinit Nayak8009e922019-09-05 11:49:53 -07002910 }
2911
2912 /**
Winson Chungdc4edb82019-12-16 16:31:04 -08002913 * Returns {@code true} if the window is animating to home as part of the recents animation and
2914 * it is consuming input from the app.
Vinit Nayak8009e922019-09-05 11:49:53 -07002915 */
Winson Chungdc4edb82019-12-16 16:31:04 -08002916 private boolean isRecentsAnimationConsumingAppInput() {
Vinit Nayak8009e922019-09-05 11:49:53 -07002917 final RecentsAnimationController recentsAnimationController =
2918 mWmService.getRecentsAnimationController();
2919 return recentsAnimationController != null
Winson Chungdc4edb82019-12-16 16:31:04 -08002920 && recentsAnimationController.shouldApplyInputConsumer(mActivityRecord);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002921 }
2922
Craig Mautner749a7bb2012-04-02 13:49:53 -07002923 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002924 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002925 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002926 }
2927
Craig Mautner749a7bb2012-04-02 13:49:53 -07002928 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002929 public boolean showLw(boolean doAnimation) {
2930 return showLw(doAnimation, true);
2931 }
2932
2933 boolean showLw(boolean doAnimation, boolean requestAnim) {
chaviw15ad49f2019-04-24 15:05:39 -07002934 if (isLegacyPolicyVisibility() && mLegacyPolicyVisibilityAfterAnim) {
Jorim Jaggi50150152019-03-27 23:08:58 +01002935 // Already showing.
2936 return false;
2937 }
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -08002938 if (!showToCurrentUser()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002939 return false;
2940 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002941 if (!mAppOpVisibility) {
2942 // Being hidden due to app op request.
2943 return false;
2944 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002945 if (mPermanentlyHidden) {
2946 // Permanently hidden until the app exists as apps aren't prepared
2947 // to handle their windows being removed from under them.
2948 return false;
2949 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002950 if (mHiddenWhileSuspended) {
2951 // Being hidden due to owner package being suspended.
2952 return false;
2953 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002954 if (mForceHideNonSystemOverlayWindow) {
2955 // This is an alert window that is currently force hidden.
2956 return false;
2957 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002958 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002959 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002960 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
lumark9bca6b42019-10-17 18:35:22 +08002961 + isLegacyPolicyVisibility()
2962 + " animating=" + isAnimating(TRANSITION | PARENTS));
David Stevens9440dc82017-03-16 19:00:20 -07002963 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002964 doAnimation = false;
lumark9bca6b42019-10-17 18:35:22 +08002965 } else if (isLegacyPolicyVisibility() && !isAnimating(TRANSITION | PARENTS)) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002966 // Check for the case where we are currently visible and
2967 // not animating; we do not want to do animation at such a
2968 // point to become visible when we already are.
2969 doAnimation = false;
2970 }
2971 }
chaviw15ad49f2019-04-24 15:05:39 -07002972 setPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
2973 mLegacyPolicyVisibilityAfterAnim = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002974 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002975 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002976 }
2977 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002978 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002979 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002980 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002981 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002982 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002983 return true;
2984 }
2985
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002986 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002987 public boolean hideLw(boolean doAnimation) {
2988 return hideLw(doAnimation, true);
2989 }
2990
2991 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2992 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002993 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002994 doAnimation = false;
2995 }
2996 }
chaviw15ad49f2019-04-24 15:05:39 -07002997 boolean current =
2998 doAnimation ? mLegacyPolicyVisibilityAfterAnim : isLegacyPolicyVisibility();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002999 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07003000 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003001 return false;
3002 }
3003 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01003004 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
lumark9bca6b42019-10-17 18:35:22 +08003005 if (!isAnimating(TRANSITION | PARENTS)) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003006 doAnimation = false;
3007 }
3008 }
chaviw15ad49f2019-04-24 15:05:39 -07003009 mLegacyPolicyVisibilityAfterAnim = false;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003010 final boolean isFocused = isFocused();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003011 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07003012 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
chaviw15ad49f2019-04-24 15:05:39 -07003013 clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003014 // Window is no longer visible -- make sure if we were waiting
3015 // for it to be displayed before enabling the display, that
3016 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003017 mWmService.enableScreenIfNeededLocked();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003018 if (isFocused) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02003019 ProtoLog.i(WM_DEBUG_FOCUS_LIGHT,
Craig Mautner58458122013-09-14 14:59:50 -07003020 "WindowState.hideLw: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003021 mWmService.mFocusMayChange = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003022 }
3023 }
3024 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003025 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003026 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003027 if (isFocused) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003028 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02003029 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003030 return true;
3031 }
3032
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003033 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
3034 if (mOwnerCanAddInternalSystemWindow
3035 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
3036 return;
3037 }
3038 if (mForceHideNonSystemOverlayWindow == forceHide) {
3039 return;
3040 }
3041 mForceHideNonSystemOverlayWindow = forceHide;
3042 if (forceHide) {
3043 hideLw(true /* doAnimation */, true /* requestAnim */);
3044 } else {
3045 showLw(true /* doAnimation */, true /* requestAnim */);
3046 }
3047 }
3048
Suprabh Shukla69c71422018-04-02 18:39:01 -07003049 void setHiddenWhileSuspended(boolean hide) {
3050 if (mOwnerCanAddInternalSystemWindow
3051 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
3052 return;
3053 }
3054 if (mHiddenWhileSuspended == hide) {
3055 return;
3056 }
3057 mHiddenWhileSuspended = hide;
3058 if (hide) {
3059 hideLw(true, true);
3060 } else {
3061 showLw(true, true);
3062 }
3063 }
3064
Svet Ganovf7b47252018-02-26 11:11:27 -08003065 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003066 if (mAppOpVisibility != state) {
3067 mAppOpVisibility = state;
3068 if (state) {
3069 // If the policy visibility had last been to hide, then this
3070 // will incorrectly show at this point since we lost that
3071 // information. Not a big deal -- for the windows that have app
3072 // ops modifies they should only be hidden by policy due to the
3073 // lock screen, and the user won't be changing this if locked.
3074 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08003075 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003076 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08003077 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003078 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003079 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003080 }
3081
Svet Ganovf7b47252018-02-26 11:11:27 -08003082 void initAppOpsState() {
3083 if (mAppOp == OP_NONE || !mAppOpVisibility) {
3084 return;
3085 }
3086 // If the app op was MODE_DEFAULT we would have checked the permission
3087 // and add the window only if the permission was granted. Therefore, if
3088 // the mode is MODE_DEFAULT we want the op to succeed as the window is
3089 // shown.
Riddle Hsue9b06e62020-03-11 22:17:39 -06003090 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, getOwningUid(),
3091 getOwningPackage(), true /* startIfModeDefault */, null /* featureId */,
3092 "init-default-visibility");
Svet Ganovf7b47252018-02-26 11:11:27 -08003093 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
3094 setAppOpVisibilityLw(false);
3095 }
3096 }
3097
3098 void resetAppOpsState() {
3099 if (mAppOp != OP_NONE && mAppOpVisibility) {
Riddle Hsue9b06e62020-03-11 22:17:39 -06003100 mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage(),
3101 null /* featureId */);
Svet Ganovf7b47252018-02-26 11:11:27 -08003102 }
3103 }
3104
3105 void updateAppOpsState() {
3106 if (mAppOp == OP_NONE) {
3107 return;
3108 }
3109 final int uid = getOwningUid();
3110 final String packageName = getOwningPackage();
3111 if (mAppOpVisibility) {
3112 // There is a race between the check and the finish calls but this is fine
3113 // as this would mean we will get another change callback and will reconcile.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003114 int mode = mWmService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08003115 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
Riddle Hsue9b06e62020-03-11 22:17:39 -06003116 mWmService.mAppOps.finishOp(mAppOp, uid, packageName, null /* featureId */);
Svet Ganovf7b47252018-02-26 11:11:27 -08003117 setAppOpVisibilityLw(false);
3118 }
3119 } else {
Riddle Hsue9b06e62020-03-11 22:17:39 -06003120 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName,
3121 true /* startIfModeDefault */, null /* featureId */, "attempt-to-be-visible");
Svet Ganovf7b47252018-02-26 11:11:27 -08003122 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
3123 setAppOpVisibilityLw(true);
3124 }
3125 }
3126 }
3127
Svetoslav Ganovaa076532016-08-01 19:16:43 -07003128 public void hidePermanentlyLw() {
3129 if (!mPermanentlyHidden) {
3130 mPermanentlyHidden = true;
3131 hideLw(true, true);
3132 }
3133 }
3134
Jeff Brownc2932a12014-11-20 18:04:05 -08003135 public void pokeDrawLockLw(long timeout) {
3136 if (isVisibleOrAdding()) {
3137 if (mDrawLock == null) {
3138 // We want the tag name to be somewhat stable so that it is easier to correlate
3139 // in wake lock statistics. So in particular, we don't want to include the
3140 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003141 final CharSequence tag = getWindowTag();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003142 mDrawLock = mWmService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08003143 mDrawLock.setReferenceCounted(false);
3144 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
3145 }
3146 // Each call to acquire resets the timeout.
3147 if (DEBUG_POWER) {
3148 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
3149 + mAttrs.packageName);
3150 }
3151 mDrawLock.acquire(timeout);
3152 } else if (DEBUG_POWER) {
3153 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
3154 + "owned by " + mAttrs.packageName);
3155 }
3156 }
3157
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003158 @Override
3159 public boolean isAlive() {
3160 return mClient.asBinder().isBinderAlive();
3161 }
3162
Craig Mautnera987d432012-10-11 14:07:58 -07003163 boolean isClosing() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07003164 return mAnimatingExit || (mActivityRecord != null && mActivityRecord.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07003165 }
3166
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003167 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
3168 animators.add(mWinAnimator);
3169
3170 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003171 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003172 c.addWinAnimatorToList(animators);
3173 }
3174 }
3175
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003176 void sendAppVisibilityToClients() {
3177 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003178
Issei Suzukid4ee1cc2019-11-08 13:20:14 +01003179 final boolean clientVisible = mActivityRecord.isClientVisible();
3180 if (mAttrs.type == TYPE_APPLICATION_STARTING && !clientVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003181 // Don't hide the starting window.
3182 return;
3183 }
3184
Issei Suzukid4ee1cc2019-11-08 13:20:14 +01003185 if (!clientVisible) {
Wale Ogunwale89973222017-04-23 18:39:45 -07003186 // Once we are notifying the client that it's visibility has changed, we need to prevent
3187 // it from destroying child surfaces until the animation has finished. We do this by
3188 // detaching any surface control the client added from the client.
3189 for (int i = mChildren.size() - 1; i >= 0; --i) {
3190 final WindowState c = mChildren.get(i);
3191 c.mWinAnimator.detachChildren();
3192 }
3193
3194 mWinAnimator.detachChildren();
3195 }
3196
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003197 try {
3198 if (DEBUG_VISIBILITY) Slog.v(TAG,
Issei Suzukid4ee1cc2019-11-08 13:20:14 +01003199 "Setting visibility of " + this + ": " + clientVisible);
3200 mClient.dispatchAppVisibility(clientVisible);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003201 } catch (RemoteException e) {
3202 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07003203 }
3204
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003205 void onStartFreezingScreen() {
3206 mAppFreezing = true;
3207 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003208 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003209 c.onStartFreezingScreen();
3210 }
3211 }
3212
3213 boolean onStopFreezingScreen() {
3214 boolean unfrozeWindows = false;
3215 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003216 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003217 unfrozeWindows |= c.onStopFreezingScreen();
3218 }
3219
3220 if (!mAppFreezing) {
3221 return unfrozeWindows;
3222 }
3223
Wale Ogunwale953171d2016-09-30 09:17:30 -07003224 mAppFreezing = false;
3225
Bryce Lee8c3cf382017-07-06 19:47:10 -07003226 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003227 && mWmService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02003228 ProtoLog.v(WM_DEBUG_ORIENTATION,
3229 "set mOrientationChanging of %s", this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003230 setOrientationChanging(true);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003231 mWmService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003232 }
3233 mLastFreezeDuration = 0;
3234 setDisplayLayoutNeeded();
3235 return true;
3236 }
3237
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003238 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
3239 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01003240
3241 // Copying to a different list as multiple children can be removed.
3242 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
3243 for (int i = childWindows.size() - 1; i >= 0; --i) {
3244 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003245 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
3246 }
3247
Robert Carrdb2f6e62017-03-01 20:17:58 -08003248 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
3249 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003250 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08003251
3252 if (appStopped || mWindowRemovalAllowed) {
3253 mWinAnimator.destroyPreservedSurfaceLocked();
3254 }
3255
3256 if (mDestroying) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02003257 ProtoLog.e(WM_DEBUG_ADD_REMOVE, "win=%s"
3258 + " destroySurfaces: appStopped=%b"
3259 + " win.mWindowRemovalAllowed=%b"
3260 + " win.mRemoveOnExit=%b", this, appStopped,
3261 mWindowRemovalAllowed, mRemoveOnExit);
Robert Carrdb2f6e62017-03-01 20:17:58 -08003262 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003263 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08003264 }
3265 if (mRemoveOnExit) {
3266 removeImmediately();
3267 }
3268 if (cleanupOnResume) {
3269 requestUpdateWallpaperIfNeeded();
3270 }
3271 mDestroying = false;
3272 destroyedSomething = true;
lumarka6681162019-04-12 01:47:54 +08003273
Garfield Tane8d84ab2019-10-11 09:49:40 -07003274 // Since mDestroying will affect ActivityRecord#allDrawn, we need to perform another
lumarka6681162019-04-12 01:47:54 +08003275 // traversal in case we are waiting on this window to start the transition.
3276 if (getDisplayContent().mAppTransition.isTransitionSet()
Garfield Tane8d84ab2019-10-11 09:49:40 -07003277 && getDisplayContent().mOpeningApps.contains(mActivityRecord)) {
lumarka6681162019-04-12 01:47:54 +08003278 mWmService.mWindowPlacerLocked.requestTraversal();
3279 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08003280 }
3281
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003282 return destroyedSomething;
3283 }
Chris Craik3131bde2016-05-06 13:39:08 -07003284
Robert Carr89a28ab2017-04-24 15:33:11 -07003285 // Destroy or save the application surface without checking
3286 // various indicators of whether the client has released the surface.
3287 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003288 void destroySurfaceUnchecked() {
3289 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08003290
Chong Zhang92147042016-05-09 12:47:11 -07003291 // Clear animating flags now, since the surface is now gone. (Note this is true even
3292 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
3293 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08003294 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07003295
Adrian Roos5f2c9a12019-07-03 18:31:46 +02003296 void onSurfaceShownChanged(boolean shown) {
3297 if (mLastShownChangedReported == shown) {
3298 return;
3299 }
3300 mLastShownChangedReported = shown;
3301
3302 if (shown) {
3303 initExclusionRestrictions();
3304 } else {
3305 logExclusionRestrictions(EXCLUSION_LEFT);
3306 logExclusionRestrictions(EXCLUSION_RIGHT);
3307 }
3308 }
3309
3310 private void logExclusionRestrictions(int side) {
3311 if (!logsGestureExclusionRestrictions(this)
3312 || SystemClock.uptimeMillis() < mLastExclusionLogUptimeMillis[side]
Adrian Roos1c2e9a12019-08-20 18:23:47 +02003313 + mWmService.mConstants.mSystemGestureExclusionLogDebounceTimeoutMillis) {
Adrian Roos5f2c9a12019-07-03 18:31:46 +02003314 // Drop the log if we have just logged; this is okay, because what we would have logged
3315 // was true only for a short duration.
3316 return;
3317 }
3318
3319 final long now = SystemClock.uptimeMillis();
3320 final long duration = now - mLastExclusionLogUptimeMillis[side];
3321 mLastExclusionLogUptimeMillis[side] = now;
3322
3323 final int requested = mLastRequestedExclusionHeight[side];
3324 final int granted = mLastGrantedExclusionHeight[side];
3325
Muhammad Qureshi759f92f2020-01-28 10:41:55 -08003326 FrameworkStatsLog.write(FrameworkStatsLog.EXCLUSION_RECT_STATE_CHANGED,
Adrian Roos5f2c9a12019-07-03 18:31:46 +02003327 mAttrs.packageName, requested, requested - granted /* rejected */,
3328 side + 1 /* Sides are 1-indexed in atoms.proto */,
3329 (getConfiguration().orientation == ORIENTATION_LANDSCAPE),
3330 isSplitScreenWindowingMode(getWindowingMode()), (int) duration);
3331 }
3332
3333 private void initExclusionRestrictions() {
3334 final long now = SystemClock.uptimeMillis();
3335 mLastExclusionLogUptimeMillis[EXCLUSION_LEFT] = now;
3336 mLastExclusionLogUptimeMillis[EXCLUSION_RIGHT] = now;
3337 }
3338
Craig Mautner69b08182012-09-05 13:07:13 -07003339 @Override
3340 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003341 final DisplayContent displayContent = getDisplayContent();
3342 if (displayContent == null) {
3343 // Only a window that was on a non-default display can be detached from it.
3344 return false;
3345 }
Winson Chung47a3e652014-05-21 16:03:42 -07003346 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07003347 }
3348
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -08003349 /** @return {@code true} if this window can be shown to all users. */
3350 boolean showForAllUsers() {
3351
3352 // If this switch statement is modified, modify the comment in the declarations of
3353 // the type in {@link WindowManager.LayoutParams} as well.
3354 switch (mAttrs.type) {
3355 default:
3356 // These are the windows that by default are shown only to the user that created
3357 // them. If this needs to be overridden, set
3358 // {@link WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS} in
3359 // {@link WindowManager.LayoutParams}. Note that permission
3360 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
3361 if ((mAttrs.privateFlags & SYSTEM_FLAG_SHOW_FOR_ALL_USERS) == 0) {
3362 return false;
3363 }
3364 break;
3365
3366 // These are the windows that by default are shown to all users. However, to
3367 // protect against spoofing, check permissions below.
3368 case TYPE_APPLICATION_STARTING:
3369 case TYPE_BOOT_PROGRESS:
3370 case TYPE_DISPLAY_OVERLAY:
3371 case TYPE_INPUT_CONSUMER:
3372 case TYPE_KEYGUARD_DIALOG:
3373 case TYPE_MAGNIFICATION_OVERLAY:
3374 case TYPE_NAVIGATION_BAR:
3375 case TYPE_NAVIGATION_BAR_PANEL:
3376 case TYPE_PHONE:
3377 case TYPE_POINTER:
3378 case TYPE_PRIORITY_PHONE:
3379 case TYPE_SEARCH_BAR:
3380 case TYPE_STATUS_BAR:
wilsonshihe8321942019-10-18 18:39:46 +08003381 case TYPE_NOTIFICATION_SHADE:
Heemin Seog2cf45dd2020-02-24 15:43:29 -08003382 case TYPE_STATUS_BAR_ADDITIONAL:
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -08003383 case TYPE_STATUS_BAR_SUB_PANEL:
3384 case TYPE_SYSTEM_DIALOG:
3385 case TYPE_VOLUME_OVERLAY:
3386 case TYPE_PRESENTATION:
3387 case TYPE_PRIVATE_PRESENTATION:
3388 case TYPE_DOCK_DIVIDER:
3389 break;
3390 }
3391
3392 // Only the system can show free windows to all users.
3393 return mOwnerCanAddInternalSystemWindow;
3394
Craig Mautner88400d32012-09-30 12:35:45 -07003395 }
3396
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -08003397 @Override
3398 boolean showToCurrentUser() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003399 // Child windows are evaluated based on their parent window.
3400 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003401 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Garfield Tane8d84ab2019-10-11 09:49:40 -07003402 && win.mActivityRecord != null && win.mActivityRecord.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07003403
3404 // All window frames that are fullscreen extend above status bar, but some don't extend
3405 // below navigation bar. Thus, check for display frame for top/left and stable frame for
3406 // bottom right.
chaviw492139a2018-07-16 16:07:35 -07003407 if (win.getFrameLw().left <= win.getDisplayFrameLw().left
3408 && win.getFrameLw().top <= win.getDisplayFrameLw().top
3409 && win.getFrameLw().right >= win.getStableFrameLw().right
3410 && win.getFrameLw().bottom >= win.getStableFrameLw().bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07003411 // Is a fullscreen window, like the clock alarm. Show to everyone.
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -08003412 return true;
Craig Mautner5962b122012-10-05 14:45:52 -07003413 }
3414 }
3415
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -08003416 return win.showForAllUsers()
wilsonshihd0fc2ca2020-03-18 22:41:55 +08003417 || mWmService.isCurrentProfile(win.mShowUserId);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07003418 }
3419
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003420 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
3421 outRegion.set(
3422 frame.left + inset.left, frame.top + inset.top,
3423 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04003424 }
3425
Riddle Hsuff03df52018-12-05 21:43:02 +08003426 /** Get the touchable region in global coordinates. */
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003427 void getTouchableRegion(Region outRegion) {
chaviw492139a2018-07-16 16:07:35 -07003428 final Rect frame = mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003429 switch (mTouchableInsets) {
3430 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003431 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003432 outRegion.set(frame);
3433 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003434 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003435 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003436 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003437 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003438 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003439 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003440 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003441 outRegion.set(mGivenTouchableRegion);
Riddle Hsub5e960f2018-12-07 14:51:26 +08003442 outRegion.translate(frame.left, frame.top);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003443 break;
3444 }
3445 }
Vishnu Nairb9246322018-12-06 13:54:02 -08003446 cropRegionToStackBoundsIfNeeded(outRegion);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08003447 subtractTouchExcludeRegionIfNeeded(outRegion);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003448 }
3449
Adrian Roosb1063792019-06-28 12:10:51 +02003450 /**
3451 * Get the effective touchable region in global coordinates.
3452 *
3453 * In contrast to {@link #getTouchableRegion}, this takes into account
3454 * {@link WindowManager.LayoutParams#FLAG_NOT_TOUCH_MODAL touch modality.}
3455 */
3456 void getEffectiveTouchableRegion(Region outRegion) {
3457 final boolean modal = (mAttrs.flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
3458 final DisplayContent dc = getDisplayContent();
3459
3460 if (modal && dc != null) {
3461 outRegion.set(dc.getBounds());
3462 cropRegionToStackBoundsIfNeeded(outRegion);
3463 subtractTouchExcludeRegionIfNeeded(outRegion);
3464 } else {
3465 getTouchableRegion(outRegion);
3466 }
3467 }
3468
Vishnu Nair93d68c22019-03-22 13:45:31 -07003469 private void setTouchableRegionCropIfNeeded(InputWindowHandle handle) {
3470 final Task task = getTask();
3471 if (task == null || !task.cropWindowsToStackBounds()) {
Evan Rosky38e9b212020-06-16 14:50:09 -07003472 handle.setTouchableRegionCrop(null);
Vishnu Nair93d68c22019-03-22 13:45:31 -07003473 return;
3474 }
3475
Wale Ogunwale0b3d2922019-12-30 08:55:07 -08003476 final ActivityStack stack = task.getStack();
arthurhungda4c2d62020-04-21 14:38:54 +08003477 if (stack == null || inFreeformWindowingMode()) {
arthurhung31fdb942020-04-27 18:51:27 +08003478 handle.setTouchableRegionCrop(null);
Vishnu Nair93d68c22019-03-22 13:45:31 -07003479 return;
3480 }
3481
3482 handle.setTouchableRegionCrop(stack.getSurfaceControl());
3483 }
3484
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003485 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003486 final Task task = getTask();
3487 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003488 return;
3489 }
3490
Wale Ogunwale0b3d2922019-12-30 08:55:07 -08003491 final ActivityStack stack = task.getStack();
Louis Changa009c762020-02-26 11:21:31 +08003492 if (stack == null || stack.mCreatedByOrganizer) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003493 return;
3494 }
3495
3496 stack.getDimBounds(mTmpRect);
arthurhungda4c2d62020-04-21 14:38:54 +08003497 adjustRegionInFreefromWindowMode(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003498 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003499 }
3500
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003501 /**
Tiger Huang04dc4cc2019-01-17 18:41:41 +08003502 * If this window has areas that cannot be touched, we subtract those areas from its touchable
3503 * region.
3504 */
3505 private void subtractTouchExcludeRegionIfNeeded(Region touchableRegion) {
chaviwaa0d74e2019-12-26 14:13:40 -08003506 if (mTapExcludeRegion.isEmpty()) {
Tiger Huang04dc4cc2019-01-17 18:41:41 +08003507 return;
3508 }
3509 final Region touchExcludeRegion = Region.obtain();
chaviwaa0d74e2019-12-26 14:13:40 -08003510 getTapExcludeRegion(touchExcludeRegion);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08003511 if (!touchExcludeRegion.isEmpty()) {
3512 touchableRegion.op(touchExcludeRegion, Region.Op.DIFFERENCE);
3513 }
3514 touchExcludeRegion.recycle();
3515 }
3516
3517 /**
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003518 * Report a focus change. Must be called with no locks held, and consistently
3519 * from the same serialized thread (such as dispatched from a handler).
3520 */
Siarhei Vishniakou3b8e8722019-09-20 16:28:12 +01003521 void reportFocusChangedSerialized(boolean focused) {
Tiger Huang51c5a1d2018-12-11 20:24:51 +08003522 if (mFocusCallbacks != null) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003523 final int N = mFocusCallbacks.beginBroadcast();
3524 for (int i=0; i<N; i++) {
3525 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
3526 try {
3527 if (focused) {
3528 obs.focusGained(mWindowId.asBinder());
3529 } else {
3530 obs.focusLost(mWindowId.asBinder());
3531 }
3532 } catch (RemoteException e) {
3533 }
3534 }
3535 mFocusCallbacks.finishBroadcast();
3536 }
3537 }
3538
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003539 @Override
3540 public Configuration getConfiguration() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07003541 if (mActivityRecord != null && mActivityRecord.mFrozenMergedConfig.size() > 0) {
3542 return mActivityRecord.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003543 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003544
Yunfan Chenb4fe58c2019-03-27 18:35:06 +09003545 // If the process has not registered to any display to listen to the configuration change,
3546 // we can simply return the mFullConfiguration as default.
3547 if (!registeredForDisplayConfigChanges()) {
3548 return super.getConfiguration();
3549 }
3550
Yunfan Chen75157d72018-07-27 14:47:21 +09003551 // We use the process config this window is associated with as the based global config since
Yunfan Chenb4fe58c2019-03-27 18:35:06 +09003552 // the process can override its config, but isn't part of the window hierarchy.
3553 mTempConfiguration.setTo(getProcessGlobalConfiguration());
3554 mTempConfiguration.updateFrom(getMergedOverrideConfiguration());
3555 return mTempConfiguration;
3556 }
3557
3558 /** @return {@code true} if the process registered to a display as a config listener. */
3559 private boolean registeredForDisplayConfigChanges() {
3560 final WindowState parentWindow = getParentWindow();
Jorim Jaggi268bf6882020-06-18 23:44:02 +02003561 final WindowProcessController wpc = parentWindow != null
3562 ? parentWindow.mWpcForDisplayConfigChanges
3563 : mWpcForDisplayConfigChanges;
3564 return wpc != null && wpc.registeredForDisplayConfigChanges();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003565 }
3566
Craig Mautnerdf88d732014-01-27 09:21:32 -08003567 void reportResized() {
Riddle Hsu07217a02019-12-04 00:24:30 +08003568 if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) {
3569 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
3570 }
3571
3572 ProtoLog.v(WM_DEBUG_RESIZE, "Reporting new frame to %s: %s", this,
3573 mWindowFrames.mCompatFrame);
3574 if (mWinAnimator.mDrawState == DRAW_PENDING) {
3575 ProtoLog.i(WM_DEBUG_ORIENTATION, "Resizing %s WITH DRAW PENDING", this);
3576 }
3577
3578 getMergedConfiguration(mLastReportedConfiguration);
3579 mLastConfigReportedToClient = true;
3580
Riddle Hsu839b5f52020-03-31 21:41:18 +08003581 final boolean reportOrientation = mReportOrientationChanged;
3582 // Always reset these states first, so if {@link IWindow#resized} fails, this
3583 // window won't be added to {@link WindowManagerService#mResizingWindows} and set
3584 // {@link #mOrientationChanging} to true again by {@link #updateResizingWindowIfNeeded}
3585 // that may cause WINDOW_FREEZE_TIMEOUT because resizing the client keeps failing.
3586 mReportOrientationChanged = false;
3587 mDragResizingChangeReported = true;
3588 mWinAnimator.mSurfaceResized = false;
3589 mWindowFrames.resetInsetsChanged();
3590
Riddle Hsu07217a02019-12-04 00:24:30 +08003591 final Rect frame = mWindowFrames.mCompatFrame;
3592 final Rect contentInsets = mWindowFrames.mLastContentInsets;
3593 final Rect visibleInsets = mWindowFrames.mLastVisibleInsets;
3594 final Rect stableInsets = mWindowFrames.mLastStableInsets;
3595 final MergedConfiguration mergedConfiguration = mLastReportedConfiguration;
Robert Carr52385c32020-06-23 15:56:28 -07003596 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING || useBLASTSync() || !mRedrawForSyncReported;
3597 final boolean forceRelayout = reportOrientation || isDragResizeChanged() || !mRedrawForSyncReported;
Riddle Hsu07217a02019-12-04 00:24:30 +08003598 final int displayId = getDisplayId();
3599 final DisplayCutout displayCutout = getWmDisplayCutout().getDisplayCutout();
3600
Robert Carr52385c32020-06-23 15:56:28 -07003601 mRedrawForSyncReported = true;
3602
Craig Mautnerdf88d732014-01-27 09:21:32 -08003603 try {
Riddle Hsu07217a02019-12-04 00:24:30 +08003604 mClient.resized(frame, contentInsets, visibleInsets, stableInsets, reportDraw,
3605 mergedConfiguration, getBackdropFrame(frame), forceRelayout,
3606 getDisplayContent().getDisplayPolicy().areSystemBarsForcedShownLw(this),
3607 displayId, new DisplayCutout.ParcelableWrapper(displayCutout));
Bryce Leef858b572017-06-29 14:03:33 -07003608
Jacky Kaof93252b2019-07-18 15:19:52 +08003609 if (mWmService.mAccessibilityController != null) {
Riddle Hsu07217a02019-12-04 00:24:30 +08003610 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(displayId);
Svetoslav4604abc2014-06-10 18:59:30 -07003611 }
Jackal Guoc43a0a62019-04-23 09:15:14 +08003612 updateLocationInParentDisplayIfNeeded();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003613 } catch (RemoteException e) {
Riddle Hsu839b5f52020-03-31 21:41:18 +08003614 // Cancel orientation change of this window to avoid blocking unfreeze display.
Bryce Lee8c3cf382017-07-06 19:47:10 -07003615 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003616 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003617 - mWmService.mDisplayFreezeTime);
Riddle Hsu839b5f52020-03-31 21:41:18 +08003618 Slog.w(TAG, "Failed to report 'resized' to " + this + " due to " + e);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003619 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003620 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003621 }
3622
Tiger Huang0426a332020-03-29 01:17:08 +08003623 boolean isClientLocal() {
3624 return mClient instanceof IWindow.Stub;
3625 }
3626
Jackal Guoc43a0a62019-04-23 09:15:14 +08003627 void updateLocationInParentDisplayIfNeeded() {
3628 final int embeddedDisplayContentsSize = mEmbeddedDisplayContents.size();
3629 // If there is any embedded display which is re-parented to this window, we need to
3630 // notify all windows in the embedded display about the location change.
3631 if (embeddedDisplayContentsSize != 0) {
3632 for (int i = embeddedDisplayContentsSize - 1; i >= 0; i--) {
3633 final DisplayContent edc = mEmbeddedDisplayContents.valueAt(i);
3634 edc.notifyLocationInParentDisplayChanged();
3635 }
3636 }
3637 // If this window is in a embedded display which is re-parented to another window,
3638 // we may need to update its correct on-screen location.
3639 final DisplayContent dc = getDisplayContent();
3640 if (dc.getParentWindow() == null) {
3641 return;
3642 }
3643
3644 final Point offset = dc.getLocationInParentDisplay();
3645 if (mLastReportedDisplayOffset.equals(offset)) {
3646 return;
3647 }
3648
3649 mLastReportedDisplayOffset.set(offset.x, offset.y);
3650 try {
3651 mClient.locationInParentDisplayChanged(mLastReportedDisplayOffset);
3652 } catch (RemoteException e) {
3653 Slog.e(TAG, "Failed to update offset from DisplayContent", e);
3654 }
3655 }
3656
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003657 /**
3658 * Called when the insets state changed.
3659 */
3660 void notifyInsetsChanged() {
Taran Singh85661e32020-05-07 14:45:34 -07003661 ProtoLog.d(WM_DEBUG_IME, "notifyInsetsChanged for %s ", this);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003662 try {
Riddle Hsu55d7c402020-02-26 22:49:29 +08003663 mClient.insetsChanged(getInsetsState());
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003664 } catch (RemoteException e) {
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -07003665 Slog.w(TAG, "Failed to deliver inset state change w=" + this, e);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003666 }
3667 }
3668
Jorim Jaggi28620472019-01-02 23:21:49 +01003669 @Override
3670 public void notifyInsetsControlChanged() {
Taran Singh85661e32020-05-07 14:45:34 -07003671 ProtoLog.d(WM_DEBUG_IME, "notifyInsetsControlChanged for %s ", this);
Tiger Huange1b67cd2020-05-30 02:17:26 +08003672 if (mAppDied || mRemoved) {
3673 return;
3674 }
Jorim Jaggib6030952018-10-23 18:31:52 +02003675 final InsetsStateController stateController =
3676 getDisplayContent().getInsetsStateController();
3677 try {
Riddle Hsu55d7c402020-02-26 22:49:29 +08003678 mClient.insetsControlChanged(getInsetsState(),
Jorim Jaggib6030952018-10-23 18:31:52 +02003679 stateController.getControlsForDispatch(this));
3680 } catch (RemoteException e) {
Wale Ogunwale0db64ac2020-04-11 10:00:42 -07003681 Slog.w(TAG, "Failed to deliver inset state change to w=" + this, e);
Jorim Jaggib6030952018-10-23 18:31:52 +02003682 }
3683 }
3684
Tarandeep Singh0bedd942019-09-26 13:34:03 -07003685 @Override
Tarandeep Singh1e5b1a82020-01-24 16:03:05 -08003686 public WindowState getWindow() {
3687 return this;
3688 }
3689
3690 @Override
Tiger Huang332793b2019-10-29 23:21:27 +08003691 public void showInsets(@InsetsType int types, boolean fromIme) {
Tarandeep Singh0bedd942019-09-26 13:34:03 -07003692 try {
3693 mClient.showInsets(types, fromIme);
3694 } catch (RemoteException e) {
3695 Slog.w(TAG, "Failed to deliver showInsets", e);
3696 }
3697 }
3698
Taran Singhf1e08872019-10-10 14:38:52 +02003699 @Override
Tiger Huang332793b2019-10-29 23:21:27 +08003700 public void hideInsets(@InsetsType int types, boolean fromIme) {
Taran Singhf1e08872019-10-10 14:38:52 +02003701 try {
3702 mClient.hideInsets(types, fromIme);
3703 } catch (RemoteException e) {
3704 Slog.w(TAG, "Failed to deliver showInsets", e);
3705 }
3706 }
3707
Jorim Jaggi956ca412019-01-07 14:49:14 +01003708 @Override
3709 public boolean canShowTransient() {
3710 return (mAttrs.insetsFlags.behavior & BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE) != 0;
3711 }
3712
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003713 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003714 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3715 // start even if we haven't received the relayout window, so that the client requests
3716 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3717 // until the window to small size, otherwise the multithread renderer will shift last
3718 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3719 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003720 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003721 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Garfield Tanfbd8ea62018-10-16 17:09:49 -07003722 // Surface position is now inherited from parent, and BackdropFrameRenderer uses
3723 // backdrop frame to position content. Thus we just keep the size of backdrop frame, and
3724 // remove the offset to avoid double offset from display origin.
3725 mTmpRect.set(frame);
3726 mTmpRect.offsetTo(0, 0);
3727 return mTmpRect;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003728 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003729 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003730 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003731 return mTmpRect;
3732 }
3733
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08003734 private int getRootTaskId() {
3735 final ActivityStack stack = getRootTask();
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003736 if (stack == null) {
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08003737 return INVALID_TASK_ID;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003738 }
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08003739 return stack.mTaskId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003740 }
3741
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003742 public void registerFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003743 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003744 if (mFocusCallbacks == null) {
3745 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3746 }
3747 mFocusCallbacks.register(observer);
3748 }
3749 }
3750
3751 public void unregisterFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003752 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003753 if (mFocusCallbacks != null) {
3754 mFocusCallbacks.unregister(observer);
3755 }
3756 }
3757 }
3758
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003759 boolean isFocused() {
3760 return getDisplayContent().mCurrentFocus == this;
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003761 }
3762
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003763
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003764 /** Is this window in a container that takes up the entire screen space? */
Evan Rosky4fb1e912019-03-06 13:54:43 -08003765 private boolean inAppWindowThatMatchesParentBounds() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07003766 return mActivityRecord == null || (mActivityRecord.matchParentBounds() && !inMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003767 }
3768
Evan Rosky4fb1e912019-03-06 13:54:43 -08003769 /** @return true when the window is in fullscreen mode, but has non-fullscreen bounds set, or
3770 * is transitioning into/out-of fullscreen. */
Andrii Kulian283acd22017-08-03 04:03:51 -07003771 boolean isLetterboxedAppWindow() {
Evan Rosky4fb1e912019-03-06 13:54:43 -08003772 return !inMultiWindowMode() && !matchesDisplayBounds()
Adrian Roos865c70f2018-01-10 17:32:27 +01003773 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003774 }
3775
Adrian Roos865c70f2018-01-10 17:32:27 +01003776 @Override
3777 public boolean isLetterboxedForDisplayCutoutLw() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07003778 if (mActivityRecord == null) {
3779 // Only windows with an ActivityRecord are letterboxed.
Adrian Roos865c70f2018-01-10 17:32:27 +01003780 return false;
3781 }
chaviwcdba9a42018-07-19 11:36:42 -07003782 if (!mWindowFrames.parentFrameWasClippedByDisplayCutout()) {
Adrian Roos5ed644f2018-03-19 17:01:05 +01003783 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003784 return false;
3785 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003786 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003787 // Layout in cutout, no letterbox.
3788 return false;
3789 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003790 if (!mAttrs.isFullscreen()) {
3791 // Not filling the parent frame, no letterbox
3792 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003793 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003794 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3795 // it to be.
3796 return !frameCoversEntireAppTokenBounds();
3797 }
3798
3799 /**
3800 * @return true if this window covers the entire bounds of its app window token
3801 * @throws NullPointerException if there is no app window token for this window
3802 */
3803 private boolean frameCoversEntireAppTokenBounds() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07003804 mTmpRect.set(mActivityRecord.getBounds());
chaviw492139a2018-07-16 16:07:35 -07003805 mTmpRect.intersectUnchecked(mWindowFrames.mFrame);
Garfield Tane8d84ab2019-10-11 09:49:40 -07003806 return mActivityRecord.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003807 }
3808
wilsonshih42eb13d2020-07-14 13:15:09 +08003809 /**
3810 * @see Letterbox#notIntersectsOrFullyContains(Rect)
3811 */
3812 boolean letterboxNotIntersectsOrFullyContains(Rect rect) {
3813 return mActivityRecord == null
3814 || mActivityRecord.letterboxNotIntersectsOrFullyContains(rect);
3815 }
3816
Adrian Roos10f164b2020-07-10 19:00:46 +00003817 public boolean isLetterboxedOverlappingWith(Rect rect) {
3818 return mActivityRecord != null && mActivityRecord.isLetterboxOverlappingWith(rect);
Adrian Roos23df3a32018-03-15 15:41:13 +01003819 }
3820
Chong Zhang3005e752015-09-18 18:46:28 -07003821 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003822 return mDragResizing != computeDragResizing();
3823 }
3824
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003825 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003826 void setWaitingForDrawnIfResizingChanged() {
3827 if (isDragResizeChanged()) {
Yunfan Chen87b5a242019-10-01 17:53:59 +09003828 mWmService.mRoot.mWaitingForDrawn.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003829 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003830 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003831 }
3832
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003833 /**
3834 * @return Whether we reported a drag resize change to the application or not already.
3835 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003836 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003837 return mDragResizingChangeReported;
3838 }
3839
3840 /**
3841 * Resets the state whether we reported a drag resize change to the app.
3842 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003843 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003844 void resetDragResizingChangeReported() {
3845 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003846 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003847 }
3848
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003849 int getResizeMode() {
3850 return mResizeMode;
3851 }
3852
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003853 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003854 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003855 if (task == null) {
3856 return false;
3857 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003858 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003859 return false;
3860 }
Evan Rosky36138542020-05-01 18:02:11 -07003861 // TODO(157912944): formalize drag-resizing so that exceptions aren't hardcoded like this
3862 if (task.getActivityType() == ACTIVITY_TYPE_HOME) {
3863 // The current sys-ui implementations never live-resize home, so to prevent WSA from
3864 // creating/destroying surfaces (which messes up sync-transactions), skip HOME tasks.
3865 return false;
3866 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003867 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003868 // Floating windows never enter drag resize mode.
3869 return false;
3870 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003871 if (task.isDragResizing()) {
3872 return true;
3873 }
Jorim Jaggi0429f3522015-12-22 16:29:16 +01003874
3875 // If the bounds are currently frozen, it means that the layout size that the app sees
3876 // and the bounds we clip this window to might be different. In order to avoid holes, we
3877 // simulate that we are still resizing so the app fills the hole with the resizing
3878 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003879 return (getDisplayContent().mDividerControllerLocked.isResizing()
Garfield Tane8d84ab2019-10-11 09:49:40 -07003880 || mActivityRecord != null && !mActivityRecord.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003881 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003882
Chong Zhang3005e752015-09-18 18:46:28 -07003883 }
3884
3885 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003886 final boolean resizing = computeDragResizing();
3887 if (resizing == mDragResizing) {
3888 return;
3889 }
3890 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003891 final Task task = getTask();
3892 if (task != null && task.isDragResizing()) {
3893 mResizeMode = task.getDragResizeMode();
3894 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003895 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003896 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3897 : DRAG_RESIZE_MODE_FREEFORM;
3898 }
Chong Zhang3005e752015-09-18 18:46:28 -07003899 }
3900
3901 boolean isDragResizing() {
3902 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003903 }
3904
Robert Carr2487ce72016-04-07 15:18:45 -07003905 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003906 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3907 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003908 }
3909
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003910 @CallSuper
3911 @Override
Jeffrey Huangcb782852019-12-05 11:28:11 -08003912 public void dumpDebug(ProtoOutputStream proto, long fieldId,
Nataniel Borges023ecb52019-01-16 14:15:43 -08003913 @WindowTraceLogLevel int logLevel) {
3914 boolean isVisible = isVisible();
3915 if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible) {
3916 return;
3917 }
3918
Steven Timotiusaf03df62017-07-18 16:56:43 -07003919 final long token = proto.start(fieldId);
Jeffrey Huangcb782852019-12-05 11:28:11 -08003920 super.dumpDebug(proto, WINDOW_CONTAINER, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003921 writeIdentifierToProto(proto, IDENTIFIER);
3922 proto.write(DISPLAY_ID, getDisplayId());
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08003923 proto.write(STACK_ID, getRootTaskId());
Jeffrey Huangcb782852019-12-05 11:28:11 -08003924 mAttrs.dumpDebug(proto, ATTRIBUTES);
3925 mGivenContentInsets.dumpDebug(proto, GIVEN_CONTENT_INSETS);
3926 mWindowFrames.dumpDebug(proto, WINDOW_FRAMES);
3927 mAttrs.surfaceInsets.dumpDebug(proto, SURFACE_INSETS);
3928 mSurfacePosition.dumpDebug(proto, SURFACE_POSITION);
3929 mWinAnimator.dumpDebug(proto, ANIMATOR);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003930 proto.write(ANIMATING_EXIT, mAnimatingExit);
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003931 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3932 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3933 proto.write(VIEW_VISIBILITY, mViewVisibility);
3934 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3935 proto.write(HAS_SURFACE, mHasSurface);
3936 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003937 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3938 proto.write(DESTROYING, mDestroying);
3939 proto.write(REMOVED, mRemoved);
3940 proto.write(IS_ON_SCREEN, isOnScreen());
Nataniel Borges023ecb52019-01-16 14:15:43 -08003941 proto.write(IS_VISIBLE, isVisible);
Vishnu Nairddd80742018-08-21 14:12:46 -07003942 proto.write(PENDING_SEAMLESS_ROTATION, mPendingSeamlessRotate != null);
3943 proto.write(FINISHED_SEAMLESS_ROTATION_FRAME, mFinishSeamlessRotateFrameNumber);
3944 proto.write(FORCE_SEAMLESS_ROTATION, mForceSeamlesslyRotate);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003945 proto.end(token);
3946 }
3947
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003948 @Override
Vishnu Nairdddc9f52020-03-09 09:37:27 -07003949 long getProtoFieldId() {
3950 return WINDOW;
3951 }
3952
3953 @Override
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003954 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003955 final long token = proto.start(fieldId);
3956 proto.write(HASH_CODE, System.identityHashCode(this));
wilsonshihd0fc2ca2020-03-18 22:41:55 +08003957 proto.write(USER_ID, mShowUserId);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003958 final CharSequence title = getWindowTag();
3959 if (title != null) {
3960 proto.write(TITLE, title.toString());
3961 }
3962 proto.end(token);
3963 }
3964
Jorim Jaggia5e10572017-11-15 14:36:26 +01003965 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003966 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003967 pw.print(prefix + "mDisplayId=" + getDisplayId());
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08003968 if (getRootTask() != null) {
3969 pw.print(" rootTaskId=" + getRootTaskId());
chaviwc65fa582018-08-09 15:33:13 -07003970 }
3971 pw.println(" mSession=" + mSession
3972 + " mClient=" + mClient.asBinder());
3973 pw.println(prefix + "mOwnerUid=" + mOwnerUid
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -08003974 + " showForAllUsers=" + showForAllUsers()
chaviwc65fa582018-08-09 15:33:13 -07003975 + " package=" + mAttrs.packageName
3976 + " appop=" + AppOpsManager.opToName(mAppOp));
3977 pw.println(prefix + "mAttrs=" + mAttrs.toString(prefix));
3978 pw.println(prefix + "Requested w=" + mRequestedWidth
3979 + " h=" + mRequestedHeight
3980 + " mLayoutSeq=" + mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003981 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
chaviwc65fa582018-08-09 15:33:13 -07003982 pw.println(prefix + "LastRequested w=" + mLastRequestedWidth
3983 + " h=" + mLastRequestedHeight);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003984 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003985 if (mIsChildWindow || mLayoutAttached) {
chaviwc65fa582018-08-09 15:33:13 -07003986 pw.println(prefix + "mParentWindow=" + getParentWindow()
3987 + " mLayoutAttached=" + mLayoutAttached);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003988 }
3989 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
chaviwc65fa582018-08-09 15:33:13 -07003990 pw.println(prefix + "mIsImWindow=" + mIsImWindow
3991 + " mIsWallpaper=" + mIsWallpaper
3992 + " mIsFloatingLayer=" + mIsFloatingLayer
3993 + " mWallpaperVisible=" + mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003994 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003995 if (dumpAll) {
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003996 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3997 pw.print(" mSubLayer="); pw.print(mSubLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003998 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003999 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07004000 pw.println(prefix + "mToken=" + mToken);
Garfield Tane8d84ab2019-10-11 09:49:40 -07004001 if (mActivityRecord != null) {
4002 pw.println(prefix + "mActivityRecord=" + mActivityRecord);
chaviwc65fa582018-08-09 15:33:13 -07004003 pw.print(prefix + "mAppDied=" + mAppDied);
4004 pw.print(prefix + "drawnStateEvaluated=" + getDrawnStateEvaluated());
4005 pw.println(prefix + "mightAffectAllDrawn=" + mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07004006 }
chaviwc65fa582018-08-09 15:33:13 -07004007 pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility)
4008 + " mHaveFrame=" + mHaveFrame
4009 + " mObscured=" + mObscured);
4010 pw.println(prefix + "mSeq=" + mSeq
4011 + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004012 }
chaviw15ad49f2019-04-24 15:05:39 -07004013 if (!isVisibleByPolicy() || !mLegacyPolicyVisibilityAfterAnim || !mAppOpVisibility
chaviwc65fa582018-08-09 15:33:13 -07004014 || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow
Suprabh Shukla69c71422018-04-02 18:39:01 -07004015 || mHiddenWhileSuspended) {
chaviw15ad49f2019-04-24 15:05:39 -07004016 pw.println(prefix + "mPolicyVisibility=" + isVisibleByPolicy()
4017 + " mLegacyPolicyVisibilityAfterAnim=" + mLegacyPolicyVisibilityAfterAnim
chaviwc65fa582018-08-09 15:33:13 -07004018 + " mAppOpVisibility=" + mAppOpVisibility
4019 + " parentHidden=" + isParentWindowHidden()
4020 + " mPermanentlyHidden=" + mPermanentlyHidden
4021 + " mHiddenWhileSuspended=" + mHiddenWhileSuspended
4022 + " mForceHideNonSystemOverlayWindow=" + mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004023 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08004024 if (!mRelayoutCalled || mLayoutNeeded) {
chaviwc65fa582018-08-09 15:33:13 -07004025 pw.println(prefix + "mRelayoutCalled=" + mRelayoutCalled
4026 + " mLayoutNeeded=" + mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004027 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07004028 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07004029 pw.println(prefix + "mGivenContentInsets=" + mGivenContentInsets.toShortString(sTmpSB)
4030 + " mGivenVisibleInsets=" + mGivenVisibleInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07004031 if (mTouchableInsets != 0 || mGivenInsetsPending) {
chaviwc65fa582018-08-09 15:33:13 -07004032 pw.println(prefix + "mTouchableInsets=" + mTouchableInsets
4033 + " mGivenInsetsPending=" + mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07004034 Region region = new Region();
4035 getTouchableRegion(region);
chaviwc65fa582018-08-09 15:33:13 -07004036 pw.println(prefix + "touchable region=" + region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07004037 }
chaviwc65fa582018-08-09 15:33:13 -07004038 pw.println(prefix + "mFullConfiguration=" + getConfiguration());
4039 pw.println(prefix + "mLastReportedConfiguration=" + getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004040 }
chaviwc65fa582018-08-09 15:33:13 -07004041 pw.println(prefix + "mHasSurface=" + mHasSurface
4042 + " isReadyForDisplay()=" + isReadyForDisplay()
4043 + " mWindowRemovalAllowed=" + mWindowRemovalAllowed);
Riddle Hsub398da32019-01-21 21:48:16 +08004044 if (inSizeCompatMode()) {
chaviw9c81e632018-07-31 11:17:52 -07004045 pw.println(prefix + "mCompatFrame=" + mWindowFrames.mCompatFrame.toShortString(sTmpSB));
Dianne Hackbornffb3d932011-05-17 17:44:51 -07004046 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07004047 if (dumpAll) {
chaviw553b0212018-07-12 13:37:01 -07004048 mWindowFrames.dump(pw, prefix);
chaviw9c81e632018-07-31 11:17:52 -07004049 pw.println(prefix + " surface=" + mAttrs.surfaceInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07004050 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004051 super.dump(pw, prefix, dumpAll);
chaviwc65fa582018-08-09 15:33:13 -07004052 pw.println(prefix + mWinAnimator + ":");
Dianne Hackborn529e7442012-11-01 14:22:28 -07004053 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08004054 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
chaviwc65fa582018-08-09 15:33:13 -07004055 pw.println(prefix + "mAnimatingExit=" + mAnimatingExit
4056 + " mRemoveOnExit=" + mRemoveOnExit
4057 + " mDestroying=" + mDestroying
4058 + " mRemoved=" + mRemoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004059 }
chaviw40234662018-02-07 09:37:16 -08004060 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
chaviwc65fa582018-08-09 15:33:13 -07004061 pw.println(prefix + "mOrientationChanging=" + mOrientationChanging
4062 + " configOrientationChanging="
4063 + (getLastReportedConfiguration().orientation != getConfiguration().orientation)
4064 + " mAppFreezing=" + mAppFreezing
4065 + " mReportOrientationChanged=" + mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004066 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07004067 if (mLastFreezeDuration != 0) {
chaviwc65fa582018-08-09 15:33:13 -07004068 pw.print(prefix + "mLastFreezeDuration=");
4069 TimeUtils.formatDuration(mLastFreezeDuration, pw);
4070 pw.println();
Dianne Hackborna57c6952013-03-29 14:46:40 -07004071 }
chaviwc65fa582018-08-09 15:33:13 -07004072 pw.print(prefix + "mForceSeamlesslyRotate=" + mForceSeamlesslyRotate
4073 + " seamlesslyRotate: pending=");
Vishnu Nairddd80742018-08-21 14:12:46 -07004074 if (mPendingSeamlessRotate != null) {
4075 mPendingSeamlessRotate.dump(pw);
4076 } else {
4077 pw.print("null");
Adrian Roos27a90d22018-07-06 02:39:54 -07004078 }
chaviwc65fa582018-08-09 15:33:13 -07004079 pw.println(" finishedFrameNumber=" + mFinishSeamlessRotateFrameNumber);
Vishnu Nairddd80742018-08-21 14:12:46 -07004080
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004081 if (mHScale != 1 || mVScale != 1) {
chaviwc65fa582018-08-09 15:33:13 -07004082 pw.println(prefix + "mHScale=" + mHScale
4083 + " mVScale=" + mVScale);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004084 }
4085 if (mWallpaperX != -1 || mWallpaperY != -1) {
chaviwc65fa582018-08-09 15:33:13 -07004086 pw.println(prefix + "mWallpaperX=" + mWallpaperX
4087 + " mWallpaperY=" + mWallpaperY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004088 }
4089 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
chaviwc65fa582018-08-09 15:33:13 -07004090 pw.println(prefix + "mWallpaperXStep=" + mWallpaperXStep
4091 + " mWallpaperYStep=" + mWallpaperYStep);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004092 }
Lucas Dupin13f4b8a2020-02-19 13:41:52 -08004093 if (mWallpaperZoomOut != -1) {
4094 pw.println(prefix + "mWallpaperZoomOut=" + mWallpaperZoomOut);
4095 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004096 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
4097 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
chaviwc65fa582018-08-09 15:33:13 -07004098 pw.println(prefix + "mWallpaperDisplayOffsetX=" + mWallpaperDisplayOffsetX
4099 + " mWallpaperDisplayOffsetY=" + mWallpaperDisplayOffsetY);
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004100 }
Jeff Brownc2932a12014-11-20 18:04:05 -08004101 if (mDrawLock != null) {
chaviwc65fa582018-08-09 15:33:13 -07004102 pw.println(prefix + "mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08004103 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08004104 if (isDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07004105 pw.println(prefix + "isDragResizing=" + isDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08004106 }
4107 if (computeDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07004108 pw.println(prefix + "computeDragResizing=" + computeDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08004109 }
chaviwc65fa582018-08-09 15:33:13 -07004110 pw.println(prefix + "isOnScreen=" + isOnScreen());
4111 pw.println(prefix + "isVisible=" + isVisible());
Jorim Jaggi49b9f6c2020-03-24 22:28:38 +01004112 if (!mEmbeddedDisplayContents.isEmpty()) {
4113 pw.println(prefix + "mEmbeddedDisplayContents=" + mEmbeddedDisplayContents);
4114 }
4115 if (dumpAll) {
4116 pw.println(prefix + "mRequestedInsetsState: " + mRequestedInsetsState);
4117 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004118 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08004119
Wale Ogunwale9adfe572016-09-08 20:43:58 -07004120 @Override
4121 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004122 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01004123 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07004124 }
4125
Robert Carra1eb4392015-12-10 12:43:51 -08004126 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07004127 CharSequence tag = mAttrs.getTitle();
4128 if (tag == null || tag.length() <= 0) {
4129 tag = mAttrs.packageName;
4130 }
4131 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004132 }
4133
4134 @Override
4135 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07004136 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08004137 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08004138 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08004139 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004140 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
wilsonshihd0fc2ca2020-03-18 22:41:55 +08004141 + " u" + mShowUserId
Wale Ogunwalec48a3542016-02-19 15:18:45 -08004142 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08004143 }
4144 return mStringNameCache;
4145 }
Robert Carr58f29132015-10-29 14:19:05 -07004146
Chia-I Wue6bcaf12016-05-27 10:58:48 +08004147 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Jorim Jaggi4981f152019-03-26 18:58:45 +01004148 if (mHScale == 1 && mVScale == 1) {
4149 return;
4150 }
4151 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08004152 clipRect.left = (int) (clipRect.left / mHScale);
4153 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07004154 }
4155 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08004156 clipRect.top = (int) (clipRect.top / mVScale);
4157 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07004158 }
4159 }
Robert Carr31e28482015-12-02 16:53:18 -08004160
Riddle Hsuc7175762020-01-10 21:03:48 +08004161 private void applyGravityAndUpdateFrame(WindowFrames windowFrames, Rect containingFrame,
4162 Rect displayFrame) {
Jorim Jaggif5834272016-04-04 20:25:41 -07004163 final int pw = containingFrame.width();
4164 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08004165 final Task task = getTask();
Evan Rosky4fb1e912019-03-06 13:54:43 -08004166 final boolean inNonFullscreenContainer = !inAppWindowThatMatchesParentBounds();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07004167 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
4168
4169 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07004170 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
4171 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07004172 // 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 -07004173 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
4174 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
4175 // the display.
4176 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07004177 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08004178 float x, y;
4179 int w,h;
4180
Riddle Hsub398da32019-01-21 21:48:16 +08004181 final boolean inSizeCompatMode = inSizeCompatMode();
Robert Carr31e28482015-12-02 16:53:18 -08004182 if ((mAttrs.flags & FLAG_SCALED) != 0) {
4183 if (mAttrs.width < 0) {
4184 w = pw;
Riddle Hsub398da32019-01-21 21:48:16 +08004185 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08004186 w = (int)(mAttrs.width * mGlobalScale + .5f);
4187 } else {
4188 w = mAttrs.width;
4189 }
4190 if (mAttrs.height < 0) {
4191 h = ph;
Riddle Hsub398da32019-01-21 21:48:16 +08004192 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08004193 h = (int)(mAttrs.height * mGlobalScale + .5f);
4194 } else {
4195 h = mAttrs.height;
4196 }
4197 } else {
4198 if (mAttrs.width == MATCH_PARENT) {
4199 w = pw;
Riddle Hsub398da32019-01-21 21:48:16 +08004200 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08004201 w = (int)(mRequestedWidth * mGlobalScale + .5f);
4202 } else {
4203 w = mRequestedWidth;
4204 }
4205 if (mAttrs.height == MATCH_PARENT) {
4206 h = ph;
Riddle Hsub398da32019-01-21 21:48:16 +08004207 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08004208 h = (int)(mRequestedHeight * mGlobalScale + .5f);
4209 } else {
4210 h = mRequestedHeight;
4211 }
4212 }
4213
Riddle Hsub398da32019-01-21 21:48:16 +08004214 if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08004215 x = mAttrs.x * mGlobalScale;
4216 y = mAttrs.y * mGlobalScale;
4217 } else {
4218 x = mAttrs.x;
4219 y = mAttrs.y;
4220 }
4221
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07004222 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08004223 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08004224 // required by {@link Gravity#apply} call.
4225 w = Math.min(w, pw);
4226 h = Math.min(h, ph);
4227 }
4228
4229 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07004230 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08004231 (int) (x + mAttrs.horizontalMargin * pw),
Riddle Hsuc7175762020-01-10 21:03:48 +08004232 (int) (y + mAttrs.verticalMargin * ph), windowFrames.mFrame);
Robert Carr31e28482015-12-02 16:53:18 -08004233
4234 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08004235 if (fitToDisplay) {
Riddle Hsuc7175762020-01-10 21:03:48 +08004236 Gravity.applyDisplay(mAttrs.gravity, displayFrame, windowFrames.mFrame);
Robert Carre6275582016-02-29 15:45:45 -08004237 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08004238
4239 // We need to make sure we update the CompatFrame as it is used for
4240 // cropping decisions, etc, on systems where we lack a decor layer.
Riddle Hsuc7175762020-01-10 21:03:48 +08004241 windowFrames.mCompatFrame.set(windowFrames.mFrame);
Riddle Hsub398da32019-01-21 21:48:16 +08004242 if (inSizeCompatMode) {
Robert Carr6e18c5e2016-02-29 15:57:13 -08004243 // See comparable block in computeFrameLw.
Riddle Hsuc7175762020-01-10 21:03:48 +08004244 windowFrames.mCompatFrame.scale(mInvGlobalScale);
Robert Carr6e18c5e2016-02-29 15:57:13 -08004245 }
Robert Carr31e28482015-12-02 16:53:18 -08004246 }
Robert Carr51a1b872015-12-08 14:03:13 -08004247
4248 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004249 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004250 }
4251
Robert Carrf3b72c72016-03-21 18:16:39 -07004252 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004253 return mIsChildWindow
4254 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07004255 }
4256
Wale Ogunwale01ad4342017-06-30 07:07:01 -07004257 /**
4258 * Returns true if any window added by an application process that if of type
4259 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
4260 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
4261 * this window is visible.
4262 */
4263 boolean hideNonSystemOverlayWindowsWhenVisible() {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -07004264 return (mAttrs.privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
Wale Ogunwale01ad4342017-06-30 07:07:01 -07004265 && mSession.mCanHideNonSystemOverlayWindows;
4266 }
4267
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07004268 /** Returns the parent window if this is a child of another window, else null. */
4269 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004270 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
4271 // WindowContainer that isn't a WindowState.
4272 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07004273 }
4274
4275 /** Returns the topmost parent window if this is a child of another window, else this. */
4276 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08004277 WindowState current = this;
4278 WindowState topParent = current;
4279 while (current != null && current.mIsChildWindow) {
4280 current = current.getParentWindow();
4281 // Parent window can be null if the child is detached from it's parent already, but
4282 // someone still has a reference to access it. So, we return the top parent value we
4283 // already have instead of null.
4284 if (current != null) {
4285 topParent = current;
4286 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07004287 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08004288 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07004289 }
4290
Wale Ogunwale9d147902016-07-16 11:58:55 -07004291 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004292 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08004293 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07004294 }
4295
Jorim Jaggib52b0452019-07-16 17:43:15 +02004296 private boolean isParentWindowGoneForLayout() {
4297 final WindowState parent = getParentWindow();
4298 return parent != null && parent.isGoneForLayoutLw();
4299 }
4300
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004301 void setWillReplaceWindow(boolean animate) {
4302 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004303 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004304 c.setWillReplaceWindow(animate);
4305 }
4306
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08004307 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
4308 || mAttrs.type == TYPE_APPLICATION_STARTING) {
4309 // We don't set replacing on starting windows since they are added by window manager and
4310 // not the client so won't be replaced by the client.
4311 return;
Robert Carra1eb4392015-12-10 12:43:51 -08004312 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08004313
4314 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004315 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08004316 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08004317 }
Chong Zhangf596cd52016-01-05 13:42:44 -08004318
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004319 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08004320 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004321 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08004322 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004323
4324 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004325 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004326 c.clearWillReplaceWindow();
4327 }
4328 }
4329
4330 boolean waitingForReplacement() {
4331 if (mWillReplaceWindow) {
4332 return true;
4333 }
4334
4335 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004336 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004337 if (c.waitingForReplacement()) {
4338 return true;
4339 }
4340 }
4341 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08004342 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08004343
Chong Zhang4d7369a2016-04-25 16:09:14 -07004344 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07004345 final DisplayContent dc = getDisplayContent();
4346 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
4347 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4348 dc.setLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004349 mWmService.mWindowPlacerLocked.requestTraversal();
Chong Zhang4d7369a2016-04-25 16:09:14 -07004350 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004351
4352 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004353 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004354 c.requestUpdateWallpaperIfNeeded();
4355 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07004356 }
4357
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08004358 float translateToWindowX(float x) {
chaviw492139a2018-07-16 16:07:35 -07004359 float winX = x - mWindowFrames.mFrame.left;
Riddle Hsub398da32019-01-21 21:48:16 +08004360 if (inSizeCompatMode()) {
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08004361 winX *= mGlobalScale;
4362 }
4363 return winX;
4364 }
4365
4366 float translateToWindowY(float y) {
chaviw492139a2018-07-16 16:07:35 -07004367 float winY = y - mWindowFrames.mFrame.top;
Riddle Hsub398da32019-01-21 21:48:16 +08004368 if (inSizeCompatMode()) {
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08004369 winY *= mGlobalScale;
4370 }
4371 return winY;
4372 }
Robert Carrd1a010f2016-04-07 22:36:22 -07004373
4374 // During activity relaunch due to resize, we sometimes use window replacement
4375 // for only child windows (as the main window is handled by window preservation)
4376 // and the big surface.
4377 //
Chong Zhangfea963e2016-08-15 17:14:16 -07004378 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
4379 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
4380 // we also want to replace them at such phases, as they won't be covered by window
4381 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07004382 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07004383 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07004384 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07004385 }
Robert Carrfd10cd12016-06-29 16:41:50 -07004386
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004387 void setWillReplaceChildWindows() {
4388 if (shouldBeReplacedWithChildren()) {
4389 setWillReplaceWindow(false /* animate */);
4390 }
4391 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004392 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004393 c.setWillReplaceChildWindows();
4394 }
4395 }
4396
4397 WindowState getReplacingWindow() {
4398 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
4399 return this;
4400 }
4401 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004402 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004403 final WindowState replacing = c.getReplacingWindow();
4404 if (replacing != null) {
4405 return replacing;
4406 }
4407 }
4408 return null;
4409 }
4410
Jorim Jaggife762342016-10-13 14:33:27 +02004411 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07004412 public int getRotationAnimationHint() {
Garfield Tane8d84ab2019-10-11 09:49:40 -07004413 if (mActivityRecord != null) {
4414 return mActivityRecord.mRotationAnimationHint;
Robert Carrfd10cd12016-06-29 16:41:50 -07004415 } else {
4416 return -1;
4417 }
4418 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07004419
Jorim Jaggife762342016-10-13 14:33:27 +02004420 @Override
4421 public boolean isInputMethodWindow() {
4422 return mIsImWindow;
4423 }
4424
Wale Ogunwale9d147902016-07-16 11:58:55 -07004425 // This must be called while inside a transaction.
4426 boolean performShowLocked() {
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -08004427 if (!showToCurrentUser()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07004428 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
chaviwbb6bd8a2019-05-28 17:05:28 -07004429 clearPolicyVisibilityFlag(VISIBLE_FOR_USER);
Wale Ogunwale9d147902016-07-16 11:58:55 -07004430 return false;
4431 }
4432
4433 logPerformShow("performShow on ");
4434
Jorim Jaggia50da602016-12-29 11:51:42 +01004435 final int drawState = mWinAnimator.mDrawState;
Winson Chung8b5d23a2020-04-06 19:23:23 -07004436 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW) && mActivityRecord != null) {
4437 if (mAttrs.type != TYPE_APPLICATION_STARTING) {
4438 mActivityRecord.onFirstWindowDrawn(this, mWinAnimator);
4439 } else {
4440 mActivityRecord.onStartingWindowDrawn();
4441 }
Jorim Jaggia50da602016-12-29 11:51:42 +01004442 }
4443
Jorim Jaggib0d27342016-11-01 16:10:42 -07004444 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07004445 return false;
4446 }
4447
4448 logPerformShow("Showing ");
4449
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004450 mWmService.enableScreenIfNeededLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07004451 mWinAnimator.applyEnterAnimationLocked();
4452
4453 // Force the show in the next prepareSurfaceLocked() call.
4454 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07004455 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07004456 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
4457 mWinAnimator.mDrawState = HAS_DRAWN;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004458 mWmService.scheduleAnimationLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07004459
4460 if (mHidden) {
4461 mHidden = false;
4462 final DisplayContent displayContent = getDisplayContent();
4463
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004464 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004465 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07004466 if (c.mWinAnimator.mSurfaceController != null) {
4467 c.performShowLocked();
4468 // It hadn't been shown, which means layout not performed on it, so now we
4469 // want to make sure to do a layout. If called from within the transaction
4470 // loop, this will cause it to restart with a new layout.
4471 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07004472 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07004473 }
4474 }
4475 }
4476 }
4477
Wale Ogunwale9d147902016-07-16 11:58:55 -07004478 return true;
4479 }
4480
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07004481 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07004482 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02004483 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07004484 Slog.v(TAG, prefix + this
4485 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07004486 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07004487 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
chaviw15ad49f2019-04-24 15:05:39 -07004488 + " during animation: policyVis=" + isVisibleByPolicy()
Wale Ogunwale9d147902016-07-16 11:58:55 -07004489 + " parentHidden=" + isParentWindowHidden()
Issei Suzuki1669ea42019-11-06 14:20:59 +01004490 + " tok.visibleRequested="
4491 + (mActivityRecord != null && mActivityRecord.mVisibleRequested)
Issei Suzukif2f6c912019-11-08 11:24:18 +01004492 + " tok.visible=" + (mActivityRecord != null && mActivityRecord.isVisible())
lumark9bca6b42019-10-17 18:35:22 +08004493 + " animating=" + isAnimating(TRANSITION | PARENTS)
Wale Ogunwale9d147902016-07-16 11:58:55 -07004494 + " tok animating="
lumark5bd11af2019-12-21 01:52:28 +08004495 + (mActivityRecord != null && mActivityRecord.isAnimating(TRANSITION | PARENTS))
Wale Ogunwale9d147902016-07-16 11:58:55 -07004496 + " Callers=" + Debug.getCallers(4));
4497 }
4498 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004499
4500 WindowInfo getWindowInfo() {
4501 WindowInfo windowInfo = WindowInfo.obtain();
RyanlwLin25a36512019-05-28 21:01:52 +08004502 windowInfo.displayId = getDisplayId();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004503 windowInfo.type = mAttrs.type;
4504 windowInfo.layer = mLayer;
4505 windowInfo.token = mClient.asBinder();
Garfield Tane8d84ab2019-10-11 09:49:40 -07004506 if (mActivityRecord != null) {
4507 windowInfo.activityToken = mActivityRecord.appToken.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07004508 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004509 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08004510 // Panel windows have no public way to set the a11y title directly. Use the
4511 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07004512 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
4513 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
4514 // Accessibility overlays should have titles that work for accessibility, and can't set
4515 // the a11y title themselves.
4516 final boolean isAccessibilityOverlay =
4517 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
4518 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Jackal Guo25a33cbd2018-08-01 16:08:45 +08004519 final CharSequence title = mAttrs.getTitle();
4520 windowInfo.title = TextUtils.isEmpty(title) ? null : title;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08004521 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004522 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
4523 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08004524 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004525 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Jackal Guoac2b62e2018-08-22 18:28:46 +08004526 windowInfo.hasFlagWatchOutsideTouch =
4527 (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004528
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004529 if (mIsChildWindow) {
4530 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004531 }
4532
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004533 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004534 if (childCount > 0) {
4535 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004536 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004537 }
4538 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004539 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004540 windowInfo.childTokens.add(child.mClient.asBinder());
4541 }
4542 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004543 return windowInfo;
4544 }
4545
Wale Ogunwale9adfe572016-09-08 20:43:58 -07004546 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004547 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004548 if (mChildren.isEmpty()) {
4549 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004550 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004551 }
4552
4553 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004554 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004555 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004556 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004557 }
4558 }
4559
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004560 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004561 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004562 // below the parent, then this window (the parent), and then the positive sublayer children
4563 // because they need to appear above the parent.
4564 int i = 0;
4565 final int count = mChildren.size();
4566 WindowState child = mChildren.get(i);
4567
4568 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004569 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004570 return true;
4571 }
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004572 i++;
4573 if (i >= count) {
4574 break;
4575 }
4576 child = mChildren.get(i);
4577 }
4578
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004579 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004580 return true;
4581 }
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004582
4583 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004584 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004585 return true;
4586 }
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004587 i++;
4588 if (i >= count) {
4589 break;
4590 }
4591 child = mChildren.get(i);
4592 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004593
4594 return false;
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004595 }
4596
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004597 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004598 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004599 // above the parent, then this window (the parent), and then the negative sublayer children
4600 // because they need to appear above the parent.
4601 int i = mChildren.size() - 1;
4602 WindowState child = mChildren.get(i);
4603
4604 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004605 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004606 return true;
4607 }
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004608 --i;
4609 if (i < 0) {
4610 break;
4611 }
4612 child = mChildren.get(i);
4613 }
4614
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004615 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004616 return true;
4617 }
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004618
4619 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004620 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004621 return true;
4622 }
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004623 --i;
4624 if (i < 0) {
4625 break;
4626 }
4627 child = mChildren.get(i);
4628 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004629
4630 return false;
Wale Ogunwaleb783fd8a2016-11-04 09:51:54 -07004631 }
4632
Robert Carr9785cf32018-04-25 15:06:07 -07004633 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
4634 boolean traverseTopToBottom) {
4635 // If this window is the current IME target, so we need to process the IME windows
4636 // directly above it. The exception is if we are in split screen
4637 // in which case we process the IME at the DisplayContent level to
4638 // ensure it is above the docked divider.
4639 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
4640 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4641 return true;
4642 }
4643 }
4644 return false;
4645 }
4646
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004647 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4648 boolean traverseTopToBottom) {
4649 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07004650 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
4651 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004652 return true;
4653 }
4654 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07004655 if (callback.apply(this)
4656 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004657 return true;
4658 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004659 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004660 return false;
4661 }
4662
Wale Ogunwaled1880962016-11-08 10:31:59 -08004663 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004664 if (mChildren.isEmpty()) {
4665 return callback.test(this) ? this : null;
4666 }
4667
4668 // We want to consume the positive sublayer children first because they need to appear
4669 // above the parent, then this window (the parent), and then the negative sublayer children
4670 // because they need to appear above the parent.
4671 int i = mChildren.size() - 1;
4672 WindowState child = mChildren.get(i);
4673
4674 while (i >= 0 && child.mSubLayer >= 0) {
4675 if (callback.test(child)) {
4676 return child;
4677 }
4678 --i;
4679 if (i < 0) {
4680 break;
4681 }
4682 child = mChildren.get(i);
4683 }
4684
Wale Ogunwaled1880962016-11-08 10:31:59 -08004685 if (callback.test(this)) {
4686 return this;
4687 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004688
4689 while (i >= 0) {
4690 if (callback.test(child)) {
4691 return child;
4692 }
4693 --i;
4694 if (i < 0) {
4695 break;
4696 }
4697 child = mChildren.get(i);
4698 }
4699
4700 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004701 }
4702
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004703 /**
4704 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
4705 * otherwise.
4706 */
4707 @VisibleForTesting
4708 boolean isSelfOrAncestorWindowAnimatingExit() {
4709 WindowState window = this;
4710 do {
4711 if (window.mAnimatingExit) {
4712 return true;
4713 }
4714 window = window.getParentWindow();
4715 } while (window != null);
4716 return false;
4717 }
4718
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004719 void onExitAnimationDone() {
4720 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4721 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
lumark9bca6b42019-10-17 18:35:22 +08004722 + " selfAnimating=" + isAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004723
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004724 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004725 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01004726 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004727 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004728 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004729 }
4730 }
4731
4732 if (mWinAnimator.mEnteringAnimation) {
4733 mWinAnimator.mEnteringAnimation = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004734 mWmService.requestTraversal();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004735 // System windows don't have an activity and an app token as a result, but need a way
4736 // to be informed about their entrance animation end.
Garfield Tane8d84ab2019-10-11 09:49:40 -07004737 if (mActivityRecord == null) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004738 try {
4739 mClient.dispatchWindowShown();
4740 } catch (RemoteException e) {
4741 }
4742 }
4743 }
4744
lumark9bca6b42019-10-17 18:35:22 +08004745 if (isAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004746 return;
4747 }
Jacky Kaof93252b2019-07-18 15:19:52 +08004748 if (mWmService.mAccessibilityController != null) {
4749 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(getDisplayId());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004750 }
4751
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004752 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004753 return;
4754 }
4755
Adrian Roosb125e0b2019-10-02 14:55:14 +02004756 ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Exit animation finished in %s: remove=%b",
4757 this, mRemoveOnExit);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004758
4759 mDestroying = true;
4760
4761 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004762
4763 // Use pendingTransaction here so hide is done the same transaction as the other
4764 // animations when exiting
4765 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004766
4767 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4768 // care to ensure the activity has actually stopped and the surface is not still in use.
4769 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4770 // transaction.
Garfield Tane8d84ab2019-10-11 09:49:40 -07004771 if (mActivityRecord != null) {
4772 mActivityRecord.destroySurfaces();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004773 } else {
4774 if (hasSurface) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004775 mWmService.mDestroySurface.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004776 }
4777 if (mRemoveOnExit) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004778 mWmService.mPendingRemove.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004779 mRemoveOnExit = false;
4780 }
4781 }
4782 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004783 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004784 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004785
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004786 boolean clearAnimatingFlags() {
4787 boolean didSomething = false;
4788 // We don't want to clear it out for windows that get replaced, because the
4789 // animation depends on the flag to remove the replaced window.
4790 //
4791 // We also don't clear the mAnimatingExit flag for windows which have the
4792 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4793 // by the client. We should let animation proceed and not clear this flag or
4794 // they won't eventually be removed by WindowStateAnimator#finishExit.
4795 if (!mWillReplaceWindow && !mRemoveOnExit) {
4796 // Clear mAnimating flag together with mAnimatingExit. When animation
4797 // changes from exiting to entering, we need to clear this flag until the
4798 // new animation gets applied, so that isAnimationStarting() becomes true
4799 // until then.
4800 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4801 // placement for this window during this period, one or more frame will
4802 // show up with wrong position or scale.
4803 if (mAnimatingExit) {
4804 mAnimatingExit = false;
4805 didSomething = true;
4806 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004807 if (mDestroying) {
4808 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004809 mWmService.mDestroySurface.remove(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004810 didSomething = true;
4811 }
4812 }
4813
4814 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004815 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004816 }
4817
4818 return didSomething;
4819 }
4820
Winson4b4ba902016-07-27 19:45:52 -07004821 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004822 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004823 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004824
4825 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004826 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004827 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004828 c.hideWallpaperWindow(wasDeferred, reason);
4829 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004830 if (!mWinAnimator.mLastHidden || wasDeferred) {
4831 mWinAnimator.hide(reason);
Tiger Huang50d45462018-05-25 22:57:52 +08004832 getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004833 dispatchWallpaperVisibility(false);
4834 final DisplayContent displayContent = getDisplayContent();
4835 if (displayContent != null) {
4836 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Tiger Huang50d45462018-05-25 22:57:52 +08004837 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004838 mWmService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this,
Tiger Huang50d45462018-05-25 22:57:52 +08004839 displayContent.pendingLayoutChanges);
4840 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004841 }
4842 }
4843 }
4844
4845 /**
4846 * Check wallpaper window for visibility change and notify window if so.
4847 * @param visible Current visibility.
4848 */
4849 void dispatchWallpaperVisibility(final boolean visible) {
4850 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004851 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004852
4853 // Only send notification if the visibility actually changed and we are not trying to hide
4854 // the wallpaper when we are deferring hiding of the wallpaper.
4855 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4856 mWallpaperVisible = visible;
4857 try {
4858 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4859 "Updating vis of wallpaper " + this
4860 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4861 mClient.dispatchAppVisibility(visible);
4862 } catch (RemoteException e) {
4863 }
4864 }
4865 }
4866
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004867 boolean hasVisibleNotDrawnWallpaper() {
4868 if (mWallpaperVisible && !isDrawnLw()) {
4869 return true;
4870 }
4871 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004872 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004873 if (c.hasVisibleNotDrawnWallpaper()) {
4874 return true;
4875 }
4876 }
4877 return false;
4878 }
4879
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004880 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4881 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004882 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004883 c.updateReportedVisibility(results);
4884 }
4885
4886 if (mAppFreezing || mViewVisibility != View.VISIBLE
4887 || mAttrs.type == TYPE_APPLICATION_STARTING
4888 || mDestroying) {
4889 return;
4890 }
4891 if (DEBUG_VISIBILITY) {
4892 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
lumark9bca6b42019-10-17 18:35:22 +08004893 + ", animating=" + isAnimating(TRANSITION | PARENTS));
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004894 if (!isDrawnLw()) {
4895 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
chaviw15ad49f2019-04-24 15:05:39 -07004896 + " pv=" + isVisibleByPolicy()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004897 + " mDrawState=" + mWinAnimator.mDrawState
4898 + " ph=" + isParentWindowHidden()
Issei Suzuki1669ea42019-11-06 14:20:59 +01004899 + " th=" + (mActivityRecord != null && mActivityRecord.mVisibleRequested)
lumark9bca6b42019-10-17 18:35:22 +08004900 + " a=" + isAnimating(TRANSITION | PARENTS));
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004901 }
4902 }
4903
4904 results.numInteresting++;
4905 if (isDrawnLw()) {
4906 results.numDrawn++;
lumark9bca6b42019-10-17 18:35:22 +08004907 if (!isAnimating(TRANSITION | PARENTS)) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004908 results.numVisible++;
4909 }
4910 results.nowGone = false;
lumark9bca6b42019-10-17 18:35:22 +08004911 } else if (isAnimating(TRANSITION | PARENTS)) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004912 results.nowGone = false;
4913 }
4914 }
4915
Robert Carr683e05d2018-04-18 15:11:04 -07004916 private boolean skipDecorCrop() {
4917 // The decor frame is used to specify the region not covered by the system
4918 // decorations (nav bar, status bar). In case this is empty, for example with
4919 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
chaviw553b0212018-07-12 13:37:01 -07004920 if (mWindowFrames.mDecorFrame.isEmpty()) {
Robert Carr683e05d2018-04-18 15:11:04 -07004921 return true;
4922 }
4923
4924 // But if we have a frame, and are an application window, then we must be cropped.
Garfield Tane8d84ab2019-10-11 09:49:40 -07004925 if (mActivityRecord != null) {
Robert Carr683e05d2018-04-18 15:11:04 -07004926 return false;
4927 }
4928
4929 // For non application windows, we may be allowed to extend over the decor bars
4930 // depending on our type and permissions assosciated with our token.
4931 return mToken.canLayerAboveSystemBars();
4932 }
4933
Robert Carrfbbde852016-10-18 11:02:28 -07004934 /**
4935 * Calculate the window crop according to system decor policy. In general this is
4936 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4937 * special cases. This rectangle is in screen space.
4938 */
4939 void calculatePolicyCrop(Rect policyCrop) {
4940 final DisplayContent displayContent = getDisplayContent();
Robert Carrfbbde852016-10-18 11:02:28 -07004941
Riddle Hsub398da32019-01-21 21:48:16 +08004942 if (!displayContent.isDefaultDisplay && !displayContent.supportsSystemDecorations()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004943 // On a different display there is no system decor. Crop the window
4944 // by the screen boundaries.
Riddle Hsu6f548e92020-01-13 13:34:09 +08004945 final DisplayInfo displayInfo = getDisplayInfo();
chaviw9c81e632018-07-31 11:17:52 -07004946 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4947 mWindowFrames.mCompatFrame.height());
4948 policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top,
4949 displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left,
4950 displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004951 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004952 // Windows without policy decor aren't cropped.
chaviw9c81e632018-07-31 11:17:52 -07004953 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4954 mWindowFrames.mCompatFrame.height());
Robert Carrfbbde852016-10-18 11:02:28 -07004955 } else {
4956 // Crop to the system decor specified by policy.
4957 calculateSystemDecorRect(policyCrop);
4958 }
4959 }
4960
4961 /**
4962 * The system decor rect is the region of the window which is not covered
4963 * by system decorations.
4964 */
4965 private void calculateSystemDecorRect(Rect systemDecorRect) {
chaviw553b0212018-07-12 13:37:01 -07004966 final Rect decorRect = mWindowFrames.mDecorFrame;
chaviw492139a2018-07-16 16:07:35 -07004967 final int width = mWindowFrames.mFrame.width();
4968 final int height = mWindowFrames.mFrame.height();
Robert Carrfbbde852016-10-18 11:02:28 -07004969
chaviw492139a2018-07-16 16:07:35 -07004970 final int left = mWindowFrames.mFrame.left;
4971 final int top = mWindowFrames.mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004972
4973 // Initialize the decor rect to the entire frame.
4974 if (isDockedResizing()) {
4975 // If we are resizing with the divider, the task bounds might be smaller than the
4976 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4977 // want in this case in order to avoid holes.
4978 //
4979 // We take care to not shrink the width, for surfaces which are larger than
4980 // the display region. Of course this area will not eventually be visible
4981 // but if we truncate the width now, we will calculate incorrectly
4982 // when adjusting to the stack bounds.
4983 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4984 systemDecorRect.set(0, 0,
4985 Math.max(width, displayInfo.logicalWidth),
4986 Math.max(height, displayInfo.logicalHeight));
4987 } else {
4988 systemDecorRect.set(0, 0, width, height);
4989 }
4990
4991 // If a freeform window is animating from a position where it would be cutoff, it would be
4992 // cutoff during the animation. We don't want that, so for the duration of the animation
4993 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004994
4995 // We also ignore cropping when the window is currently being drag resized in split screen
4996 // to prevent issues with the crop for screenshot.
4997 final boolean cropToDecor =
4998 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004999 if (cropToDecor) {
5000 // Intersect with the decor rect, offsetted by window position.
5001 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
5002 decorRect.right - left, decorRect.bottom - top);
5003 }
5004
5005 // If size compatibility is being applied to the window, the
5006 // surface is scaled relative to the screen. Also apply this
5007 // scaling to the crop rect. We aren't using the standard rect
5008 // scale function because we want to round things to make the crop
5009 // always round to a larger rect to ensure we don't crop too
5010 // much and hide part of the window that should be seen.
Jorim Jaggi4981f152019-03-26 18:58:45 +01005011 if (mInvGlobalScale != 1.0f && inSizeCompatMode()) {
Robert Carrfbbde852016-10-18 11:02:28 -07005012 final float scale = mInvGlobalScale;
5013 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
5014 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
5015 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
5016 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
5017 }
5018
5019 }
5020
5021 /**
5022 * Expand the given rectangle by this windows surface insets. This
5023 * takes you from the 'window size' to the 'surface size'.
5024 * The surface insets are positive in each direction, so we inset by
5025 * the inverse.
5026 */
5027 void expandForSurfaceInsets(Rect r) {
5028 r.inset(-mAttrs.surfaceInsets.left,
5029 -mAttrs.surfaceInsets.top,
5030 -mAttrs.surfaceInsets.right,
5031 -mAttrs.surfaceInsets.bottom);
5032 }
5033
Robert Carrc91d1c32017-02-15 19:37:46 -08005034 boolean surfaceInsetsChanging() {
5035 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
5036 }
5037
Tiger Huang1ffefc22019-04-08 15:49:18 +08005038 int relayoutVisibleWindow(int result, int attrChanges) {
Robert Carrecc06b32017-04-18 14:25:10 -07005039 final boolean wasVisible = isVisibleLw();
5040
5041 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07005042
Robert Carrc91d1c32017-02-15 19:37:46 -08005043 if (mAnimatingExit) {
5044 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
5045 + mRemoveOnExit + ", mDestroying=" + mDestroying);
5046
Riddle Hsub8d704b2019-02-22 12:44:12 +08005047 // Cancel the existing exit animation for the next enter animation.
lumark9bca6b42019-10-17 18:35:22 +08005048 if (isAnimating()) {
Riddle Hsub8d704b2019-02-22 12:44:12 +08005049 cancelAnimation();
5050 destroySurfaceUnchecked();
5051 }
Robert Carrc91d1c32017-02-15 19:37:46 -08005052 mAnimatingExit = false;
5053 }
5054 if (mDestroying) {
5055 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08005056 mWmService.mDestroySurface.remove(this);
Robert Carrc91d1c32017-02-15 19:37:46 -08005057 }
Tiger Huang1ffefc22019-04-08 15:49:18 +08005058 if (!wasVisible) {
Robert Carrc91d1c32017-02-15 19:37:46 -08005059 mWinAnimator.mEnterAnimationPending = true;
5060 }
5061
Andrii Kulian8ee72852017-03-10 10:36:45 -08005062 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08005063
5064 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07005065
Jorim Jaggi4981f152019-03-26 18:58:45 +01005066 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "prepareToDisplay");
5067 try {
5068 prepareWindowToDisplayDuringRelayout(wasVisible);
5069 } finally {
5070 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
5071 }
Bryce Leeae73ba42017-05-05 09:58:25 -07005072
Robert Carrc91d1c32017-02-15 19:37:46 -08005073 if ((attrChanges & FORMAT_CHANGED) != 0) {
5074 // If the format can't be changed in place, preserve the old surface until the app draws
5075 // on the new one. This prevents blinking when we change elevation of freeform and
5076 // pinned windows.
5077 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
5078 mWinAnimator.preserveSurfaceLocked();
5079 result |= RELAYOUT_RES_SURFACE_CHANGED
5080 | RELAYOUT_RES_FIRST_TIME;
5081 }
5082 }
5083
5084 // When we change the Surface size, in scenarios which may require changing
5085 // the surface position in sync with the resize, we use a preserved surface
5086 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08005087 // sized surface. At the moment this logic is only in place for switching
5088 // in and out of the big surface for split screen resize.
5089 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08005090 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08005091 // We can only change top level windows to the full-screen surface when
5092 // resizing (as we only have one full-screen surface). So there is no need
5093 // to preserve and destroy windows which are attached to another, they
5094 // will keep their surface and its size may change over time.
5095 if (mHasSurface && !isChildWindow()) {
5096 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08005097 result |= RELAYOUT_RES_SURFACE_CHANGED |
5098 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08005099 }
5100 }
5101 final boolean freeformResizing = isDragResizing()
5102 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
5103 final boolean dockedResizing = isDragResizing()
5104 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
5105 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
5106 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08005107 return result;
5108 }
5109
Jorim Jaggidc9385a2017-05-13 02:00:31 +02005110 /**
5111 * @return True if this window has been laid out at least once; false otherwise.
5112 */
5113 boolean isLaidOut() {
5114 return mLayoutSeq != -1;
5115 }
5116
5117 /**
Jackal Guoc43a0a62019-04-23 09:15:14 +08005118 * Add the DisplayContent of the embedded display which is re-parented to this window to
5119 * the list of embedded displays.
5120 *
5121 * @param dc DisplayContent of the re-parented embedded display.
5122 * @return {@code true} if the giving DisplayContent is added, {@code false} otherwise.
5123 */
5124 boolean addEmbeddedDisplayContent(DisplayContent dc) {
5125 return mEmbeddedDisplayContents.add(dc);
5126 }
5127
5128 /**
5129 * Remove the DisplayContent of the embedded display which is re-parented to this window from
5130 * the list of embedded displays.
5131 *
5132 * @param dc DisplayContent of the re-parented embedded display.
5133 * @return {@code true} if the giving DisplayContent is removed, {@code false} otherwise.
5134 */
5135 boolean removeEmbeddedDisplayContent(DisplayContent dc) {
5136 return mEmbeddedDisplayContents.remove(dc);
5137 }
5138
Riddle Hsu2652da82019-11-29 18:08:26 +08005139 /** Updates the last frames and relative frames to the current ones. */
5140 void updateLastFrames() {
5141 mWindowFrames.mLastFrame.set(mWindowFrames.mFrame);
5142 mWindowFrames.mLastRelFrame.set(mWindowFrames.mRelFrame);
5143 }
5144
Jackal Guoc43a0a62019-04-23 09:15:14 +08005145 /**
Jorim Jaggidc9385a2017-05-13 02:00:31 +02005146 * Updates the last inset values to the current ones.
5147 */
5148 void updateLastInsetValues() {
chaviw9c81e632018-07-31 11:17:52 -07005149 mWindowFrames.updateLastInsetValues();
Jorim Jaggidc9385a2017-05-13 02:00:31 +02005150 }
5151
Jorim Jaggi924ef752020-01-29 17:26:55 +01005152 @Override
Jorim Jaggi268bf6882020-06-18 23:44:02 +02005153 protected boolean isSelfAnimating(int flags, int typesToCheck) {
Jorim Jaggi924ef752020-01-29 17:26:55 +01005154 if (mControllableInsetProvider != null) {
Jorim Jaggi268bf6882020-06-18 23:44:02 +02005155 return false;
Jorim Jaggi924ef752020-01-29 17:26:55 +01005156 }
Jorim Jaggi268bf6882020-06-18 23:44:02 +02005157 return super.isSelfAnimating(flags, typesToCheck);
Jorim Jaggi924ef752020-01-29 17:26:55 +01005158 }
5159
Jorim Jaggia5e10572017-11-15 14:36:26 +01005160 void startAnimation(Animation anim) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01005161
5162 // If we are an inset provider, all our animations are driven by the inset client.
Jorim Jaggi956ca412019-01-07 14:49:14 +01005163 if (mControllableInsetProvider != null) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01005164 return;
5165 }
5166
Riddle Hsu6f548e92020-01-13 13:34:09 +08005167 final DisplayInfo displayInfo = getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07005168 anim.initialize(mWindowFrames.mFrame.width(), mWindowFrames.mFrame.height(),
Jorim Jaggia5e10572017-11-15 14:36:26 +01005169 displayInfo.appWidth, displayInfo.appHeight);
5170 anim.restrictDuration(MAX_ANIMATION_DURATION);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08005171 anim.scaleCurrentDuration(mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01005172 final AnimationAdapter adapter = new LocalAnimationAdapter(
Lucas Dupin3e1dc202018-12-02 15:14:20 -08005173 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */,
Lucas Dupin95acf432019-04-29 17:55:38 -07005174 0 /* windowCornerRadius */),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08005175 mWmService.mSurfaceAnimationRunner);
Tiger Huanged6794e2019-05-07 20:07:59 +08005176 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005177 commitPendingTransaction();
5178 }
5179
chaviw161ea3e2018-01-31 12:01:12 -08005180 private void startMoveAnimation(int left, int top) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01005181
5182 // If we are an inset provider, all our animations are driven by the inset client.
Jorim Jaggi956ca412019-01-07 14:49:14 +01005183 if (mControllableInsetProvider != null) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01005184 return;
5185 }
5186
Jorim Jaggia5e10572017-11-15 14:36:26 +01005187 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01005188 final Point oldPosition = new Point();
5189 final Point newPosition = new Point();
chaviw492139a2018-07-16 16:07:35 -07005190 transformFrameToSurfacePosition(mWindowFrames.mLastFrame.left, mWindowFrames.mLastFrame.top,
5191 oldPosition);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01005192 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005193 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01005194 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08005195 mWmService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08005196 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005197 }
5198
5199 private void startAnimation(Transaction t, AnimationAdapter adapter) {
Issei Suzuki737b7f12020-05-25 14:54:06 +02005200 startAnimation(t, adapter, mWinAnimator.mLastHidden, ANIMATION_TYPE_WINDOW_ANIMATION);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005201 }
5202
5203 @Override
Issei Suzuki8b995df2020-01-08 12:23:04 +01005204 protected void onAnimationFinished(@AnimationType int type, AnimationAdapter anim) {
5205 super.onAnimationFinished(type, anim);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005206 mWinAnimator.onAnimationFinished();
5207 }
5208
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01005209 /**
5210 * Retrieves the current transformation matrix of the window, relative to the display.
5211 *
5212 * @param float9 A temporary array of 9 floats.
5213 * @param outMatrix Matrix to fill in the transformation.
5214 */
5215 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
5216 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
5217 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
5218 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
5219 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Tiger Huang83754532020-06-08 19:48:17 +08005220 transformSurfaceInsetsPosition(mTmpPoint, mAttrs.surfaceInsets);
5221 int x = mSurfacePosition.x + mTmpPoint.x;
5222 int y = mSurfacePosition.y + mTmpPoint.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01005223
Tiger Huangd8ec9382019-04-18 14:35:09 -07005224 // We might be on a display which has been re-parented to a view in another window, so here
5225 // computes the global location of our display.
5226 DisplayContent dc = getDisplayContent();
5227 while (dc != null && dc.getParentWindow() != null) {
5228 final WindowState displayParent = dc.getParentWindow();
Tiger Huang83754532020-06-08 19:48:17 +08005229 x += displayParent.mWindowFrames.mFrame.left
Tiger Huangd8ec9382019-04-18 14:35:09 -07005230 + (dc.getLocationInParentWindow().x * displayParent.mGlobalScale + 0.5f);
Tiger Huang83754532020-06-08 19:48:17 +08005231 y += displayParent.mWindowFrames.mFrame.top
Tiger Huangd8ec9382019-04-18 14:35:09 -07005232 + (dc.getLocationInParentWindow().y * displayParent.mGlobalScale + 0.5f);
5233 dc = displayParent.getDisplayContent();
5234 }
5235
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01005236 // If changed, also adjust transformFrameToSurfacePosition
5237 final WindowContainer parent = getParent();
5238 if (isChildWindow()) {
5239 final WindowState parentWindow = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07005240 x += parentWindow.mWindowFrames.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
5241 y += parentWindow.mWindowFrames.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01005242 } else if (parent != null) {
5243 final Rect parentBounds = parent.getBounds();
5244 x += parentBounds.left;
5245 y += parentBounds.top;
5246 }
5247 float9[Matrix.MTRANS_X] = x;
5248 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01005249 float9[Matrix.MPERSP_0] = 0;
5250 float9[Matrix.MPERSP_1] = 0;
5251 float9[Matrix.MPERSP_2] = 1;
5252 outMatrix.setValues(float9);
5253 }
5254
Garfield Tane8d84ab2019-10-11 09:49:40 -07005255 // TODO: Hack to work around the number of states ActivityRecord needs to access without having
Wale Ogunwale9bc47732016-08-10 14:44:22 -07005256 // access to its windows children. Need to investigate re-writing
Garfield Tane8d84ab2019-10-11 09:49:40 -07005257 // {@link ActivityRecord#updateReportedVisibilityLocked} so this can be removed.
Wale Ogunwale9bc47732016-08-10 14:44:22 -07005258 static final class UpdateReportedVisibilityResults {
5259 int numInteresting;
5260 int numVisible;
5261 int numDrawn;
5262 boolean nowGone = true;
5263
5264 void reset() {
5265 numInteresting = 0;
5266 numVisible = 0;
5267 numDrawn = 0;
5268 nowGone = true;
5269 }
5270 }
Robert Carraf422a82017-04-10 18:34:33 -07005271
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02005272 private static final class WindowId extends IWindowId.Stub {
5273 private final WeakReference<WindowState> mOuter;
5274
5275 private WindowId(WindowState outer) {
5276
5277 // Use a weak reference for the outer class. This is important to prevent the following
5278 // leak: Since we send this class to the client process, binder will keep it alive as
5279 // long as the client keeps it alive. Now, if the window is removed, we need to clear
5280 // out our reference so even though this class is kept alive we don't leak WindowState,
5281 // which can keep a whole lot of classes alive.
5282 mOuter = new WeakReference<>(outer);
5283 }
5284
5285 @Override
5286 public void registerFocusObserver(IWindowFocusObserver observer) {
5287 final WindowState outer = mOuter.get();
5288 if (outer != null) {
5289 outer.registerFocusObserver(observer);
5290 }
5291 }
5292 @Override
5293 public void unregisterFocusObserver(IWindowFocusObserver observer) {
5294 final WindowState outer = mOuter.get();
5295 if (outer != null) {
5296 outer.unregisterFocusObserver(observer);
5297 }
5298 }
5299 @Override
5300 public boolean isFocused() {
5301 final WindowState outer = mOuter.get();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08005302 if (outer != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08005303 synchronized (outer.mWmService.mGlobalLock) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +08005304 return outer.isFocused();
5305 }
5306 }
5307 return false;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02005308 }
5309 }
5310
Robert Carrb1579c82017-09-05 14:54:47 -07005311
5312 @Override
5313 boolean shouldMagnify() {
5314 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08005315 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
5316 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
5317 mAttrs.type == TYPE_NAVIGATION_BAR ||
5318 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
5319 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla9552b262018-03-13 12:24:50 -07005320 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07005321 return false;
5322 }
5323 return true;
5324 }
5325
5326 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07005327 SurfaceSession getSession() {
5328 if (mSession.mSurfaceSession != null) {
5329 return mSession.mSurfaceSession;
5330 } else {
5331 return getParent().getSession();
5332 }
5333 }
5334
5335 @Override
5336 boolean needsZBoost() {
lumarkff0ab692018-11-05 20:32:30 +08005337 final WindowState inputMethodTarget = getDisplayContent().mInputMethodTarget;
5338 if (mIsImWindow && inputMethodTarget != null) {
Garfield Tane8d84ab2019-10-11 09:49:40 -07005339 final ActivityRecord activity = inputMethodTarget.mActivityRecord;
5340 if (activity != null) {
5341 return activity.needsZBoost();
Jorim Jaggib0fc8172017-11-23 17:04:08 +00005342 }
5343 }
5344 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07005345 }
5346
Jorim Jaggibfa95a72020-06-18 22:51:49 +02005347 private void applyDims() {
Robert Carrf59b8dd2017-10-02 18:58:36 -07005348 if (!mAnimatingExit && mAppDied) {
5349 mIsDimming = true;
Jorim Jaggibfa95a72020-06-18 22:51:49 +02005350 getDimmer().dimAbove(getSyncTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08005351 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08005352 // Only show a dim behind when the following is satisfied:
5353 // 1. The window has the flag FLAG_DIM_BEHIND
5354 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
5355 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08005356 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07005357 mIsDimming = true;
Jorim Jaggibfa95a72020-06-18 22:51:49 +02005358 getDimmer().dimBelow(getSyncTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07005359 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08005360 }
5361
Ana Krulecfea97172019-11-02 23:11:02 +01005362
5363 /**
5364 * Notifies SF about the priority of the window, if it changed. SF then uses this information
5365 * to decide which window's desired rendering rate should have a priority when deciding about
5366 * the refresh rate of the screen. Priority
5367 * {@link RefreshRatePolicy#LAYER_PRIORITY_FOCUSED_WITH_MODE} is considered the highest.
5368 */
5369 @VisibleForTesting
5370 void updateFrameRateSelectionPriorityIfNeeded() {
5371 final int priority = getDisplayContent().getDisplayPolicy().getRefreshRatePolicy()
5372 .calculatePriority(this);
5373 if (mFrameRateSelectionPriority != priority) {
5374 mFrameRateSelectionPriority = priority;
5375 getPendingTransaction().setFrameRateSelectionPriority(mSurfaceControl,
5376 mFrameRateSelectionPriority);
5377 }
5378 }
5379
Robert Carrf07ef9e2017-11-21 12:12:49 -08005380 @Override
5381 void prepareSurfaces() {
Robert Carrf07ef9e2017-11-21 12:12:49 -08005382 mIsDimming = false;
Jorim Jaggibfa95a72020-06-18 22:51:49 +02005383 applyDims();
chaviw2f0567b2018-01-29 16:22:02 -08005384 updateSurfacePosition();
Ana Krulecfea97172019-11-02 23:11:02 +01005385 // Send information to SufaceFlinger about the priority of the current window.
5386 updateFrameRateSelectionPriorityIfNeeded();
Jorim Jaggia5e10572017-11-15 14:36:26 +01005387
Robert Carrb1579c82017-09-05 14:54:47 -07005388 mWinAnimator.prepareSurfaceLocked(true);
chaviw54521692020-06-12 14:34:30 -07005389 notifyBlastSyncTransaction();
Robert Carrb1579c82017-09-05 14:54:47 -07005390 super.prepareSurfaces();
5391 }
5392
5393 @Override
Vishnu Naird8c664b2018-09-24 12:52:35 -07005394 @VisibleForTesting
5395 void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01005396 if (mSurfaceControl == null) {
5397 return;
5398 }
5399
chaviw492139a2018-07-16 16:07:35 -07005400 transformFrameToSurfacePosition(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top,
5401 mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08005402
Vishnu Nair83537a72018-07-19 21:27:48 -07005403 // Freeze position while we're unrotated, so the surface remains at the position it was
5404 // prior to the rotation.
Vishnu Nairddd80742018-08-21 14:12:46 -07005405 if (!mSurfaceAnimator.hasLeash() && mPendingSeamlessRotate == null
5406 && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01005407 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08005408 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08005409 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
5410 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
5411 t.deferTransactionUntil(mSurfaceControl,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07005412 mWinAnimator.mSurfaceController.mSurfaceControl,
chaviwbe43ac82018-04-04 15:14:49 -07005413 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08005414 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01005415 }
5416 }
5417
5418 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
5419 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01005420
5421 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08005422 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01005423 if (isChildWindow()) {
5424 // TODO: This probably falls apart at some point and we should
5425 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01005426
5427 // Since the parent was outset by its surface insets, we need to undo the outsetting
5428 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01005429 final WindowState parent = getParentWindow();
Riddle Hsub398da32019-01-21 21:48:16 +08005430 transformSurfaceInsetsPosition(mTmpPoint, parent.mAttrs.surfaceInsets);
5431 outPoint.offset(-parent.mWindowFrames.mFrame.left + mTmpPoint.x,
5432 -parent.mWindowFrames.mFrame.top + mTmpPoint.y);
chaviwe07246a2017-12-12 16:18:29 -08005433 } else if (parentWindowContainer != null) {
Evan Rosky6ecd67c2020-04-14 11:50:43 -07005434 final Rect parentBounds = parentWindowContainer.getBounds();
chaviwe07246a2017-12-12 16:18:29 -08005435 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005436 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01005437
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08005438 ActivityStack stack = getRootTask();
Robert Carr32bcb102018-01-29 15:03:23 -08005439
5440 // If we have stack outsets, that means the top-left
5441 // will be outset, and we need to inset ourselves
5442 // to account for it. If we actually have shadows we will
5443 // then un-inset ourselves by the surfaceInsets.
5444 if (stack != null) {
Louis Chang2570e332020-04-10 11:58:49 +08005445 final int outset = stack.getTaskOutset();
Robert Carr32bcb102018-01-29 15:03:23 -08005446 outPoint.offset(outset, outset);
5447 }
5448
Jorim Jaggi9af095b2017-12-12 17:18:57 +01005449 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Riddle Hsub398da32019-01-21 21:48:16 +08005450 transformSurfaceInsetsPosition(mTmpPoint, mAttrs.surfaceInsets);
5451 outPoint.offset(-mTmpPoint.x, -mTmpPoint.y);
5452 }
5453
5454 /**
5455 * The surface insets from layout parameter are in application coordinate. If the window is
5456 * scaled, the insets also need to be scaled for surface position in global coordinate.
5457 */
5458 private void transformSurfaceInsetsPosition(Point outPos, Rect surfaceInsets) {
5459 if (!inSizeCompatMode()) {
5460 outPos.x = surfaceInsets.left;
5461 outPos.y = surfaceInsets.top;
5462 return;
5463 }
5464 outPos.x = (int) (surfaceInsets.left * mGlobalScale + 0.5f);
5465 outPos.y = (int) (surfaceInsets.top * mGlobalScale + 0.5f);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005466 }
5467
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005468 boolean needsRelativeLayeringToIme() {
5469 // We only use the relative layering mode in split screen, as part of elevating the IME
5470 // and windows above it's target above the docked divider.
5471 if (!inSplitScreenWindowingMode()) {
5472 return false;
5473 }
5474
5475 if (isChildWindow()) {
5476 // If we are a child of the input method target we need this promotion.
5477 if (getParentWindow().isInputMethodTarget()) {
5478 return true;
5479 }
Garfield Tane8d84ab2019-10-11 09:49:40 -07005480 } else if (mActivityRecord != null) {
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005481 // Likewise if we share a token with the Input method target and are ordered
5482 // above it but not necessarily a child (e.g. a Dialog) then we also need
5483 // this promotion.
lumarkff0ab692018-11-05 20:32:30 +08005484 final WindowState imeTarget = getDisplayContent().mInputMethodTarget;
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005485 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
Jorim Jaggib895e202020-04-16 00:39:55 +02005486 && imeTarget.mToken == mToken
chaviwce12f852020-06-12 17:39:41 -07005487 && mAttrs.type != TYPE_APPLICATION_STARTING
Jorim Jaggib895e202020-04-16 00:39:55 +02005488 && getParent() != null
5489 && imeTarget.compareTo(this) <= 0;
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005490 return inTokenWithAndAboveImeTarget;
5491 }
5492 return false;
5493 }
5494
Tarandeep Singh1e5b1a82020-01-24 16:03:05 -08005495 /**
5496 * Get IME target that should host IME when this window's display has a parent.
5497 * Note: IME is never hosted by a display that has a parent.
5498 * When window calling
5499 * {@link android.view.inputmethod.InputMethodManager#showSoftInput(View, int)} is unknown,
5500 * use {@link DisplayContent#getImeControlTarget()} instead.
5501 *
Taran Singh66219b42020-06-04 10:28:57 -07005502 * @return {@link InsetsControlTarget} of host that controls the IME.
Tarandeep Singh1e5b1a82020-01-24 16:03:05 -08005503 * When window is doesn't have a parent, it is returned as-is.
5504 */
Taran Singh66219b42020-06-04 10:28:57 -07005505 InsetsControlTarget getImeControlTarget() {
Tarandeep Singh1e5b1a82020-01-24 16:03:05 -08005506 final DisplayContent dc = getDisplayContent();
5507 final WindowState parentWindow = dc.getParentWindow();
5508
5509 // If target's display has a parent, IME is displayed in the parent display.
5510 return dc.getImeHostOrFallback(parentWindow != null ? parentWindow : this);
5511 }
5512
Jorim Jaggia5e10572017-11-15 14:36:26 +01005513 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07005514 void assignLayer(Transaction t, int layer) {
5515 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005516 if (needsRelativeLayeringToIme()) {
5517 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07005518 return;
5519 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07005520 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07005521 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07005522
5523 @Override
5524 public boolean isDimming() {
5525 return mIsDimming;
5526 }
Robert Carr0eff1872017-12-01 14:27:04 -08005527
5528 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
5529 // then we can drop all negative layering on the windowing side and simply inherit
5530 // the default implementation here.
5531 public void assignChildLayers(Transaction t) {
Tiger Huang9c8ee262019-02-19 20:44:27 +08005532 // The surface of the main window might be preserved. So the child window on top of the main
5533 // window should be also on top of the preserved surface.
5534 int layer = PRESERVED_SURFACE_LAYER + 1;
Robert Carr0eff1872017-12-01 14:27:04 -08005535 for (int i = 0; i < mChildren.size(); i++) {
5536 final WindowState w = mChildren.get(i);
5537
5538 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
5539 // while they both need to go below the main window. However the
5540 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
5541 // been defined and so we can use static layers and leave it that way.
5542 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
shubangcdc23b52019-06-19 11:08:10 -07005543 if (mWinAnimator.hasSurface()) {
5544 w.assignRelativeLayer(t, mWinAnimator.mSurfaceController.mSurfaceControl, -2);
5545 } else {
5546 w.assignLayer(t, -2);
5547 }
Robert Carr0eff1872017-12-01 14:27:04 -08005548 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
shubangcdc23b52019-06-19 11:08:10 -07005549 if (mWinAnimator.hasSurface()) {
5550 w.assignRelativeLayer(t, mWinAnimator.mSurfaceController.mSurfaceControl, -1);
5551 } else {
5552 w.assignLayer(t, -1);
5553 }
Robert Carr0eff1872017-12-01 14:27:04 -08005554 } else {
5555 w.assignLayer(t, layer);
5556 }
5557 w.assignChildLayers(t);
5558 layer++;
5559 }
5560 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01005561
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005562 /**
Tiger Huang2b210c22019-03-18 21:21:26 +08005563 * Update a tap exclude region identified by provided id. The requested area will be clipped to
5564 * the window bounds.
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005565 */
chaviwaa0d74e2019-12-26 14:13:40 -08005566 void updateTapExcludeRegion(Region region) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005567 final DisplayContent currentDisplay = getDisplayContent();
5568 if (currentDisplay == null) {
5569 throw new IllegalStateException("Trying to update window not attached to any display.");
5570 }
5571
chaviwaa0d74e2019-12-26 14:13:40 -08005572 // Clear the tap excluded region if the region passed in is null or empty.
5573 if (region == null || region.isEmpty()) {
5574 mTapExcludeRegion.setEmpty();
5575 // Remove this window from mTapExcludeProvidingWindows since it won't be providing
5576 // tap exclude regions.
5577 currentDisplay.mTapExcludeProvidingWindows.remove(this);
5578 } else {
5579 mTapExcludeRegion.set(region);
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005580 // Make sure that this window is registered as one that provides a tap exclude region
5581 // for its containing display.
5582 currentDisplay.mTapExcludeProvidingWindows.add(this);
5583 }
5584
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005585 // Trigger touch exclude region update on current display.
Tiger Huang1e5b10a2018-07-30 20:19:51 +08005586 currentDisplay.updateTouchExcludeRegion();
Tiger Huang04dc4cc2019-01-17 18:41:41 +08005587 // Trigger touchable region update for this window.
5588 currentDisplay.getInputMonitor().updateInputWindowsLw(true /* force */);
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005589 }
5590
Tiger Huang04dc4cc2019-01-17 18:41:41 +08005591 /**
chaviwaa0d74e2019-12-26 14:13:40 -08005592 * Get the tap excluded region for this window in screen coordinates.
Tiger Huang04dc4cc2019-01-17 18:41:41 +08005593 *
chaviwaa0d74e2019-12-26 14:13:40 -08005594 * @param outRegion The returned tap excluded region. It is on the screen coordinates.
Tiger Huang04dc4cc2019-01-17 18:41:41 +08005595 */
chaviwaa0d74e2019-12-26 14:13:40 -08005596 void getTapExcludeRegion(Region outRegion) {
Tiger Huang04dc4cc2019-01-17 18:41:41 +08005597 mTmpRect.set(mWindowFrames.mFrame);
5598 mTmpRect.offsetTo(0, 0);
chaviwaa0d74e2019-12-26 14:13:40 -08005599
5600 outRegion.set(mTapExcludeRegion);
5601 outRegion.op(mTmpRect, Region.Op.INTERSECT);
5602
5603 // The region is on the window coordinates, so it needs to be translated into screen
5604 // coordinates. There's no need to scale since that will be done by native code.
5605 outRegion.translate(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top);
Andrii Kulian4b6599e2018-01-15 17:24:08 -08005606 }
5607
Jackal Guoc43a0a62019-04-23 09:15:14 +08005608 boolean hasTapExcludeRegion() {
chaviwaa0d74e2019-12-26 14:13:40 -08005609 return !mTapExcludeRegion.isEmpty();
Jackal Guoc43a0a62019-04-23 09:15:14 +08005610 }
5611
Robert Carr825581a2018-03-30 14:00:53 -07005612 @Override
5613 public boolean isInputMethodTarget() {
lumarkff0ab692018-11-05 20:32:30 +08005614 return getDisplayContent().mInputMethodTarget == this;
Robert Carr825581a2018-03-30 14:00:53 -07005615 }
5616
chaviwbe43ac82018-04-04 15:14:49 -07005617 long getFrameNumber() {
Vishnu Nair1a7075f2020-05-26 14:03:54 -07005618 // Return the frame number in which changes requested in this layout will be rendered or
5619 // -1 if we do not expect the frame to be rendered.
5620 return getFrameLw().isEmpty() ? -1 : mFrameNumber;
chaviwbe43ac82018-04-04 15:14:49 -07005621 }
5622
5623 void setFrameNumber(long frameNumber) {
5624 mFrameNumber = frameNumber;
5625 }
5626
chaviw553b0212018-07-12 13:37:01 -07005627 public void getMaxVisibleBounds(Rect out) {
5628 if (out.isEmpty()) {
5629 out.set(mWindowFrames.mVisibleFrame);
5630 return;
5631 }
5632
5633 if (mWindowFrames.mVisibleFrame.left < out.left) {
5634 out.left = mWindowFrames.mVisibleFrame.left;
5635 }
5636 if (mWindowFrames.mVisibleFrame.top < out.top) {
5637 out.top = mWindowFrames.mVisibleFrame.top;
5638 }
5639 if (mWindowFrames.mVisibleFrame.right > out.right) {
5640 out.right = mWindowFrames.mVisibleFrame.right;
5641 }
5642 if (mWindowFrames.mVisibleFrame.bottom > out.bottom) {
5643 out.bottom = mWindowFrames.mVisibleFrame.bottom;
5644 }
5645 }
5646
chaviw9c81e632018-07-31 11:17:52 -07005647 /**
5648 * Copy the inset values over so they can be sent back to the client when a relayout occurs.
5649 */
Jorim Jaggif081f062019-10-24 16:24:54 +02005650 void getInsetsForRelayout(Rect outContentInsets, Rect outVisibleInsets,
5651 Rect outStableInsets) {
chaviw9c81e632018-07-31 11:17:52 -07005652 outContentInsets.set(mWindowFrames.mContentInsets);
5653 outVisibleInsets.set(mWindowFrames.mVisibleInsets);
5654 outStableInsets.set(mWindowFrames.mStableInsets);
chaviw9c81e632018-07-31 11:17:52 -07005655
5656 mLastRelayoutContentInsets.set(mWindowFrames.mContentInsets);
5657 }
5658
5659 void getContentInsets(Rect outContentInsets) {
5660 outContentInsets.set(mWindowFrames.mContentInsets);
5661 }
5662
5663 Rect getContentInsets() {
5664 return mWindowFrames.mContentInsets;
5665 }
5666
5667 void getStableInsets(Rect outStableInsets) {
5668 outStableInsets.set(mWindowFrames.mStableInsets);
5669 }
5670
5671 Rect getStableInsets() {
5672 return mWindowFrames.mStableInsets;
5673 }
5674
5675 void resetLastContentInsets() {
5676 mWindowFrames.resetLastContentInsets();
5677 }
5678
5679 Rect getVisibleInsets() {
5680 return mWindowFrames.mVisibleInsets;
5681 }
5682
chaviw1454b392018-08-06 09:54:04 -07005683 @Override
5684 public WindowFrames getWindowFrames() {
5685 return mWindowFrames;
5686 }
5687
Riddle Hsuc7175762020-01-10 21:03:48 +08005688 /**
Riddle Hsu6f548e92020-01-13 13:34:09 +08005689 * If the simulated frame is set, the computed result won't be used in real layout. So this
Riddle Hsuc7175762020-01-10 21:03:48 +08005690 * frames must be cleared when the simulated computation is done.
5691 */
5692 void setSimulatedWindowFrames(WindowFrames windowFrames) {
5693 mSimulatedWindowFrames = windowFrames;
5694 }
5695
5696 /**
5697 * Use this method only when the simulated frames may be set, so it is clearer that the calling
5698 * path may be used to simulate layout.
5699 */
5700 WindowFrames getLayoutingWindowFrames() {
5701 return mSimulatedWindowFrames != null ? mSimulatedWindowFrames : mWindowFrames;
5702 }
5703
chaviw1454b392018-08-06 09:54:04 -07005704 void resetContentChanged() {
5705 mWindowFrames.setContentChanged(false);
5706 }
5707
Jorim Jaggi956ca412019-01-07 14:49:14 +01005708 /**
5709 * Set's an {@link InsetsSourceProvider} to be associated with this window, but only if the
5710 * provider itself is controllable, as one window can be the provider of more than one inset
5711 * type (i.e. gesture insets). If this window is controllable, all its animations must be
5712 * controlled by its control target, and the visibility of this window should be taken account
5713 * into the state of the control target.
5714 *
5715 * @param insetProvider the provider which should not be visible to the client.
5716 * @see InsetsStateController#getInsetsForDispatch(WindowState)
5717 */
5718 void setControllableInsetProvider(InsetsSourceProvider insetProvider) {
5719 mControllableInsetProvider = insetProvider;
Jorim Jaggif96c90a2018-09-26 16:55:15 +02005720 }
5721
Jorim Jaggi956ca412019-01-07 14:49:14 +01005722 InsetsSourceProvider getControllableInsetProvider() {
5723 return mControllableInsetProvider;
Jorim Jaggif96c90a2018-09-26 16:55:15 +02005724 }
5725
Jorim Jaggia5e10572017-11-15 14:36:26 +01005726 private final class MoveAnimationSpec implements AnimationSpec {
5727
5728 private final long mDuration;
5729 private Interpolator mInterpolator;
5730 private Point mFrom = new Point();
5731 private Point mTo = new Point();
5732
5733 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
5734 final Animation anim = AnimationUtils.loadAnimation(mContext,
5735 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01005736 mDuration = (long)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08005737 (anim.computeDurationHint() * mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01005738 mInterpolator = anim.getInterpolator();
5739 mFrom.set(fromX, fromY);
5740 mTo.set(toX, toY);
5741 }
5742
5743 @Override
5744 public long getDuration() {
5745 return mDuration;
5746 }
5747
5748 @Override
5749 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
arthurhungd3b0e542020-04-23 15:30:21 +08005750 final float fraction = getFraction(currentPlayTime);
Jorim Jaggia5e10572017-11-15 14:36:26 +01005751 final float v = mInterpolator.getInterpolation(fraction);
5752 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
5753 mFrom.y + (mTo.y - mFrom.y) * v);
5754 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01005755
5756 @Override
5757 public void dump(PrintWriter pw, String prefix) {
chaviwc65fa582018-08-09 15:33:13 -07005758 pw.println(prefix + "from=" + mFrom
5759 + " to=" + mTo
5760 + " duration=" + mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01005761 }
5762
5763 @Override
Jeffrey Huangcb782852019-12-05 11:28:11 -08005764 public void dumpDebugInner(ProtoOutputStream proto) {
Jorim Jaggif75d1612018-02-27 15:05:21 +01005765 final long token = proto.start(MOVE);
Jeffrey Huangcb782852019-12-05 11:28:11 -08005766 mFrom.dumpDebug(proto, FROM);
5767 mTo.dumpDebug(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07005768 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01005769 proto.end(token);
5770 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01005771 }
Vishnu Nair539334a2019-09-20 10:46:21 -07005772
5773 KeyInterceptionInfo getKeyInterceptionInfo() {
5774 if (mKeyInterceptionInfo == null
5775 || mKeyInterceptionInfo.layoutParamsPrivateFlags != getAttrs().privateFlags
5776 || mKeyInterceptionInfo.layoutParamsType != getAttrs().type
5777 || mKeyInterceptionInfo.windowTitle != getWindowTag()) {
5778 mKeyInterceptionInfo = new KeyInterceptionInfo(getAttrs().type, getAttrs().privateFlags,
5779 getWindowTag().toString());
5780 }
5781 return mKeyInterceptionInfo;
5782 }
lumark19a5d2e2019-10-11 16:19:30 +08005783
5784 @Override
5785 void getAnimationFrames(Rect outFrame, Rect outInsets, Rect outStableInsets,
5786 Rect outSurfaceInsets) {
5787 // Containing frame will usually cover the whole screen, including dialog windows.
5788 // For freeform workspace windows it will not cover the whole screen and it also
5789 // won't exactly match the final freeform window frame (e.g. when overlapping with
5790 // the status bar). In that case we need to use the final frame.
5791 if (inFreeformWindowingMode()) {
5792 outFrame.set(getFrameLw());
Riddle Hsuf41034c2020-03-19 13:10:46 +08005793 } else if (isLetterboxedAppWindow() || mToken.isFixedRotationTransforming()) {
5794 // 1. The letterbox surfaces should be animated with the owner activity, so use task
5795 // bounds to include them.
5796 // 2. If the activity has fixed rotation transform, its windows are rotated in activity
5797 // level. Because the animation runs before display is rotated, task bounds should
5798 // represent the frames in display space coordinates.
lumark19a5d2e2019-10-11 16:19:30 +08005799 outFrame.set(getTask().getBounds());
5800 } else if (isDockedResizing()) {
5801 // If we are animating while docked resizing, then use the stack bounds as the
5802 // animation target (which will be different than the task bounds)
5803 outFrame.set(getTask().getParent().getBounds());
5804 } else {
5805 outFrame.set(getContainingFrame());
5806 }
5807 outSurfaceInsets.set(getAttrs().surfaceInsets);
5808 // TODO(b/72757033): These are insets relative to the window frame, but we're really
5809 // interested in the insets relative to the frame we chose in the if-blocks above.
5810 getContentInsets(outInsets);
5811 getStableInsets(outStableInsets);
5812 }
Charles Chen173ae782019-11-11 20:39:02 +08005813
5814 /**
5815 * Returns {@code true} if this window is not {@link WindowManager.LayoutParams#TYPE_TOAST}
5816 * or {@link WindowManager.LayoutParams#TYPE_APPLICATION_STARTING},
5817 * since this window doesn't belong to apps.
5818 */
5819 boolean isNonToastOrStarting() {
5820 return mAttrs.type != TYPE_TOAST && mAttrs.type != TYPE_APPLICATION_STARTING;
5821 }
5822
5823 boolean isNonToastWindowVisibleForUid(int callingUid) {
5824 return getOwningUid() == callingUid && isNonToastOrStarting() && isVisibleNow();
5825 }
5826
5827 boolean isNonToastWindowVisibleForPid(int pid) {
5828 return mSession.mPid == pid && isNonToastOrStarting() && isVisibleNow();
5829 }
Robert Carr2e20bcd2020-01-22 13:32:38 -08005830
chaviw0cf68522020-05-04 19:57:23 -07005831 void setViewVisibility(int viewVisibility) {
5832 mViewVisibility = viewVisibility;
5833 // The viewVisibility is set to GONE with a client request to relayout. If this occurs and
5834 // there's a blast sync transaction waiting, finishDrawing will never be called since the
5835 // client will not render when visibility is GONE. Therefore, call finishDrawing here to
5836 // prevent system server from blocking on a window that will not draw.
5837 if (viewVisibility == View.GONE && mUsingBLASTSyncTransaction) {
chaviw355befd2020-06-23 08:11:46 -07005838 immediatelyNotifyBlastSync();
chaviw0cf68522020-05-04 19:57:23 -07005839 }
5840 }
5841
Rob Carr698b6842020-03-06 15:33:31 -08005842 SurfaceControl getClientViewRootSurface() {
5843 return mWinAnimator.getClientViewRootSurface();
Robert Carr2e20bcd2020-01-22 13:32:38 -08005844 }
Robert Carre10ee3d2019-11-11 15:03:15 -08005845
5846 @Override
5847 boolean prepareForSync(BLASTSyncEngine.TransactionReadyListener waitingListener,
5848 int waitingId) {
Robert Carr6a08d322020-05-19 10:21:55 -07005849 boolean willSync = setPendingListener(waitingListener, waitingId);
5850 if (!willSync) {
Rob Carrcba6a722020-03-10 12:41:06 -07005851 return false;
5852 }
Robert Carr52385c32020-06-23 15:56:28 -07005853 requestRedrawForSync();
Rob Carrae0100b2020-03-09 14:46:19 -07005854
Rob Carr25376512020-03-09 15:23:19 -07005855 mLocalSyncId = mBLASTSyncEngine.startSyncSet(this);
5856 addChildrenToSyncSet(mLocalSyncId);
5857
Robert Carr6a08d322020-05-19 10:21:55 -07005858 // In the WindowContainer implementation we immediately mark ready
5859 // since a generic WindowContainer only needs to wait for its
5860 // children to finish and is immediately ready from its own
5861 // perspective but at the WindowState level we need to wait for ourselves
5862 // to draw even if the children draw first our don't need to sync, so we omit
5863 // the set ready call until later in finishDrawing()
Rob Carrae0100b2020-03-09 14:46:19 -07005864 mWmService.mH.removeMessages(WINDOW_STATE_BLAST_SYNC_TIMEOUT, this);
5865 mWmService.mH.sendNewMessageDelayed(WINDOW_STATE_BLAST_SYNC_TIMEOUT, this,
5866 BLAST_TIMEOUT_DURATION);
5867
Robert Carre10ee3d2019-11-11 15:03:15 -08005868 return true;
5869 }
5870
5871 boolean finishDrawing(SurfaceControl.Transaction postDrawTransaction) {
5872 if (!mUsingBLASTSyncTransaction) {
5873 return mWinAnimator.finishDrawingLocked(postDrawTransaction);
5874 }
Rob Carrae0100b2020-03-09 14:46:19 -07005875
Rob Carr25376512020-03-09 15:23:19 -07005876 if (postDrawTransaction != null) {
5877 mBLASTSyncTransaction.merge(postDrawTransaction);
Robert Carre10ee3d2019-11-11 15:03:15 -08005878 }
Rob Carr25376512020-03-09 15:23:19 -07005879
chaviw54521692020-06-12 14:34:30 -07005880 mNotifyBlastOnSurfacePlacement = true;
5881 return mWinAnimator.finishDrawingLocked(null);
5882 }
5883
chaviw355befd2020-06-23 08:11:46 -07005884 private void notifyBlastSyncTransaction() {
5885 mWmService.mH.removeMessages(WINDOW_STATE_BLAST_SYNC_TIMEOUT, this);
5886
chaviw54521692020-06-12 14:34:30 -07005887 if (!mNotifyBlastOnSurfacePlacement || mWaitingListener == null) {
5888 mNotifyBlastOnSurfacePlacement = false;
5889 return;
5890 }
5891
Rob Carr25376512020-03-09 15:23:19 -07005892 // If localSyncId is >0 then we are syncing with children and will
5893 // invoke transaction ready from our own #transactionReady callback
5894 // we just need to signal our side of the sync (setReady). But if we
5895 // have no sync operation at this level transactionReady will never
5896 // be invoked and we need to invoke it ourself.
5897 if (mLocalSyncId >= 0) {
5898 mBLASTSyncEngine.setReady(mLocalSyncId);
chaviw54521692020-06-12 14:34:30 -07005899 return;
Rob Carr25376512020-03-09 15:23:19 -07005900 }
5901
chaviw54521692020-06-12 14:34:30 -07005902 mWaitingListener.onTransactionReady(mWaitingSyncId, Collections.singleton(this));
Robert Carre10ee3d2019-11-11 15:03:15 -08005903
5904 mWaitingSyncId = 0;
5905 mWaitingListener = null;
chaviw54521692020-06-12 14:34:30 -07005906 mNotifyBlastOnSurfacePlacement = false;
Robert Carre10ee3d2019-11-11 15:03:15 -08005907 }
chaviw73abde92020-05-18 17:56:35 -07005908
chaviw355befd2020-06-23 08:11:46 -07005909 void immediatelyNotifyBlastSync() {
5910 finishDrawing(null);
5911 notifyBlastSyncTransaction();
5912 }
5913
Robert Carr52385c32020-06-23 15:56:28 -07005914 /**
5915 * When using the two WindowOrganizer sync-primitives (BoundsChangeTransaction, BLASTSync)
5916 * it can be a little difficult to predict whether your change will actually trigger redrawing
5917 * on the client side. To ease the burden on shell developers, we force send MSG_RESIZED
5918 * for Windows involved in these Syncs
5919 */
5920 private boolean shouldSendRedrawForSync() {
5921 final Task task = getTask();
5922 if (task != null && task.getMainWindowSizeChangeTransaction() != null)
5923 return !mRedrawForSyncReported;
5924 return useBLASTSync() && !mRedrawForSyncReported;
5925 }
5926
5927 void requestRedrawForSync() {
5928 mRedrawForSyncReported = false;
chaviw73abde92020-05-18 17:56:35 -07005929 }
satokcef37fb2011-10-24 21:49:38 +09005930}