blob: ddc1eace1ea2ea3bfcef19a5160a64a4c97e6451 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Jorim Jaggi02886a82016-12-06 09:10:06 -080019import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080020import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
21import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggia5e10572017-11-15 14:36:26 +010022import static android.view.SurfaceControl.Transaction;
Jorim Jaggi02886a82016-12-06 09:10:06 -080023import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
24import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
25import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
26import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
27import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
28import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
29import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
30import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
31import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
32import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
33import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
34import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
35import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
36import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080037import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
38import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
39import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080040import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080041import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
42import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
43import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070044import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080045import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
46import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
47import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
48import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
49import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
50import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carraf422a82017-04-10 18:34:33 -070051import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Robert Carr0eff1872017-12-01 14:27:04 -080052import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Jorim Jaggi02886a82016-12-06 09:10:06 -080053import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
54import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
55import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
56import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
57import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
58import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Robert Carrb1579c82017-09-05 14:54:47 -070059import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
60import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Robert Carree4d4b92017-11-22 12:21:46 -080061import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
Robert Carrb1579c82017-09-05 14:54:47 -070062import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070063import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080064import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070065import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080066import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
67import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
68import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
69import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Adrian Roose99bc052017-11-20 17:55:31 +010070import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
71import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
72import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
73import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080074import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
75import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
76import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
77import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
78import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
79import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
80import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080083import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
85import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
86import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
87import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
91import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
92import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
93import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Jorim Jaggia5e10572017-11-15 14:36:26 +010094import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -080095import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
96import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
97import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
98import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
99import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
100import static com.android.server.wm.WindowManagerService.localLOGV;
101import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
102import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
103import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
104import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700105import static com.android.server.wm.proto.IdentifierProto.HASH_CODE;
106import static com.android.server.wm.proto.IdentifierProto.TITLE;
107import static com.android.server.wm.proto.IdentifierProto.USER_ID;
108import static com.android.server.wm.proto.WindowStateProto.ANIMATING_EXIT;
109import static com.android.server.wm.proto.WindowStateProto.ANIMATOR;
110import static com.android.server.wm.proto.WindowStateProto.ATTRIBUTES;
111import static com.android.server.wm.proto.WindowStateProto.CHILD_WINDOWS;
112import static com.android.server.wm.proto.WindowStateProto.CONTAINING_FRAME;
113import static com.android.server.wm.proto.WindowStateProto.CONTENT_FRAME;
114import static com.android.server.wm.proto.WindowStateProto.CONTENT_INSETS;
115import static com.android.server.wm.proto.WindowStateProto.DISPLAY_ID;
116import static com.android.server.wm.proto.WindowStateProto.FRAME;
117import static com.android.server.wm.proto.WindowStateProto.GIVEN_CONTENT_INSETS;
118import static com.android.server.wm.proto.WindowStateProto.IDENTIFIER;
119import static com.android.server.wm.proto.WindowStateProto.PARENT_FRAME;
120import static com.android.server.wm.proto.WindowStateProto.STACK_ID;
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +0100121import static com.android.server.wm.proto.WindowStateProto.SHOWN_POSITION;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700122import static com.android.server.wm.proto.WindowStateProto.SURFACE_INSETS;
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +0100123import static com.android.server.wm.proto.WindowStateProto.SURFACE_POSITION;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700124import static com.android.server.wm.proto.WindowStateProto.WINDOW_CONTAINER;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800125
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700126import android.annotation.CallSuper;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800127import android.app.AppOpsManager;
128import android.content.Context;
129import android.content.res.Configuration;
130import android.graphics.Matrix;
131import android.graphics.PixelFormat;
132import android.graphics.Point;
133import android.graphics.Rect;
134import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700135import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700136import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800137import android.os.IBinder;
138import android.os.PowerManager;
139import android.os.RemoteCallbackList;
140import android.os.RemoteException;
141import android.os.SystemClock;
142import android.os.Trace;
143import android.os.UserHandle;
144import android.os.WorkSource;
145import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200146import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800147import android.util.Slog;
148import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700149import android.util.proto.ProtoOutputStream;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100150import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800151import android.view.DisplayInfo;
152import android.view.Gravity;
153import android.view.IApplicationToken;
154import android.view.IWindow;
155import android.view.IWindowFocusObserver;
156import android.view.IWindowId;
157import android.view.InputChannel;
158import android.view.InputEvent;
159import android.view.InputEventReceiver;
Robert Carrb1579c82017-09-05 14:54:47 -0700160import android.view.SurfaceControl;
161import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800162import android.view.View;
163import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700164import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800165import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100166import android.view.animation.Animation;
167import android.view.animation.AnimationUtils;
168import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800169
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800170import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800171import com.android.server.input.InputWindowHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100172import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100173import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800174
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800175import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200176import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800177import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700178import java.util.Comparator;
179import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800180import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800181
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700182/** A window in the window manager. */
183class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800184 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800185
Skuhne81c524a2015-08-12 13:34:14 -0700186 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700187 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
188 // use hard-coded min sizes for now.
189 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
190 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700191
192 // The thickness of a window resize handle outside the window bounds on the free form workspace
193 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700194 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700195
Craig Mautnere7ae2502012-03-26 17:11:19 -0700196 final WindowManagerPolicy mPolicy;
197 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198 final Session mSession;
199 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800200 final int mAppOp;
201 // UserId and appId of the owner. Don't display windows of non-current user.
202 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800203 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
204 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200205 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700207 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700209
210 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
211 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800212 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
213 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700214 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800215 final int mBaseLayer;
216 final int mSubLayer;
217 final boolean mLayoutAttached;
218 final boolean mIsImWindow;
219 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700220 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700221 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700222 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700224 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700225 /**
226 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
227 * Normally set by calling {@link #showLw} and {@link #hideLw}.
228 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700230 /**
231 * What {@link #mPolicyVisibility} should be set to after a transition animation.
232 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
233 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
234 * animation is done.
235 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700237 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700238 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700239 // This is a non-system overlay window that is currently force hidden.
240 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700242 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700244 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200245 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700246 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700247
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700248 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800249
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700250 /**
251 * The window size that was requested by the application. These are in
252 * the application's coordinate space (without compatibility scale applied).
253 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254 int mRequestedWidth;
255 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700256 private int mLastRequestedWidth;
257 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700258
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260 boolean mHaveFrame;
261 boolean mObscured;
262 boolean mTurnOnScreen;
263
264 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700265
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700266 /**
267 * Used to store last reported to client configuration and check if we have newer available.
268 * We'll send configuration to client only if it is different from the last applied one and
269 * client won't perform unnecessary updates.
270 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700271 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700272
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700273 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700274 * Actual position of the surface shown on-screen (may be modified by animation). These are
275 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700276 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700277 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278
279 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700280 * Insets that determine the actually visible area. These are in the application's
281 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 */
283 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700284 private final Rect mLastVisibleInsets = new Rect();
285 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286
287 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700288 * Insets that are covered by system windows (such as the status bar) and
289 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700290 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 */
292 final Rect mContentInsets = new Rect();
293 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700294
295 /**
296 * The last content insets returned to the client in relayout. We use
297 * these in the bounds animation to ensure we only observe inset changes
298 * at the same time that a client resizes it's surface so that we may use
299 * the geometryAppliesWithResize synchronization mechanism to keep
300 * the contents in place.
301 */
302 final Rect mLastRelayoutContentInsets = new Rect();
303
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700304 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305
306 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800307 * Insets that determine the area covered by the display overscan region. These are in the
308 * application's coordinate space (without compatibility scale applied).
309 */
310 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700311 private final Rect mLastOverscanInsets = new Rect();
312 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800313
314 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700315 * Insets that determine the area covered by the stable system windows. These are in the
316 * application's coordinate space (without compatibility scale applied).
317 */
318 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700319 private final Rect mLastStableInsets = new Rect();
320 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700321
322 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700323 * Outsets determine the area outside of the surface where we want to pretend that it's possible
324 * to draw anyway.
325 */
326 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700327 private final Rect mLastOutsets = new Rect();
328 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700329
Adrian Roos5c6b6222017-11-07 17:36:10 +0100330 /** Part of the display that has been cut away. See {@link DisplayCutout}. */
331 DisplayCutout mDisplayCutout = DisplayCutout.NO_CUTOUT;
332 private DisplayCutout mLastDisplayCutout = DisplayCutout.NO_CUTOUT;
333 private boolean mDisplayCutoutChanged;
334
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700335 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336 * Set to true if we are waiting for this window to receive its
337 * given internal insets before laying out other windows based on it.
338 */
339 boolean mGivenInsetsPending;
340
341 /**
342 * These are the content insets that were given during layout for
343 * this window, to be applied to windows behind it.
344 */
345 final Rect mGivenContentInsets = new Rect();
346
347 /**
348 * These are the visible insets that were given during layout for
349 * this window, to be applied to windows behind it.
350 */
351 final Rect mGivenVisibleInsets = new Rect();
352
353 /**
354 * This is the given touchable area relative to the window frame, or null if none.
355 */
356 final Region mGivenTouchableRegion = new Region();
357
358 /**
359 * Flag indicating whether the touchable region should be adjusted by
360 * the visible insets; if false the area outside the visible insets is
361 * NOT touchable, so we must use those to adjust the frame during hit
362 * tests.
363 */
364 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
365
366 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400367 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700368 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800369 float mHScale=1, mVScale=1;
370 float mLastHScale=1, mLastVScale=1;
371 final Matrix mTmpMatrix = new Matrix();
372
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700373 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800374 final Rect mFrame = new Rect();
375 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700376 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700377 // Frame that is scaled to the application's coordinate space when in
378 // screen size compatibility mode.
379 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800380
381 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700382
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700383 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700384
Wale Ogunwale94596652015-02-06 19:27:34 -0800385 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
386 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700387 final Rect mDisplayFrame = new Rect();
388
389 // The region of the display frame that the display type supports displaying content on. This
390 // is mostly a special case for TV where some displays don’t have the entire display usable.
391 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
392 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700393 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700394
395 // The display frame minus the stable insets. This value is always constant regardless of if
396 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700397 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800398
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700399 // The area not occupied by the status and navigation bars. So, if both status and navigation
400 // bars are visible, the decor frame is equal to the stable frame.
401 final Rect mDecorFrame = new Rect();
402
403 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
404 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700405 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700406
407 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
408 // displays hint text.
409 final Rect mVisibleFrame = new Rect();
410
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700411 // Frame that includes dead area outside of the surface but where we want to pretend that it's
412 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700413 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700414
Jorim Jaggidc249c42015-12-15 14:57:31 -0800415 /**
416 * Usually empty. Set to the task's tempInsetFrame. See
417 *{@link android.app.IActivityManager#resizeDockedStack}.
418 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700419 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800420
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800421 boolean mContentChanged;
422
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800423 // If a window showing a wallpaper: the requested offset for the
424 // wallpaper; if a wallpaper window: the currently applied offset.
425 float mWallpaperX = -1;
426 float mWallpaperY = -1;
427
428 // If a window showing a wallpaper: what fraction of the offset
429 // range corresponds to a full virtual screen.
430 float mWallpaperXStep = -1;
431 float mWallpaperYStep = -1;
432
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700433 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
434 // to its window; if a wallpaper window: not used.
435 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
436 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
437
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800438 // Wallpaper windows: pixels offset based on above variables.
439 int mXOffset;
440 int mYOffset;
441
Craig Mautner2268e7e2012-12-13 15:40:00 -0800442 /**
443 * This is set after IWindowSession.relayout() has been called at
444 * least once for the window. It allows us to detect the situation
445 * where we don't yet have a surface, but should have one soon, so
446 * we can give the window focus before waiting for the relayout.
447 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800448 boolean mRelayoutCalled;
449
Robert Carrfed10072016-05-26 11:48:49 -0700450 boolean mInRelayout;
451
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800452 /**
453 * If the application has called relayout() with changes that can
454 * impact its window's size, we need to perform a layout pass on it
455 * even if it is not currently visible for layout. This is set
456 * when in that case until the layout is done.
457 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800458 boolean mLayoutNeeded;
459
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800460 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800461 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800462
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800463 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464 boolean mDestroying;
465
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800466 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800467 boolean mRemoveOnExit;
468
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800469 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800470 * Whether the app died while it was visible, if true we might need
471 * to continue to show it until it's restarted.
472 */
473 boolean mAppDied;
474
475 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800476 * Set when the orientation is changing and this window has not yet
477 * been updated for the new orientation.
478 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700479 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800480
Dianne Hackborna57c6952013-03-29 14:46:40 -0700481 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700482 * Sometimes in addition to the mOrientationChanging
483 * flag we report that the orientation is changing
484 * due to a mismatch in current and reported configuration.
485 *
486 * In the case of timeout we still need to make sure we
487 * leave the orientation changing state though, so we
488 * use this as a special time out escape hatch.
489 */
490 private boolean mOrientationChangeTimedOut;
491
492 /**
Robert Carr237028a2016-07-26 10:39:45 -0700493 * The orientation during the last visible call to relayout. If our
494 * current orientation is different, the window can't be ready
495 * to be shown.
496 */
497 int mLastVisibleLayoutRotation = -1;
498
499 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800500 * Set when we need to report the orientation change to client to trigger a relayout.
501 */
502 boolean mReportOrientationChanged;
503
504 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700505 * How long we last kept the screen frozen.
506 */
507 int mLastFreezeDuration;
508
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800509 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800510 boolean mRemoved;
511
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800512 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800513 * It is save to remove the window and destroy the surface because the client requested removal
514 * or some other higher level component said so (e.g. activity manager).
515 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800516 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700517 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800518
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700520 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800521 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700522 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800523
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800524 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700525 private String mStringNameCache;
526 private CharSequence mLastTitle;
527 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800528
Craig Mautnera2c77052012-03-26 12:14:43 -0700529 final WindowStateAnimator mWinAnimator;
530
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700531 boolean mHasSurface = false;
532
Craig Mautner88400d32012-09-30 12:35:45 -0700533 /** When true this window can be displayed on screens owther than mOwnerUid's */
534 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700535
Chong Zhang92147042016-05-09 12:47:11 -0700536 // Whether the window was visible when we set the app to invisible last time. WM uses
537 // this as a hint to restore the surface (if available) for early animation next time
538 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700539 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800540
Robert Carra1eb4392015-12-10 12:43:51 -0800541 // This window will be replaced due to relaunch. This allows window manager
542 // to differentiate between simple removal of a window and replacement. In the latter case it
543 // will preserve the old window until the new one is drawn.
544 boolean mWillReplaceWindow = false;
545 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700546 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800547 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700548 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800549 // If not null, the window that will be used to replace the old one. This is being set when
550 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700551 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700552 // For the new window in the replacement transition, if we have
553 // requested to replace without animation, then we should
554 // make sure we also don't apply an enter animation for
555 // the new window.
556 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800557 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700558 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800559
Jeff Brownc2932a12014-11-20 18:04:05 -0800560 /**
561 * Wake lock for drawing.
562 * Even though it's slightly more expensive to do so, we will use a separate wake lock
563 * for each app that is requesting to draw while dozing so that we can accurately track
564 * who is preventing the system from suspending.
565 * This lock is only acquired on first use.
566 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700567 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800568
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700569 final private Rect mTmpRect = new Rect();
570
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800571 /**
572 * Whether the window was resized by us while it was gone for layout.
573 */
574 boolean mResizedWhileGone = false;
575
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700576 /** @see #isResizedWhileNotDragResizing(). */
577 private boolean mResizedWhileNotDragResizing;
578
579 /** @see #isResizedWhileNotDragResizingReported(). */
580 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700581
Robert Carr6da3cc02016-06-16 15:17:07 -0700582 /**
583 * During seamless rotation we have two phases, first the old window contents
584 * are rotated to look as if they didn't move in the new coordinate system. Then we
585 * have to freeze updates to this layer (to preserve the transformation) until
586 * the resize actually occurs. This is true from when the transformation is set
587 * and false until the transaction to resize is sent.
588 */
589 boolean mSeamlesslyRotated = false;
590
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700591 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800592 * Surface insets from the previous call to relayout(), used to track
593 * if we are changing the Surface insets.
594 */
595 final Rect mLastSurfaceInsets = new Rect();
596
597 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700598 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
599 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
600 * make sure all children have been considered.
601 */
602 private boolean mDrawnStateEvaluated;
603
Jorim Jaggia5e10572017-11-15 14:36:26 +0100604 private final Point mSurfacePosition = new Point();
605
Bryce Leed390deb2017-06-22 13:14:28 -0700606 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700607 * 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 -0700608 * of z-order and 1 otherwise.
609 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800610 private static final Comparator<WindowState> sWindowSubLayerComparator =
611 new Comparator<WindowState>() {
612 @Override
613 public int compare(WindowState w1, WindowState w2) {
614 final int layer1 = w1.mSubLayer;
615 final int layer2 = w2.mSubLayer;
616 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
617 // We insert the child window into the list ordered by
618 // the sub-layer. For same sub-layers, the negative one
619 // should go below others; the positive one should go
620 // above others.
621 return -1;
622 }
623 return 1;
624 };
625 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700626
Robert Carrf59b8dd2017-10-02 18:58:36 -0700627 /**
628 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
629 * container.
630 */
631 private boolean mIsDimming = false;
632
633 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
634
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800635 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700636 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800637 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100638 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800639 mSession = s;
640 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800641 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700643 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700644 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800645 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200646 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800647 mAttrs.copyFrom(a);
648 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700649 mPolicy = mService.mPolicy;
650 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700652 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700653 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700654 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700655 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700656 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800657 try {
658 c.asBinder().linkToDeath(deathRecipient, 0);
659 } catch (RemoteException e) {
660 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700661 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800662 mLayoutAttached = false;
663 mIsImWindow = false;
664 mIsWallpaper = false;
665 mIsFloatingLayer = false;
666 mBaseLayer = 0;
667 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700668 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700669 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800670 return;
671 }
672 mDeathRecipient = deathRecipient;
673
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700674 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800675 // The multiplier here is to reserve space for multiple
676 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800677 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700678 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800679 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700680 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900681
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700682 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
683 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900684
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800685 mLayoutAttached = mAttrs.type !=
686 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700687 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
688 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
689 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800690 } else {
691 // The multiplier here is to reserve space for multiple
692 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800693 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700694 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800695 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700696 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800697 mLayoutAttached = false;
698 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
699 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
700 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800701 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700702 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800703
Wale Ogunwale72919d22016-12-08 18:58:50 -0800704 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700705 // Windows for apps that can show for all users should also show when the device is
706 // locked.
707 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700708 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800709
Craig Mautner322e4032012-07-13 13:35:20 -0700710 mWinAnimator = new WindowStateAnimator(this);
711 mWinAnimator.mAlpha = a.alpha;
712
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800713 mRequestedWidth = 0;
714 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700715 mLastRequestedWidth = 0;
716 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800717 mXOffset = 0;
718 mYOffset = 0;
719 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800720 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800721 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
722 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800723 }
724
725 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700726 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800727 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800728 }
729
Bryce Leed390deb2017-06-22 13:14:28 -0700730 /**
731 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
732 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700733 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700734 return mDrawnStateEvaluated;
735 }
736
737 /**
738 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
739 * be cleared when detached from parent.
740 */
741 void setDrawnStateEvaluated(boolean evaluated) {
742 mDrawnStateEvaluated = evaluated;
743 }
744
745 @Override
746 void onParentSet() {
747 super.onParentSet();
748 setDrawnStateEvaluated(false /*evaluated*/);
749 }
750
Craig Mautnera2c77052012-03-26 12:14:43 -0700751 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800752 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800753 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800754 }
755
756 @Override
757 public String getOwningPackage() {
758 return mAttrs.packageName;
759 }
760
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800761 @Override
762 public boolean canAddInternalSystemWindow() {
763 return mOwnerCanAddInternalSystemWindow;
764 }
765
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200766 @Override
767 public boolean canAcquireSleepToken() {
768 return mSession.mCanAcquireSleepToken;
769 }
770
Jorim Jaggif5834272016-04-04 20:25:41 -0700771 /**
772 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
773 * from {@param frame}. In other words, it applies the insets that would result if
774 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700775 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
776 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700777 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700778 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
779 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
780 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
781 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
782 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700783 frame.inset(left, top, right, bottom);
784 }
785
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800786 @Override
Robert Carr43521762016-10-28 13:15:04 -0700787 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
788 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100789 Rect outsetFrame, DisplayCutout displayCutout) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800790 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700791 // This window is being replaced and either already got information that it's being
792 // removed or we are still waiting for some information. Because of this we don't
793 // want to apply any more changes to it, so it remains in this state until new window
794 // appears.
795 return;
796 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800797 mHaveFrame = true;
798
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700799 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700800 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800801 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700802 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800803
Chong Zhangae35fef2016-03-16 15:56:55 -0700804 // If the task has temp inset bounds set, we have to make sure all its windows uses
805 // the temp inset frame. Otherwise different display frames get applied to the main
806 // window and the child window, making them misaligned.
Andrii Kulianc24f3732017-08-08 19:35:17 -0700807 if (inFullscreenContainer || isLetterboxedAppWindow()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700808 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700809 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700810 task.getTempInsetBounds(mInsetFrame);
811 }
812
Jorim Jaggif5834272016-04-04 20:25:41 -0700813 // Denotes the actual frame used to calculate the insets and to perform the layout. When
814 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
815 // insets temporarily. By the notion of a task having a different layout frame, we can
816 // achieve that while still moving the task around.
817 final Rect layoutContainingFrame;
818 final Rect layoutDisplayFrame;
819
820 // The offset from the layout containing frame to the actual containing frame.
821 final int layoutXDiff;
822 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700823 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800824 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700825 mContainingFrame.set(parentFrame);
826 mDisplayFrame.set(displayFrame);
827 layoutDisplayFrame = displayFrame;
828 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700829 layoutXDiff = 0;
830 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800831 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800832 getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100833 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
834
835 // If the bounds are frozen, we still want to translate the window freely and only
836 // freeze the size.
837 Rect frozen = mAppToken.mFrozenBounds.peek();
838 mContainingFrame.right = mContainingFrame.left + frozen.width();
839 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
840 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800841 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700842 // IME is up and obscuring this window. Adjust the window position so it is visible.
843 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700844 if (inFreeformWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700845 && mContainingFrame.bottom > contentFrame.bottom) {
846 // In freeform we want to move the top up directly.
847 // TODO: Investigate why this is contentFrame not parentFrame.
848 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700849 } else if (!inPinnedWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700850 && mContainingFrame.bottom > parentFrame.bottom) {
851 // But in docked we want to behave like fullscreen and behave as if the task
852 // were given smaller bounds for the purposes of layout. Skip adjustments for
853 // the pinned stack, they are handled separately in the PinnedStackController.
854 mContainingFrame.bottom = parentFrame.bottom;
855 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700856 }
Skuhne81c524a2015-08-12 13:34:14 -0700857
Robert Carre6275582016-02-29 15:45:45 -0800858 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700859 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
860 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800861 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700862 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700863 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700864 }
Doris Liu06d582d2015-06-01 13:18:43 -0700865 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800866 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700867 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
868 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
869 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700870 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700871 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700872 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700873 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
874 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700875 }
Robert Carr43521762016-10-28 13:15:04 -0700876 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700877 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700878 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800879
Craig Mautner967212c2013-04-13 21:10:58 -0700880 final int pw = mContainingFrame.width();
881 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800882
Robert Carr43521762016-10-28 13:15:04 -0700883 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800884 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700885 // + " to " + parentFrame);
886 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800887 mContentChanged = true;
888 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700889 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
890 mLastRequestedWidth = mRequestedWidth;
891 mLastRequestedHeight = mRequestedHeight;
892 mContentChanged = true;
893 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800894
Robert Carr43521762016-10-28 13:15:04 -0700895 mOverscanFrame.set(overscanFrame);
896 mContentFrame.set(contentFrame);
897 mVisibleFrame.set(visibleFrame);
898 mDecorFrame.set(decorFrame);
899 mStableFrame.set(stableFrame);
900 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700901 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700902 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700903 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800904
Craig Mautnereda67292013-04-28 13:50:14 -0700905 final int fw = mFrame.width();
906 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800907
Jorim Jaggif5834272016-04-04 20:25:41 -0700908 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
909
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700910 // Calculate the outsets before the content frame gets shrinked to the window frame.
911 if (hasOutsets) {
912 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
913 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
914 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
915 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
916 } else {
917 mOutsets.set(0, 0, 0, 0);
918 }
919
Craig Mautnera248eee2013-05-07 11:41:27 -0700920 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800921 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800922 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800923 // For pinned workspace the frame isn't limited in any particular
924 // way since SystemUI controls the bounds. For freeform however
925 // we want to keep things inside the content frame.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700926 final Rect limitFrame = task.inPinnedWindowingMode() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700927 // Keep the frame out of the blocked system area, limit it in size to the content area
928 // and make sure that there is always a minimum visible so that the user can drag it
929 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800930 final int height = Math.min(mFrame.height(), limitFrame.height());
931 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700932 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900933 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
934 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
935 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
936 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800937 final int top = Math.max(limitFrame.top,
938 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
939 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
940 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700941 mFrame.set(left, top, left + width, top + height);
942 mContentFrame.set(mFrame);
943 mVisibleFrame.set(mContentFrame);
944 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700945 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700946 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100947 mContentFrame.set(mFrame);
948 if (!mFrame.equals(mLastFrame)) {
949 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800950 }
Skuhne81c524a2015-08-12 13:34:14 -0700951 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700952 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
953 Math.max(mContentFrame.top, mFrame.top),
954 Math.min(mContentFrame.right, mFrame.right),
955 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800956
Jorim Jaggi656f6502016-04-11 21:08:17 -0700957 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
958 Math.max(mVisibleFrame.top, mFrame.top),
959 Math.min(mVisibleFrame.right, mFrame.right),
960 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800961
Jorim Jaggi656f6502016-04-11 21:08:17 -0700962 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
963 Math.max(mStableFrame.top, mFrame.top),
964 Math.min(mStableFrame.right, mFrame.right),
965 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700966 }
Adrian Roosfa104232014-06-20 16:10:14 -0700967
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700968 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500969 // Windows that are not fullscreen can be positioned outside of the display frame,
970 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700971 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
972 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
973 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
974 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800975 }
Craig Mautnereda67292013-04-28 13:50:14 -0700976
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100977 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100978 // For the docked divider, we calculate the stable insets like a full-screen window
979 // so it can use it to calculate the snap positions.
980 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
981 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
982 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
983 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800984
985 // The divider doesn't care about insets in any case, so set it to empty so we don't
986 // trigger a relayout when moving it.
987 mContentInsets.setEmpty();
988 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100989 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800990 getDisplayContent().getBounds(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700991 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
992 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700993 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
994 && mFrame.right > mTmpRect.right;
995 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
996 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700997 mContentInsets.set(mContentFrame.left - mFrame.left,
998 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700999 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001000 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001001 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001002 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001003
Jorim Jaggi656f6502016-04-11 21:08:17 -07001004 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
1005 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001006 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001007 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001008 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001009 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001010
Jorim Jaggi656f6502016-04-11 21:08:17 -07001011 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
1012 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001013 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001014 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001015 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001016 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001017 }
Adrian Roosfa104232014-06-20 16:10:14 -07001018
Jorim Jaggi656f6502016-04-11 21:08:17 -07001019 // Offset the actual frame by the amount layout frame is off.
1020 mFrame.offset(-layoutXDiff, -layoutYDiff);
1021 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001022 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
1023 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
1024 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1025
Adrian Roos5c6b6222017-11-07 17:36:10 +01001026 // TODO(roosa): Figure out what frame exactly this needs to be calculated with.
1027 mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
1028
1029
Craig Mautnereda67292013-04-28 13:50:14 -07001030 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001031 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001032 // If there is a size compatibility scale being applied to the
1033 // window, we need to apply this to its insets so that they are
1034 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001035 mOverscanInsets.scale(mInvGlobalScale);
1036 mContentInsets.scale(mInvGlobalScale);
1037 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001038 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001039 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001040
1041 // Also the scaled frame that we report to the app needs to be
1042 // adjusted to be in its coordinate space.
1043 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001044 }
1045
Craig Mautnereda67292013-04-28 13:50:14 -07001046 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001047 final DisplayContent displayContent = getDisplayContent();
1048 if (displayContent != null) {
1049 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001050 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001051 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001052 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001053 }
1054
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001055 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001056 "Resolving (mRequestedWidth="
1057 + mRequestedWidth + ", mRequestedheight="
1058 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1059 + "): frame=" + mFrame.toShortString()
1060 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001061 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001062 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001063 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001064 }
1065
Bryce Leef3c6a472017-11-14 14:53:06 -08001066 // TODO: Look into whether this override is still necessary.
1067 @Override
1068 public Rect getBounds() {
1069 if (isInMultiWindowMode()) {
1070 return getTask().getBounds();
1071 } else if (mAppToken != null){
1072 return mAppToken.getBounds();
1073 } else {
1074 return super.getBounds();
1075 }
1076 }
1077
Craig Mautnera2c77052012-03-26 12:14:43 -07001078 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001079 public Rect getFrameLw() {
1080 return mFrame;
1081 }
1082
Craig Mautnera2c77052012-03-26 12:14:43 -07001083 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001084 public Point getShownPositionLw() {
1085 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001086 }
1087
Craig Mautnera2c77052012-03-26 12:14:43 -07001088 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001089 public Rect getDisplayFrameLw() {
1090 return mDisplayFrame;
1091 }
1092
Craig Mautnera2c77052012-03-26 12:14:43 -07001093 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001094 public Rect getOverscanFrameLw() {
1095 return mOverscanFrame;
1096 }
1097
1098 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001099 public Rect getContentFrameLw() {
1100 return mContentFrame;
1101 }
1102
Craig Mautnera2c77052012-03-26 12:14:43 -07001103 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001104 public Rect getVisibleFrameLw() {
1105 return mVisibleFrame;
1106 }
1107
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001108 Rect getStableFrameLw() {
1109 return mStableFrame;
1110 }
1111
Craig Mautnera2c77052012-03-26 12:14:43 -07001112 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001113 public boolean getGivenInsetsPendingLw() {
1114 return mGivenInsetsPending;
1115 }
1116
Craig Mautnera2c77052012-03-26 12:14:43 -07001117 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001118 public Rect getGivenContentInsetsLw() {
1119 return mGivenContentInsets;
1120 }
1121
Craig Mautnera2c77052012-03-26 12:14:43 -07001122 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001123 public Rect getGivenVisibleInsetsLw() {
1124 return mGivenVisibleInsets;
1125 }
1126
Craig Mautnera2c77052012-03-26 12:14:43 -07001127 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001128 public WindowManager.LayoutParams getAttrs() {
1129 return mAttrs;
1130 }
1131
Craig Mautner812d2ca2012-09-27 15:35:34 -07001132 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001133 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001134 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001135 }
1136
Craig Mautner19d59bc2012-09-04 11:15:56 -07001137 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001138 public int getSystemUiVisibility() {
1139 return mSystemUiVisibility;
1140 }
1141
Craig Mautner19d59bc2012-09-04 11:15:56 -07001142 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001143 public int getSurfaceLayer() {
1144 return mLayer;
1145 }
1146
Craig Mautner812d2ca2012-09-27 15:35:34 -07001147 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001148 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001149 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001150 }
1151
1152 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001153 public IApplicationToken getAppToken() {
1154 return mAppToken != null ? mAppToken.appToken : null;
1155 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001156
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001157 @Override
1158 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001159 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001160 }
1161
Robert Carr31aa98b2016-07-20 15:29:03 -07001162 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001163 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1164 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1165 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001166 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001167 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001168 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1169 (mLastFrame.height() != mFrame.height());
Adrian Roos5c6b6222017-11-07 17:36:10 +01001170 mDisplayCutoutChanged |= !mLastDisplayCutout.equals(mDisplayCutout);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001171 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001172 || mOutsetsChanged || mFrameSizeChanged || mDisplayCutoutChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001173 }
1174
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001175 /**
1176 * Adds the window to the resizing list if any of the parameters we use to track the window
1177 * dimensions or insets have changed.
1178 */
1179 void updateResizingWindowIfNeeded() {
1180 final WindowStateAnimator winAnimator = mWinAnimator;
1181 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1182 return;
1183 }
1184
1185 final Task task = getTask();
1186 // In the case of stack bound animations, the window frames will update (unlike other
1187 // animations which just modify various transformation properties). We don't want to
1188 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1189 // the frame may not correspond to the surface size or the onscreen area at various
1190 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001191 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001192 return;
1193 }
1194
1195 setReportResizeHints();
1196 boolean configChanged = isConfigChanged();
1197 if (DEBUG_CONFIGURATION && configChanged) {
1198 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1199 }
1200
1201 final boolean dragResizingChanged = isDragResizeChanged()
1202 && !isDragResizingChangeReported();
1203
1204 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1205 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1206 + " frame=" + mFrame);
1207
1208 // We update mLastFrame always rather than in the conditional with the last inset
1209 // variables, because mFrameSizeChanged only tracks the width and height changing.
1210 mLastFrame.set(mFrame);
1211
1212 if (mContentInsetsChanged
1213 || mVisibleInsetsChanged
1214 || winAnimator.mSurfaceResized
1215 || mOutsetsChanged
1216 || mFrameSizeChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001217 || mDisplayCutoutChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001218 || configChanged
1219 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001220 || !isResizedWhileNotDragResizingReported()
1221 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001222 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1223 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1224 + " contentInsetsChanged=" + mContentInsetsChanged
1225 + " " + mContentInsets.toShortString()
1226 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1227 + " " + mVisibleInsets.toShortString()
1228 + " stableInsetsChanged=" + mStableInsetsChanged
1229 + " " + mStableInsets.toShortString()
1230 + " outsetsChanged=" + mOutsetsChanged
1231 + " " + mOutsets.toShortString()
1232 + " surfaceResized=" + winAnimator.mSurfaceResized
1233 + " configChanged=" + configChanged
1234 + " dragResizingChanged=" + dragResizingChanged
1235 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001236 + isResizedWhileNotDragResizingReported()
Adrian Roos5c6b6222017-11-07 17:36:10 +01001237 + " reportOrientationChanged=" + mReportOrientationChanged
1238 + " displayCutoutChanged=" + mDisplayCutoutChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001239 }
1240
1241 // If it's a dead window left on screen, and the configuration changed, there is nothing
1242 // we can do about it. Remove the window now.
1243 if (mAppToken != null && mAppDied) {
1244 mAppToken.removeDeadWindows();
1245 return;
1246 }
1247
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001248 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001249 mService.makeWindowFreezingScreenIfNeededLocked(this);
1250
1251 // If the orientation is changing, or we're starting or ending a drag resizing action,
1252 // then we need to hold off on unfreezing the display until this window has been
1253 // redrawn; to do that, we need to go through the process of getting informed by the
1254 // application when it has finished drawing.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001255 if (getOrientationChanging() || dragResizingChanged
1256 || isResizedWhileNotDragResizing()) {
Robert Carre13b58e2017-08-31 14:50:44 -07001257 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001258 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1259 + ", mDrawState=DRAW_PENDING in " + this
1260 + ", surfaceController " + winAnimator.mSurfaceController);
1261 }
1262 winAnimator.mDrawState = DRAW_PENDING;
1263 if (mAppToken != null) {
1264 mAppToken.clearAllDrawn();
1265 }
1266 }
1267 if (!mService.mResizingWindows.contains(this)) {
1268 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1269 mService.mResizingWindows.add(this);
1270 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001271 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001272 if (isDrawnLw()) {
1273 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1274 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001275 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001276 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1277 - mService.mDisplayFreezeTime);
1278 }
1279 }
1280 }
1281
Bryce Lee8c3cf382017-07-06 19:47:10 -07001282 boolean getOrientationChanging() {
1283 // In addition to the local state flag, we must also consider the difference in the last
1284 // reported configuration vs. the current state. If the client code has not been informed of
1285 // the change, logic dependent on having finished processing the orientation, such as
1286 // unfreezing, could be improperly triggered.
1287 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1288 // this is not necessarily what the client has processed yet. Find a
1289 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001290 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001291 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001292 && !mSeamlesslyRotated
1293 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001294 }
1295
1296 void setOrientationChanging(boolean changing) {
1297 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001298 mOrientationChangeTimedOut = false;
1299 }
1300
1301 void orientationChangeTimedOut() {
1302 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001303 }
1304
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001305 DisplayContent getDisplayContent() {
1306 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001307 }
1308
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001309 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001310 final DisplayContent displayContent = getDisplayContent();
1311 return displayContent != null ? displayContent.getDisplayInfo() : null;
1312 }
1313
Jorim Jaggife762342016-10-13 14:33:27 +02001314 @Override
1315 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001316 final DisplayContent displayContent = getDisplayContent();
1317 if (displayContent == null) {
1318 return -1;
1319 }
1320 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001321 }
1322
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001323 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001324 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001325 }
1326
1327 TaskStack getStack() {
1328 Task task = getTask();
1329 if (task != null) {
1330 if (task.mStack != null) {
1331 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001332 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001333 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001334 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1335 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001336 final DisplayContent dc = getDisplayContent();
1337 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001338 }
1339
Skuhnef932e562015-08-20 12:07:30 -07001340 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001341 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001342 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001343 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001344 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001345 final Task task = getTask();
1346 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001347 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001348 mTmpRect.setEmpty();
1349 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001350 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001351 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001352 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001353 } else {
1354 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001355 }
1356 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001357
Chong Zhang9184ec62015-09-24 12:32:21 -07001358 bounds.set(mVisibleFrame);
1359 if (intersectWithStackBounds) {
1360 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001361 }
1362
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001363 if (bounds.isEmpty()) {
1364 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001365 if (intersectWithStackBounds) {
1366 bounds.intersect(mTmpRect);
1367 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001368 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001369 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001370 }
1371
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001372 public long getInputDispatchingTimeoutNanos() {
1373 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001374 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001375 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1376 }
1377
Craig Mautnere8552142012-11-07 13:55:47 -08001378 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001379 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001380 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001381 }
1382
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001383 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1384 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1385 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1386 if (dtdx < -.000001f || dtdx > .000001f) return false;
1387 if (dsdy < -.000001f || dsdy > .000001f) return false;
1388 return true;
1389 }
1390
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001391 void prelayout() {
1392 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001393 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1394 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001395 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001396 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001397 }
1398 }
1399
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001400 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001401 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001402 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001403 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1404 return true;
1405 }
1406
Wale Ogunwale44f21802016-09-02 12:49:48 -07001407 return super.hasContentToDisplay();
1408 }
1409
1410 @Override
1411 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001412 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001413 }
1414
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001415 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001416 * @return True if the window would be visible if we'd ignore policy visibility, false
1417 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001418 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001419 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001420 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001421 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001422 }
1423
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001424 @Override
1425 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001426 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001427 }
1428
1429 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001430 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1431 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001432 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001433 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1434 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001435 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001436 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001437 }
1438
1439 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001440 * The same as isVisible(), but follows the current hidden state of the associated app token,
1441 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001442 */
1443 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001444 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001445 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001446 }
1447
1448 /**
1449 * Can this window possibly be a drag/drop target? The test here is
1450 * a combination of the above "visible now" with the check that the
1451 * Input Manager uses when discarding windows from input consideration.
1452 */
1453 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001454 return isVisibleNow() && !mRemoved
1455 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001456 }
1457
1458 /**
1459 * Same as isVisible(), but we also count it as visible between the
1460 * call to IWindowSession.add() and the first relayout().
1461 */
1462 boolean isVisibleOrAdding() {
1463 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001464 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001465 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001466 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001467 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001468 }
1469
1470 /**
1471 * Is this window currently on-screen? It is on-screen either if it
1472 * is visible or it is currently running an animation before no longer
1473 * being visible.
1474 */
1475 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001476 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001477 return false;
1478 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001479 final AppWindowToken atoken = mAppToken;
1480 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001481 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggia5e10572017-11-15 14:36:26 +01001482 || mWinAnimator.isAnimationSet() || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001483 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001484 return !isParentWindowHidden() || mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001485 }
1486
1487 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001488 * Whether this window's drawn state might affect the drawn states of the app token.
1489 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001490 * @return true if the window should be considered while evaluating allDrawn flags.
1491 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001492 boolean mightAffectAllDrawn() {
1493 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1494 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1495 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001496 }
1497
1498 /**
1499 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1500 * it must be drawn before allDrawn can become true.
1501 */
1502 boolean isInteresting() {
1503 return mAppToken != null && !mAppDied
1504 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1505 }
1506
1507 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001508 * Like isOnScreen(), but we don't return true if the window is part
1509 * of a transition that has not yet been started.
1510 */
1511 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001512 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001513 return false;
1514 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001515 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001516 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Jorim Jaggia5e10572017-11-15 14:36:26 +01001517 || mWinAnimator.isAnimationSet()
Craig Mautner59431632012-04-04 11:56:44 -07001518 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001519 }
1520
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001521 // TODO: Another visibility method that was added late in the release to minimize risk.
1522 @Override
1523 public boolean canAffectSystemUiFlags() {
Jorim Jaggib7202a82017-09-11 16:58:53 +02001524 final boolean shown = mWinAnimator.getShown();
Jorim Jaggic0c93242017-08-04 16:05:02 +02001525
1526 // We only consider the app to be exiting when the animation has started. After the app
1527 // transition is executed the windows are marked exiting before the new windows have been
1528 // shown. Thus, wait considering a window to be exiting after the animation has actually
1529 // started.
1530 final boolean appAnimationStarting = mAppToken != null
1531 && mAppToken.mAppAnimator.isAnimationStarting();
Jorim Jaggia5e10572017-11-15 14:36:26 +01001532 final boolean exitingSelf = mAnimatingExit && !appAnimationStarting;
Jorim Jaggic0c93242017-08-04 16:05:02 +02001533 final boolean appExiting = mAppToken != null && mAppToken.hidden && !appAnimationStarting;
1534
1535 final boolean exiting = exitingSelf || mDestroying || appExiting;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001536 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggib7202a82017-09-11 16:58:53 +02001537
1538 // If we are entering with a dummy animation, avoid affecting SystemUI flags until the
1539 // transition is starting.
1540 final boolean enteringWithDummyAnimation =
1541 mWinAnimator.isDummyAnimation() && mWinAnimator.mShownAlpha == 0f;
1542 return shown && !exiting && !translucent && !enteringWithDummyAnimation;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001543 }
1544
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001545 /**
1546 * Like isOnScreen, but returns false if the surface hasn't yet
1547 * been drawn.
1548 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001549 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001550 public boolean isDisplayedLw() {
1551 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001552 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001553 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001554 (atoken == null || !atoken.hiddenRequested))
Jorim Jaggia5e10572017-11-15 14:36:26 +01001555 || mWinAnimator.isAnimationSet()
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001556 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001557 }
1558
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001559 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001560 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001561 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001562 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001563 public boolean isAnimatingLw() {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001564 return mWinAnimator.isAnimationSet()
Craig Mautnerae446592012-12-06 19:05:05 -08001565 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001566 }
1567
Craig Mautner812d2ca2012-09-27 15:35:34 -07001568 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001569 public boolean isGoneForLayoutLw() {
1570 final AppWindowToken atoken = mAppToken;
1571 return mViewVisibility == View.GONE
1572 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001573 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001574 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001575 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001576 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001577 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001578 }
1579
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001580 /**
1581 * Returns true if the window has a surface that it has drawn a
1582 * complete UI in to.
1583 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001584 public boolean isDrawFinishedLw() {
1585 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001586 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1587 || mWinAnimator.mDrawState == READY_TO_SHOW
1588 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001589 }
1590
1591 /**
1592 * Returns true if the window has a surface that it has drawn a
1593 * complete UI in to.
1594 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001595 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001596 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001597 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001598 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001599 }
1600
1601 /**
1602 * Return true if the window is opaque and fully drawn. This indicates
1603 * it may obscure windows behind it.
1604 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001605 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001606 // When there is keyguard, wallpaper could be placed over the secure app
1607 // window but invisible. We need to check wallpaper visibility explicitly
1608 // to determine if it's occluding apps.
1609 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1610 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggia5e10572017-11-15 14:36:26 +01001611 && isDrawnLw() && !mWinAnimator.isAnimationSet()
Craig Mautner59431632012-04-04 11:56:44 -07001612 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001613 }
1614
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001615 @Override
1616 void onMovedByResize() {
1617 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001618 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001619 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001620 }
1621
1622 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1623 boolean changed = false;
1624
1625 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001626 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001627 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1628 }
1629
1630 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1631 // Starting window that's exiting will be removed when the animation finishes.
1632 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1633 // to actually remove it.
1634 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1635 mAnimatingExit = true;
1636 mRemoveOnExit = true;
1637 mWindowRemovalAllowed = true;
1638 }
1639 return changed;
1640 }
1641
Robert Carrd5c7dd62017-03-08 10:39:30 -08001642 // Next up we will notify the client that it's visibility has changed.
1643 // We need to prevent it from destroying child surfaces until
1644 // the animation has finished.
1645 if (!visible && isVisibleNow()) {
1646 mWinAnimator.detachChildren();
1647 }
1648
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001649 if (visible != isVisibleNow()) {
1650 if (!runningAppAnimation) {
1651 final AccessibilityController accessibilityController =
1652 mService.mAccessibilityController;
1653 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1654 mWinAnimator.applyAnimationLocked(winTransit, visible);
1655 //TODO (multidisplay): Magnification is supported only for the default
1656 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1657 accessibilityController.onWindowTransitionLocked(this, winTransit);
1658 }
1659 }
1660 changed = true;
1661 setDisplayLayoutNeeded();
1662 }
1663
1664 return changed;
1665 }
1666
1667 boolean onSetAppExiting() {
1668 final DisplayContent displayContent = getDisplayContent();
1669 boolean changed = false;
1670
1671 if (isVisibleNow()) {
1672 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1673 //TODO (multidisplay): Magnification is supported only for the default
1674 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1675 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1676 }
1677 changed = true;
1678 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001679 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001680 }
1681 }
1682
1683 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001684 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001685 changed |= c.onSetAppExiting();
1686 }
1687
1688 return changed;
1689 }
1690
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001691 @Override
1692 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001693 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1694 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001695 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001696 resizingWindows.add(this);
1697
1698 // If we are not drag resizing, force recreating of a new surface so updating
1699 // the content and positioning that surface will be in sync.
1700 //
1701 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1702 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1703 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1704 // their frame to update crop, etc...
1705 //
1706 // Anyway we don't need to synchronize position and content updates for these
1707 // windows since they aren't at the base layer and could be moved around anyway.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001708 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION
1709 && !mWinAnimator.isForceScaled() && !isGoneForLayoutLw()
1710 && !getTask().inPinnedWindowingMode()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001711 setResizedWhileNotDragResizing(true);
1712 }
1713 }
1714 if (isGoneForLayoutLw()) {
1715 mResizedWhileGone = true;
1716 }
1717
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001718 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001719 }
1720
1721 void onUnfreezeBounds() {
1722 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001723 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001724 c.onUnfreezeBounds();
1725 }
1726
1727 if (!mHasSurface) {
1728 return;
1729 }
1730
1731 mLayoutNeeded = true;
1732 setDisplayLayoutNeeded();
1733 if (!mService.mResizingWindows.contains(this)) {
1734 mService.mResizingWindows.add(this);
1735 }
1736 }
1737
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001738 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001739 * If the window has moved due to its containing content frame changing, then notify the
1740 * listeners and optionally animate it. Simply checking a change of position is not enough,
1741 * because being move due to dock divider is not a trigger for animation.
1742 */
Jorim Jaggia5e10572017-11-15 14:36:26 +01001743 void handleWindowMovedIfNeeded(Transaction t) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001744 if (!hasMoved()) {
1745 return;
1746 }
1747
1748 // Frame has moved, containing content frame has also moved, and we're not currently
1749 // animating... let's do something.
1750 final int left = mFrame.left;
1751 final int top = mFrame.top;
1752 final Task task = getTask();
1753 final boolean adjustedForMinimizedDockOrIme = task != null
1754 && (task.mStack.isAdjustedForMinimizedDockedStack()
1755 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001756 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001757 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1758 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001759 && getWindowConfiguration().hasMovementAnimations()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001760 && !mWinAnimator.mLastHidden) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001761 startMoveAnimation(t, left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001762 }
1763
1764 //TODO (multidisplay): Accessibility supported only for the default display.
1765 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001766 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001767 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1768 }
1769
1770 try {
1771 mClient.moved(left, top);
1772 } catch (RemoteException e) {
1773 }
1774 mMovedByResize = false;
1775 }
1776
1777 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001778 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001779 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1780 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001781 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001782 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001783 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001784 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001785 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001786 }
1787
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001788 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001789 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001790 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001791 return false;
1792 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001793 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001794 }
1795
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001796 boolean fillsDisplay() {
1797 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001798 return mFrame.left <= 0 && mFrame.top <= 0
1799 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001800 }
1801
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001802 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001803 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001804 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001805 }
1806
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001807 void onWindowReplacementTimeout() {
1808 if (mWillReplaceWindow) {
1809 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001810 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001811 // delays removal on certain conditions, which will leave the stale window in the
1812 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1813 //
1814 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001815 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001816 } else {
1817 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001818 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001819 c.onWindowReplacementTimeout();
1820 }
1821 }
1822 }
1823
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001824 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001825 void forceWindowsScaleableInTransaction(boolean force) {
1826 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1827 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1828 }
1829
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001830 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001831 }
1832
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001833 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001834 void removeImmediately() {
1835 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001836
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001837 if (mRemoved) {
1838 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001839 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1840 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001841 return;
1842 }
1843
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001844 mRemoved = true;
1845
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001846 mWillReplaceWindow = false;
1847 if (mReplacementWindow != null) {
1848 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1849 }
1850
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001851 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001852 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001853 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001854 }
1855
1856 final int type = mAttrs.type;
1857 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001858 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001859 }
1860 mPolicy.removeWindowLw(this);
1861
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001862 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001863
Craig Mautner96868332012-12-04 14:29:11 -08001864 mWinAnimator.destroyDeferredSurfaceLocked();
1865 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001866 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001867 try {
1868 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1869 } catch (RuntimeException e) {
1870 // Ignore if it has already been removed (usually because
1871 // we are doing this as part of processing a death note.)
1872 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001873
1874 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001875 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001876
Wale Ogunwale571771c2016-08-26 13:18:50 -07001877 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001878 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001879 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001880 removeIfPossible(false /*keepVisibleDeadWindow*/);
1881 }
1882
Wale Ogunwale571771c2016-08-26 13:18:50 -07001883 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001884 mWindowRemovalAllowed = true;
1885 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1886 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1887
1888 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1889 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1890 "Starting window removed " + this);
1891
1892 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1893 Slog.v(TAG_WM, "Remove " + this + " client="
1894 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1895 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1896 + Debug.getCallers(5));
1897
1898 final long origId = Binder.clearCallingIdentity();
1899
Peter Visontay3556a3b2017-11-01 17:23:17 +00001900 try {
1901 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001902
Peter Visontay3556a3b2017-11-01 17:23:17 +00001903 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1904 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1905 + " mAnimatingExit=" + mAnimatingExit
1906 + " mRemoveOnExit=" + mRemoveOnExit
1907 + " mHasSurface=" + mHasSurface
1908 + " surfaceShowing=" + mWinAnimator.getShown()
1909 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1910 + " app-animation="
1911 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1912 + " mWillReplaceWindow=" + mWillReplaceWindow
1913 + " inPendingTransaction="
1914 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1915 + " mDisplayFrozen=" + mService.mDisplayFrozen
1916 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001917
Peter Visontay3556a3b2017-11-01 17:23:17 +00001918 // Visibility of the removed window. Will be used later to update orientation later on.
1919 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001920
Peter Visontay3556a3b2017-11-01 17:23:17 +00001921 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001922
Peter Visontay3556a3b2017-11-01 17:23:17 +00001923 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1924 // window until the animation is done. If the display is frozen, just remove immediately,
1925 // since the animation wouldn't be seen.
1926 if (mHasSurface && mToken.okToAnimate()) {
1927 if (mWillReplaceWindow) {
1928 // This window is going to be replaced. We need to keep it around until the new one
1929 // gets added, then we will get rid of this one.
1930 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1931 "Preserving " + this + " until the new one is " + "added");
1932 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1933 // been removed. We probably need another flag to indicate that window removal
1934 // should be deffered vs. overloading the flag that says we are playing an exit
1935 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001936 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001937 mReplacingRemoveRequested = true;
1938 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001939 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001940
Peter Visontay3556a3b2017-11-01 17:23:17 +00001941 // If we are not currently running the exit animation, we need to see about starting one
1942 wasVisible = isWinVisibleLw();
1943
1944 if (keepVisibleDeadWindow) {
1945 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1946 "Not removing " + this + " because app died while it's visible");
1947
1948 mAppDied = true;
1949 setDisplayLayoutNeeded();
1950 mService.mWindowPlacerLocked.performSurfacePlacement();
1951
1952 // Set up a replacement input channel since the app is now dead.
1953 // We need to catch tapping on the dead window to restart the app.
1954 openInputChannel(null);
1955 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1956 return;
1957 }
1958
1959 if (wasVisible) {
1960 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1961
1962 // Try starting an animation.
1963 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1964 mAnimatingExit = true;
1965 }
1966 //TODO (multidisplay): Magnification is supported only for the default display.
1967 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
1968 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1969 }
1970 }
1971 final boolean isAnimating =
1972 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1973 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1974 && mAppToken.isLastWindow(this);
1975 // We delay the removal of a window if it has a showing surface that can be used to run
1976 // exit animation and it is marked as exiting.
1977 // Also, If isn't the an animating starting window that is the last window in the app.
1978 // We allow the removal of the non-animating starting window now as there is no
1979 // additional window or animation that will trigger its removal.
1980 if (mWinAnimator.getShown() && mAnimatingExit
1981 && (!lastWindowIsStartingWindow || isAnimating)) {
1982 // The exit animation is running or should run... wait for it!
1983 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1984 "Not removing " + this + " due to exit animation ");
1985 setupWindowForRemoveOnExit();
1986 if (mAppToken != null) {
1987 mAppToken.updateReportedVisibilityLocked();
1988 }
1989 return;
1990 }
1991 }
1992
1993 removeImmediately();
1994 // Removing a visible window will effect the computed orientation
1995 // So just update orientation if needed.
1996 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1997 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
1998 }
1999 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
2000 } finally {
2001 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002002 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002003 }
2004
2005 private void setupWindowForRemoveOnExit() {
2006 mRemoveOnExit = true;
2007 setDisplayLayoutNeeded();
2008 // Request a focus update as this window's input channel is already gone. Otherwise
2009 // we could have no focused window in input manager.
2010 final boolean focusChanged = mService.updateFocusedWindowLocked(
2011 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
2012 mService.mWindowPlacerLocked.performSurfacePlacement();
2013 if (focusChanged) {
2014 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2015 }
2016 }
2017
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002018 void setHasSurface(boolean hasSurface) {
2019 mHasSurface = hasSurface;
2020 }
2021
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002022 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08002023 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07002024 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
2025 if (appToken != null) {
Robert Carrdee1b3f2017-02-27 11:33:33 -08002026 return appToken.getAnimLayerAdjustment();
Wale Ogunwale455fac52016-07-21 07:24:49 -07002027 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002028 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07002029
Robert Carrdee1b3f2017-02-27 11:33:33 -08002030 return mToken.getAnimLayerAdjustment();
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002031 }
2032
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002033 int getSpecialWindowAnimLayerAdjustment() {
2034 int specialAdjustment = 0;
2035 if (mIsImWindow) {
2036 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
2037 } else if (mIsWallpaper) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07002038 specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment();
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002039 }
2040
2041 return mLayer + specialAdjustment;
2042 }
2043
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002044 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002045 if (mIsImWindow) {
2046 // IME windows can't be IME targets. IME targets are required to be below the IME
2047 // windows and that wouldn't be possible if the IME window is its own target...silly.
2048 return false;
2049 }
2050
Winson Chung3d0a74a2017-07-12 12:37:19 -07002051 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002052 if (!windowsAreFocusable) {
2053 // This window can't be an IME target if the app's windows should not be focusable.
2054 return false;
2055 }
2056
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002057 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002058 final int type = mAttrs.type;
2059
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002060 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2061 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002062 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2063 && type != TYPE_APPLICATION_STARTING) {
2064 return false;
2065 }
2066
2067 if (DEBUG_INPUT_METHOD) {
2068 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2069 if (!isVisibleOrAdding()) {
2070 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2071 + " relayoutCalled=" + mRelayoutCalled
2072 + " viewVis=" + mViewVisibility
2073 + " policyVis=" + mPolicyVisibility
2074 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2075 + " parentHidden=" + isParentWindowHidden()
2076 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2077 if (mAppToken != null) {
2078 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2079 }
2080 }
2081 }
2082 return isVisibleOrAdding();
2083 }
2084
Chong Zhangacf11402015-11-04 16:23:10 -08002085 private final class DeadWindowEventReceiver extends InputEventReceiver {
2086 DeadWindowEventReceiver(InputChannel inputChannel) {
2087 super(inputChannel, mService.mH.getLooper());
2088 }
2089 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002090 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002091 finishInputEvent(event, true);
2092 }
2093 }
2094 /**
2095 * Dummy event receiver for windows that died visible.
2096 */
2097 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2098
Chong Zhang112eb8c2015-11-02 11:17:00 -08002099 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002100 if (mInputChannel != null) {
2101 throw new IllegalStateException("Window already has an input channel.");
2102 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002103 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002104 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2105 mInputChannel = inputChannels[0];
2106 mClientChannel = inputChannels[1];
2107 mInputWindowHandle.inputChannel = inputChannels[0];
2108 if (outInputChannel != null) {
2109 mClientChannel.transferTo(outInputChannel);
2110 mClientChannel.dispose();
2111 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002112 } else {
2113 // If the window died visible, we setup a dummy input channel, so that taps
2114 // can still detected by input monitor channel, and we can relaunch the app.
2115 // Create dummy event receiver that simply reports all events as handled.
2116 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002117 }
2118 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002119 }
2120
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002121 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002122 if (mDeadWindowEventReceiver != null) {
2123 mDeadWindowEventReceiver.dispose();
2124 mDeadWindowEventReceiver = null;
2125 }
2126
2127 // unregister server channel first otherwise it complains about broken channel
2128 if (mInputChannel != null) {
2129 mService.mInputManager.unregisterInputChannel(mInputChannel);
2130 mInputChannel.dispose();
2131 mInputChannel = null;
2132 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002133 if (mClientChannel != null) {
2134 mClientChannel.dispose();
2135 mClientChannel = null;
2136 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002137 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002138 }
2139
Robert Carrf59b8dd2017-10-02 18:58:36 -07002140 private Dimmer getDimmer() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002141 Task task = getTask();
2142 if (task != null) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002143 return task.getDimmer();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002144 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08002145 TaskStack taskStack = getStack();
2146 if (taskStack != null) {
2147 return taskStack.getDimmer();
2148 }
2149 return null;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002150 }
2151
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002152 /** Returns true if the replacement window was removed. */
2153 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2154 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2155 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2156 removeReplacedWindow();
2157 return true;
2158 }
2159
2160 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002161 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002162 if (c.removeReplacedWindowIfNeeded(replacement)) {
2163 return true;
2164 }
2165 }
2166 return false;
2167 }
2168
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002169 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002170 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002171 mWillReplaceWindow = false;
2172 mAnimateReplacingWindow = false;
2173 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002174 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002175 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002176 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002177 }
2178 }
2179
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002180 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2181 boolean replacementSet = false;
2182
2183 if (mWillReplaceWindow && mReplacementWindow == null
2184 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2185
2186 mReplacementWindow = replacementCandidate;
2187 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2188 replacementSet = true;
2189 }
2190
2191 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002192 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002193 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2194 }
2195
2196 return replacementSet;
2197 }
2198
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002199 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002200 final DisplayContent dc = getDisplayContent();
2201 if (dc != null) {
2202 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002203 }
2204 }
2205
Chong Zhang5117e272016-05-03 12:47:34 -07002206 void applyAdjustForImeIfNeeded() {
2207 final Task task = getTask();
2208 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2209 task.mStack.applyAdjustForImeIfNeeded(task);
2210 }
2211 }
2212
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002213 @Override
2214 void switchUser() {
2215 super.switchUser();
2216 if (isHiddenFromUserLocked()) {
2217 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2218 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2219 hideLw(false);
2220 }
2221 }
2222
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002223 int getTouchableRegion(Region region, int flags) {
2224 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002225 if (modal && mAppToken != null) {
2226 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002227 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002228 // If this is a modal window we need to dismiss it if it's not full screen and the
2229 // touch happens outside of the frame that displays the content. This means we
2230 // need to intercept touches outside of that window. The dim layer user
2231 // associated with the window (task or stack) will give us the good bounds, as
2232 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002233 final Task task = getTask();
2234 if (task != null) {
2235 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002236 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002237 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002238 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002239 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002240 // For freeform windows we the touch region to include the whole surface for the
2241 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002242 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2243 final int delta = WindowManagerService.dipToPixel(
2244 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2245 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002246 }
2247 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002248 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002249 } else {
2250 // Not modal or full screen modal
2251 getTouchableRegion(region);
2252 }
2253 return flags;
2254 }
2255
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002256 void checkPolicyVisibilityChange() {
2257 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2258 if (DEBUG_VISIBILITY) {
2259 Slog.v(TAG, "Policy visibility changing after anim in " +
2260 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2261 }
2262 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002263 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002264 if (!mPolicyVisibility) {
2265 if (mService.mCurrentFocus == this) {
2266 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2267 "setAnimationLocked: setting mFocusMayChange true");
2268 mService.mFocusMayChange = true;
2269 }
2270 // Window is no longer visible -- make sure if we were waiting
2271 // for it to be displayed before enabling the display, that
2272 // we allow the display to be enabled now.
2273 mService.enableScreenIfNeededLocked();
2274 }
2275 }
2276 }
2277
2278 void setRequestedSize(int requestedWidth, int requestedHeight) {
2279 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2280 mLayoutNeeded = true;
2281 mRequestedWidth = requestedWidth;
2282 mRequestedHeight = requestedHeight;
2283 }
2284 }
2285
Bryce Leef858b572017-06-29 14:03:33 -07002286 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002287 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002288 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2289 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2290 mTurnOnScreen = true;
2291 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002292
2293 // If we were already visible, skip rest of preparation.
2294 if (wasVisible) {
2295 if (DEBUG_VISIBILITY) Slog.v(TAG,
2296 "Already visible and does not turn on screen, skip preparing: " + this);
2297 return;
2298 }
2299
2300 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2301 == SOFT_INPUT_ADJUST_RESIZE) {
2302 mLayoutNeeded = true;
2303 }
2304
David Stevens9440dc82017-03-16 19:00:20 -07002305 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002306 mWinAnimator.applyEnterAnimationLocked();
2307 }
Bryce Leef858b572017-06-29 14:03:33 -07002308 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002309
Bryce Leef858b572017-06-29 14:03:33 -07002310 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2311 final Configuration globalConfig = mService.mRoot.getConfiguration();
2312 final Configuration overrideConfig = getMergedOverrideConfiguration();
2313 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2314 }
2315
Bryce Lee2b17afd2017-09-21 10:38:20 -07002316 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2317 mLastReportedConfiguration.setTo(config);
2318 }
2319
2320 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2321 config.setTo(mLastReportedConfiguration);
2322 }
2323
2324 private Configuration getLastReportedConfiguration() {
2325 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002326 }
2327
2328 void adjustStartingWindowFlags() {
2329 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2330 && mAppToken.startingWindow != null) {
2331 // Special handling of starting window over the base
2332 // window of the app: propagate lock screen flags to it,
2333 // to provide the correct semantics while starting.
2334 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2335 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2336 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2337 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2338 }
2339 }
2340
2341 void setWindowScale(int requestedWidth, int requestedHeight) {
2342 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2343
2344 if (scaledWindow) {
2345 // requested{Width|Height} Surface's physical size
2346 // attrs.{width|height} Size on screen
2347 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2348 mHScale = (mAttrs.width != requestedWidth) ?
2349 (mAttrs.width / (float)requestedWidth) : 1.0f;
2350 mVScale = (mAttrs.height != requestedHeight) ?
2351 (mAttrs.height / (float)requestedHeight) : 1.0f;
2352 } else {
2353 mHScale = mVScale = 1;
2354 }
2355 }
2356
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002357 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002358 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002359 public void binderDied() {
2360 try {
2361 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002362 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002363 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002364 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002365 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002366 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2367 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2368 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002369 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002370 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2371 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002372 // just in case they have the divider at an unstable position. Better
2373 // also reset drag resizing state, because the owner can't do it
2374 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002375 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002376 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002377 if (stack != null) {
2378 stack.resetDockedStackToMiddle();
2379 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002380 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002381 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002382 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002383 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002384 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002385 }
2386 }
2387 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002388 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002389 }
2390 }
2391 }
2392
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002393 /**
2394 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2395 * because we want to preserve its location on screen to be re-activated later when the user
2396 * interacts with it.
2397 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002398 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002399 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002400 // Not a visible app window or the app isn't dead.
2401 return false;
2402 }
2403
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002404 if (mAttrs.token != mClient.asBinder()) {
2405 // The window was add by a client using another client's app token. We don't want to
2406 // keep the dead window around for this case since this is meant for 'real' apps.
2407 return false;
2408 }
2409
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002410 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2411 // We don't keep starting windows since they were added by the window manager before
2412 // the app even launched.
2413 return false;
2414 }
2415
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002416 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002417 }
2418
Wale Ogunwaled045c822015-12-02 09:14:28 -08002419 /** @return true if this window desires key events. */
2420 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002421 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002422 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002423 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002424 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002425 && !canReceiveTouchInput();
2426 }
2427
2428 /** @return true if this window desires touch events. */
2429 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002430 return mAppToken != null && mAppToken.getTask() != null
2431 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002432 }
2433
Craig Mautner749a7bb2012-04-02 13:49:53 -07002434 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002435 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002436 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002437 }
2438
Craig Mautner749a7bb2012-04-02 13:49:53 -07002439 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002440 public boolean showLw(boolean doAnimation) {
2441 return showLw(doAnimation, true);
2442 }
2443
2444 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002445 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002446 return false;
2447 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002448 if (!mAppOpVisibility) {
2449 // Being hidden due to app op request.
2450 return false;
2451 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002452 if (mPermanentlyHidden) {
2453 // Permanently hidden until the app exists as apps aren't prepared
2454 // to handle their windows being removed from under them.
2455 return false;
2456 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002457 if (mForceHideNonSystemOverlayWindow) {
2458 // This is an alert window that is currently force hidden.
2459 return false;
2460 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002461 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002462 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002463 return false;
2464 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002465 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002466 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002467 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggia5e10572017-11-15 14:36:26 +01002468 + mPolicyVisibility + " isAnimationSet=" + mWinAnimator.isAnimationSet());
David Stevens9440dc82017-03-16 19:00:20 -07002469 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002470 doAnimation = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +01002471 } else if (mPolicyVisibility && !mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002472 // Check for the case where we are currently visible and
2473 // not animating; we do not want to do animation at such a
2474 // point to become visible when we already are.
2475 doAnimation = false;
2476 }
2477 }
2478 mPolicyVisibility = true;
2479 mPolicyVisibilityAfterAnim = true;
2480 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002481 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002482 }
2483 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002484 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002485 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002486 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2487 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2488 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002489 return true;
2490 }
2491
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002492 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002493 public boolean hideLw(boolean doAnimation) {
2494 return hideLw(doAnimation, true);
2495 }
2496
2497 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2498 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002499 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002500 doAnimation = false;
2501 }
2502 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002503 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002504 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002505 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002506 return false;
2507 }
2508 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002509 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggia5e10572017-11-15 14:36:26 +01002510 if (!mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002511 doAnimation = false;
2512 }
2513 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002514 mPolicyVisibilityAfterAnim = false;
2515 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002516 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002517 mPolicyVisibility = false;
2518 // Window is no longer visible -- make sure if we were waiting
2519 // for it to be displayed before enabling the display, that
2520 // we allow the display to be enabled now.
2521 mService.enableScreenIfNeededLocked();
2522 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002523 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002524 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002525 mService.mFocusMayChange = true;
2526 }
2527 }
2528 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002529 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002530 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002531 if (mService.mCurrentFocus == this) {
2532 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2533 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002534 return true;
2535 }
2536
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002537 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2538 if (mOwnerCanAddInternalSystemWindow
2539 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2540 return;
2541 }
2542 if (mForceHideNonSystemOverlayWindow == forceHide) {
2543 return;
2544 }
2545 mForceHideNonSystemOverlayWindow = forceHide;
2546 if (forceHide) {
2547 hideLw(true /* doAnimation */, true /* requestAnim */);
2548 } else {
2549 showLw(true /* doAnimation */, true /* requestAnim */);
2550 }
2551 }
2552
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002553 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002554 if (mAppOpVisibility != state) {
2555 mAppOpVisibility = state;
2556 if (state) {
2557 // If the policy visibility had last been to hide, then this
2558 // will incorrectly show at this point since we lost that
2559 // information. Not a big deal -- for the windows that have app
2560 // ops modifies they should only be hidden by policy due to the
2561 // lock screen, and the user won't be changing this if locked.
2562 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002563 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002564 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002565 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002566 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002567 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002568 }
2569
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002570 public void hidePermanentlyLw() {
2571 if (!mPermanentlyHidden) {
2572 mPermanentlyHidden = true;
2573 hideLw(true, true);
2574 }
2575 }
2576
Jeff Brownc2932a12014-11-20 18:04:05 -08002577 public void pokeDrawLockLw(long timeout) {
2578 if (isVisibleOrAdding()) {
2579 if (mDrawLock == null) {
2580 // We want the tag name to be somewhat stable so that it is easier to correlate
2581 // in wake lock statistics. So in particular, we don't want to include the
2582 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002583 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002584 mDrawLock = mService.mPowerManager.newWakeLock(
2585 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2586 mDrawLock.setReferenceCounted(false);
2587 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2588 }
2589 // Each call to acquire resets the timeout.
2590 if (DEBUG_POWER) {
2591 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2592 + mAttrs.packageName);
2593 }
2594 mDrawLock.acquire(timeout);
2595 } else if (DEBUG_POWER) {
2596 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2597 + "owned by " + mAttrs.packageName);
2598 }
2599 }
2600
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002601 @Override
2602 public boolean isAlive() {
2603 return mClient.asBinder().isBinderAlive();
2604 }
2605
Craig Mautnera987d432012-10-11 14:07:58 -07002606 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002607 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002608 }
2609
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002610 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2611 animators.add(mWinAnimator);
2612
2613 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002614 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002615 c.addWinAnimatorToList(animators);
2616 }
2617 }
2618
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002619 void sendAppVisibilityToClients() {
2620 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002621
Wale Ogunwale89973222017-04-23 18:39:45 -07002622 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002623 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2624 // Don't hide the starting window.
2625 return;
2626 }
2627
Wale Ogunwale89973222017-04-23 18:39:45 -07002628 if (clientHidden) {
2629 // Once we are notifying the client that it's visibility has changed, we need to prevent
2630 // it from destroying child surfaces until the animation has finished. We do this by
2631 // detaching any surface control the client added from the client.
2632 for (int i = mChildren.size() - 1; i >= 0; --i) {
2633 final WindowState c = mChildren.get(i);
2634 c.mWinAnimator.detachChildren();
2635 }
2636
2637 mWinAnimator.detachChildren();
2638 }
2639
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002640 try {
2641 if (DEBUG_VISIBILITY) Slog.v(TAG,
2642 "Setting visibility of " + this + ": " + (!clientHidden));
2643 mClient.dispatchAppVisibility(!clientHidden);
2644 } catch (RemoteException e) {
2645 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002646 }
2647
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002648 void onStartFreezingScreen() {
2649 mAppFreezing = true;
2650 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002651 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002652 c.onStartFreezingScreen();
2653 }
2654 }
2655
2656 boolean onStopFreezingScreen() {
2657 boolean unfrozeWindows = false;
2658 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002659 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002660 unfrozeWindows |= c.onStopFreezingScreen();
2661 }
2662
2663 if (!mAppFreezing) {
2664 return unfrozeWindows;
2665 }
2666
Wale Ogunwale953171d2016-09-30 09:17:30 -07002667 mAppFreezing = false;
2668
Bryce Lee8c3cf382017-07-06 19:47:10 -07002669 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002670 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2671 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002672 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002673 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002674 }
2675 mLastFreezeDuration = 0;
2676 setDisplayLayoutNeeded();
2677 return true;
2678 }
2679
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002680 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2681 boolean destroyedSomething = false;
2682 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002683 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002684 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2685 }
2686
Robert Carrdb2f6e62017-03-01 20:17:58 -08002687 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2688 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002689 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002690
2691 if (appStopped || mWindowRemovalAllowed) {
2692 mWinAnimator.destroyPreservedSurfaceLocked();
2693 }
2694
2695 if (mDestroying) {
2696 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2697 + " destroySurfaces: appStopped=" + appStopped
2698 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2699 + " win.mRemoveOnExit=" + mRemoveOnExit);
2700 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002701 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002702 }
2703 if (mRemoveOnExit) {
2704 removeImmediately();
2705 }
2706 if (cleanupOnResume) {
2707 requestUpdateWallpaperIfNeeded();
2708 }
2709 mDestroying = false;
2710 destroyedSomething = true;
2711 }
2712
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002713 return destroyedSomething;
2714 }
Chris Craik3131bde2016-05-06 13:39:08 -07002715
Robert Carr89a28ab2017-04-24 15:33:11 -07002716 // Destroy or save the application surface without checking
2717 // various indicators of whether the client has released the surface.
2718 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002719 void destroySurfaceUnchecked() {
2720 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002721
Chong Zhang92147042016-05-09 12:47:11 -07002722 // Clear animating flags now, since the surface is now gone. (Note this is true even
2723 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2724 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002725 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002726
Craig Mautner69b08182012-09-05 13:07:13 -07002727 @Override
2728 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002729 final DisplayContent displayContent = getDisplayContent();
2730 if (displayContent == null) {
2731 // Only a window that was on a non-default display can be detached from it.
2732 return false;
2733 }
Winson Chung47a3e652014-05-21 16:03:42 -07002734 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002735 }
2736
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002737 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002738 mShowToOwnerOnly = showToOwnerOnly;
2739 }
2740
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002741 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002742 // Child windows are evaluated based on their parent window.
2743 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002744 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002745 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002746
2747 // All window frames that are fullscreen extend above status bar, but some don't extend
2748 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2749 // bottom right.
2750 if (win.mFrame.left <= win.mDisplayFrame.left
2751 && win.mFrame.top <= win.mDisplayFrame.top
2752 && win.mFrame.right >= win.mStableFrame.right
2753 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002754 // Is a fullscreen window, like the clock alarm. Show to everyone.
2755 return false;
2756 }
2757 }
2758
Craig Mautner341220f2012-10-16 15:20:09 -07002759 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002760 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002761 }
2762
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002763 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2764 outRegion.set(
2765 frame.left + inset.left, frame.top + inset.top,
2766 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002767 }
2768
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002769 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002770 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002771 switch (mTouchableInsets) {
2772 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002773 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002774 outRegion.set(frame);
2775 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002776 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002777 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002778 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002779 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002780 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002781 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002782 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002783 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002784 outRegion.translate(frame.left, frame.top);
2785 break;
2786 }
2787 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002788 cropRegionToStackBoundsIfNeeded(outRegion);
2789 }
2790
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002791 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002792 final Task task = getTask();
2793 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002794 return;
2795 }
2796
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002797 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002798 if (stack == null) {
2799 return;
2800 }
2801
2802 stack.getDimBounds(mTmpRect);
2803 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002804 }
2805
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002806 /**
2807 * Report a focus change. Must be called with no locks held, and consistently
2808 * from the same serialized thread (such as dispatched from a handler).
2809 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002810 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002811 try {
2812 mClient.windowFocusChanged(focused, inTouchMode);
2813 } catch (RemoteException e) {
2814 }
2815 if (mFocusCallbacks != null) {
2816 final int N = mFocusCallbacks.beginBroadcast();
2817 for (int i=0; i<N; i++) {
2818 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2819 try {
2820 if (focused) {
2821 obs.focusGained(mWindowId.asBinder());
2822 } else {
2823 obs.focusLost(mWindowId.asBinder());
2824 }
2825 } catch (RemoteException e) {
2826 }
2827 }
2828 mFocusCallbacks.finishBroadcast();
2829 }
2830 }
2831
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002832 @Override
2833 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002834 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002835 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002836 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002837
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002838 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002839 }
2840
Craig Mautnerdf88d732014-01-27 09:21:32 -08002841 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002842 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002843 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002844 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2845 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002846 final MergedConfiguration mergedConfiguration =
2847 new MergedConfiguration(mService.mRoot.getConfiguration(),
2848 getMergedOverrideConfiguration());
2849
Bryce Lee2b17afd2017-09-21 10:38:20 -07002850 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002851
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002852 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002853 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2854
Craig Mautnerdf88d732014-01-27 09:21:32 -08002855 final Rect frame = mFrame;
2856 final Rect overscanInsets = mLastOverscanInsets;
2857 final Rect contentInsets = mLastContentInsets;
2858 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002859 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002860 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002861 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002862 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002863 final int displayId = getDisplayId();
Adrian Roos5c6b6222017-11-07 17:36:10 +01002864 final DisplayCutout displayCutout = mDisplayCutout;
Chet Haase8eb48d22014-09-24 07:31:29 -07002865 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2866 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002867 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2868 mService.mH.post(new Runnable() {
2869 @Override
2870 public void run() {
2871 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002872 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002873 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002874 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002875 } catch (RemoteException e) {
2876 // Not a remote call, RemoteException won't be raised.
2877 }
2878 }
2879 });
2880 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002881 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002882 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
2883 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002884 }
Svetoslav4604abc2014-06-10 18:59:30 -07002885
2886 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002887 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002888 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002889 }
2890
Craig Mautnerdf88d732014-01-27 09:21:32 -08002891 mOverscanInsetsChanged = false;
2892 mContentInsetsChanged = false;
2893 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002894 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002895 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07002896 mFrameSizeChanged = false;
Adrian Roos5c6b6222017-11-07 17:36:10 +01002897 mDisplayCutoutChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002898 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002899 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002900 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002901 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002902 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002903 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2904 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002905 // We are assuming the hosting process is dead or in a zombie state.
2906 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2907 + ", removing this window.");
2908 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002909 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002910 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002911 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002912 }
2913
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002914 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002915 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2916 // start even if we haven't received the relayout window, so that the client requests
2917 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2918 // until the window to small size, otherwise the multithread renderer will shift last
2919 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2920 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002921 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002922 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002923 return frame;
2924 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002925 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002926 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002927 return mTmpRect;
2928 }
2929
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002930 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002931 final TaskStack stack = getStack();
2932 if (stack == null) {
2933 return INVALID_STACK_ID;
2934 }
2935 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002936 }
2937
2938 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2939 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002940 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
2941 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002942 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08002943 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
2944 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07002945
Jorim Jaggidc249c42015-12-15 14:57:31 -08002946 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002947 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002948 mPolicy.isNavBarForcedShownLw(this), displayId,
2949 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002950 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002951 }
2952
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002953 public void registerFocusObserver(IWindowFocusObserver observer) {
2954 synchronized(mService.mWindowMap) {
2955 if (mFocusCallbacks == null) {
2956 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2957 }
2958 mFocusCallbacks.register(observer);
2959 }
2960 }
2961
2962 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2963 synchronized(mService.mWindowMap) {
2964 if (mFocusCallbacks != null) {
2965 mFocusCallbacks.unregister(observer);
2966 }
2967 }
2968 }
2969
2970 public boolean isFocused() {
2971 synchronized(mService.mWindowMap) {
2972 return mService.mCurrentFocus == this;
2973 }
2974 }
2975
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002976 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002977 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002978 final Task task = getTask();
2979 return task != null && !task.isFullscreen();
2980 }
2981
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002982 /** Is this window in a container that takes up the entire screen space? */
2983 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08002984 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002985 }
2986
Andrii Kulian283acd22017-08-03 04:03:51 -07002987 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
2988 boolean isLetterboxedAppWindow() {
Bryce Leef3c6a472017-11-14 14:53:06 -08002989 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002990 }
2991
Chong Zhang3005e752015-09-18 18:46:28 -07002992 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002993 return mDragResizing != computeDragResizing();
2994 }
2995
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002996 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002997 void setWaitingForDrawnIfResizingChanged() {
2998 if (isDragResizeChanged()) {
2999 mService.mWaitingForDrawn.add(this);
3000 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003001 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003002 }
3003
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003004 /**
3005 * @return Whether we reported a drag resize change to the application or not already.
3006 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003007 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003008 return mDragResizingChangeReported;
3009 }
3010
3011 /**
3012 * Resets the state whether we reported a drag resize change to the app.
3013 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003014 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003015 void resetDragResizingChangeReported() {
3016 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003017 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003018 }
3019
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003020 /**
3021 * Set whether we got resized but drag resizing flag was false.
3022 * @see #isResizedWhileNotDragResizing().
3023 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003024 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003025 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3026 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3027 }
3028
3029 /**
3030 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3031 * need to recreate the surface and defer surface bound updates in order to make sure the
3032 * buffer contents and the positioning/size stay in sync.
3033 */
3034 boolean isResizedWhileNotDragResizing() {
3035 return mResizedWhileNotDragResizing;
3036 }
3037
3038 /**
3039 * @return Whether we reported "resize while not drag resizing" to the application.
3040 * @see #isResizedWhileNotDragResizing()
3041 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003042 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003043 return mResizedWhileNotDragResizingReported;
3044 }
3045
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003046 int getResizeMode() {
3047 return mResizeMode;
3048 }
3049
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003050 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003051 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003052 if (task == null) {
3053 return false;
3054 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003055 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003056 return false;
3057 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003058 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003059 // Floating windows never enter drag resize mode.
3060 return false;
3061 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003062 if (task.isDragResizing()) {
3063 return true;
3064 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003065
3066 // If the bounds are currently frozen, it means that the layout size that the app sees
3067 // and the bounds we clip this window to might be different. In order to avoid holes, we
3068 // simulate that we are still resizing so the app fills the hole with the resizing
3069 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003070 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003071 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003072 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003073
Chong Zhang3005e752015-09-18 18:46:28 -07003074 }
3075
3076 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003077 final boolean resizing = computeDragResizing();
3078 if (resizing == mDragResizing) {
3079 return;
3080 }
3081 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003082 final Task task = getTask();
3083 if (task != null && task.isDragResizing()) {
3084 mResizeMode = task.getDragResizeMode();
3085 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003086 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003087 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3088 : DRAG_RESIZE_MODE_FREEFORM;
3089 }
Chong Zhang3005e752015-09-18 18:46:28 -07003090 }
3091
3092 boolean isDragResizing() {
3093 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003094 }
3095
Robert Carr2487ce72016-04-07 15:18:45 -07003096 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003097 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3098 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003099 }
3100
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003101 @CallSuper
3102 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003103 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003104 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003105 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003106 writeIdentifierToProto(proto, IDENTIFIER);
3107 proto.write(DISPLAY_ID, getDisplayId());
3108 proto.write(STACK_ID, getStackId());
3109 mAttrs.writeToProto(proto, ATTRIBUTES);
3110 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3111 mFrame.writeToProto(proto, FRAME);
3112 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3113 mParentFrame.writeToProto(proto, PARENT_FRAME);
3114 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3115 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3116 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003117 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
3118 mShownPosition.writeToProto(proto, SHOWN_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003119 mWinAnimator.writeToProto(proto, ANIMATOR);
3120 proto.write(ANIMATING_EXIT, mAnimatingExit);
3121 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003122 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003123 }
3124 proto.end(token);
3125 }
3126
3127 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
3128 final long token = proto.start(fieldId);
3129 proto.write(HASH_CODE, System.identityHashCode(this));
3130 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3131 final CharSequence title = getWindowTag();
3132 if (title != null) {
3133 proto.write(TITLE, title.toString());
3134 }
3135 proto.end(token);
3136 }
3137
Jorim Jaggia5e10572017-11-15 14:36:26 +01003138 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003139 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003140 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003141 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003142 if (stack != null) {
3143 pw.print(" stackId="); pw.print(stack.mStackId);
3144 }
Craig Mautner59c00972012-07-30 12:10:24 -07003145 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003146 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003147 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003148 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3149 pw.print(" package="); pw.print(mAttrs.packageName);
3150 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003151 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003152 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3153 pw.print(" h="); pw.print(mRequestedHeight);
3154 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003155 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3156 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3157 pw.print(" h="); pw.println(mLastRequestedHeight);
3158 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003159 if (mIsChildWindow || mLayoutAttached) {
3160 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003161 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3162 }
3163 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3164 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3165 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3166 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3167 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3168 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003169 if (dumpAll) {
3170 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3171 pw.print(" mSubLayer="); pw.print(mSubLayer);
3172 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003173 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003174 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3175 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003176 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003177 if (dumpAll) {
3178 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003179 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003180 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3181 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003182 pw.print(" mAppDied=");pw.print(mAppDied);
3183 pw.print(prefix); pw.print("drawnStateEvaluated=");
3184 pw.print(getDrawnStateEvaluated());
3185 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003186 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003187 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003188 pw.print(prefix); pw.print("mViewVisibility=0x");
3189 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003190 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3191 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003192 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3193 pw.print(" mSystemUiVisibility=0x");
3194 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003195 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003196 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003197 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003198 pw.print(prefix); pw.print("mPolicyVisibility=");
3199 pw.print(mPolicyVisibility);
3200 pw.print(" mPolicyVisibilityAfterAnim=");
3201 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003202 pw.print(" mAppOpVisibility=");
3203 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003204 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003205 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
3206 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3207 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003208 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003209 if (!mRelayoutCalled || mLayoutNeeded) {
3210 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3211 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003212 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003213 if (mXOffset != 0 || mYOffset != 0) {
3214 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3215 pw.print(" y="); pw.println(mYOffset);
3216 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003217 if (dumpAll) {
3218 pw.print(prefix); pw.print("mGivenContentInsets=");
3219 mGivenContentInsets.printShortString(pw);
3220 pw.print(" mGivenVisibleInsets=");
3221 mGivenVisibleInsets.printShortString(pw);
3222 pw.println();
3223 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3224 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3225 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003226 Region region = new Region();
3227 getTouchableRegion(region);
3228 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003229 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003230 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3231 pw.print(prefix); pw.print("mLastReportedConfiguration=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003232 pw.println(getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003233 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003234 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003235 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003236 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003237 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003238 if (dumpAll) {
3239 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3240 pw.print(" last="); mLastFrame.printShortString(pw);
3241 pw.println();
3242 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003243 if (mEnforceSizeCompat) {
3244 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003245 pw.println();
3246 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003247 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003248 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003249 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003250 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003251 pw.println();
3252 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3253 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003254 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003255 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003256 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003257 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003258 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3259 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003260 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3261 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003262 pw.print(prefix); pw.print("Cur insets: overscan=");
3263 mOverscanInsets.printShortString(pw);
3264 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003265 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003266 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003267 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003268 pw.print(" outsets="); mOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003269 pw.print(" cutout=" + mDisplayCutout);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003270 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003271 pw.print(prefix); pw.print("Lst insets: overscan=");
3272 mLastOverscanInsets.printShortString(pw);
3273 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003274 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003275 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003276 pw.print(" physical="); mLastOutsets.printShortString(pw);
3277 pw.print(" outset="); mLastOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003278 pw.print(" cutout=" + mLastDisplayCutout);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003279 pw.println();
3280 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003281 super.dump(pw, prefix, dumpAll);
Dianne Hackborn529e7442012-11-01 14:22:28 -07003282 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3283 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003284 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3285 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003286 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3287 pw.print(" mDestroying="); pw.print(mDestroying);
3288 pw.print(" mRemoved="); pw.println(mRemoved);
3289 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003290 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003291 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003292 pw.print(prefix); pw.print("mOrientationChanging=");
3293 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003294 pw.print(" configOrientationChanging=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003295 pw.print(getLastReportedConfiguration().orientation
Bryce Lee8c3cf382017-07-06 19:47:10 -07003296 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003297 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003298 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003299 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003300 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003301 if (mLastFreezeDuration != 0) {
3302 pw.print(prefix); pw.print("mLastFreezeDuration=");
3303 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3304 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003305 if (mHScale != 1 || mVScale != 1) {
3306 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3307 pw.print(" mVScale="); pw.println(mVScale);
3308 }
3309 if (mWallpaperX != -1 || mWallpaperY != -1) {
3310 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3311 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3312 }
3313 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3314 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3315 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3316 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003317 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3318 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3319 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3320 pw.print(mWallpaperDisplayOffsetX);
3321 pw.print(" mWallpaperDisplayOffsetY=");
3322 pw.println(mWallpaperDisplayOffsetY);
3323 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003324 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003325 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003326 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003327 if (isDragResizing()) {
3328 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3329 }
3330 if (computeDragResizing()) {
3331 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3332 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003333 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3334 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003335 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003336
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003337 @Override
3338 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003339 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003340 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003341 }
3342
Robert Carra1eb4392015-12-10 12:43:51 -08003343 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003344 CharSequence tag = mAttrs.getTitle();
3345 if (tag == null || tag.length() <= 0) {
3346 tag = mAttrs.packageName;
3347 }
3348 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003349 }
3350
3351 @Override
3352 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003353 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003354 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003355 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003356 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003357 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003358 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003359 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003360 }
3361 return mStringNameCache;
3362 }
Robert Carr58f29132015-10-29 14:19:05 -07003363
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003364 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003365 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003366 clipRect.left = (int) (clipRect.left / mHScale);
3367 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003368 }
3369 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003370 clipRect.top = (int) (clipRect.top / mVScale);
3371 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003372 }
3373 }
Robert Carr31e28482015-12-02 16:53:18 -08003374
Jorim Jaggif5834272016-04-04 20:25:41 -07003375 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3376 final int pw = containingFrame.width();
3377 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003378 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003379 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003380 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3381
3382 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003383 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3384 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003385 // 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 -07003386 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3387 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3388 // the display.
3389 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003390 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003391 float x, y;
3392 int w,h;
3393
3394 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3395 if (mAttrs.width < 0) {
3396 w = pw;
3397 } else if (mEnforceSizeCompat) {
3398 w = (int)(mAttrs.width * mGlobalScale + .5f);
3399 } else {
3400 w = mAttrs.width;
3401 }
3402 if (mAttrs.height < 0) {
3403 h = ph;
3404 } else if (mEnforceSizeCompat) {
3405 h = (int)(mAttrs.height * mGlobalScale + .5f);
3406 } else {
3407 h = mAttrs.height;
3408 }
3409 } else {
3410 if (mAttrs.width == MATCH_PARENT) {
3411 w = pw;
3412 } else if (mEnforceSizeCompat) {
3413 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3414 } else {
3415 w = mRequestedWidth;
3416 }
3417 if (mAttrs.height == MATCH_PARENT) {
3418 h = ph;
3419 } else if (mEnforceSizeCompat) {
3420 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3421 } else {
3422 h = mRequestedHeight;
3423 }
3424 }
3425
3426 if (mEnforceSizeCompat) {
3427 x = mAttrs.x * mGlobalScale;
3428 y = mAttrs.y * mGlobalScale;
3429 } else {
3430 x = mAttrs.x;
3431 y = mAttrs.y;
3432 }
3433
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003434 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003435 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003436 // required by {@link Gravity#apply} call.
3437 w = Math.min(w, pw);
3438 h = Math.min(h, ph);
3439 }
3440
3441 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003442 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003443 (int) (x + mAttrs.horizontalMargin * pw),
3444 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3445
3446 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003447 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003448 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003449 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003450
3451 // We need to make sure we update the CompatFrame as it is used for
3452 // cropping decisions, etc, on systems where we lack a decor layer.
3453 mCompatFrame.set(mFrame);
3454 if (mEnforceSizeCompat) {
3455 // See comparable block in computeFrameLw.
3456 mCompatFrame.scale(mInvGlobalScale);
3457 }
Robert Carr31e28482015-12-02 16:53:18 -08003458 }
Robert Carr51a1b872015-12-08 14:03:13 -08003459
3460 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003461 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003462 }
3463
Robert Carrf3b72c72016-03-21 18:16:39 -07003464 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003465 return mIsChildWindow
3466 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003467 }
3468
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003469 /**
3470 * Returns true if any window added by an application process that if of type
3471 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3472 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3473 * this window is visible.
3474 */
3475 boolean hideNonSystemOverlayWindowsWhenVisible() {
3476 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3477 && mSession.mCanHideNonSystemOverlayWindows;
3478 }
3479
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003480 /** Returns the parent window if this is a child of another window, else null. */
3481 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003482 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3483 // WindowContainer that isn't a WindowState.
3484 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003485 }
3486
3487 /** Returns the topmost parent window if this is a child of another window, else this. */
3488 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003489 WindowState current = this;
3490 WindowState topParent = current;
3491 while (current != null && current.mIsChildWindow) {
3492 current = current.getParentWindow();
3493 // Parent window can be null if the child is detached from it's parent already, but
3494 // someone still has a reference to access it. So, we return the top parent value we
3495 // already have instead of null.
3496 if (current != null) {
3497 topParent = current;
3498 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003499 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003500 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003501 }
3502
Wale Ogunwale9d147902016-07-16 11:58:55 -07003503 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003504 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003505 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003506 }
3507
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003508 void setWillReplaceWindow(boolean animate) {
3509 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003510 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003511 c.setWillReplaceWindow(animate);
3512 }
3513
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003514 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3515 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3516 // We don't set replacing on starting windows since they are added by window manager and
3517 // not the client so won't be replaced by the client.
3518 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003519 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003520
3521 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003522 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003523 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003524 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003525
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003526 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003527 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003528 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003529 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003530
3531 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003532 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003533 c.clearWillReplaceWindow();
3534 }
3535 }
3536
3537 boolean waitingForReplacement() {
3538 if (mWillReplaceWindow) {
3539 return true;
3540 }
3541
3542 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003543 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003544 if (c.waitingForReplacement()) {
3545 return true;
3546 }
3547 }
3548 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003549 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003550
Chong Zhang4d7369a2016-04-25 16:09:14 -07003551 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003552 final DisplayContent dc = getDisplayContent();
3553 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3554 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3555 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003556 mService.mWindowPlacerLocked.requestTraversal();
3557 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003558
3559 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003560 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003561 c.requestUpdateWallpaperIfNeeded();
3562 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003563 }
3564
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003565 float translateToWindowX(float x) {
3566 float winX = x - mFrame.left;
3567 if (mEnforceSizeCompat) {
3568 winX *= mGlobalScale;
3569 }
3570 return winX;
3571 }
3572
3573 float translateToWindowY(float y) {
3574 float winY = y - mFrame.top;
3575 if (mEnforceSizeCompat) {
3576 winY *= mGlobalScale;
3577 }
3578 return winY;
3579 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003580
3581 // During activity relaunch due to resize, we sometimes use window replacement
3582 // for only child windows (as the main window is handled by window preservation)
3583 // and the big surface.
3584 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003585 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3586 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3587 // we also want to replace them at such phases, as they won't be covered by window
3588 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003589 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003590 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003591 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003592 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003593
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003594 void setWillReplaceChildWindows() {
3595 if (shouldBeReplacedWithChildren()) {
3596 setWillReplaceWindow(false /* animate */);
3597 }
3598 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003599 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003600 c.setWillReplaceChildWindows();
3601 }
3602 }
3603
3604 WindowState getReplacingWindow() {
3605 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3606 return this;
3607 }
3608 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003609 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003610 final WindowState replacing = c.getReplacingWindow();
3611 if (replacing != null) {
3612 return replacing;
3613 }
3614 }
3615 return null;
3616 }
3617
Jorim Jaggife762342016-10-13 14:33:27 +02003618 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003619 public int getRotationAnimationHint() {
3620 if (mAppToken != null) {
3621 return mAppToken.mRotationAnimationHint;
3622 } else {
3623 return -1;
3624 }
3625 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003626
Jorim Jaggife762342016-10-13 14:33:27 +02003627 @Override
3628 public boolean isInputMethodWindow() {
3629 return mIsImWindow;
3630 }
3631
Wale Ogunwale9d147902016-07-16 11:58:55 -07003632 // This must be called while inside a transaction.
3633 boolean performShowLocked() {
3634 if (isHiddenFromUserLocked()) {
3635 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3636 hideLw(false);
3637 return false;
3638 }
3639
3640 logPerformShow("performShow on ");
3641
Jorim Jaggia50da602016-12-29 11:51:42 +01003642 final int drawState = mWinAnimator.mDrawState;
3643 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3644 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3645 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3646 }
3647
Jorim Jaggib0d27342016-11-01 16:10:42 -07003648 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003649 return false;
3650 }
3651
3652 logPerformShow("Showing ");
3653
3654 mService.enableScreenIfNeededLocked();
3655 mWinAnimator.applyEnterAnimationLocked();
3656
3657 // Force the show in the next prepareSurfaceLocked() call.
3658 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003659 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003660 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3661 mWinAnimator.mDrawState = HAS_DRAWN;
3662 mService.scheduleAnimationLocked();
3663
3664 if (mHidden) {
3665 mHidden = false;
3666 final DisplayContent displayContent = getDisplayContent();
3667
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003668 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003669 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003670 if (c.mWinAnimator.mSurfaceController != null) {
3671 c.performShowLocked();
3672 // It hadn't been shown, which means layout not performed on it, so now we
3673 // want to make sure to do a layout. If called from within the transaction
3674 // loop, this will cause it to restart with a new layout.
3675 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003676 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003677 }
3678 }
3679 }
3680 }
3681
Wale Ogunwale9d147902016-07-16 11:58:55 -07003682 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003683 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003684 }
3685
3686 return true;
3687 }
3688
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003689 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003690 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003691 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003692 Slog.v(TAG, prefix + this
3693 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003694 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003695 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3696 + " during animation: policyVis=" + mPolicyVisibility
3697 + " parentHidden=" + isParentWindowHidden()
3698 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003699 + (mAppToken != null && mAppToken.hiddenRequested)
3700 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Jorim Jaggia5e10572017-11-15 14:36:26 +01003701 + " animationSet=" + mWinAnimator.isAnimationSet()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003702 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003703 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003704 + " Callers=" + Debug.getCallers(4));
3705 }
3706 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003707
3708 WindowInfo getWindowInfo() {
3709 WindowInfo windowInfo = WindowInfo.obtain();
3710 windowInfo.type = mAttrs.type;
3711 windowInfo.layer = mLayer;
3712 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003713 if (mAppToken != null) {
3714 windowInfo.activityToken = mAppToken.appToken.asBinder();
3715 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003716 windowInfo.title = mAttrs.accessibilityTitle;
3717 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3718 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003719 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003720 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003721
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003722 if (mIsChildWindow) {
3723 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003724 }
3725
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003726 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003727 if (childCount > 0) {
3728 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003729 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003730 }
3731 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003732 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003733 windowInfo.childTokens.add(child.mClient.asBinder());
3734 }
3735 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003736 return windowInfo;
3737 }
3738
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003739 int getHighestAnimLayer() {
3740 int highest = mWinAnimator.mAnimLayer;
3741 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003742 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003743 final int childLayer = c.getHighestAnimLayer();
3744 if (childLayer > highest) {
3745 highest = childLayer;
3746 }
3747 }
3748 return highest;
3749 }
3750
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003751 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003752 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003753 if (mChildren.isEmpty()) {
3754 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003755 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003756 }
3757
3758 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003759 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003760 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003761 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003762 }
3763 }
3764
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003765 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003766 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003767 // below the parent, then this window (the parent), and then the positive sublayer children
3768 // because they need to appear above the parent.
3769 int i = 0;
3770 final int count = mChildren.size();
3771 WindowState child = mChildren.get(i);
3772
3773 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003774 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003775 return true;
3776 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003777 i++;
3778 if (i >= count) {
3779 break;
3780 }
3781 child = mChildren.get(i);
3782 }
3783
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003784 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003785 return true;
3786 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003787
3788 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003789 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003790 return true;
3791 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003792 i++;
3793 if (i >= count) {
3794 break;
3795 }
3796 child = mChildren.get(i);
3797 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003798
3799 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003800 }
3801
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003802 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003803 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003804 // above the parent, then this window (the parent), and then the negative sublayer children
3805 // because they need to appear above the parent.
3806 int i = mChildren.size() - 1;
3807 WindowState child = mChildren.get(i);
3808
3809 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003810 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003811 return true;
3812 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003813 --i;
3814 if (i < 0) {
3815 break;
3816 }
3817 child = mChildren.get(i);
3818 }
3819
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003820 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003821 return true;
3822 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003823
3824 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003825 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003826 return true;
3827 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003828 --i;
3829 if (i < 0) {
3830 break;
3831 }
3832 child = mChildren.get(i);
3833 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003834
3835 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003836 }
3837
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003838 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3839 boolean traverseTopToBottom) {
3840 if (traverseTopToBottom) {
3841 if (mService.mInputMethodTarget == this) {
3842 // This window is the current IME target, so we need to process the IME windows
3843 // directly above it.
3844 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3845 return true;
3846 }
3847 }
3848 if (callback.apply(this)) {
3849 return true;
3850 }
3851 } else {
3852 if (callback.apply(this)) {
3853 return true;
3854 }
3855 if (mService.mInputMethodTarget == this) {
3856 // This window is the current IME target, so we need to process the IME windows
3857 // directly above it.
3858 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3859 return true;
3860 }
3861 }
3862 }
3863
3864 return false;
3865 }
3866
Wale Ogunwaled1880962016-11-08 10:31:59 -08003867 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003868 if (mChildren.isEmpty()) {
3869 return callback.test(this) ? this : null;
3870 }
3871
3872 // We want to consume the positive sublayer children first because they need to appear
3873 // above the parent, then this window (the parent), and then the negative sublayer children
3874 // because they need to appear above the parent.
3875 int i = mChildren.size() - 1;
3876 WindowState child = mChildren.get(i);
3877
3878 while (i >= 0 && child.mSubLayer >= 0) {
3879 if (callback.test(child)) {
3880 return child;
3881 }
3882 --i;
3883 if (i < 0) {
3884 break;
3885 }
3886 child = mChildren.get(i);
3887 }
3888
Wale Ogunwaled1880962016-11-08 10:31:59 -08003889 if (callback.test(this)) {
3890 return this;
3891 }
Wale Ogunwale34247952017-02-19 11:57:53 -08003892
3893 while (i >= 0) {
3894 if (callback.test(child)) {
3895 return child;
3896 }
3897 --i;
3898 if (i < 0) {
3899 break;
3900 }
3901 child = mChildren.get(i);
3902 }
3903
3904 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08003905 }
3906
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003907 void onExitAnimationDone() {
3908 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3909 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01003910 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003911
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003912 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003913 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003914 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003915 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003916 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003917 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003918 }
3919 }
3920
3921 if (mWinAnimator.mEnteringAnimation) {
3922 mWinAnimator.mEnteringAnimation = false;
3923 mService.requestTraversal();
3924 // System windows don't have an activity and an app token as a result, but need a way
3925 // to be informed about their entrance animation end.
3926 if (mAppToken == null) {
3927 try {
3928 mClient.dispatchWindowShown();
3929 } catch (RemoteException e) {
3930 }
3931 }
3932 }
3933
Jorim Jaggia5e10572017-11-15 14:36:26 +01003934 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003935 return;
3936 }
3937
Jorim Jaggia5e10572017-11-15 14:36:26 +01003938 //TODO (multidisplay): Accessibility is supported only for the default display.
3939 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3940 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3941 }
3942
3943 if (!mAnimatingExit) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003944 return;
3945 }
3946
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003947 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003948 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3949
3950 mDestroying = true;
3951
3952 final boolean hasSurface = mWinAnimator.hasSurface();
3953 if (hasSurface) {
3954 mWinAnimator.hide("onExitAnimationDone");
3955 }
3956
3957 // If we have an app token, we ask it to destroy the surface for us, so that it can take
3958 // care to ensure the activity has actually stopped and the surface is not still in use.
3959 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
3960 // transaction.
3961 if (mAppToken != null) {
3962 mAppToken.destroySurfaces();
3963 } else {
3964 if (hasSurface) {
3965 mService.mDestroySurface.add(this);
3966 }
3967 if (mRemoveOnExit) {
3968 mService.mPendingRemove.add(this);
3969 mRemoveOnExit = false;
3970 }
3971 }
3972 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07003973 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003974 }
Dan Willemsen117197f2016-07-30 13:02:59 -07003975
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003976 boolean clearAnimatingFlags() {
3977 boolean didSomething = false;
3978 // We don't want to clear it out for windows that get replaced, because the
3979 // animation depends on the flag to remove the replaced window.
3980 //
3981 // We also don't clear the mAnimatingExit flag for windows which have the
3982 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
3983 // by the client. We should let animation proceed and not clear this flag or
3984 // they won't eventually be removed by WindowStateAnimator#finishExit.
3985 if (!mWillReplaceWindow && !mRemoveOnExit) {
3986 // Clear mAnimating flag together with mAnimatingExit. When animation
3987 // changes from exiting to entering, we need to clear this flag until the
3988 // new animation gets applied, so that isAnimationStarting() becomes true
3989 // until then.
3990 // Otherwise applySurfaceChangesTransaction will fail to skip surface
3991 // placement for this window during this period, one or more frame will
3992 // show up with wrong position or scale.
3993 if (mAnimatingExit) {
3994 mAnimatingExit = false;
3995 didSomething = true;
3996 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003997 if (mDestroying) {
3998 mDestroying = false;
3999 mService.mDestroySurface.remove(this);
4000 didSomething = true;
4001 }
4002 }
4003
4004 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004005 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004006 }
4007
4008 return didSomething;
4009 }
4010
Winson4b4ba902016-07-27 19:45:52 -07004011 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004012 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004013 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004014
4015 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004016 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004017 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004018 c.hideWallpaperWindow(wasDeferred, reason);
4019 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004020 if (!mWinAnimator.mLastHidden || wasDeferred) {
4021 mWinAnimator.hide(reason);
4022 dispatchWallpaperVisibility(false);
4023 final DisplayContent displayContent = getDisplayContent();
4024 if (displayContent != null) {
4025 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4026 }
4027 }
4028 }
4029
4030 /**
4031 * Check wallpaper window for visibility change and notify window if so.
4032 * @param visible Current visibility.
4033 */
4034 void dispatchWallpaperVisibility(final boolean visible) {
4035 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004036 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004037
4038 // Only send notification if the visibility actually changed and we are not trying to hide
4039 // the wallpaper when we are deferring hiding of the wallpaper.
4040 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4041 mWallpaperVisible = visible;
4042 try {
4043 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4044 "Updating vis of wallpaper " + this
4045 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4046 mClient.dispatchAppVisibility(visible);
4047 } catch (RemoteException e) {
4048 }
4049 }
4050 }
4051
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004052 boolean hasVisibleNotDrawnWallpaper() {
4053 if (mWallpaperVisible && !isDrawnLw()) {
4054 return true;
4055 }
4056 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004057 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004058 if (c.hasVisibleNotDrawnWallpaper()) {
4059 return true;
4060 }
4061 }
4062 return false;
4063 }
4064
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004065 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4066 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004067 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004068 c.updateReportedVisibility(results);
4069 }
4070
4071 if (mAppFreezing || mViewVisibility != View.VISIBLE
4072 || mAttrs.type == TYPE_APPLICATION_STARTING
4073 || mDestroying) {
4074 return;
4075 }
4076 if (DEBUG_VISIBILITY) {
4077 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4078 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4079 if (!isDrawnLw()) {
4080 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4081 + " pv=" + mPolicyVisibility
4082 + " mDrawState=" + mWinAnimator.mDrawState
4083 + " ph=" + isParentWindowHidden()
4084 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggia5e10572017-11-15 14:36:26 +01004085 + " a=" + mWinAnimator.isAnimationSet());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004086 }
4087 }
4088
4089 results.numInteresting++;
4090 if (isDrawnLw()) {
4091 results.numDrawn++;
4092 if (!mWinAnimator.isAnimationSet()) {
4093 results.numVisible++;
4094 }
4095 results.nowGone = false;
4096 } else if (mWinAnimator.isAnimationSet()) {
4097 results.nowGone = false;
4098 }
4099 }
4100
Robert Carrfbbde852016-10-18 11:02:28 -07004101 /**
4102 * Calculate the window crop according to system decor policy. In general this is
4103 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4104 * special cases. This rectangle is in screen space.
4105 */
4106 void calculatePolicyCrop(Rect policyCrop) {
4107 final DisplayContent displayContent = getDisplayContent();
4108 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4109
4110 if (!isDefaultDisplay()) {
4111 // On a different display there is no system decor. Crop the window
4112 // by the screen boundaries.
4113 // TODO(multi-display)
4114 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4115 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4116 displayInfo.logicalWidth - mCompatFrame.left,
4117 displayInfo.logicalHeight - mCompatFrame.top);
Robert Carrfbbde852016-10-18 11:02:28 -07004118 } else if (mDecorFrame.isEmpty()) {
4119 // Windows without policy decor aren't cropped.
4120 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4121 } else {
4122 // Crop to the system decor specified by policy.
4123 calculateSystemDecorRect(policyCrop);
4124 }
4125 }
4126
4127 /**
4128 * The system decor rect is the region of the window which is not covered
4129 * by system decorations.
4130 */
4131 private void calculateSystemDecorRect(Rect systemDecorRect) {
4132 final Rect decorRect = mDecorFrame;
4133 final int width = mFrame.width();
4134 final int height = mFrame.height();
4135
4136 // Compute the offset of the window in relation to the decor rect.
4137 final int left = mXOffset + mFrame.left;
4138 final int top = mYOffset + mFrame.top;
4139
4140 // Initialize the decor rect to the entire frame.
4141 if (isDockedResizing()) {
4142 // If we are resizing with the divider, the task bounds might be smaller than the
4143 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4144 // want in this case in order to avoid holes.
4145 //
4146 // We take care to not shrink the width, for surfaces which are larger than
4147 // the display region. Of course this area will not eventually be visible
4148 // but if we truncate the width now, we will calculate incorrectly
4149 // when adjusting to the stack bounds.
4150 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4151 systemDecorRect.set(0, 0,
4152 Math.max(width, displayInfo.logicalWidth),
4153 Math.max(height, displayInfo.logicalHeight));
4154 } else {
4155 systemDecorRect.set(0, 0, width, height);
4156 }
4157
4158 // If a freeform window is animating from a position where it would be cutoff, it would be
4159 // cutoff during the animation. We don't want that, so for the duration of the animation
4160 // we ignore the decor cropping and depend on layering to position windows correctly.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004161 final boolean cropToDecor = !(inFreeformWindowingMode() && isAnimatingLw());
Robert Carrfbbde852016-10-18 11:02:28 -07004162 if (cropToDecor) {
4163 // Intersect with the decor rect, offsetted by window position.
4164 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4165 decorRect.right - left, decorRect.bottom - top);
4166 }
4167
4168 // If size compatibility is being applied to the window, the
4169 // surface is scaled relative to the screen. Also apply this
4170 // scaling to the crop rect. We aren't using the standard rect
4171 // scale function because we want to round things to make the crop
4172 // always round to a larger rect to ensure we don't crop too
4173 // much and hide part of the window that should be seen.
4174 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4175 final float scale = mInvGlobalScale;
4176 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4177 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4178 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4179 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4180 }
4181
4182 }
4183
4184 /**
4185 * Expand the given rectangle by this windows surface insets. This
4186 * takes you from the 'window size' to the 'surface size'.
4187 * The surface insets are positive in each direction, so we inset by
4188 * the inverse.
4189 */
4190 void expandForSurfaceInsets(Rect r) {
4191 r.inset(-mAttrs.surfaceInsets.left,
4192 -mAttrs.surfaceInsets.top,
4193 -mAttrs.surfaceInsets.right,
4194 -mAttrs.surfaceInsets.bottom);
4195 }
4196
Robert Carrc91d1c32017-02-15 19:37:46 -08004197 boolean surfaceInsetsChanging() {
4198 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4199 }
4200
Bryce Leef858b572017-06-29 14:03:33 -07004201 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004202 final boolean wasVisible = isVisibleLw();
4203
4204 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004205 if (mAnimatingExit) {
4206 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4207 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4208
4209 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4210 mAnimatingExit = false;
4211 }
4212 if (mDestroying) {
4213 mDestroying = false;
4214 mService.mDestroySurface.remove(this);
4215 }
4216 if (oldVisibility == View.GONE) {
4217 mWinAnimator.mEnterAnimationPending = true;
4218 }
4219
Andrii Kulian8ee72852017-03-10 10:36:45 -08004220 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004221
4222 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004223
Bryce Leef858b572017-06-29 14:03:33 -07004224 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004225
Robert Carrc91d1c32017-02-15 19:37:46 -08004226 if ((attrChanges & FORMAT_CHANGED) != 0) {
4227 // If the format can't be changed in place, preserve the old surface until the app draws
4228 // on the new one. This prevents blinking when we change elevation of freeform and
4229 // pinned windows.
4230 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4231 mWinAnimator.preserveSurfaceLocked();
4232 result |= RELAYOUT_RES_SURFACE_CHANGED
4233 | RELAYOUT_RES_FIRST_TIME;
4234 }
4235 }
4236
4237 // When we change the Surface size, in scenarios which may require changing
4238 // the surface position in sync with the resize, we use a preserved surface
4239 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004240 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4241 // stack since it can lead to issues if a new surface is created while calculating the
4242 // scale for the animation using the source hint rect
4243 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004244 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004245 || (surfaceInsetsChanging() && !inPinnedWindowingMode())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004246 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4247
4248 setDragResizing();
4249 setResizedWhileNotDragResizing(false);
4250 // We can only change top level windows to the full-screen surface when
4251 // resizing (as we only have one full-screen surface). So there is no need
4252 // to preserve and destroy windows which are attached to another, they
4253 // will keep their surface and its size may change over time.
4254 if (mHasSurface && !isChildWindow()) {
4255 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004256 result |= RELAYOUT_RES_SURFACE_CHANGED |
4257 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004258 }
4259 }
4260 final boolean freeformResizing = isDragResizing()
4261 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4262 final boolean dockedResizing = isDragResizing()
4263 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4264 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4265 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004266 return result;
4267 }
4268
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004269 /**
4270 * @return True if this window has been laid out at least once; false otherwise.
4271 */
4272 boolean isLaidOut() {
4273 return mLayoutSeq != -1;
4274 }
4275
4276 /**
4277 * Updates the last inset values to the current ones.
4278 */
4279 void updateLastInsetValues() {
4280 mLastOverscanInsets.set(mOverscanInsets);
4281 mLastContentInsets.set(mContentInsets);
4282 mLastVisibleInsets.set(mVisibleInsets);
4283 mLastStableInsets.set(mStableInsets);
4284 mLastOutsets.set(mOutsets);
Adrian Roos5c6b6222017-11-07 17:36:10 +01004285 mLastDisplayCutout = mDisplayCutout;
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004286 }
4287
Jorim Jaggia5e10572017-11-15 14:36:26 +01004288 void startAnimation(Animation anim) {
4289 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4290 anim.initialize(mFrame.width(), mFrame.height(),
4291 displayInfo.appWidth, displayInfo.appHeight);
4292 anim.restrictDuration(MAX_ANIMATION_DURATION);
4293 anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
4294 final AnimationAdapter adapter = new LocalAnimationAdapter(
4295 new WindowAnimationSpec(anim, mSurfacePosition), mService.mSurfaceAnimationRunner);
4296 startAnimation(mPendingTransaction, adapter);
4297 commitPendingTransaction();
4298 }
4299
4300 private void startMoveAnimation(Transaction t, int left, int top) {
4301 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004302 final Point oldPosition = new Point();
4303 final Point newPosition = new Point();
4304 transformFrameToSurfacePosition(mLastFrame.left, mLastFrame.top, oldPosition);
4305 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004306 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004307 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004308 mService.mSurfaceAnimationRunner);
4309 startAnimation(t, adapter);
4310 }
4311
4312 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4313 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4314 }
4315
4316 @Override
4317 protected void onAnimationFinished() {
4318 mWinAnimator.onAnimationFinished();
4319 }
4320
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004321 /**
4322 * Retrieves the current transformation matrix of the window, relative to the display.
4323 *
4324 * @param float9 A temporary array of 9 floats.
4325 * @param outMatrix Matrix to fill in the transformation.
4326 */
4327 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4328 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4329 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4330 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4331 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
4332 float9[Matrix.MTRANS_X] = mSurfacePosition.x + mShownPosition.x;
4333 float9[Matrix.MTRANS_Y] = mSurfacePosition.y + mShownPosition.y;
4334 float9[Matrix.MPERSP_0] = 0;
4335 float9[Matrix.MPERSP_1] = 0;
4336 float9[Matrix.MPERSP_2] = 1;
4337 outMatrix.setValues(float9);
4338 }
4339
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004340 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4341 // access to its windows children. Need to investigate re-writing
4342 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4343 static final class UpdateReportedVisibilityResults {
4344 int numInteresting;
4345 int numVisible;
4346 int numDrawn;
4347 boolean nowGone = true;
4348
4349 void reset() {
4350 numInteresting = 0;
4351 numVisible = 0;
4352 numDrawn = 0;
4353 nowGone = true;
4354 }
4355 }
Robert Carraf422a82017-04-10 18:34:33 -07004356
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004357 private static final class WindowId extends IWindowId.Stub {
4358 private final WeakReference<WindowState> mOuter;
4359
4360 private WindowId(WindowState outer) {
4361
4362 // Use a weak reference for the outer class. This is important to prevent the following
4363 // leak: Since we send this class to the client process, binder will keep it alive as
4364 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4365 // out our reference so even though this class is kept alive we don't leak WindowState,
4366 // which can keep a whole lot of classes alive.
4367 mOuter = new WeakReference<>(outer);
4368 }
4369
4370 @Override
4371 public void registerFocusObserver(IWindowFocusObserver observer) {
4372 final WindowState outer = mOuter.get();
4373 if (outer != null) {
4374 outer.registerFocusObserver(observer);
4375 }
4376 }
4377 @Override
4378 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4379 final WindowState outer = mOuter.get();
4380 if (outer != null) {
4381 outer.unregisterFocusObserver(observer);
4382 }
4383 }
4384 @Override
4385 public boolean isFocused() {
4386 final WindowState outer = mOuter.get();
4387 return outer != null && outer.isFocused();
4388 }
4389 }
4390
Robert Carrb1579c82017-09-05 14:54:47 -07004391
4392 @Override
4393 boolean shouldMagnify() {
4394 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004395 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4396 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4397 mAttrs.type == TYPE_NAVIGATION_BAR ||
4398 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4399 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
4400 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL ||
4401 mAttrs.type == TYPE_STATUS_BAR) {
Robert Carrb1579c82017-09-05 14:54:47 -07004402 return false;
4403 }
4404 return true;
4405 }
4406
4407 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004408 SurfaceSession getSession() {
4409 if (mSession.mSurfaceSession != null) {
4410 return mSession.mSurfaceSession;
4411 } else {
4412 return getParent().getSession();
4413 }
4414 }
4415
4416 @Override
4417 boolean needsZBoost() {
4418 return getAnimLayerAdjustment() > 0 || mWillReplaceWindow;
4419 }
4420
Robert Carrf07ef9e2017-11-21 12:12:49 -08004421 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004422 if (!mAnimatingExit && mAppDied) {
4423 mIsDimming = true;
4424 getDimmer().dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
4425 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
4426 && !mAnimatingExit && isVisible()) {
4427 mIsDimming = true;
4428 getDimmer().dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
4429 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004430 }
4431
4432 @Override
4433 void prepareSurfaces() {
4434 final Dimmer dimmer = getDimmer();
4435 mIsDimming = false;
4436 if (dimmer != null) {
4437 applyDims(dimmer);
4438 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004439
Jorim Jaggia5e10572017-11-15 14:36:26 +01004440 updateSurfacePosition(mPendingTransaction);
4441
Robert Carrb1579c82017-09-05 14:54:47 -07004442 mWinAnimator.prepareSurfaceLocked(true);
4443 super.prepareSurfaces();
4444 }
4445
4446 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004447 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4448 super.onAnimationLeashCreated(t, leash);
4449
4450 // Leash is now responsible for position, so set our position to 0.
4451 t.setPosition(mSurfaceControl, 0, 0);
4452 }
4453
4454 @Override
4455 public void onAnimationLeashDestroyed(Transaction t) {
4456 super.onAnimationLeashDestroyed(t);
4457 updateSurfacePosition(t);
4458 }
4459
4460 void updateSurfacePosition(Transaction t) {
4461 if (mSurfaceControl == null) {
4462 return;
4463 }
4464
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004465 transformFrameToSurfacePosition(mFrame.left, mFrame.top, mSurfacePosition);
4466 if (!mSurfaceAnimator.hasLeash()) {
4467 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
4468 }
4469 }
4470
4471 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4472 outPoint.set(left, top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004473 if (isChildWindow()) {
4474 // TODO: This probably falls apart at some point and we should
4475 // actually compute relative coordinates.
4476 final WindowState parent = getParentWindow();
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004477 outPoint.offset(-parent.mFrame.left, -parent.mFrame.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004478 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004479
4480 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004481 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004482 }
4483
4484 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004485 void assignLayer(Transaction t, int layer) {
4486 // See comment in assignRelativeLayerForImeTargetChild
4487 if (!isChildWindow()
4488 || (mService.mInputMethodTarget != getParentWindow())
4489 || !inSplitScreenWindowingMode()) {
4490 super.assignLayer(t, layer);
4491 return;
4492 }
4493 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
4494 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004495
4496 @Override
4497 public boolean isDimming() {
4498 return mIsDimming;
4499 }
Robert Carr0eff1872017-12-01 14:27:04 -08004500
4501 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4502 // then we can drop all negative layering on the windowing side and simply inherit
4503 // the default implementation here.
4504 public void assignChildLayers(Transaction t) {
4505 int layer = 1;
4506 for (int i = 0; i < mChildren.size(); i++) {
4507 final WindowState w = mChildren.get(i);
4508
4509 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4510 // while they both need to go below the main window. However the
4511 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4512 // been defined and so we can use static layers and leave it that way.
4513 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4514 w.assignLayer(t, -2);
4515 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4516 w.assignLayer(t, -1);
4517 } else {
4518 w.assignLayer(t, layer);
4519 }
4520 w.assignChildLayers(t);
4521 layer++;
4522 }
4523 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004524
4525 private final class MoveAnimationSpec implements AnimationSpec {
4526
4527 private final long mDuration;
4528 private Interpolator mInterpolator;
4529 private Point mFrom = new Point();
4530 private Point mTo = new Point();
4531
4532 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4533 final Animation anim = AnimationUtils.loadAnimation(mContext,
4534 com.android.internal.R.anim.window_move_from_decor);
4535 mDuration = anim.computeDurationHint();
4536 mInterpolator = anim.getInterpolator();
4537 mFrom.set(fromX, fromY);
4538 mTo.set(toX, toY);
4539 }
4540
4541 @Override
4542 public long getDuration() {
4543 return mDuration;
4544 }
4545
4546 @Override
4547 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4548 final float fraction = (float) currentPlayTime / getDuration();
4549 final float v = mInterpolator.getInterpolation(fraction);
4550 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4551 mFrom.y + (mTo.y - mFrom.y) * v);
4552 }
4553 }
satokcef37fb2011-10-24 21:49:38 +09004554}