blob: 337db1b066f869c2c59e87c0525bc96d47373fb7 [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() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001435 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
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() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001444 return (!mToken.isHidden() || 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 Jaggif5f9e122017-10-24 18:21:09 +02001482 || mWinAnimator.isAnimationSet());
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
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001504 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001505 }
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
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001516 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.isHidden())
1517 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001518 }
1519
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001520 // TODO: Another visibility method that was added late in the release to minimize risk.
1521 @Override
1522 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001523 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001524 if (mAppToken == null) {
1525 final boolean shown = mWinAnimator.getShown();
1526 final boolean exiting = mAnimatingExit || mDestroying;
1527 return shown && !exiting && !translucent;
1528 } else {
1529 return !mAppToken.isHidden();
1530 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001531 }
1532
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001533 /**
1534 * Like isOnScreen, but returns false if the surface hasn't yet
1535 * been drawn.
1536 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001537 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001538 public boolean isDisplayedLw() {
1539 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001540 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001541 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
1542 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001543 }
1544
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001545 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001546 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001547 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001548 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001549 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001550 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001551 }
1552
Craig Mautner812d2ca2012-09-27 15:35:34 -07001553 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001554 public boolean isGoneForLayoutLw() {
1555 final AppWindowToken atoken = mAppToken;
1556 return mViewVisibility == View.GONE
1557 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001558 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001559 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001560 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001561 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001562 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001563 }
1564
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001565 /**
1566 * Returns true if the window has a surface that it has drawn a
1567 * complete UI in to.
1568 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001569 public boolean isDrawFinishedLw() {
1570 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001571 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1572 || mWinAnimator.mDrawState == READY_TO_SHOW
1573 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001574 }
1575
1576 /**
1577 * Returns true if the window has a surface that it has drawn a
1578 * complete UI in to.
1579 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001580 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001581 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001582 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001583 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001584 }
1585
1586 /**
1587 * Return true if the window is opaque and fully drawn. This indicates
1588 * it may obscure windows behind it.
1589 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001590 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001591 // When there is keyguard, wallpaper could be placed over the secure app
1592 // window but invisible. We need to check wallpaper visibility explicitly
1593 // to determine if it's occluding apps.
1594 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1595 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001596 && isDrawnLw() && !mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001597 }
1598
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001599 @Override
1600 void onMovedByResize() {
1601 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001602 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001603 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001604 }
1605
1606 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1607 boolean changed = false;
1608
1609 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001610 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001611 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1612 }
1613
1614 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1615 // Starting window that's exiting will be removed when the animation finishes.
1616 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1617 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001618 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001619 mAnimatingExit = true;
1620 mRemoveOnExit = true;
1621 mWindowRemovalAllowed = true;
1622 }
1623 return changed;
1624 }
1625
Robert Carrd5c7dd62017-03-08 10:39:30 -08001626 // Next up we will notify the client that it's visibility has changed.
1627 // We need to prevent it from destroying child surfaces until
1628 // the animation has finished.
1629 if (!visible && isVisibleNow()) {
1630 mWinAnimator.detachChildren();
1631 }
1632
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001633 if (visible != isVisibleNow()) {
1634 if (!runningAppAnimation) {
1635 final AccessibilityController accessibilityController =
1636 mService.mAccessibilityController;
1637 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1638 mWinAnimator.applyAnimationLocked(winTransit, visible);
1639 //TODO (multidisplay): Magnification is supported only for the default
1640 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1641 accessibilityController.onWindowTransitionLocked(this, winTransit);
1642 }
1643 }
1644 changed = true;
1645 setDisplayLayoutNeeded();
1646 }
1647
1648 return changed;
1649 }
1650
1651 boolean onSetAppExiting() {
1652 final DisplayContent displayContent = getDisplayContent();
1653 boolean changed = false;
1654
1655 if (isVisibleNow()) {
1656 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1657 //TODO (multidisplay): Magnification is supported only for the default
1658 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1659 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1660 }
1661 changed = true;
1662 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001663 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001664 }
1665 }
1666
1667 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001668 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001669 changed |= c.onSetAppExiting();
1670 }
1671
1672 return changed;
1673 }
1674
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001675 @Override
1676 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001677 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1678 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001679 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001680 resizingWindows.add(this);
1681
1682 // If we are not drag resizing, force recreating of a new surface so updating
1683 // the content and positioning that surface will be in sync.
1684 //
1685 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1686 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1687 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1688 // their frame to update crop, etc...
1689 //
1690 // Anyway we don't need to synchronize position and content updates for these
1691 // windows since they aren't at the base layer and could be moved around anyway.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001692 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION
1693 && !mWinAnimator.isForceScaled() && !isGoneForLayoutLw()
1694 && !getTask().inPinnedWindowingMode()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001695 setResizedWhileNotDragResizing(true);
1696 }
1697 }
1698 if (isGoneForLayoutLw()) {
1699 mResizedWhileGone = true;
1700 }
1701
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001702 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001703 }
1704
1705 void onUnfreezeBounds() {
1706 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001707 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001708 c.onUnfreezeBounds();
1709 }
1710
1711 if (!mHasSurface) {
1712 return;
1713 }
1714
1715 mLayoutNeeded = true;
1716 setDisplayLayoutNeeded();
1717 if (!mService.mResizingWindows.contains(this)) {
1718 mService.mResizingWindows.add(this);
1719 }
1720 }
1721
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001722 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001723 * If the window has moved due to its containing content frame changing, then notify the
1724 * listeners and optionally animate it. Simply checking a change of position is not enough,
1725 * because being move due to dock divider is not a trigger for animation.
1726 */
Jorim Jaggia5e10572017-11-15 14:36:26 +01001727 void handleWindowMovedIfNeeded(Transaction t) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001728 if (!hasMoved()) {
1729 return;
1730 }
1731
1732 // Frame has moved, containing content frame has also moved, and we're not currently
1733 // animating... let's do something.
1734 final int left = mFrame.left;
1735 final int top = mFrame.top;
1736 final Task task = getTask();
1737 final boolean adjustedForMinimizedDockOrIme = task != null
1738 && (task.mStack.isAdjustedForMinimizedDockedStack()
1739 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001740 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001741 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1742 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001743 && getWindowConfiguration().hasMovementAnimations()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001744 && !mWinAnimator.mLastHidden) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001745 startMoveAnimation(t, left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001746 }
1747
1748 //TODO (multidisplay): Accessibility supported only for the default display.
1749 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001750 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001751 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1752 }
1753
1754 try {
1755 mClient.moved(left, top);
1756 } catch (RemoteException e) {
1757 }
1758 mMovedByResize = false;
1759 }
1760
1761 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001762 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001763 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1764 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001765 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001766 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001767 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001768 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001769 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001770 }
1771
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001772 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001773 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001774 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001775 return false;
1776 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001777 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001778 }
1779
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001780 boolean fillsDisplay() {
1781 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001782 return mFrame.left <= 0 && mFrame.top <= 0
1783 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001784 }
1785
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001786 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001787 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001788 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001789 }
1790
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001791 void onWindowReplacementTimeout() {
1792 if (mWillReplaceWindow) {
1793 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001794 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001795 // delays removal on certain conditions, which will leave the stale window in the
1796 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1797 //
1798 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001799 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001800 } else {
1801 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001802 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001803 c.onWindowReplacementTimeout();
1804 }
1805 }
1806 }
1807
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001808 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001809 void forceWindowsScaleableInTransaction(boolean force) {
1810 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1811 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1812 }
1813
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001814 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001815 }
1816
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001817 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001818 void removeImmediately() {
1819 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001820
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001821 if (mRemoved) {
1822 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001823 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1824 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001825 return;
1826 }
1827
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001828 mRemoved = true;
1829
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001830 mWillReplaceWindow = false;
1831 if (mReplacementWindow != null) {
1832 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1833 }
1834
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001835 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001836 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001837 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001838 }
1839
1840 final int type = mAttrs.type;
1841 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001842 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001843 }
1844 mPolicy.removeWindowLw(this);
1845
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001846 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001847
Craig Mautner96868332012-12-04 14:29:11 -08001848 mWinAnimator.destroyDeferredSurfaceLocked();
1849 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001850 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001851 try {
1852 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1853 } catch (RuntimeException e) {
1854 // Ignore if it has already been removed (usually because
1855 // we are doing this as part of processing a death note.)
1856 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001857
1858 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001859 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001860
Wale Ogunwale571771c2016-08-26 13:18:50 -07001861 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001862 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001863 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001864 removeIfPossible(false /*keepVisibleDeadWindow*/);
1865 }
1866
Wale Ogunwale571771c2016-08-26 13:18:50 -07001867 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001868 mWindowRemovalAllowed = true;
1869 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1870 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1871
1872 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1873 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1874 "Starting window removed " + this);
1875
1876 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1877 Slog.v(TAG_WM, "Remove " + this + " client="
1878 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1879 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1880 + Debug.getCallers(5));
1881
1882 final long origId = Binder.clearCallingIdentity();
1883
Peter Visontay3556a3b2017-11-01 17:23:17 +00001884 try {
1885 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001886
Peter Visontay3556a3b2017-11-01 17:23:17 +00001887 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1888 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1889 + " mAnimatingExit=" + mAnimatingExit
1890 + " mRemoveOnExit=" + mRemoveOnExit
1891 + " mHasSurface=" + mHasSurface
1892 + " surfaceShowing=" + mWinAnimator.getShown()
1893 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1894 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001895 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001896 + " mWillReplaceWindow=" + mWillReplaceWindow
1897 + " inPendingTransaction="
1898 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1899 + " mDisplayFrozen=" + mService.mDisplayFrozen
1900 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001901
Peter Visontay3556a3b2017-11-01 17:23:17 +00001902 // Visibility of the removed window. Will be used later to update orientation later on.
1903 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001904
Peter Visontay3556a3b2017-11-01 17:23:17 +00001905 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001906
Peter Visontay3556a3b2017-11-01 17:23:17 +00001907 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1908 // window until the animation is done. If the display is frozen, just remove immediately,
1909 // since the animation wouldn't be seen.
1910 if (mHasSurface && mToken.okToAnimate()) {
1911 if (mWillReplaceWindow) {
1912 // This window is going to be replaced. We need to keep it around until the new one
1913 // gets added, then we will get rid of this one.
1914 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1915 "Preserving " + this + " until the new one is " + "added");
1916 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1917 // been removed. We probably need another flag to indicate that window removal
1918 // should be deffered vs. overloading the flag that says we are playing an exit
1919 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001920 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001921 mReplacingRemoveRequested = true;
1922 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001923 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001924
Peter Visontay3556a3b2017-11-01 17:23:17 +00001925 // If we are not currently running the exit animation, we need to see about starting one
1926 wasVisible = isWinVisibleLw();
1927
1928 if (keepVisibleDeadWindow) {
1929 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1930 "Not removing " + this + " because app died while it's visible");
1931
1932 mAppDied = true;
1933 setDisplayLayoutNeeded();
1934 mService.mWindowPlacerLocked.performSurfacePlacement();
1935
1936 // Set up a replacement input channel since the app is now dead.
1937 // We need to catch tapping on the dead window to restart the app.
1938 openInputChannel(null);
1939 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1940 return;
1941 }
1942
1943 if (wasVisible) {
1944 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1945
1946 // Try starting an animation.
1947 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1948 mAnimatingExit = true;
1949 }
1950 //TODO (multidisplay): Magnification is supported only for the default display.
1951 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
1952 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1953 }
1954 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001955 final boolean isAnimating = mWinAnimator.isAnimationSet()
1956 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00001957 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1958 && mAppToken.isLastWindow(this);
1959 // We delay the removal of a window if it has a showing surface that can be used to run
1960 // exit animation and it is marked as exiting.
1961 // Also, If isn't the an animating starting window that is the last window in the app.
1962 // We allow the removal of the non-animating starting window now as there is no
1963 // additional window or animation that will trigger its removal.
1964 if (mWinAnimator.getShown() && mAnimatingExit
1965 && (!lastWindowIsStartingWindow || isAnimating)) {
1966 // The exit animation is running or should run... wait for it!
1967 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1968 "Not removing " + this + " due to exit animation ");
1969 setupWindowForRemoveOnExit();
1970 if (mAppToken != null) {
1971 mAppToken.updateReportedVisibilityLocked();
1972 }
1973 return;
1974 }
1975 }
1976
1977 removeImmediately();
1978 // Removing a visible window will effect the computed orientation
1979 // So just update orientation if needed.
1980 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1981 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
1982 }
1983 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1984 } finally {
1985 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001986 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001987 }
1988
1989 private void setupWindowForRemoveOnExit() {
1990 mRemoveOnExit = true;
1991 setDisplayLayoutNeeded();
1992 // Request a focus update as this window's input channel is already gone. Otherwise
1993 // we could have no focused window in input manager.
1994 final boolean focusChanged = mService.updateFocusedWindowLocked(
1995 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1996 mService.mWindowPlacerLocked.performSurfacePlacement();
1997 if (focusChanged) {
1998 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1999 }
2000 }
2001
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002002 void setHasSurface(boolean hasSurface) {
2003 mHasSurface = hasSurface;
2004 }
2005
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002006 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002007 if (mIsImWindow) {
2008 // IME windows can't be IME targets. IME targets are required to be below the IME
2009 // windows and that wouldn't be possible if the IME window is its own target...silly.
2010 return false;
2011 }
2012
Winson Chung3d0a74a2017-07-12 12:37:19 -07002013 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002014 if (!windowsAreFocusable) {
2015 // This window can't be an IME target if the app's windows should not be focusable.
2016 return false;
2017 }
2018
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002019 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002020 final int type = mAttrs.type;
2021
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002022 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2023 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002024 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2025 && type != TYPE_APPLICATION_STARTING) {
2026 return false;
2027 }
2028
2029 if (DEBUG_INPUT_METHOD) {
2030 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2031 if (!isVisibleOrAdding()) {
2032 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2033 + " relayoutCalled=" + mRelayoutCalled
2034 + " viewVis=" + mViewVisibility
2035 + " policyVis=" + mPolicyVisibility
2036 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2037 + " parentHidden=" + isParentWindowHidden()
2038 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2039 if (mAppToken != null) {
2040 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2041 }
2042 }
2043 }
2044 return isVisibleOrAdding();
2045 }
2046
Chong Zhangacf11402015-11-04 16:23:10 -08002047 private final class DeadWindowEventReceiver extends InputEventReceiver {
2048 DeadWindowEventReceiver(InputChannel inputChannel) {
2049 super(inputChannel, mService.mH.getLooper());
2050 }
2051 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002052 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002053 finishInputEvent(event, true);
2054 }
2055 }
2056 /**
2057 * Dummy event receiver for windows that died visible.
2058 */
2059 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2060
Chong Zhang112eb8c2015-11-02 11:17:00 -08002061 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002062 if (mInputChannel != null) {
2063 throw new IllegalStateException("Window already has an input channel.");
2064 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002065 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002066 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2067 mInputChannel = inputChannels[0];
2068 mClientChannel = inputChannels[1];
2069 mInputWindowHandle.inputChannel = inputChannels[0];
2070 if (outInputChannel != null) {
2071 mClientChannel.transferTo(outInputChannel);
2072 mClientChannel.dispose();
2073 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002074 } else {
2075 // If the window died visible, we setup a dummy input channel, so that taps
2076 // can still detected by input monitor channel, and we can relaunch the app.
2077 // Create dummy event receiver that simply reports all events as handled.
2078 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002079 }
2080 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002081 }
2082
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002083 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002084 if (mDeadWindowEventReceiver != null) {
2085 mDeadWindowEventReceiver.dispose();
2086 mDeadWindowEventReceiver = null;
2087 }
2088
2089 // unregister server channel first otherwise it complains about broken channel
2090 if (mInputChannel != null) {
2091 mService.mInputManager.unregisterInputChannel(mInputChannel);
2092 mInputChannel.dispose();
2093 mInputChannel = null;
2094 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002095 if (mClientChannel != null) {
2096 mClientChannel.dispose();
2097 mClientChannel = null;
2098 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002099 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002100 }
2101
Robert Carrf59b8dd2017-10-02 18:58:36 -07002102 private Dimmer getDimmer() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002103 Task task = getTask();
2104 if (task != null) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002105 return task.getDimmer();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002106 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08002107 TaskStack taskStack = getStack();
2108 if (taskStack != null) {
2109 return taskStack.getDimmer();
2110 }
2111 return null;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002112 }
2113
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002114 /** Returns true if the replacement window was removed. */
2115 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2116 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2117 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2118 removeReplacedWindow();
2119 return true;
2120 }
2121
2122 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002123 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002124 if (c.removeReplacedWindowIfNeeded(replacement)) {
2125 return true;
2126 }
2127 }
2128 return false;
2129 }
2130
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002131 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002132 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002133 mWillReplaceWindow = false;
2134 mAnimateReplacingWindow = false;
2135 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002136 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002137 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002138 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002139 }
2140 }
2141
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002142 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2143 boolean replacementSet = false;
2144
2145 if (mWillReplaceWindow && mReplacementWindow == null
2146 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2147
2148 mReplacementWindow = replacementCandidate;
2149 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2150 replacementSet = true;
2151 }
2152
2153 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002154 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002155 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2156 }
2157
2158 return replacementSet;
2159 }
2160
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002161 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002162 final DisplayContent dc = getDisplayContent();
2163 if (dc != null) {
2164 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002165 }
2166 }
2167
Chong Zhang5117e272016-05-03 12:47:34 -07002168 void applyAdjustForImeIfNeeded() {
2169 final Task task = getTask();
2170 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2171 task.mStack.applyAdjustForImeIfNeeded(task);
2172 }
2173 }
2174
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002175 @Override
2176 void switchUser() {
2177 super.switchUser();
2178 if (isHiddenFromUserLocked()) {
2179 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2180 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2181 hideLw(false);
2182 }
2183 }
2184
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002185 int getTouchableRegion(Region region, int flags) {
2186 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002187 if (modal && mAppToken != null) {
2188 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002189 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002190 // If this is a modal window we need to dismiss it if it's not full screen and the
2191 // touch happens outside of the frame that displays the content. This means we
2192 // need to intercept touches outside of that window. The dim layer user
2193 // associated with the window (task or stack) will give us the good bounds, as
2194 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002195 final Task task = getTask();
2196 if (task != null) {
2197 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002198 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002199 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002200 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002201 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002202 // For freeform windows we the touch region to include the whole surface for the
2203 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002204 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2205 final int delta = WindowManagerService.dipToPixel(
2206 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2207 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002208 }
2209 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002210 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002211 } else {
2212 // Not modal or full screen modal
2213 getTouchableRegion(region);
2214 }
2215 return flags;
2216 }
2217
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002218 void checkPolicyVisibilityChange() {
2219 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2220 if (DEBUG_VISIBILITY) {
2221 Slog.v(TAG, "Policy visibility changing after anim in " +
2222 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2223 }
2224 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002225 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002226 mWinAnimator.hide("checkPolicyVisibilityChange");
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002227 if (mService.mCurrentFocus == this) {
2228 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2229 "setAnimationLocked: setting mFocusMayChange true");
2230 mService.mFocusMayChange = true;
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002231 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002232 }
2233 // Window is no longer visible -- make sure if we were waiting
2234 // for it to be displayed before enabling the display, that
2235 // we allow the display to be enabled now.
2236 mService.enableScreenIfNeededLocked();
2237 }
2238 }
2239 }
2240
2241 void setRequestedSize(int requestedWidth, int requestedHeight) {
2242 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2243 mLayoutNeeded = true;
2244 mRequestedWidth = requestedWidth;
2245 mRequestedHeight = requestedHeight;
2246 }
2247 }
2248
Bryce Leef858b572017-06-29 14:03:33 -07002249 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002250 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002251 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2252 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2253 mTurnOnScreen = true;
2254 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002255
2256 // If we were already visible, skip rest of preparation.
2257 if (wasVisible) {
2258 if (DEBUG_VISIBILITY) Slog.v(TAG,
2259 "Already visible and does not turn on screen, skip preparing: " + this);
2260 return;
2261 }
2262
2263 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2264 == SOFT_INPUT_ADJUST_RESIZE) {
2265 mLayoutNeeded = true;
2266 }
2267
David Stevens9440dc82017-03-16 19:00:20 -07002268 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002269 mWinAnimator.applyEnterAnimationLocked();
2270 }
Bryce Leef858b572017-06-29 14:03:33 -07002271 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002272
Bryce Leef858b572017-06-29 14:03:33 -07002273 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2274 final Configuration globalConfig = mService.mRoot.getConfiguration();
2275 final Configuration overrideConfig = getMergedOverrideConfiguration();
2276 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2277 }
2278
Bryce Lee2b17afd2017-09-21 10:38:20 -07002279 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2280 mLastReportedConfiguration.setTo(config);
2281 }
2282
2283 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2284 config.setTo(mLastReportedConfiguration);
2285 }
2286
2287 private Configuration getLastReportedConfiguration() {
2288 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002289 }
2290
2291 void adjustStartingWindowFlags() {
2292 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2293 && mAppToken.startingWindow != null) {
2294 // Special handling of starting window over the base
2295 // window of the app: propagate lock screen flags to it,
2296 // to provide the correct semantics while starting.
2297 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2298 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2299 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2300 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2301 }
2302 }
2303
2304 void setWindowScale(int requestedWidth, int requestedHeight) {
2305 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2306
2307 if (scaledWindow) {
2308 // requested{Width|Height} Surface's physical size
2309 // attrs.{width|height} Size on screen
2310 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2311 mHScale = (mAttrs.width != requestedWidth) ?
2312 (mAttrs.width / (float)requestedWidth) : 1.0f;
2313 mVScale = (mAttrs.height != requestedHeight) ?
2314 (mAttrs.height / (float)requestedHeight) : 1.0f;
2315 } else {
2316 mHScale = mVScale = 1;
2317 }
2318 }
2319
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002320 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002321 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002322 public void binderDied() {
2323 try {
2324 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002325 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002326 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002327 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002328 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002329 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2330 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2331 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002332 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002333 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2334 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002335 // just in case they have the divider at an unstable position. Better
2336 // also reset drag resizing state, because the owner can't do it
2337 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002338 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002339 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002340 if (stack != null) {
2341 stack.resetDockedStackToMiddle();
2342 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002343 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002344 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002345 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002346 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002347 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002348 }
2349 }
2350 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002351 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002352 }
2353 }
2354 }
2355
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002356 /**
2357 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2358 * because we want to preserve its location on screen to be re-activated later when the user
2359 * interacts with it.
2360 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002361 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002362 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002363 // Not a visible app window or the app isn't dead.
2364 return false;
2365 }
2366
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002367 if (mAttrs.token != mClient.asBinder()) {
2368 // The window was add by a client using another client's app token. We don't want to
2369 // keep the dead window around for this case since this is meant for 'real' apps.
2370 return false;
2371 }
2372
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002373 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2374 // We don't keep starting windows since they were added by the window manager before
2375 // the app even launched.
2376 return false;
2377 }
2378
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002379 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002380 }
2381
Wale Ogunwaled045c822015-12-02 09:14:28 -08002382 /** @return true if this window desires key events. */
2383 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002384 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002385 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002386 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002387 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002388 && !canReceiveTouchInput();
2389 }
2390
2391 /** @return true if this window desires touch events. */
2392 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002393 return mAppToken != null && mAppToken.getTask() != null
2394 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002395 }
2396
Craig Mautner749a7bb2012-04-02 13:49:53 -07002397 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002398 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002399 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002400 }
2401
Craig Mautner749a7bb2012-04-02 13:49:53 -07002402 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002403 public boolean showLw(boolean doAnimation) {
2404 return showLw(doAnimation, true);
2405 }
2406
2407 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002408 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002409 return false;
2410 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002411 if (!mAppOpVisibility) {
2412 // Being hidden due to app op request.
2413 return false;
2414 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002415 if (mPermanentlyHidden) {
2416 // Permanently hidden until the app exists as apps aren't prepared
2417 // to handle their windows being removed from under them.
2418 return false;
2419 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002420 if (mForceHideNonSystemOverlayWindow) {
2421 // This is an alert window that is currently force hidden.
2422 return false;
2423 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002424 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002425 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002426 return false;
2427 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002428 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002429 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002430 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggia5e10572017-11-15 14:36:26 +01002431 + mPolicyVisibility + " isAnimationSet=" + mWinAnimator.isAnimationSet());
David Stevens9440dc82017-03-16 19:00:20 -07002432 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002433 doAnimation = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +01002434 } else if (mPolicyVisibility && !mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002435 // Check for the case where we are currently visible and
2436 // not animating; we do not want to do animation at such a
2437 // point to become visible when we already are.
2438 doAnimation = false;
2439 }
2440 }
2441 mPolicyVisibility = true;
2442 mPolicyVisibilityAfterAnim = true;
2443 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002444 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002445 }
2446 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002447 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002448 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002449 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2450 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2451 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002452 return true;
2453 }
2454
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002455 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002456 public boolean hideLw(boolean doAnimation) {
2457 return hideLw(doAnimation, true);
2458 }
2459
2460 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2461 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002462 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002463 doAnimation = false;
2464 }
2465 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002466 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002467 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002468 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002469 return false;
2470 }
2471 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002472 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggia5e10572017-11-15 14:36:26 +01002473 if (!mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002474 doAnimation = false;
2475 }
2476 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002477 mPolicyVisibilityAfterAnim = false;
2478 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002479 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002480 mPolicyVisibility = false;
2481 // Window is no longer visible -- make sure if we were waiting
2482 // for it to be displayed before enabling the display, that
2483 // we allow the display to be enabled now.
2484 mService.enableScreenIfNeededLocked();
2485 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002486 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002487 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002488 mService.mFocusMayChange = true;
2489 }
2490 }
2491 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002492 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002493 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002494 if (mService.mCurrentFocus == this) {
2495 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2496 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002497 return true;
2498 }
2499
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002500 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2501 if (mOwnerCanAddInternalSystemWindow
2502 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2503 return;
2504 }
2505 if (mForceHideNonSystemOverlayWindow == forceHide) {
2506 return;
2507 }
2508 mForceHideNonSystemOverlayWindow = forceHide;
2509 if (forceHide) {
2510 hideLw(true /* doAnimation */, true /* requestAnim */);
2511 } else {
2512 showLw(true /* doAnimation */, true /* requestAnim */);
2513 }
2514 }
2515
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002516 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002517 if (mAppOpVisibility != state) {
2518 mAppOpVisibility = state;
2519 if (state) {
2520 // If the policy visibility had last been to hide, then this
2521 // will incorrectly show at this point since we lost that
2522 // information. Not a big deal -- for the windows that have app
2523 // ops modifies they should only be hidden by policy due to the
2524 // lock screen, and the user won't be changing this if locked.
2525 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002526 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002527 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002528 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002529 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002530 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002531 }
2532
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002533 public void hidePermanentlyLw() {
2534 if (!mPermanentlyHidden) {
2535 mPermanentlyHidden = true;
2536 hideLw(true, true);
2537 }
2538 }
2539
Jeff Brownc2932a12014-11-20 18:04:05 -08002540 public void pokeDrawLockLw(long timeout) {
2541 if (isVisibleOrAdding()) {
2542 if (mDrawLock == null) {
2543 // We want the tag name to be somewhat stable so that it is easier to correlate
2544 // in wake lock statistics. So in particular, we don't want to include the
2545 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002546 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002547 mDrawLock = mService.mPowerManager.newWakeLock(
2548 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2549 mDrawLock.setReferenceCounted(false);
2550 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2551 }
2552 // Each call to acquire resets the timeout.
2553 if (DEBUG_POWER) {
2554 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2555 + mAttrs.packageName);
2556 }
2557 mDrawLock.acquire(timeout);
2558 } else if (DEBUG_POWER) {
2559 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2560 + "owned by " + mAttrs.packageName);
2561 }
2562 }
2563
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002564 @Override
2565 public boolean isAlive() {
2566 return mClient.asBinder().isBinderAlive();
2567 }
2568
Craig Mautnera987d432012-10-11 14:07:58 -07002569 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002570 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002571 }
2572
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002573 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2574 animators.add(mWinAnimator);
2575
2576 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002577 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002578 c.addWinAnimatorToList(animators);
2579 }
2580 }
2581
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002582 void sendAppVisibilityToClients() {
2583 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002584
Wale Ogunwale89973222017-04-23 18:39:45 -07002585 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002586 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2587 // Don't hide the starting window.
2588 return;
2589 }
2590
Wale Ogunwale89973222017-04-23 18:39:45 -07002591 if (clientHidden) {
2592 // Once we are notifying the client that it's visibility has changed, we need to prevent
2593 // it from destroying child surfaces until the animation has finished. We do this by
2594 // detaching any surface control the client added from the client.
2595 for (int i = mChildren.size() - 1; i >= 0; --i) {
2596 final WindowState c = mChildren.get(i);
2597 c.mWinAnimator.detachChildren();
2598 }
2599
2600 mWinAnimator.detachChildren();
2601 }
2602
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002603 try {
2604 if (DEBUG_VISIBILITY) Slog.v(TAG,
2605 "Setting visibility of " + this + ": " + (!clientHidden));
2606 mClient.dispatchAppVisibility(!clientHidden);
2607 } catch (RemoteException e) {
2608 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002609 }
2610
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002611 void onStartFreezingScreen() {
2612 mAppFreezing = true;
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.onStartFreezingScreen();
2616 }
2617 }
2618
2619 boolean onStopFreezingScreen() {
2620 boolean unfrozeWindows = false;
2621 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002622 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002623 unfrozeWindows |= c.onStopFreezingScreen();
2624 }
2625
2626 if (!mAppFreezing) {
2627 return unfrozeWindows;
2628 }
2629
Wale Ogunwale953171d2016-09-30 09:17:30 -07002630 mAppFreezing = false;
2631
Bryce Lee8c3cf382017-07-06 19:47:10 -07002632 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002633 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2634 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002635 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002636 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002637 }
2638 mLastFreezeDuration = 0;
2639 setDisplayLayoutNeeded();
2640 return true;
2641 }
2642
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002643 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2644 boolean destroyedSomething = false;
2645 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002646 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002647 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2648 }
2649
Robert Carrdb2f6e62017-03-01 20:17:58 -08002650 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2651 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002652 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002653
2654 if (appStopped || mWindowRemovalAllowed) {
2655 mWinAnimator.destroyPreservedSurfaceLocked();
2656 }
2657
2658 if (mDestroying) {
2659 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2660 + " destroySurfaces: appStopped=" + appStopped
2661 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2662 + " win.mRemoveOnExit=" + mRemoveOnExit);
2663 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002664 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002665 }
2666 if (mRemoveOnExit) {
2667 removeImmediately();
2668 }
2669 if (cleanupOnResume) {
2670 requestUpdateWallpaperIfNeeded();
2671 }
2672 mDestroying = false;
2673 destroyedSomething = true;
2674 }
2675
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002676 return destroyedSomething;
2677 }
Chris Craik3131bde2016-05-06 13:39:08 -07002678
Robert Carr89a28ab2017-04-24 15:33:11 -07002679 // Destroy or save the application surface without checking
2680 // various indicators of whether the client has released the surface.
2681 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002682 void destroySurfaceUnchecked() {
2683 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002684
Chong Zhang92147042016-05-09 12:47:11 -07002685 // Clear animating flags now, since the surface is now gone. (Note this is true even
2686 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2687 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002688 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002689
Craig Mautner69b08182012-09-05 13:07:13 -07002690 @Override
2691 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002692 final DisplayContent displayContent = getDisplayContent();
2693 if (displayContent == null) {
2694 // Only a window that was on a non-default display can be detached from it.
2695 return false;
2696 }
Winson Chung47a3e652014-05-21 16:03:42 -07002697 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002698 }
2699
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002700 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002701 mShowToOwnerOnly = showToOwnerOnly;
2702 }
2703
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002704 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002705 // Child windows are evaluated based on their parent window.
2706 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002707 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002708 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002709
2710 // All window frames that are fullscreen extend above status bar, but some don't extend
2711 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2712 // bottom right.
2713 if (win.mFrame.left <= win.mDisplayFrame.left
2714 && win.mFrame.top <= win.mDisplayFrame.top
2715 && win.mFrame.right >= win.mStableFrame.right
2716 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002717 // Is a fullscreen window, like the clock alarm. Show to everyone.
2718 return false;
2719 }
2720 }
2721
Craig Mautner341220f2012-10-16 15:20:09 -07002722 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002723 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002724 }
2725
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002726 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2727 outRegion.set(
2728 frame.left + inset.left, frame.top + inset.top,
2729 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002730 }
2731
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002732 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002733 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002734 switch (mTouchableInsets) {
2735 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002736 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002737 outRegion.set(frame);
2738 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002739 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002740 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002741 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002742 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002743 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002744 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002745 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002746 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002747 outRegion.translate(frame.left, frame.top);
2748 break;
2749 }
2750 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002751 cropRegionToStackBoundsIfNeeded(outRegion);
2752 }
2753
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002754 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002755 final Task task = getTask();
2756 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002757 return;
2758 }
2759
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002760 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002761 if (stack == null) {
2762 return;
2763 }
2764
2765 stack.getDimBounds(mTmpRect);
2766 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002767 }
2768
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002769 /**
2770 * Report a focus change. Must be called with no locks held, and consistently
2771 * from the same serialized thread (such as dispatched from a handler).
2772 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002773 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002774 try {
2775 mClient.windowFocusChanged(focused, inTouchMode);
2776 } catch (RemoteException e) {
2777 }
2778 if (mFocusCallbacks != null) {
2779 final int N = mFocusCallbacks.beginBroadcast();
2780 for (int i=0; i<N; i++) {
2781 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2782 try {
2783 if (focused) {
2784 obs.focusGained(mWindowId.asBinder());
2785 } else {
2786 obs.focusLost(mWindowId.asBinder());
2787 }
2788 } catch (RemoteException e) {
2789 }
2790 }
2791 mFocusCallbacks.finishBroadcast();
2792 }
2793 }
2794
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002795 @Override
2796 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002797 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002798 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002799 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002800
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002801 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002802 }
2803
Craig Mautnerdf88d732014-01-27 09:21:32 -08002804 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002805 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002806 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002807 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2808 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002809 final MergedConfiguration mergedConfiguration =
2810 new MergedConfiguration(mService.mRoot.getConfiguration(),
2811 getMergedOverrideConfiguration());
2812
Bryce Lee2b17afd2017-09-21 10:38:20 -07002813 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002814
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002815 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002816 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2817
Craig Mautnerdf88d732014-01-27 09:21:32 -08002818 final Rect frame = mFrame;
2819 final Rect overscanInsets = mLastOverscanInsets;
2820 final Rect contentInsets = mLastContentInsets;
2821 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002822 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002823 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002824 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002825 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002826 final int displayId = getDisplayId();
Adrian Roos5c6b6222017-11-07 17:36:10 +01002827 final DisplayCutout displayCutout = mDisplayCutout;
Chet Haase8eb48d22014-09-24 07:31:29 -07002828 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2829 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002830 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2831 mService.mH.post(new Runnable() {
2832 @Override
2833 public void run() {
2834 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002835 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002836 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002837 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002838 } catch (RemoteException e) {
2839 // Not a remote call, RemoteException won't be raised.
2840 }
2841 }
2842 });
2843 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002844 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002845 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
2846 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002847 }
Svetoslav4604abc2014-06-10 18:59:30 -07002848
2849 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002850 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002851 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002852 }
2853
Craig Mautnerdf88d732014-01-27 09:21:32 -08002854 mOverscanInsetsChanged = false;
2855 mContentInsetsChanged = false;
2856 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002857 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002858 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07002859 mFrameSizeChanged = false;
Adrian Roos5c6b6222017-11-07 17:36:10 +01002860 mDisplayCutoutChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002861 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002862 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002863 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002864 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002865 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002866 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2867 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002868 // We are assuming the hosting process is dead or in a zombie state.
2869 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2870 + ", removing this window.");
2871 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002872 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002873 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002874 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002875 }
2876
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002877 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002878 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2879 // start even if we haven't received the relayout window, so that the client requests
2880 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2881 // until the window to small size, otherwise the multithread renderer will shift last
2882 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2883 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002884 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002885 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002886 return frame;
2887 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002888 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002889 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002890 return mTmpRect;
2891 }
2892
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002893 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002894 final TaskStack stack = getStack();
2895 if (stack == null) {
2896 return INVALID_STACK_ID;
2897 }
2898 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002899 }
2900
2901 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2902 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002903 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
2904 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002905 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08002906 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
2907 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07002908
Jorim Jaggidc249c42015-12-15 14:57:31 -08002909 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002910 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002911 mPolicy.isNavBarForcedShownLw(this), displayId,
2912 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002913 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002914 }
2915
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002916 public void registerFocusObserver(IWindowFocusObserver observer) {
2917 synchronized(mService.mWindowMap) {
2918 if (mFocusCallbacks == null) {
2919 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2920 }
2921 mFocusCallbacks.register(observer);
2922 }
2923 }
2924
2925 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2926 synchronized(mService.mWindowMap) {
2927 if (mFocusCallbacks != null) {
2928 mFocusCallbacks.unregister(observer);
2929 }
2930 }
2931 }
2932
2933 public boolean isFocused() {
2934 synchronized(mService.mWindowMap) {
2935 return mService.mCurrentFocus == this;
2936 }
2937 }
2938
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002939 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002940 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002941 final Task task = getTask();
2942 return task != null && !task.isFullscreen();
2943 }
2944
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002945 /** Is this window in a container that takes up the entire screen space? */
2946 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08002947 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002948 }
2949
Andrii Kulian283acd22017-08-03 04:03:51 -07002950 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
2951 boolean isLetterboxedAppWindow() {
Bryce Leef3c6a472017-11-14 14:53:06 -08002952 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002953 }
2954
Chong Zhang3005e752015-09-18 18:46:28 -07002955 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002956 return mDragResizing != computeDragResizing();
2957 }
2958
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002959 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002960 void setWaitingForDrawnIfResizingChanged() {
2961 if (isDragResizeChanged()) {
2962 mService.mWaitingForDrawn.add(this);
2963 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002964 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002965 }
2966
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002967 /**
2968 * @return Whether we reported a drag resize change to the application or not already.
2969 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002970 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002971 return mDragResizingChangeReported;
2972 }
2973
2974 /**
2975 * Resets the state whether we reported a drag resize change to the app.
2976 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002977 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002978 void resetDragResizingChangeReported() {
2979 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002980 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002981 }
2982
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002983 /**
2984 * Set whether we got resized but drag resizing flag was false.
2985 * @see #isResizedWhileNotDragResizing().
2986 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002987 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002988 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
2989 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
2990 }
2991
2992 /**
2993 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
2994 * need to recreate the surface and defer surface bound updates in order to make sure the
2995 * buffer contents and the positioning/size stay in sync.
2996 */
2997 boolean isResizedWhileNotDragResizing() {
2998 return mResizedWhileNotDragResizing;
2999 }
3000
3001 /**
3002 * @return Whether we reported "resize while not drag resizing" to the application.
3003 * @see #isResizedWhileNotDragResizing()
3004 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003005 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003006 return mResizedWhileNotDragResizingReported;
3007 }
3008
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003009 int getResizeMode() {
3010 return mResizeMode;
3011 }
3012
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003013 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003014 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003015 if (task == null) {
3016 return false;
3017 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003018 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003019 return false;
3020 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003021 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003022 // Floating windows never enter drag resize mode.
3023 return false;
3024 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003025 if (task.isDragResizing()) {
3026 return true;
3027 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003028
3029 // If the bounds are currently frozen, it means that the layout size that the app sees
3030 // and the bounds we clip this window to might be different. In order to avoid holes, we
3031 // simulate that we are still resizing so the app fills the hole with the resizing
3032 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003033 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003034 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003035 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003036
Chong Zhang3005e752015-09-18 18:46:28 -07003037 }
3038
3039 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003040 final boolean resizing = computeDragResizing();
3041 if (resizing == mDragResizing) {
3042 return;
3043 }
3044 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003045 final Task task = getTask();
3046 if (task != null && task.isDragResizing()) {
3047 mResizeMode = task.getDragResizeMode();
3048 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003049 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003050 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3051 : DRAG_RESIZE_MODE_FREEFORM;
3052 }
Chong Zhang3005e752015-09-18 18:46:28 -07003053 }
3054
3055 boolean isDragResizing() {
3056 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003057 }
3058
Robert Carr2487ce72016-04-07 15:18:45 -07003059 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003060 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3061 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003062 }
3063
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003064 @CallSuper
3065 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003066 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003067 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003068 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003069 writeIdentifierToProto(proto, IDENTIFIER);
3070 proto.write(DISPLAY_ID, getDisplayId());
3071 proto.write(STACK_ID, getStackId());
3072 mAttrs.writeToProto(proto, ATTRIBUTES);
3073 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3074 mFrame.writeToProto(proto, FRAME);
3075 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3076 mParentFrame.writeToProto(proto, PARENT_FRAME);
3077 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3078 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3079 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003080 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
3081 mShownPosition.writeToProto(proto, SHOWN_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003082 mWinAnimator.writeToProto(proto, ANIMATOR);
3083 proto.write(ANIMATING_EXIT, mAnimatingExit);
3084 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003085 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003086 }
3087 proto.end(token);
3088 }
3089
3090 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
3091 final long token = proto.start(fieldId);
3092 proto.write(HASH_CODE, System.identityHashCode(this));
3093 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3094 final CharSequence title = getWindowTag();
3095 if (title != null) {
3096 proto.write(TITLE, title.toString());
3097 }
3098 proto.end(token);
3099 }
3100
Jorim Jaggia5e10572017-11-15 14:36:26 +01003101 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003102 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003103 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003104 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003105 if (stack != null) {
3106 pw.print(" stackId="); pw.print(stack.mStackId);
3107 }
Craig Mautner59c00972012-07-30 12:10:24 -07003108 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003109 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003110 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003111 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3112 pw.print(" package="); pw.print(mAttrs.packageName);
3113 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003114 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003115 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3116 pw.print(" h="); pw.print(mRequestedHeight);
3117 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003118 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3119 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3120 pw.print(" h="); pw.println(mLastRequestedHeight);
3121 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003122 if (mIsChildWindow || mLayoutAttached) {
3123 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003124 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3125 }
3126 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3127 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3128 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3129 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3130 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3131 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003132 if (dumpAll) {
3133 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3134 pw.print(" mSubLayer="); pw.print(mSubLayer);
3135 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003136 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3137 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003138 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003139 if (dumpAll) {
3140 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003141 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003142 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3143 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003144 pw.print(" mAppDied=");pw.print(mAppDied);
3145 pw.print(prefix); pw.print("drawnStateEvaluated=");
3146 pw.print(getDrawnStateEvaluated());
3147 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003148 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003149 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003150 pw.print(prefix); pw.print("mViewVisibility=0x");
3151 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003152 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3153 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003154 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3155 pw.print(" mSystemUiVisibility=0x");
3156 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003157 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003158 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003159 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003160 pw.print(prefix); pw.print("mPolicyVisibility=");
3161 pw.print(mPolicyVisibility);
3162 pw.print(" mPolicyVisibilityAfterAnim=");
3163 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003164 pw.print(" mAppOpVisibility=");
3165 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003166 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003167 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
3168 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3169 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003170 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003171 if (!mRelayoutCalled || mLayoutNeeded) {
3172 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3173 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003174 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003175 if (mXOffset != 0 || mYOffset != 0) {
3176 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3177 pw.print(" y="); pw.println(mYOffset);
3178 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003179 if (dumpAll) {
3180 pw.print(prefix); pw.print("mGivenContentInsets=");
3181 mGivenContentInsets.printShortString(pw);
3182 pw.print(" mGivenVisibleInsets=");
3183 mGivenVisibleInsets.printShortString(pw);
3184 pw.println();
3185 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3186 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3187 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003188 Region region = new Region();
3189 getTouchableRegion(region);
3190 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003191 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003192 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3193 pw.print(prefix); pw.print("mLastReportedConfiguration=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003194 pw.println(getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003195 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003196 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003197 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003198 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003199 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003200 if (dumpAll) {
3201 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3202 pw.print(" last="); mLastFrame.printShortString(pw);
3203 pw.println();
3204 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003205 if (mEnforceSizeCompat) {
3206 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003207 pw.println();
3208 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003209 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003210 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003211 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003212 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003213 pw.println();
3214 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3215 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003216 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003217 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003218 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003219 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003220 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3221 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003222 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3223 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003224 pw.print(prefix); pw.print("Cur insets: overscan=");
3225 mOverscanInsets.printShortString(pw);
3226 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003227 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003228 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003229 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003230 pw.print(" outsets="); mOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003231 pw.print(" cutout=" + mDisplayCutout);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003232 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003233 pw.print(prefix); pw.print("Lst insets: overscan=");
3234 mLastOverscanInsets.printShortString(pw);
3235 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003236 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003237 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003238 pw.print(" physical="); mLastOutsets.printShortString(pw);
3239 pw.print(" outset="); mLastOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003240 pw.print(" cutout=" + mLastDisplayCutout);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003241 pw.println();
3242 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003243 super.dump(pw, prefix, dumpAll);
Dianne Hackborn529e7442012-11-01 14:22:28 -07003244 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3245 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003246 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3247 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003248 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3249 pw.print(" mDestroying="); pw.print(mDestroying);
3250 pw.print(" mRemoved="); pw.println(mRemoved);
3251 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003252 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003253 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003254 pw.print(prefix); pw.print("mOrientationChanging=");
3255 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003256 pw.print(" configOrientationChanging=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003257 pw.print(getLastReportedConfiguration().orientation
Bryce Lee8c3cf382017-07-06 19:47:10 -07003258 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003259 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003260 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003261 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003262 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003263 if (mLastFreezeDuration != 0) {
3264 pw.print(prefix); pw.print("mLastFreezeDuration=");
3265 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3266 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003267 if (mHScale != 1 || mVScale != 1) {
3268 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3269 pw.print(" mVScale="); pw.println(mVScale);
3270 }
3271 if (mWallpaperX != -1 || mWallpaperY != -1) {
3272 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3273 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3274 }
3275 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3276 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3277 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3278 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003279 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3280 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3281 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3282 pw.print(mWallpaperDisplayOffsetX);
3283 pw.print(" mWallpaperDisplayOffsetY=");
3284 pw.println(mWallpaperDisplayOffsetY);
3285 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003286 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003287 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003288 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003289 if (isDragResizing()) {
3290 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3291 }
3292 if (computeDragResizing()) {
3293 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3294 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003295 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3296 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003297 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003298
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003299 @Override
3300 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003301 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003302 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003303 }
3304
Robert Carra1eb4392015-12-10 12:43:51 -08003305 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003306 CharSequence tag = mAttrs.getTitle();
3307 if (tag == null || tag.length() <= 0) {
3308 tag = mAttrs.packageName;
3309 }
3310 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003311 }
3312
3313 @Override
3314 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003315 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003316 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003317 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003318 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003319 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003320 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003321 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003322 }
3323 return mStringNameCache;
3324 }
Robert Carr58f29132015-10-29 14:19:05 -07003325
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003326 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003327 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003328 clipRect.left = (int) (clipRect.left / mHScale);
3329 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003330 }
3331 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003332 clipRect.top = (int) (clipRect.top / mVScale);
3333 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003334 }
3335 }
Robert Carr31e28482015-12-02 16:53:18 -08003336
Jorim Jaggif5834272016-04-04 20:25:41 -07003337 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3338 final int pw = containingFrame.width();
3339 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003340 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003341 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003342 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3343
3344 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003345 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3346 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003347 // 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 -07003348 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3349 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3350 // the display.
3351 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003352 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003353 float x, y;
3354 int w,h;
3355
3356 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3357 if (mAttrs.width < 0) {
3358 w = pw;
3359 } else if (mEnforceSizeCompat) {
3360 w = (int)(mAttrs.width * mGlobalScale + .5f);
3361 } else {
3362 w = mAttrs.width;
3363 }
3364 if (mAttrs.height < 0) {
3365 h = ph;
3366 } else if (mEnforceSizeCompat) {
3367 h = (int)(mAttrs.height * mGlobalScale + .5f);
3368 } else {
3369 h = mAttrs.height;
3370 }
3371 } else {
3372 if (mAttrs.width == MATCH_PARENT) {
3373 w = pw;
3374 } else if (mEnforceSizeCompat) {
3375 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3376 } else {
3377 w = mRequestedWidth;
3378 }
3379 if (mAttrs.height == MATCH_PARENT) {
3380 h = ph;
3381 } else if (mEnforceSizeCompat) {
3382 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3383 } else {
3384 h = mRequestedHeight;
3385 }
3386 }
3387
3388 if (mEnforceSizeCompat) {
3389 x = mAttrs.x * mGlobalScale;
3390 y = mAttrs.y * mGlobalScale;
3391 } else {
3392 x = mAttrs.x;
3393 y = mAttrs.y;
3394 }
3395
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003396 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003397 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003398 // required by {@link Gravity#apply} call.
3399 w = Math.min(w, pw);
3400 h = Math.min(h, ph);
3401 }
3402
3403 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003404 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003405 (int) (x + mAttrs.horizontalMargin * pw),
3406 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3407
3408 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003409 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003410 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003411 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003412
3413 // We need to make sure we update the CompatFrame as it is used for
3414 // cropping decisions, etc, on systems where we lack a decor layer.
3415 mCompatFrame.set(mFrame);
3416 if (mEnforceSizeCompat) {
3417 // See comparable block in computeFrameLw.
3418 mCompatFrame.scale(mInvGlobalScale);
3419 }
Robert Carr31e28482015-12-02 16:53:18 -08003420 }
Robert Carr51a1b872015-12-08 14:03:13 -08003421
3422 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003423 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003424 }
3425
Robert Carrf3b72c72016-03-21 18:16:39 -07003426 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003427 return mIsChildWindow
3428 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003429 }
3430
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003431 /**
3432 * Returns true if any window added by an application process that if of type
3433 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3434 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3435 * this window is visible.
3436 */
3437 boolean hideNonSystemOverlayWindowsWhenVisible() {
3438 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3439 && mSession.mCanHideNonSystemOverlayWindows;
3440 }
3441
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003442 /** Returns the parent window if this is a child of another window, else null. */
3443 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003444 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3445 // WindowContainer that isn't a WindowState.
3446 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003447 }
3448
3449 /** Returns the topmost parent window if this is a child of another window, else this. */
3450 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003451 WindowState current = this;
3452 WindowState topParent = current;
3453 while (current != null && current.mIsChildWindow) {
3454 current = current.getParentWindow();
3455 // Parent window can be null if the child is detached from it's parent already, but
3456 // someone still has a reference to access it. So, we return the top parent value we
3457 // already have instead of null.
3458 if (current != null) {
3459 topParent = current;
3460 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003461 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003462 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003463 }
3464
Wale Ogunwale9d147902016-07-16 11:58:55 -07003465 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003466 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003467 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003468 }
3469
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003470 void setWillReplaceWindow(boolean animate) {
3471 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003472 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003473 c.setWillReplaceWindow(animate);
3474 }
3475
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003476 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3477 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3478 // We don't set replacing on starting windows since they are added by window manager and
3479 // not the client so won't be replaced by the client.
3480 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003481 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003482
3483 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003484 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003485 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003486 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003487
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003488 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003489 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003490 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003491 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003492
3493 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003494 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003495 c.clearWillReplaceWindow();
3496 }
3497 }
3498
3499 boolean waitingForReplacement() {
3500 if (mWillReplaceWindow) {
3501 return true;
3502 }
3503
3504 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003505 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003506 if (c.waitingForReplacement()) {
3507 return true;
3508 }
3509 }
3510 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003511 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003512
Chong Zhang4d7369a2016-04-25 16:09:14 -07003513 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003514 final DisplayContent dc = getDisplayContent();
3515 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3516 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3517 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003518 mService.mWindowPlacerLocked.requestTraversal();
3519 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003520
3521 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003522 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003523 c.requestUpdateWallpaperIfNeeded();
3524 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003525 }
3526
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003527 float translateToWindowX(float x) {
3528 float winX = x - mFrame.left;
3529 if (mEnforceSizeCompat) {
3530 winX *= mGlobalScale;
3531 }
3532 return winX;
3533 }
3534
3535 float translateToWindowY(float y) {
3536 float winY = y - mFrame.top;
3537 if (mEnforceSizeCompat) {
3538 winY *= mGlobalScale;
3539 }
3540 return winY;
3541 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003542
3543 // During activity relaunch due to resize, we sometimes use window replacement
3544 // for only child windows (as the main window is handled by window preservation)
3545 // and the big surface.
3546 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003547 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3548 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3549 // we also want to replace them at such phases, as they won't be covered by window
3550 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003551 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003552 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003553 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003554 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003555
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003556 void setWillReplaceChildWindows() {
3557 if (shouldBeReplacedWithChildren()) {
3558 setWillReplaceWindow(false /* animate */);
3559 }
3560 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003561 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003562 c.setWillReplaceChildWindows();
3563 }
3564 }
3565
3566 WindowState getReplacingWindow() {
3567 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3568 return this;
3569 }
3570 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003571 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003572 final WindowState replacing = c.getReplacingWindow();
3573 if (replacing != null) {
3574 return replacing;
3575 }
3576 }
3577 return null;
3578 }
3579
Jorim Jaggife762342016-10-13 14:33:27 +02003580 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003581 public int getRotationAnimationHint() {
3582 if (mAppToken != null) {
3583 return mAppToken.mRotationAnimationHint;
3584 } else {
3585 return -1;
3586 }
3587 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003588
Jorim Jaggife762342016-10-13 14:33:27 +02003589 @Override
3590 public boolean isInputMethodWindow() {
3591 return mIsImWindow;
3592 }
3593
Wale Ogunwale9d147902016-07-16 11:58:55 -07003594 // This must be called while inside a transaction.
3595 boolean performShowLocked() {
3596 if (isHiddenFromUserLocked()) {
3597 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3598 hideLw(false);
3599 return false;
3600 }
3601
3602 logPerformShow("performShow on ");
3603
Jorim Jaggia50da602016-12-29 11:51:42 +01003604 final int drawState = mWinAnimator.mDrawState;
3605 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3606 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3607 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3608 }
3609
Jorim Jaggib0d27342016-11-01 16:10:42 -07003610 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003611 return false;
3612 }
3613
3614 logPerformShow("Showing ");
3615
3616 mService.enableScreenIfNeededLocked();
3617 mWinAnimator.applyEnterAnimationLocked();
3618
3619 // Force the show in the next prepareSurfaceLocked() call.
3620 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003621 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003622 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3623 mWinAnimator.mDrawState = HAS_DRAWN;
3624 mService.scheduleAnimationLocked();
3625
3626 if (mHidden) {
3627 mHidden = false;
3628 final DisplayContent displayContent = getDisplayContent();
3629
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003630 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003631 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003632 if (c.mWinAnimator.mSurfaceController != null) {
3633 c.performShowLocked();
3634 // It hadn't been shown, which means layout not performed on it, so now we
3635 // want to make sure to do a layout. If called from within the transaction
3636 // loop, this will cause it to restart with a new layout.
3637 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003638 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003639 }
3640 }
3641 }
3642 }
3643
Wale Ogunwale9d147902016-07-16 11:58:55 -07003644 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003645 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003646 }
3647
3648 return true;
3649 }
3650
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003651 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003652 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003653 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003654 Slog.v(TAG, prefix + this
3655 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003656 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003657 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3658 + " during animation: policyVis=" + mPolicyVisibility
3659 + " parentHidden=" + isParentWindowHidden()
3660 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003661 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003662 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggia5e10572017-11-15 14:36:26 +01003663 + " animationSet=" + mWinAnimator.isAnimationSet()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003664 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003665 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003666 + " Callers=" + Debug.getCallers(4));
3667 }
3668 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003669
3670 WindowInfo getWindowInfo() {
3671 WindowInfo windowInfo = WindowInfo.obtain();
3672 windowInfo.type = mAttrs.type;
3673 windowInfo.layer = mLayer;
3674 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003675 if (mAppToken != null) {
3676 windowInfo.activityToken = mAppToken.appToken.asBinder();
3677 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003678 windowInfo.title = mAttrs.accessibilityTitle;
3679 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3680 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003681 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003682 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003683
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003684 if (mIsChildWindow) {
3685 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003686 }
3687
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003688 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003689 if (childCount > 0) {
3690 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003691 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003692 }
3693 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003694 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003695 windowInfo.childTokens.add(child.mClient.asBinder());
3696 }
3697 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003698 return windowInfo;
3699 }
3700
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003701 int getHighestAnimLayer() {
3702 int highest = mWinAnimator.mAnimLayer;
3703 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003704 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003705 final int childLayer = c.getHighestAnimLayer();
3706 if (childLayer > highest) {
3707 highest = childLayer;
3708 }
3709 }
3710 return highest;
3711 }
3712
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003713 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003714 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003715 if (mChildren.isEmpty()) {
3716 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003717 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003718 }
3719
3720 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003721 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003722 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003723 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003724 }
3725 }
3726
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003727 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003728 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003729 // below the parent, then this window (the parent), and then the positive sublayer children
3730 // because they need to appear above the parent.
3731 int i = 0;
3732 final int count = mChildren.size();
3733 WindowState child = mChildren.get(i);
3734
3735 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003736 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003737 return true;
3738 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003739 i++;
3740 if (i >= count) {
3741 break;
3742 }
3743 child = mChildren.get(i);
3744 }
3745
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003746 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003747 return true;
3748 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003749
3750 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003751 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003752 return true;
3753 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003754 i++;
3755 if (i >= count) {
3756 break;
3757 }
3758 child = mChildren.get(i);
3759 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003760
3761 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003762 }
3763
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003764 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003765 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003766 // above the parent, then this window (the parent), and then the negative sublayer children
3767 // because they need to appear above the parent.
3768 int i = mChildren.size() - 1;
3769 WindowState child = mChildren.get(i);
3770
3771 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003772 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003773 return true;
3774 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003775 --i;
3776 if (i < 0) {
3777 break;
3778 }
3779 child = mChildren.get(i);
3780 }
3781
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003782 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003783 return true;
3784 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003785
3786 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003787 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003788 return true;
3789 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003790 --i;
3791 if (i < 0) {
3792 break;
3793 }
3794 child = mChildren.get(i);
3795 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003796
3797 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003798 }
3799
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003800 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3801 boolean traverseTopToBottom) {
3802 if (traverseTopToBottom) {
3803 if (mService.mInputMethodTarget == this) {
3804 // This window is the current IME target, so we need to process the IME windows
3805 // directly above it.
3806 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3807 return true;
3808 }
3809 }
3810 if (callback.apply(this)) {
3811 return true;
3812 }
3813 } else {
3814 if (callback.apply(this)) {
3815 return true;
3816 }
3817 if (mService.mInputMethodTarget == this) {
3818 // This window is the current IME target, so we need to process the IME windows
3819 // directly above it.
3820 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3821 return true;
3822 }
3823 }
3824 }
3825
3826 return false;
3827 }
3828
Wale Ogunwaled1880962016-11-08 10:31:59 -08003829 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003830 if (mChildren.isEmpty()) {
3831 return callback.test(this) ? this : null;
3832 }
3833
3834 // We want to consume the positive sublayer children first because they need to appear
3835 // above the parent, then this window (the parent), and then the negative sublayer children
3836 // because they need to appear above the parent.
3837 int i = mChildren.size() - 1;
3838 WindowState child = mChildren.get(i);
3839
3840 while (i >= 0 && child.mSubLayer >= 0) {
3841 if (callback.test(child)) {
3842 return child;
3843 }
3844 --i;
3845 if (i < 0) {
3846 break;
3847 }
3848 child = mChildren.get(i);
3849 }
3850
Wale Ogunwaled1880962016-11-08 10:31:59 -08003851 if (callback.test(this)) {
3852 return this;
3853 }
Wale Ogunwale34247952017-02-19 11:57:53 -08003854
3855 while (i >= 0) {
3856 if (callback.test(child)) {
3857 return child;
3858 }
3859 --i;
3860 if (i < 0) {
3861 break;
3862 }
3863 child = mChildren.get(i);
3864 }
3865
3866 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08003867 }
3868
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003869 void onExitAnimationDone() {
3870 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3871 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01003872 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003873
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003874 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003875 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003876 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003877 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003878 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003879 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003880 }
3881 }
3882
3883 if (mWinAnimator.mEnteringAnimation) {
3884 mWinAnimator.mEnteringAnimation = false;
3885 mService.requestTraversal();
3886 // System windows don't have an activity and an app token as a result, but need a way
3887 // to be informed about their entrance animation end.
3888 if (mAppToken == null) {
3889 try {
3890 mClient.dispatchWindowShown();
3891 } catch (RemoteException e) {
3892 }
3893 }
3894 }
3895
Jorim Jaggia5e10572017-11-15 14:36:26 +01003896 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003897 return;
3898 }
3899
Jorim Jaggia5e10572017-11-15 14:36:26 +01003900 //TODO (multidisplay): Accessibility is supported only for the default display.
3901 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3902 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3903 }
3904
3905 if (!mAnimatingExit) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003906 return;
3907 }
3908
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003909 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003910 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3911
3912 mDestroying = true;
3913
3914 final boolean hasSurface = mWinAnimator.hasSurface();
3915 if (hasSurface) {
3916 mWinAnimator.hide("onExitAnimationDone");
3917 }
3918
3919 // If we have an app token, we ask it to destroy the surface for us, so that it can take
3920 // care to ensure the activity has actually stopped and the surface is not still in use.
3921 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
3922 // transaction.
3923 if (mAppToken != null) {
3924 mAppToken.destroySurfaces();
3925 } else {
3926 if (hasSurface) {
3927 mService.mDestroySurface.add(this);
3928 }
3929 if (mRemoveOnExit) {
3930 mService.mPendingRemove.add(this);
3931 mRemoveOnExit = false;
3932 }
3933 }
3934 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07003935 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003936 }
Dan Willemsen117197f2016-07-30 13:02:59 -07003937
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003938 boolean clearAnimatingFlags() {
3939 boolean didSomething = false;
3940 // We don't want to clear it out for windows that get replaced, because the
3941 // animation depends on the flag to remove the replaced window.
3942 //
3943 // We also don't clear the mAnimatingExit flag for windows which have the
3944 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
3945 // by the client. We should let animation proceed and not clear this flag or
3946 // they won't eventually be removed by WindowStateAnimator#finishExit.
3947 if (!mWillReplaceWindow && !mRemoveOnExit) {
3948 // Clear mAnimating flag together with mAnimatingExit. When animation
3949 // changes from exiting to entering, we need to clear this flag until the
3950 // new animation gets applied, so that isAnimationStarting() becomes true
3951 // until then.
3952 // Otherwise applySurfaceChangesTransaction will fail to skip surface
3953 // placement for this window during this period, one or more frame will
3954 // show up with wrong position or scale.
3955 if (mAnimatingExit) {
3956 mAnimatingExit = false;
3957 didSomething = true;
3958 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003959 if (mDestroying) {
3960 mDestroying = false;
3961 mService.mDestroySurface.remove(this);
3962 didSomething = true;
3963 }
3964 }
3965
3966 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003967 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003968 }
3969
3970 return didSomething;
3971 }
3972
Winson4b4ba902016-07-27 19:45:52 -07003973 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003974 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07003975 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07003976
3977 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003978 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003979 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003980 c.hideWallpaperWindow(wasDeferred, reason);
3981 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07003982 if (!mWinAnimator.mLastHidden || wasDeferred) {
3983 mWinAnimator.hide(reason);
3984 dispatchWallpaperVisibility(false);
3985 final DisplayContent displayContent = getDisplayContent();
3986 if (displayContent != null) {
3987 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3988 }
3989 }
3990 }
3991
3992 /**
3993 * Check wallpaper window for visibility change and notify window if so.
3994 * @param visible Current visibility.
3995 */
3996 void dispatchWallpaperVisibility(final boolean visible) {
3997 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07003998 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07003999
4000 // Only send notification if the visibility actually changed and we are not trying to hide
4001 // the wallpaper when we are deferring hiding of the wallpaper.
4002 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4003 mWallpaperVisible = visible;
4004 try {
4005 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4006 "Updating vis of wallpaper " + this
4007 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4008 mClient.dispatchAppVisibility(visible);
4009 } catch (RemoteException e) {
4010 }
4011 }
4012 }
4013
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004014 boolean hasVisibleNotDrawnWallpaper() {
4015 if (mWallpaperVisible && !isDrawnLw()) {
4016 return true;
4017 }
4018 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004019 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004020 if (c.hasVisibleNotDrawnWallpaper()) {
4021 return true;
4022 }
4023 }
4024 return false;
4025 }
4026
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004027 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4028 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004029 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004030 c.updateReportedVisibility(results);
4031 }
4032
4033 if (mAppFreezing || mViewVisibility != View.VISIBLE
4034 || mAttrs.type == TYPE_APPLICATION_STARTING
4035 || mDestroying) {
4036 return;
4037 }
4038 if (DEBUG_VISIBILITY) {
4039 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4040 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4041 if (!isDrawnLw()) {
4042 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4043 + " pv=" + mPolicyVisibility
4044 + " mDrawState=" + mWinAnimator.mDrawState
4045 + " ph=" + isParentWindowHidden()
4046 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggia5e10572017-11-15 14:36:26 +01004047 + " a=" + mWinAnimator.isAnimationSet());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004048 }
4049 }
4050
4051 results.numInteresting++;
4052 if (isDrawnLw()) {
4053 results.numDrawn++;
4054 if (!mWinAnimator.isAnimationSet()) {
4055 results.numVisible++;
4056 }
4057 results.nowGone = false;
4058 } else if (mWinAnimator.isAnimationSet()) {
4059 results.nowGone = false;
4060 }
4061 }
4062
Robert Carrfbbde852016-10-18 11:02:28 -07004063 /**
4064 * Calculate the window crop according to system decor policy. In general this is
4065 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4066 * special cases. This rectangle is in screen space.
4067 */
4068 void calculatePolicyCrop(Rect policyCrop) {
4069 final DisplayContent displayContent = getDisplayContent();
4070 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4071
4072 if (!isDefaultDisplay()) {
4073 // On a different display there is no system decor. Crop the window
4074 // by the screen boundaries.
4075 // TODO(multi-display)
4076 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4077 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4078 displayInfo.logicalWidth - mCompatFrame.left,
4079 displayInfo.logicalHeight - mCompatFrame.top);
Robert Carrfbbde852016-10-18 11:02:28 -07004080 } else if (mDecorFrame.isEmpty()) {
4081 // Windows without policy decor aren't cropped.
4082 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4083 } else {
4084 // Crop to the system decor specified by policy.
4085 calculateSystemDecorRect(policyCrop);
4086 }
4087 }
4088
4089 /**
4090 * The system decor rect is the region of the window which is not covered
4091 * by system decorations.
4092 */
4093 private void calculateSystemDecorRect(Rect systemDecorRect) {
4094 final Rect decorRect = mDecorFrame;
4095 final int width = mFrame.width();
4096 final int height = mFrame.height();
4097
4098 // Compute the offset of the window in relation to the decor rect.
4099 final int left = mXOffset + mFrame.left;
4100 final int top = mYOffset + mFrame.top;
4101
4102 // Initialize the decor rect to the entire frame.
4103 if (isDockedResizing()) {
4104 // If we are resizing with the divider, the task bounds might be smaller than the
4105 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4106 // want in this case in order to avoid holes.
4107 //
4108 // We take care to not shrink the width, for surfaces which are larger than
4109 // the display region. Of course this area will not eventually be visible
4110 // but if we truncate the width now, we will calculate incorrectly
4111 // when adjusting to the stack bounds.
4112 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4113 systemDecorRect.set(0, 0,
4114 Math.max(width, displayInfo.logicalWidth),
4115 Math.max(height, displayInfo.logicalHeight));
4116 } else {
4117 systemDecorRect.set(0, 0, width, height);
4118 }
4119
4120 // If a freeform window is animating from a position where it would be cutoff, it would be
4121 // cutoff during the animation. We don't want that, so for the duration of the animation
4122 // we ignore the decor cropping and depend on layering to position windows correctly.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004123 final boolean cropToDecor = !(inFreeformWindowingMode() && isAnimatingLw());
Robert Carrfbbde852016-10-18 11:02:28 -07004124 if (cropToDecor) {
4125 // Intersect with the decor rect, offsetted by window position.
4126 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4127 decorRect.right - left, decorRect.bottom - top);
4128 }
4129
4130 // If size compatibility is being applied to the window, the
4131 // surface is scaled relative to the screen. Also apply this
4132 // scaling to the crop rect. We aren't using the standard rect
4133 // scale function because we want to round things to make the crop
4134 // always round to a larger rect to ensure we don't crop too
4135 // much and hide part of the window that should be seen.
4136 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4137 final float scale = mInvGlobalScale;
4138 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4139 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4140 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4141 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4142 }
4143
4144 }
4145
4146 /**
4147 * Expand the given rectangle by this windows surface insets. This
4148 * takes you from the 'window size' to the 'surface size'.
4149 * The surface insets are positive in each direction, so we inset by
4150 * the inverse.
4151 */
4152 void expandForSurfaceInsets(Rect r) {
4153 r.inset(-mAttrs.surfaceInsets.left,
4154 -mAttrs.surfaceInsets.top,
4155 -mAttrs.surfaceInsets.right,
4156 -mAttrs.surfaceInsets.bottom);
4157 }
4158
Robert Carrc91d1c32017-02-15 19:37:46 -08004159 boolean surfaceInsetsChanging() {
4160 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4161 }
4162
Bryce Leef858b572017-06-29 14:03:33 -07004163 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004164 final boolean wasVisible = isVisibleLw();
4165
4166 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004167 if (mAnimatingExit) {
4168 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4169 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4170
4171 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4172 mAnimatingExit = false;
4173 }
4174 if (mDestroying) {
4175 mDestroying = false;
4176 mService.mDestroySurface.remove(this);
4177 }
4178 if (oldVisibility == View.GONE) {
4179 mWinAnimator.mEnterAnimationPending = true;
4180 }
4181
Andrii Kulian8ee72852017-03-10 10:36:45 -08004182 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004183
4184 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004185
Bryce Leef858b572017-06-29 14:03:33 -07004186 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004187
Robert Carrc91d1c32017-02-15 19:37:46 -08004188 if ((attrChanges & FORMAT_CHANGED) != 0) {
4189 // If the format can't be changed in place, preserve the old surface until the app draws
4190 // on the new one. This prevents blinking when we change elevation of freeform and
4191 // pinned windows.
4192 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4193 mWinAnimator.preserveSurfaceLocked();
4194 result |= RELAYOUT_RES_SURFACE_CHANGED
4195 | RELAYOUT_RES_FIRST_TIME;
4196 }
4197 }
4198
4199 // When we change the Surface size, in scenarios which may require changing
4200 // the surface position in sync with the resize, we use a preserved surface
4201 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004202 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4203 // stack since it can lead to issues if a new surface is created while calculating the
4204 // scale for the animation using the source hint rect
4205 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004206 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004207 || (surfaceInsetsChanging() && !inPinnedWindowingMode())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004208 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4209
4210 setDragResizing();
4211 setResizedWhileNotDragResizing(false);
4212 // We can only change top level windows to the full-screen surface when
4213 // resizing (as we only have one full-screen surface). So there is no need
4214 // to preserve and destroy windows which are attached to another, they
4215 // will keep their surface and its size may change over time.
4216 if (mHasSurface && !isChildWindow()) {
4217 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004218 result |= RELAYOUT_RES_SURFACE_CHANGED |
4219 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004220 }
4221 }
4222 final boolean freeformResizing = isDragResizing()
4223 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4224 final boolean dockedResizing = isDragResizing()
4225 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4226 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4227 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004228 return result;
4229 }
4230
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004231 /**
4232 * @return True if this window has been laid out at least once; false otherwise.
4233 */
4234 boolean isLaidOut() {
4235 return mLayoutSeq != -1;
4236 }
4237
4238 /**
4239 * Updates the last inset values to the current ones.
4240 */
4241 void updateLastInsetValues() {
4242 mLastOverscanInsets.set(mOverscanInsets);
4243 mLastContentInsets.set(mContentInsets);
4244 mLastVisibleInsets.set(mVisibleInsets);
4245 mLastStableInsets.set(mStableInsets);
4246 mLastOutsets.set(mOutsets);
Adrian Roos5c6b6222017-11-07 17:36:10 +01004247 mLastDisplayCutout = mDisplayCutout;
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004248 }
4249
Jorim Jaggia5e10572017-11-15 14:36:26 +01004250 void startAnimation(Animation anim) {
4251 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4252 anim.initialize(mFrame.width(), mFrame.height(),
4253 displayInfo.appWidth, displayInfo.appHeight);
4254 anim.restrictDuration(MAX_ANIMATION_DURATION);
4255 anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
4256 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004257 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
4258 mService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004259 startAnimation(mPendingTransaction, adapter);
4260 commitPendingTransaction();
4261 }
4262
4263 private void startMoveAnimation(Transaction t, int left, int top) {
4264 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004265 final Point oldPosition = new Point();
4266 final Point newPosition = new Point();
4267 transformFrameToSurfacePosition(mLastFrame.left, mLastFrame.top, oldPosition);
4268 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004269 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004270 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004271 mService.mSurfaceAnimationRunner);
4272 startAnimation(t, adapter);
4273 }
4274
4275 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4276 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4277 }
4278
4279 @Override
4280 protected void onAnimationFinished() {
4281 mWinAnimator.onAnimationFinished();
4282 }
4283
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004284 /**
4285 * Retrieves the current transformation matrix of the window, relative to the display.
4286 *
4287 * @param float9 A temporary array of 9 floats.
4288 * @param outMatrix Matrix to fill in the transformation.
4289 */
4290 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4291 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4292 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4293 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4294 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
4295 float9[Matrix.MTRANS_X] = mSurfacePosition.x + mShownPosition.x;
4296 float9[Matrix.MTRANS_Y] = mSurfacePosition.y + mShownPosition.y;
4297 float9[Matrix.MPERSP_0] = 0;
4298 float9[Matrix.MPERSP_1] = 0;
4299 float9[Matrix.MPERSP_2] = 1;
4300 outMatrix.setValues(float9);
4301 }
4302
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004303 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4304 // access to its windows children. Need to investigate re-writing
4305 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4306 static final class UpdateReportedVisibilityResults {
4307 int numInteresting;
4308 int numVisible;
4309 int numDrawn;
4310 boolean nowGone = true;
4311
4312 void reset() {
4313 numInteresting = 0;
4314 numVisible = 0;
4315 numDrawn = 0;
4316 nowGone = true;
4317 }
4318 }
Robert Carraf422a82017-04-10 18:34:33 -07004319
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004320 private static final class WindowId extends IWindowId.Stub {
4321 private final WeakReference<WindowState> mOuter;
4322
4323 private WindowId(WindowState outer) {
4324
4325 // Use a weak reference for the outer class. This is important to prevent the following
4326 // leak: Since we send this class to the client process, binder will keep it alive as
4327 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4328 // out our reference so even though this class is kept alive we don't leak WindowState,
4329 // which can keep a whole lot of classes alive.
4330 mOuter = new WeakReference<>(outer);
4331 }
4332
4333 @Override
4334 public void registerFocusObserver(IWindowFocusObserver observer) {
4335 final WindowState outer = mOuter.get();
4336 if (outer != null) {
4337 outer.registerFocusObserver(observer);
4338 }
4339 }
4340 @Override
4341 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4342 final WindowState outer = mOuter.get();
4343 if (outer != null) {
4344 outer.unregisterFocusObserver(observer);
4345 }
4346 }
4347 @Override
4348 public boolean isFocused() {
4349 final WindowState outer = mOuter.get();
4350 return outer != null && outer.isFocused();
4351 }
4352 }
4353
Robert Carrb1579c82017-09-05 14:54:47 -07004354
4355 @Override
4356 boolean shouldMagnify() {
4357 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004358 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4359 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4360 mAttrs.type == TYPE_NAVIGATION_BAR ||
4361 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4362 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
4363 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL ||
4364 mAttrs.type == TYPE_STATUS_BAR) {
Robert Carrb1579c82017-09-05 14:54:47 -07004365 return false;
4366 }
4367 return true;
4368 }
4369
4370 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004371 SurfaceSession getSession() {
4372 if (mSession.mSurfaceSession != null) {
4373 return mSession.mSurfaceSession;
4374 } else {
4375 return getParent().getSession();
4376 }
4377 }
4378
4379 @Override
4380 boolean needsZBoost() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004381 if (mIsImWindow && mService.mInputMethodTarget != null) {
4382 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
4383 if (appToken != null) {
4384 return appToken.needsZBoost();
4385 }
4386 }
4387 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004388 }
4389
Robert Carrf07ef9e2017-11-21 12:12:49 -08004390 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004391 if (!mAnimatingExit && mAppDied) {
4392 mIsDimming = true;
4393 getDimmer().dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
4394 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
4395 && !mAnimatingExit && isVisible()) {
4396 mIsDimming = true;
4397 getDimmer().dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
4398 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004399 }
4400
4401 @Override
4402 void prepareSurfaces() {
4403 final Dimmer dimmer = getDimmer();
4404 mIsDimming = false;
4405 if (dimmer != null) {
4406 applyDims(dimmer);
4407 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004408
Jorim Jaggia5e10572017-11-15 14:36:26 +01004409 updateSurfacePosition(mPendingTransaction);
4410
Robert Carrb1579c82017-09-05 14:54:47 -07004411 mWinAnimator.prepareSurfaceLocked(true);
4412 super.prepareSurfaces();
4413 }
4414
4415 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004416 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4417 super.onAnimationLeashCreated(t, leash);
4418
4419 // Leash is now responsible for position, so set our position to 0.
4420 t.setPosition(mSurfaceControl, 0, 0);
4421 }
4422
4423 @Override
4424 public void onAnimationLeashDestroyed(Transaction t) {
4425 super.onAnimationLeashDestroyed(t);
4426 updateSurfacePosition(t);
4427 }
4428
chaviwe07246a2017-12-12 16:18:29 -08004429 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004430 void updateSurfacePosition(Transaction t) {
4431 if (mSurfaceControl == null) {
4432 return;
4433 }
4434
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004435 transformFrameToSurfacePosition(mFrame.left, mFrame.top, mSurfacePosition);
4436 if (!mSurfaceAnimator.hasLeash()) {
4437 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
4438 }
4439 }
4440
4441 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4442 outPoint.set(left, top);
chaviwe07246a2017-12-12 16:18:29 -08004443 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004444 if (isChildWindow()) {
4445 // TODO: This probably falls apart at some point and we should
4446 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004447
4448 // Since the parent was outset by its surface insets, we need to undo the outsetting
4449 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004450 final WindowState parent = getParentWindow();
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004451 outPoint.offset(-parent.mFrame.left + parent.mAttrs.surfaceInsets.left,
4452 -parent.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004453 } else if (parentWindowContainer != null) {
4454 final Rect parentBounds = parentWindowContainer.getBounds();
4455 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004456 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004457
4458 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004459 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004460 }
4461
4462 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004463 void assignLayer(Transaction t, int layer) {
4464 // See comment in assignRelativeLayerForImeTargetChild
4465 if (!isChildWindow()
4466 || (mService.mInputMethodTarget != getParentWindow())
4467 || !inSplitScreenWindowingMode()) {
4468 super.assignLayer(t, layer);
4469 return;
4470 }
4471 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
4472 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004473
4474 @Override
4475 public boolean isDimming() {
4476 return mIsDimming;
4477 }
Robert Carr0eff1872017-12-01 14:27:04 -08004478
4479 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4480 // then we can drop all negative layering on the windowing side and simply inherit
4481 // the default implementation here.
4482 public void assignChildLayers(Transaction t) {
4483 int layer = 1;
4484 for (int i = 0; i < mChildren.size(); i++) {
4485 final WindowState w = mChildren.get(i);
4486
4487 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4488 // while they both need to go below the main window. However the
4489 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4490 // been defined and so we can use static layers and leave it that way.
4491 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4492 w.assignLayer(t, -2);
4493 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4494 w.assignLayer(t, -1);
4495 } else {
4496 w.assignLayer(t, layer);
4497 }
4498 w.assignChildLayers(t);
4499 layer++;
4500 }
4501 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004502
4503 private final class MoveAnimationSpec implements AnimationSpec {
4504
4505 private final long mDuration;
4506 private Interpolator mInterpolator;
4507 private Point mFrom = new Point();
4508 private Point mTo = new Point();
4509
4510 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4511 final Animation anim = AnimationUtils.loadAnimation(mContext,
4512 com.android.internal.R.anim.window_move_from_decor);
4513 mDuration = anim.computeDurationHint();
4514 mInterpolator = anim.getInterpolator();
4515 mFrom.set(fromX, fromY);
4516 mTo.set(toX, toY);
4517 }
4518
4519 @Override
4520 public long getDuration() {
4521 return mDuration;
4522 }
4523
4524 @Override
4525 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4526 final float fraction = (float) currentPlayTime / getDuration();
4527 final float v = mInterpolator.getInterpolation(fraction);
4528 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4529 mFrom.y + (mTo.y - mFrom.y) * v);
4530 }
4531 }
satokcef37fb2011-10-24 21:49:38 +09004532}