blob: eba7c3aa35cadcaf563e66f786edec5a86f45610 [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;
Winson Chungd73e94b2017-05-31 16:25:30 -070020import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080021import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Winson Chungd73e94b2017-05-31 16:25:30 -070022import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080023import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
24import static android.view.Display.DEFAULT_DISPLAY;
25import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
26import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
27import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
29import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
30import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
31import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
32import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
33import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
34import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
35import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
36import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
37import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
38import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080039import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
40import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
41import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080042import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080043import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
44import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
45import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070046import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080047import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
48import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
49import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
50import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
51import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
52import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carraf422a82017-04-10 18:34:33 -070053import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080054import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
55import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
56import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
57import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
58import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
59import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070060import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080061import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070062import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080063import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
64import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
65import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
66import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080067import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
68import static android.view.WindowManagerPolicy.TRANSIT_ENTER;
69import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
70import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
71import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
72import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
73import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
74import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
75import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
76import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
77import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
78import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
79import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
83import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020085import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080086import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
87import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
89import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
90import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
91import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
92import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
93import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
94import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
95import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
96import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
97import static com.android.server.wm.WindowManagerService.localLOGV;
98import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
99import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
100import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
101import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700102import static com.android.server.wm.proto.IdentifierProto.HASH_CODE;
103import static com.android.server.wm.proto.IdentifierProto.TITLE;
104import static com.android.server.wm.proto.IdentifierProto.USER_ID;
105import static com.android.server.wm.proto.WindowStateProto.ANIMATING_EXIT;
106import static com.android.server.wm.proto.WindowStateProto.ANIMATOR;
107import static com.android.server.wm.proto.WindowStateProto.ATTRIBUTES;
108import static com.android.server.wm.proto.WindowStateProto.CHILD_WINDOWS;
109import static com.android.server.wm.proto.WindowStateProto.CONTAINING_FRAME;
110import static com.android.server.wm.proto.WindowStateProto.CONTENT_FRAME;
111import static com.android.server.wm.proto.WindowStateProto.CONTENT_INSETS;
112import static com.android.server.wm.proto.WindowStateProto.DISPLAY_ID;
113import static com.android.server.wm.proto.WindowStateProto.FRAME;
114import static com.android.server.wm.proto.WindowStateProto.GIVEN_CONTENT_INSETS;
115import static com.android.server.wm.proto.WindowStateProto.IDENTIFIER;
116import static com.android.server.wm.proto.WindowStateProto.PARENT_FRAME;
117import static com.android.server.wm.proto.WindowStateProto.STACK_ID;
118import static com.android.server.wm.proto.WindowStateProto.SURFACE_INSETS;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700119import static com.android.server.wm.proto.WindowStateProto.WINDOW_CONTAINER;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800120
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700121import android.annotation.CallSuper;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800122import android.app.AppOpsManager;
123import android.content.Context;
124import android.content.res.Configuration;
125import android.graphics.Matrix;
126import android.graphics.PixelFormat;
127import android.graphics.Point;
128import android.graphics.Rect;
129import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700130import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700131import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800132import android.os.IBinder;
133import android.os.PowerManager;
134import android.os.RemoteCallbackList;
135import android.os.RemoteException;
136import android.os.SystemClock;
137import android.os.Trace;
138import android.os.UserHandle;
139import android.os.WorkSource;
140import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200141import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800142import android.util.Slog;
143import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700144import android.util.proto.ProtoOutputStream;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800145import android.view.DisplayInfo;
146import android.view.Gravity;
147import android.view.IApplicationToken;
148import android.view.IWindow;
149import android.view.IWindowFocusObserver;
150import android.view.IWindowId;
151import android.view.InputChannel;
152import android.view.InputEvent;
153import android.view.InputEventReceiver;
154import android.view.View;
155import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700156import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800157import android.view.WindowManager;
158import android.view.WindowManagerPolicy;
159
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800160import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800161import com.android.server.input.InputWindowHandle;
162
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800163import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200164import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800165import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700166import java.util.Comparator;
167import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800168import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800169
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700170/** A window in the window manager. */
171class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800172 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800173
Skuhne81c524a2015-08-12 13:34:14 -0700174 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700175 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
176 // use hard-coded min sizes for now.
177 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
178 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700179
180 // The thickness of a window resize handle outside the window bounds on the free form workspace
181 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700182 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700183
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700185 final WindowManagerPolicy mPolicy;
186 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 final Session mSession;
188 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800189 final int mAppOp;
190 // UserId and appId of the owner. Don't display windows of non-current user.
191 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800192 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
193 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200194 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700196 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700198
199 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
200 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
202 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700203 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 final int mBaseLayer;
205 final int mSubLayer;
206 final boolean mLayoutAttached;
207 final boolean mIsImWindow;
208 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700209 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700210 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700211 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800212 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700213 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700214 /**
215 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
216 * Normally set by calling {@link #showLw} and {@link #hideLw}.
217 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800218 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700219 /**
220 * What {@link #mPolicyVisibility} should be set to after a transition animation.
221 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
222 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
223 * animation is done.
224 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700226 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700227 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700228 // This is a non-system overlay window that is currently force hidden.
229 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700231 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700233 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200234 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700235 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700236
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700237 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800238
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700239 /**
240 * The window size that was requested by the application. These are in
241 * the application's coordinate space (without compatibility scale applied).
242 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 int mRequestedWidth;
244 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700245 private int mLastRequestedWidth;
246 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700247
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 boolean mHaveFrame;
250 boolean mObscured;
251 boolean mTurnOnScreen;
252
253 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700254
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700255 /**
256 * Used to store last reported to client configuration and check if we have newer available.
257 * We'll send configuration to client only if it is different from the last applied one and
258 * client won't perform unnecessary updates.
259 */
260 private final Configuration mLastReportedConfiguration = new Configuration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700261
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700262 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700263 * Actual position of the surface shown on-screen (may be modified by animation). These are
264 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700265 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700266 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267
268 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700269 * Insets that determine the actually visible area. These are in the application's
270 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271 */
272 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700273 private final Rect mLastVisibleInsets = new Rect();
274 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275
276 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700277 * Insets that are covered by system windows (such as the status bar) and
278 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700279 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280 */
281 final Rect mContentInsets = new Rect();
282 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700283
284 /**
285 * The last content insets returned to the client in relayout. We use
286 * these in the bounds animation to ensure we only observe inset changes
287 * at the same time that a client resizes it's surface so that we may use
288 * the geometryAppliesWithResize synchronization mechanism to keep
289 * the contents in place.
290 */
291 final Rect mLastRelayoutContentInsets = new Rect();
292
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700293 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294
295 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800296 * Insets that determine the area covered by the display overscan region. These are in the
297 * application's coordinate space (without compatibility scale applied).
298 */
299 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700300 private final Rect mLastOverscanInsets = new Rect();
301 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800302
303 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700304 * Insets that determine the area covered by the stable system windows. These are in the
305 * application's coordinate space (without compatibility scale applied).
306 */
307 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700308 private final Rect mLastStableInsets = new Rect();
309 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700310
311 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700312 * Outsets determine the area outside of the surface where we want to pretend that it's possible
313 * to draw anyway.
314 */
315 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700316 private final Rect mLastOutsets = new Rect();
317 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700318
319 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800320 * Set to true if we are waiting for this window to receive its
321 * given internal insets before laying out other windows based on it.
322 */
323 boolean mGivenInsetsPending;
324
325 /**
326 * These are the content insets that were given during layout for
327 * this window, to be applied to windows behind it.
328 */
329 final Rect mGivenContentInsets = new Rect();
330
331 /**
332 * These are the visible insets that were given during layout for
333 * this window, to be applied to windows behind it.
334 */
335 final Rect mGivenVisibleInsets = new Rect();
336
337 /**
338 * This is the given touchable area relative to the window frame, or null if none.
339 */
340 final Region mGivenTouchableRegion = new Region();
341
342 /**
343 * Flag indicating whether the touchable region should be adjusted by
344 * the visible insets; if false the area outside the visible insets is
345 * NOT touchable, so we must use those to adjust the frame during hit
346 * tests.
347 */
348 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
349
350 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400351 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700352 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 float mHScale=1, mVScale=1;
354 float mLastHScale=1, mLastVScale=1;
355 final Matrix mTmpMatrix = new Matrix();
356
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700357 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 final Rect mFrame = new Rect();
359 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700360 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700361 // Frame that is scaled to the application's coordinate space when in
362 // screen size compatibility mode.
363 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800364
365 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700366
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700367 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700368
Wale Ogunwale94596652015-02-06 19:27:34 -0800369 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
370 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700371 final Rect mDisplayFrame = new Rect();
372
373 // The region of the display frame that the display type supports displaying content on. This
374 // is mostly a special case for TV where some displays don’t have the entire display usable.
375 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
376 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700377 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700378
379 // The display frame minus the stable insets. This value is always constant regardless of if
380 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700381 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800382
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700383 // The area not occupied by the status and navigation bars. So, if both status and navigation
384 // bars are visible, the decor frame is equal to the stable frame.
385 final Rect mDecorFrame = new Rect();
386
387 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
388 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700389 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700390
391 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
392 // displays hint text.
393 final Rect mVisibleFrame = new Rect();
394
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700395 // Frame that includes dead area outside of the surface but where we want to pretend that it's
396 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700397 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700398
Jorim Jaggidc249c42015-12-15 14:57:31 -0800399 /**
400 * Usually empty. Set to the task's tempInsetFrame. See
401 *{@link android.app.IActivityManager#resizeDockedStack}.
402 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700403 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800404
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800405 boolean mContentChanged;
406
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800407 // If a window showing a wallpaper: the requested offset for the
408 // wallpaper; if a wallpaper window: the currently applied offset.
409 float mWallpaperX = -1;
410 float mWallpaperY = -1;
411
412 // If a window showing a wallpaper: what fraction of the offset
413 // range corresponds to a full virtual screen.
414 float mWallpaperXStep = -1;
415 float mWallpaperYStep = -1;
416
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700417 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
418 // to its window; if a wallpaper window: not used.
419 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
420 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
421
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800422 // Wallpaper windows: pixels offset based on above variables.
423 int mXOffset;
424 int mYOffset;
425
Craig Mautner2268e7e2012-12-13 15:40:00 -0800426 /**
427 * This is set after IWindowSession.relayout() has been called at
428 * least once for the window. It allows us to detect the situation
429 * where we don't yet have a surface, but should have one soon, so
430 * we can give the window focus before waiting for the relayout.
431 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800432 boolean mRelayoutCalled;
433
Robert Carrfed10072016-05-26 11:48:49 -0700434 boolean mInRelayout;
435
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800436 /**
437 * If the application has called relayout() with changes that can
438 * impact its window's size, we need to perform a layout pass on it
439 * even if it is not currently visible for layout. This is set
440 * when in that case until the layout is done.
441 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800442 boolean mLayoutNeeded;
443
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800444 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800445 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800446
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800447 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800448 boolean mDestroying;
449
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800450 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800451 boolean mRemoveOnExit;
452
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800453 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800454 * Whether the app died while it was visible, if true we might need
455 * to continue to show it until it's restarted.
456 */
457 boolean mAppDied;
458
459 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800460 * Set when the orientation is changing and this window has not yet
461 * been updated for the new orientation.
462 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700463 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464
Dianne Hackborna57c6952013-03-29 14:46:40 -0700465 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700466 * Sometimes in addition to the mOrientationChanging
467 * flag we report that the orientation is changing
468 * due to a mismatch in current and reported configuration.
469 *
470 * In the case of timeout we still need to make sure we
471 * leave the orientation changing state though, so we
472 * use this as a special time out escape hatch.
473 */
474 private boolean mOrientationChangeTimedOut;
475
476 /**
Robert Carr237028a2016-07-26 10:39:45 -0700477 * The orientation during the last visible call to relayout. If our
478 * current orientation is different, the window can't be ready
479 * to be shown.
480 */
481 int mLastVisibleLayoutRotation = -1;
482
483 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800484 * Set when we need to report the orientation change to client to trigger a relayout.
485 */
486 boolean mReportOrientationChanged;
487
488 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700489 * How long we last kept the screen frozen.
490 */
491 int mLastFreezeDuration;
492
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800493 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800494 boolean mRemoved;
495
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800496 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800497 * It is save to remove the window and destroy the surface because the client requested removal
498 * or some other higher level component said so (e.g. activity manager).
499 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800500 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700501 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800502
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800503 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700504 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800505 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700506 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800507
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800508 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700509 private String mStringNameCache;
510 private CharSequence mLastTitle;
511 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800512
Craig Mautnera2c77052012-03-26 12:14:43 -0700513 final WindowStateAnimator mWinAnimator;
514
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700515 boolean mHasSurface = false;
516
Craig Mautner88400d32012-09-30 12:35:45 -0700517 /** When true this window can be displayed on screens owther than mOwnerUid's */
518 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700519
Chong Zhang92147042016-05-09 12:47:11 -0700520 // Whether the window was visible when we set the app to invisible last time. WM uses
521 // this as a hint to restore the surface (if available) for early animation next time
522 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700523 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800524
Robert Carra1eb4392015-12-10 12:43:51 -0800525 // This window will be replaced due to relaunch. This allows window manager
526 // to differentiate between simple removal of a window and replacement. In the latter case it
527 // will preserve the old window until the new one is drawn.
528 boolean mWillReplaceWindow = false;
529 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700530 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800531 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700532 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800533 // If not null, the window that will be used to replace the old one. This is being set when
534 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700535 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700536 // For the new window in the replacement transition, if we have
537 // requested to replace without animation, then we should
538 // make sure we also don't apply an enter animation for
539 // the new window.
540 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800541 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700542 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800543
Jeff Brownc2932a12014-11-20 18:04:05 -0800544 /**
545 * Wake lock for drawing.
546 * Even though it's slightly more expensive to do so, we will use a separate wake lock
547 * for each app that is requesting to draw while dozing so that we can accurately track
548 * who is preventing the system from suspending.
549 * This lock is only acquired on first use.
550 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700551 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800552
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700553 final private Rect mTmpRect = new Rect();
554
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800555 /**
556 * Whether the window was resized by us while it was gone for layout.
557 */
558 boolean mResizedWhileGone = false;
559
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700560 /** @see #isResizedWhileNotDragResizing(). */
561 private boolean mResizedWhileNotDragResizing;
562
563 /** @see #isResizedWhileNotDragResizingReported(). */
564 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700565
Robert Carr6da3cc02016-06-16 15:17:07 -0700566 /**
567 * During seamless rotation we have two phases, first the old window contents
568 * are rotated to look as if they didn't move in the new coordinate system. Then we
569 * have to freeze updates to this layer (to preserve the transformation) until
570 * the resize actually occurs. This is true from when the transformation is set
571 * and false until the transaction to resize is sent.
572 */
573 boolean mSeamlesslyRotated = false;
574
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700575 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800576 * Surface insets from the previous call to relayout(), used to track
577 * if we are changing the Surface insets.
578 */
579 final Rect mLastSurfaceInsets = new Rect();
580
581 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700582 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
583 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
584 * make sure all children have been considered.
585 */
586 private boolean mDrawnStateEvaluated;
587
588 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700589 * 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 -0700590 * of z-order and 1 otherwise.
591 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800592 private static final Comparator<WindowState> sWindowSubLayerComparator =
593 new Comparator<WindowState>() {
594 @Override
595 public int compare(WindowState w1, WindowState w2) {
596 final int layer1 = w1.mSubLayer;
597 final int layer2 = w2.mSubLayer;
598 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
599 // We insert the child window into the list ordered by
600 // the sub-layer. For same sub-layers, the negative one
601 // should go below others; the positive one should go
602 // above others.
603 return -1;
604 }
605 return 1;
606 };
607 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700608
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800609 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700610 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800611 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800612 mService = service;
613 mSession = s;
614 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800615 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800616 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700617 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700618 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800619 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200620 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800621 mAttrs.copyFrom(a);
622 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700623 mPolicy = mService.mPolicy;
624 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800625 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700626 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700627 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700628 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700629 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700630 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800631 try {
632 c.asBinder().linkToDeath(deathRecipient, 0);
633 } catch (RemoteException e) {
634 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700635 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636 mLayoutAttached = false;
637 mIsImWindow = false;
638 mIsWallpaper = false;
639 mIsFloatingLayer = false;
640 mBaseLayer = 0;
641 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700642 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700643 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800644 return;
645 }
646 mDeathRecipient = deathRecipient;
647
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700648 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800649 // The multiplier here is to reserve space for multiple
650 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800651 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700652 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800653 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700654 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900655
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700656 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
657 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900658
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800659 mLayoutAttached = mAttrs.type !=
660 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700661 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
662 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
663 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664 } else {
665 // The multiplier here is to reserve space for multiple
666 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800667 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700668 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800669 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700670 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800671 mLayoutAttached = false;
672 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
673 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
674 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800675 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700676 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800677
Wale Ogunwale72919d22016-12-08 18:58:50 -0800678 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700679 // Windows for apps that can show for all users should also show when the device is
680 // locked.
681 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700682 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800683
Craig Mautner322e4032012-07-13 13:35:20 -0700684 mWinAnimator = new WindowStateAnimator(this);
685 mWinAnimator.mAlpha = a.alpha;
686
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800687 mRequestedWidth = 0;
688 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700689 mLastRequestedWidth = 0;
690 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800691 mXOffset = 0;
692 mYOffset = 0;
693 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800694 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800695 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
696 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800697 }
698
699 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700700 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800701 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800702 }
703
Bryce Leed390deb2017-06-22 13:14:28 -0700704 /**
705 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
706 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700707 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700708 return mDrawnStateEvaluated;
709 }
710
711 /**
712 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
713 * be cleared when detached from parent.
714 */
715 void setDrawnStateEvaluated(boolean evaluated) {
716 mDrawnStateEvaluated = evaluated;
717 }
718
719 @Override
720 void onParentSet() {
721 super.onParentSet();
722 setDrawnStateEvaluated(false /*evaluated*/);
723 }
724
Craig Mautnera2c77052012-03-26 12:14:43 -0700725 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800726 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800727 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800728 }
729
730 @Override
731 public String getOwningPackage() {
732 return mAttrs.packageName;
733 }
734
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800735 @Override
736 public boolean canAddInternalSystemWindow() {
737 return mOwnerCanAddInternalSystemWindow;
738 }
739
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200740 @Override
741 public boolean canAcquireSleepToken() {
742 return mSession.mCanAcquireSleepToken;
743 }
744
Jorim Jaggif5834272016-04-04 20:25:41 -0700745 /**
746 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
747 * from {@param frame}. In other words, it applies the insets that would result if
748 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700749 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
750 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700751 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700752 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
753 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
754 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
755 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
756 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700757 frame.inset(left, top, right, bottom);
758 }
759
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800760 @Override
Robert Carr43521762016-10-28 13:15:04 -0700761 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
762 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
763 Rect outsetFrame) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800764 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700765 // This window is being replaced and either already got information that it's being
766 // removed or we are still waiting for some information. Because of this we don't
767 // want to apply any more changes to it, so it remains in this state until new window
768 // appears.
769 return;
770 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800771 mHaveFrame = true;
772
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700773 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700774 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800775 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700776 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800777
Chong Zhangae35fef2016-03-16 15:56:55 -0700778 // If the task has temp inset bounds set, we have to make sure all its windows uses
779 // the temp inset frame. Otherwise different display frames get applied to the main
780 // window and the child window, making them misaligned.
Andrii Kulianc24f3732017-08-08 19:35:17 -0700781 if (inFullscreenContainer || isLetterboxedAppWindow()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700782 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700783 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700784 task.getTempInsetBounds(mInsetFrame);
785 }
786
Jorim Jaggif5834272016-04-04 20:25:41 -0700787 // Denotes the actual frame used to calculate the insets and to perform the layout. When
788 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
789 // insets temporarily. By the notion of a task having a different layout frame, we can
790 // achieve that while still moving the task around.
791 final Rect layoutContainingFrame;
792 final Rect layoutDisplayFrame;
793
794 // The offset from the layout containing frame to the actual containing frame.
795 final int layoutXDiff;
796 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700797 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800798 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700799 mContainingFrame.set(parentFrame);
800 mDisplayFrame.set(displayFrame);
801 layoutDisplayFrame = displayFrame;
802 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700803 layoutXDiff = 0;
804 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800805 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700806 getContainerBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100807 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
808
809 // If the bounds are frozen, we still want to translate the window freely and only
810 // freeze the size.
811 Rect frozen = mAppToken.mFrozenBounds.peek();
812 mContainingFrame.right = mContainingFrame.left + frozen.width();
813 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
814 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800815 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700816 // IME is up and obscuring this window. Adjust the window position so it is visible.
817 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700818 final int stackId = getStackId();
819 if (stackId == FREEFORM_WORKSPACE_STACK_ID
820 && mContainingFrame.bottom > contentFrame.bottom) {
821 // In freeform we want to move the top up directly.
822 // TODO: Investigate why this is contentFrame not parentFrame.
823 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
824 } else if (stackId != PINNED_STACK_ID
825 && mContainingFrame.bottom > parentFrame.bottom) {
826 // But in docked we want to behave like fullscreen and behave as if the task
827 // were given smaller bounds for the purposes of layout. Skip adjustments for
828 // the pinned stack, they are handled separately in the PinnedStackController.
829 mContainingFrame.bottom = parentFrame.bottom;
830 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700831 }
Skuhne81c524a2015-08-12 13:34:14 -0700832
Robert Carre6275582016-02-29 15:45:45 -0800833 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700834 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
835 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800836 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700837 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700838 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700839 }
Doris Liu06d582d2015-06-01 13:18:43 -0700840 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800841 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700842 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
843 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
844 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700845 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700846 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700847 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700848 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
849 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700850 }
Robert Carr43521762016-10-28 13:15:04 -0700851 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700852 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700853 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800854
Craig Mautner967212c2013-04-13 21:10:58 -0700855 final int pw = mContainingFrame.width();
856 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800857
Robert Carr43521762016-10-28 13:15:04 -0700858 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800859 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700860 // + " to " + parentFrame);
861 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800862 mContentChanged = true;
863 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700864 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
865 mLastRequestedWidth = mRequestedWidth;
866 mLastRequestedHeight = mRequestedHeight;
867 mContentChanged = true;
868 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800869
Robert Carr43521762016-10-28 13:15:04 -0700870 mOverscanFrame.set(overscanFrame);
871 mContentFrame.set(contentFrame);
872 mVisibleFrame.set(visibleFrame);
873 mDecorFrame.set(decorFrame);
874 mStableFrame.set(stableFrame);
875 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700876 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700877 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700878 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800879
Craig Mautnereda67292013-04-28 13:50:14 -0700880 final int fw = mFrame.width();
881 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800882
Jorim Jaggif5834272016-04-04 20:25:41 -0700883 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
884
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700885 // Calculate the outsets before the content frame gets shrinked to the window frame.
886 if (hasOutsets) {
887 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
888 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
889 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
890 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
891 } else {
892 mOutsets.set(0, 0, 0, 0);
893 }
894
Craig Mautnera248eee2013-05-07 11:41:27 -0700895 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800896 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800897 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800898 // For pinned workspace the frame isn't limited in any particular
899 // way since SystemUI controls the bounds. For freeform however
900 // we want to keep things inside the content frame.
901 final Rect limitFrame = task.inPinnedWorkspace() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700902 // Keep the frame out of the blocked system area, limit it in size to the content area
903 // and make sure that there is always a minimum visible so that the user can drag it
904 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800905 final int height = Math.min(mFrame.height(), limitFrame.height());
906 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700907 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900908 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
909 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
910 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
911 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800912 final int top = Math.max(limitFrame.top,
913 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
914 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
915 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700916 mFrame.set(left, top, left + width, top + height);
917 mContentFrame.set(mFrame);
918 mVisibleFrame.set(mContentFrame);
919 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700920 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700921 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100922 mContentFrame.set(mFrame);
923 if (!mFrame.equals(mLastFrame)) {
924 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800925 }
Skuhne81c524a2015-08-12 13:34:14 -0700926 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700927 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
928 Math.max(mContentFrame.top, mFrame.top),
929 Math.min(mContentFrame.right, mFrame.right),
930 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800931
Jorim Jaggi656f6502016-04-11 21:08:17 -0700932 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
933 Math.max(mVisibleFrame.top, mFrame.top),
934 Math.min(mVisibleFrame.right, mFrame.right),
935 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800936
Jorim Jaggi656f6502016-04-11 21:08:17 -0700937 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
938 Math.max(mStableFrame.top, mFrame.top),
939 Math.min(mStableFrame.right, mFrame.right),
940 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700941 }
Adrian Roosfa104232014-06-20 16:10:14 -0700942
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700943 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500944 // Windows that are not fullscreen can be positioned outside of the display frame,
945 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700946 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
947 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
948 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
949 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800950 }
Craig Mautnereda67292013-04-28 13:50:14 -0700951
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100952 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100953 // For the docked divider, we calculate the stable insets like a full-screen window
954 // so it can use it to calculate the snap positions.
955 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
956 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
957 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
958 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800959
960 // The divider doesn't care about insets in any case, so set it to empty so we don't
961 // trigger a relayout when moving it.
962 mContentInsets.setEmpty();
963 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100964 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700965 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700966 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
967 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700968 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
969 && mFrame.right > mTmpRect.right;
970 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
971 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700972 mContentInsets.set(mContentFrame.left - mFrame.left,
973 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700974 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700975 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700976 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700977 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800978
Jorim Jaggi656f6502016-04-11 21:08:17 -0700979 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
980 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700981 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700982 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700983 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700984 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800985
Jorim Jaggi656f6502016-04-11 21:08:17 -0700986 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
987 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700988 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700989 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700990 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700991 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100992 }
Adrian Roosfa104232014-06-20 16:10:14 -0700993
Jorim Jaggi656f6502016-04-11 21:08:17 -0700994 // Offset the actual frame by the amount layout frame is off.
995 mFrame.offset(-layoutXDiff, -layoutYDiff);
996 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700997 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
998 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
999 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1000
Craig Mautnereda67292013-04-28 13:50:14 -07001001 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001002 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001003 // If there is a size compatibility scale being applied to the
1004 // window, we need to apply this to its insets so that they are
1005 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001006 mOverscanInsets.scale(mInvGlobalScale);
1007 mContentInsets.scale(mInvGlobalScale);
1008 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001009 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001010 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001011
1012 // Also the scaled frame that we report to the app needs to be
1013 // adjusted to be in its coordinate space.
1014 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001015 }
1016
Craig Mautnereda67292013-04-28 13:50:14 -07001017 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001018 final DisplayContent displayContent = getDisplayContent();
1019 if (displayContent != null) {
1020 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001021 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001022 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001023 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001024 }
1025
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001026 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001027 "Resolving (mRequestedWidth="
1028 + mRequestedWidth + ", mRequestedheight="
1029 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1030 + "): frame=" + mFrame.toShortString()
1031 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001032 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001033 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001034 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001035 }
1036
Craig Mautnera2c77052012-03-26 12:14:43 -07001037 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001038 public Rect getFrameLw() {
1039 return mFrame;
1040 }
1041
Craig Mautnera2c77052012-03-26 12:14:43 -07001042 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001043 public Point getShownPositionLw() {
1044 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001045 }
1046
Craig Mautnera2c77052012-03-26 12:14:43 -07001047 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001048 public Rect getDisplayFrameLw() {
1049 return mDisplayFrame;
1050 }
1051
Craig Mautnera2c77052012-03-26 12:14:43 -07001052 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001053 public Rect getOverscanFrameLw() {
1054 return mOverscanFrame;
1055 }
1056
1057 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001058 public Rect getContentFrameLw() {
1059 return mContentFrame;
1060 }
1061
Craig Mautnera2c77052012-03-26 12:14:43 -07001062 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001063 public Rect getVisibleFrameLw() {
1064 return mVisibleFrame;
1065 }
1066
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001067 Rect getStableFrameLw() {
1068 return mStableFrame;
1069 }
1070
Craig Mautnera2c77052012-03-26 12:14:43 -07001071 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001072 public boolean getGivenInsetsPendingLw() {
1073 return mGivenInsetsPending;
1074 }
1075
Craig Mautnera2c77052012-03-26 12:14:43 -07001076 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001077 public Rect getGivenContentInsetsLw() {
1078 return mGivenContentInsets;
1079 }
1080
Craig Mautnera2c77052012-03-26 12:14:43 -07001081 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001082 public Rect getGivenVisibleInsetsLw() {
1083 return mGivenVisibleInsets;
1084 }
1085
Craig Mautnera2c77052012-03-26 12:14:43 -07001086 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001087 public WindowManager.LayoutParams getAttrs() {
1088 return mAttrs;
1089 }
1090
Craig Mautner812d2ca2012-09-27 15:35:34 -07001091 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001092 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001093 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001094 }
1095
Craig Mautner19d59bc2012-09-04 11:15:56 -07001096 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001097 public int getSystemUiVisibility() {
1098 return mSystemUiVisibility;
1099 }
1100
Craig Mautner19d59bc2012-09-04 11:15:56 -07001101 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001102 public int getSurfaceLayer() {
1103 return mLayer;
1104 }
1105
Craig Mautner812d2ca2012-09-27 15:35:34 -07001106 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001107 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001108 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001109 }
1110
1111 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001112 public IApplicationToken getAppToken() {
1113 return mAppToken != null ? mAppToken.appToken : null;
1114 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001115
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001116 @Override
1117 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001118 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001119 }
1120
Robert Carr31aa98b2016-07-20 15:29:03 -07001121 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001122 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1123 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1124 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001125 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001126 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001127 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1128 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001129 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001130 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001131 }
1132
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001133 /**
1134 * Adds the window to the resizing list if any of the parameters we use to track the window
1135 * dimensions or insets have changed.
1136 */
1137 void updateResizingWindowIfNeeded() {
1138 final WindowStateAnimator winAnimator = mWinAnimator;
1139 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1140 return;
1141 }
1142
1143 final Task task = getTask();
1144 // In the case of stack bound animations, the window frames will update (unlike other
1145 // animations which just modify various transformation properties). We don't want to
1146 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1147 // the frame may not correspond to the surface size or the onscreen area at various
1148 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001149 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001150 return;
1151 }
1152
1153 setReportResizeHints();
1154 boolean configChanged = isConfigChanged();
1155 if (DEBUG_CONFIGURATION && configChanged) {
1156 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1157 }
1158
1159 final boolean dragResizingChanged = isDragResizeChanged()
1160 && !isDragResizingChangeReported();
1161
1162 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1163 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1164 + " frame=" + mFrame);
1165
1166 // We update mLastFrame always rather than in the conditional with the last inset
1167 // variables, because mFrameSizeChanged only tracks the width and height changing.
1168 mLastFrame.set(mFrame);
1169
1170 if (mContentInsetsChanged
1171 || mVisibleInsetsChanged
1172 || winAnimator.mSurfaceResized
1173 || mOutsetsChanged
1174 || mFrameSizeChanged
1175 || configChanged
1176 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001177 || !isResizedWhileNotDragResizingReported()
1178 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001179 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1180 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1181 + " contentInsetsChanged=" + mContentInsetsChanged
1182 + " " + mContentInsets.toShortString()
1183 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1184 + " " + mVisibleInsets.toShortString()
1185 + " stableInsetsChanged=" + mStableInsetsChanged
1186 + " " + mStableInsets.toShortString()
1187 + " outsetsChanged=" + mOutsetsChanged
1188 + " " + mOutsets.toShortString()
1189 + " surfaceResized=" + winAnimator.mSurfaceResized
1190 + " configChanged=" + configChanged
1191 + " dragResizingChanged=" + dragResizingChanged
1192 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001193 + isResizedWhileNotDragResizingReported()
1194 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001195 }
1196
1197 // If it's a dead window left on screen, and the configuration changed, there is nothing
1198 // we can do about it. Remove the window now.
1199 if (mAppToken != null && mAppDied) {
1200 mAppToken.removeDeadWindows();
1201 return;
1202 }
1203
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001204 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001205 mService.makeWindowFreezingScreenIfNeededLocked(this);
1206
1207 // If the orientation is changing, or we're starting or ending a drag resizing action,
1208 // then we need to hold off on unfreezing the display until this window has been
1209 // redrawn; to do that, we need to go through the process of getting informed by the
1210 // application when it has finished drawing.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001211 if (getOrientationChanging() || dragResizingChanged
1212 || isResizedWhileNotDragResizing()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001213 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1214 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1215 + ", mDrawState=DRAW_PENDING in " + this
1216 + ", surfaceController " + winAnimator.mSurfaceController);
1217 }
1218 winAnimator.mDrawState = DRAW_PENDING;
1219 if (mAppToken != null) {
1220 mAppToken.clearAllDrawn();
1221 }
1222 }
1223 if (!mService.mResizingWindows.contains(this)) {
1224 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1225 mService.mResizingWindows.add(this);
1226 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001227 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001228 if (isDrawnLw()) {
1229 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1230 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001231 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001232 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1233 - mService.mDisplayFreezeTime);
1234 }
1235 }
1236 }
1237
Bryce Lee8c3cf382017-07-06 19:47:10 -07001238 boolean getOrientationChanging() {
1239 // In addition to the local state flag, we must also consider the difference in the last
1240 // reported configuration vs. the current state. If the client code has not been informed of
1241 // the change, logic dependent on having finished processing the orientation, such as
1242 // unfreezing, could be improperly triggered.
1243 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1244 // this is not necessarily what the client has processed yet. Find a
1245 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001246 return (mOrientationChanging || (isVisible()
1247 && getConfiguration().orientation != mLastReportedConfiguration.orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001248 && !mSeamlesslyRotated
1249 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001250 }
1251
1252 void setOrientationChanging(boolean changing) {
1253 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001254 mOrientationChangeTimedOut = false;
1255 }
1256
1257 void orientationChangeTimedOut() {
1258 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001259 }
1260
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001261 DisplayContent getDisplayContent() {
1262 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001263 }
1264
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001265 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001266 final DisplayContent displayContent = getDisplayContent();
1267 return displayContent != null ? displayContent.getDisplayInfo() : null;
1268 }
1269
Jorim Jaggife762342016-10-13 14:33:27 +02001270 @Override
1271 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001272 final DisplayContent displayContent = getDisplayContent();
1273 if (displayContent == null) {
1274 return -1;
1275 }
1276 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001277 }
1278
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001279 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001280 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001281 }
1282
1283 TaskStack getStack() {
1284 Task task = getTask();
1285 if (task != null) {
1286 if (task.mStack != null) {
1287 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001288 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001289 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001290 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1291 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001292 final DisplayContent dc = getDisplayContent();
1293 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001294 }
1295
Skuhnef932e562015-08-20 12:07:30 -07001296 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001297 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001298 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001299 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001300 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001301 final Task task = getTask();
1302 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001303 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001304 mTmpRect.setEmpty();
1305 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001306 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001307 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001308 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001309 } else {
1310 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001311 }
1312 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001313
Chong Zhang9184ec62015-09-24 12:32:21 -07001314 bounds.set(mVisibleFrame);
1315 if (intersectWithStackBounds) {
1316 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001317 }
1318
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001319 if (bounds.isEmpty()) {
1320 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001321 if (intersectWithStackBounds) {
1322 bounds.intersect(mTmpRect);
1323 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001324 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001325 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001326 }
1327
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001328 public long getInputDispatchingTimeoutNanos() {
1329 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001330 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001331 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1332 }
1333
Craig Mautnere8552142012-11-07 13:55:47 -08001334 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001335 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001336 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001337 }
1338
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001339 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1340 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1341 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1342 if (dtdx < -.000001f || dtdx > .000001f) return false;
1343 if (dsdy < -.000001f || dsdy > .000001f) return false;
1344 return true;
1345 }
1346
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001347 void prelayout() {
1348 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001349 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1350 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001351 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001352 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001353 }
1354 }
1355
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001356 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001357 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001358 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001359 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1360 return true;
1361 }
1362
Wale Ogunwale44f21802016-09-02 12:49:48 -07001363 return super.hasContentToDisplay();
1364 }
1365
1366 @Override
1367 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001368 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001369 }
1370
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001371 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001372 * @return True if the window would be visible if we'd ignore policy visibility, false
1373 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001374 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001375 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001376 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001377 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001378 }
1379
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001380 @Override
1381 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001382 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001383 }
1384
1385 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001386 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1387 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001388 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001389 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1390 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001391 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001392 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001393 }
1394
1395 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001396 * The same as isVisible(), but follows the current hidden state of the associated app token,
1397 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001398 */
1399 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001400 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001401 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001402 }
1403
1404 /**
1405 * Can this window possibly be a drag/drop target? The test here is
1406 * a combination of the above "visible now" with the check that the
1407 * Input Manager uses when discarding windows from input consideration.
1408 */
1409 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001410 return isVisibleNow() && !mRemoved
1411 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 }
1413
1414 /**
1415 * Same as isVisible(), but we also count it as visible between the
1416 * call to IWindowSession.add() and the first relayout().
1417 */
1418 boolean isVisibleOrAdding() {
1419 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001420 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001421 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001422 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001423 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001424 }
1425
1426 /**
1427 * Is this window currently on-screen? It is on-screen either if it
1428 * is visible or it is currently running an animation before no longer
1429 * being visible.
1430 */
1431 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001432 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001433 return false;
1434 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001435 final AppWindowToken atoken = mAppToken;
1436 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001437 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001438 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001439 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001440 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001441 }
1442
1443 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001444 * Whether this window's drawn state might affect the drawn states of the app token.
1445 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001446 * @return true if the window should be considered while evaluating allDrawn flags.
1447 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001448 boolean mightAffectAllDrawn() {
1449 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1450 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1451 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001452 }
1453
1454 /**
1455 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1456 * it must be drawn before allDrawn can become true.
1457 */
1458 boolean isInteresting() {
1459 return mAppToken != null && !mAppDied
1460 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1461 }
1462
1463 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001464 * Like isOnScreen(), but we don't return true if the window is part
1465 * of a transition that has not yet been started.
1466 */
1467 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001468 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001469 return false;
1470 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001471 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001472 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001473 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001474 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001475 }
1476
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001477 // TODO: Another visibility method that was added late in the release to minimize risk.
1478 @Override
1479 public boolean canAffectSystemUiFlags() {
Jorim Jaggib7202a82017-09-11 16:58:53 +02001480 final boolean shown = mWinAnimator.getShown();
Jorim Jaggic0c93242017-08-04 16:05:02 +02001481
1482 // We only consider the app to be exiting when the animation has started. After the app
1483 // transition is executed the windows are marked exiting before the new windows have been
1484 // shown. Thus, wait considering a window to be exiting after the animation has actually
1485 // started.
1486 final boolean appAnimationStarting = mAppToken != null
1487 && mAppToken.mAppAnimator.isAnimationStarting();
1488 final boolean exitingSelf = mAnimatingExit && (!mWinAnimator.isAnimationStarting()
1489 && !appAnimationStarting);
1490 final boolean appExiting = mAppToken != null && mAppToken.hidden && !appAnimationStarting;
1491
1492 final boolean exiting = exitingSelf || mDestroying || appExiting;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001493 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggib7202a82017-09-11 16:58:53 +02001494
1495 // If we are entering with a dummy animation, avoid affecting SystemUI flags until the
1496 // transition is starting.
1497 final boolean enteringWithDummyAnimation =
1498 mWinAnimator.isDummyAnimation() && mWinAnimator.mShownAlpha == 0f;
1499 return shown && !exiting && !translucent && !enteringWithDummyAnimation;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001500 }
1501
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001502 /**
1503 * Like isOnScreen, but returns false if the surface hasn't yet
1504 * been drawn.
1505 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001506 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001507 public boolean isDisplayedLw() {
1508 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001509 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001510 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001511 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001512 || mWinAnimator.mAnimating
1513 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001514 }
1515
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001516 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001517 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001518 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001519 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001520 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001521 return mWinAnimator.mAnimation != null
1522 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001523 }
1524
Craig Mautner812d2ca2012-09-27 15:35:34 -07001525 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001526 public boolean isGoneForLayoutLw() {
1527 final AppWindowToken atoken = mAppToken;
1528 return mViewVisibility == View.GONE
1529 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001530 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001531 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001532 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001533 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001534 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001535 }
1536
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001537 /**
1538 * Returns true if the window has a surface that it has drawn a
1539 * complete UI in to.
1540 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001541 public boolean isDrawFinishedLw() {
1542 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001543 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1544 || mWinAnimator.mDrawState == READY_TO_SHOW
1545 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001546 }
1547
1548 /**
1549 * Returns true if the window has a surface that it has drawn a
1550 * complete UI in to.
1551 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001552 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001553 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001554 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001555 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001556 }
1557
1558 /**
1559 * Return true if the window is opaque and fully drawn. This indicates
1560 * it may obscure windows behind it.
1561 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001562 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001563 // When there is keyguard, wallpaper could be placed over the secure app
1564 // window but invisible. We need to check wallpaper visibility explicitly
1565 // to determine if it's occluding apps.
1566 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1567 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001568 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001569 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001570 }
1571
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001572 @Override
1573 void onMovedByResize() {
1574 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001575 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001576 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001577 }
1578
1579 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1580 boolean changed = false;
1581
1582 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001583 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001584 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1585 }
1586
1587 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1588 // Starting window that's exiting will be removed when the animation finishes.
1589 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1590 // to actually remove it.
1591 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1592 mAnimatingExit = true;
1593 mRemoveOnExit = true;
1594 mWindowRemovalAllowed = true;
1595 }
1596 return changed;
1597 }
1598
Robert Carrd5c7dd62017-03-08 10:39:30 -08001599 // Next up we will notify the client that it's visibility has changed.
1600 // We need to prevent it from destroying child surfaces until
1601 // the animation has finished.
1602 if (!visible && isVisibleNow()) {
1603 mWinAnimator.detachChildren();
1604 }
1605
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001606 if (visible != isVisibleNow()) {
1607 if (!runningAppAnimation) {
1608 final AccessibilityController accessibilityController =
1609 mService.mAccessibilityController;
1610 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1611 mWinAnimator.applyAnimationLocked(winTransit, visible);
1612 //TODO (multidisplay): Magnification is supported only for the default
1613 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1614 accessibilityController.onWindowTransitionLocked(this, winTransit);
1615 }
1616 }
1617 changed = true;
1618 setDisplayLayoutNeeded();
1619 }
1620
1621 return changed;
1622 }
1623
1624 boolean onSetAppExiting() {
1625 final DisplayContent displayContent = getDisplayContent();
1626 boolean changed = false;
1627
1628 if (isVisibleNow()) {
1629 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1630 //TODO (multidisplay): Magnification is supported only for the default
1631 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1632 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1633 }
1634 changed = true;
1635 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001636 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001637 }
1638 }
1639
1640 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001641 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001642 changed |= c.onSetAppExiting();
1643 }
1644
1645 return changed;
1646 }
1647
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001648 @Override
1649 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001650 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1651 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001652 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001653 resizingWindows.add(this);
1654
1655 // If we are not drag resizing, force recreating of a new surface so updating
1656 // the content and positioning that surface will be in sync.
1657 //
1658 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1659 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1660 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1661 // their frame to update crop, etc...
1662 //
1663 // Anyway we don't need to synchronize position and content updates for these
1664 // windows since they aren't at the base layer and could be moved around anyway.
1665 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001666 !mWinAnimator.isForceScaled() && !isGoneForLayoutLw() &&
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001667 !getTask().inPinnedWorkspace()) {
1668 setResizedWhileNotDragResizing(true);
1669 }
1670 }
1671 if (isGoneForLayoutLw()) {
1672 mResizedWhileGone = true;
1673 }
1674
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001675 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001676 }
1677
1678 void onUnfreezeBounds() {
1679 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001680 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001681 c.onUnfreezeBounds();
1682 }
1683
1684 if (!mHasSurface) {
1685 return;
1686 }
1687
1688 mLayoutNeeded = true;
1689 setDisplayLayoutNeeded();
1690 if (!mService.mResizingWindows.contains(this)) {
1691 mService.mResizingWindows.add(this);
1692 }
1693 }
1694
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001695 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001696 * If the window has moved due to its containing content frame changing, then notify the
1697 * listeners and optionally animate it. Simply checking a change of position is not enough,
1698 * because being move due to dock divider is not a trigger for animation.
1699 */
1700 void handleWindowMovedIfNeeded() {
1701 if (!hasMoved()) {
1702 return;
1703 }
1704
1705 // Frame has moved, containing content frame has also moved, and we're not currently
1706 // animating... let's do something.
1707 final int left = mFrame.left;
1708 final int top = mFrame.top;
1709 final Task task = getTask();
1710 final boolean adjustedForMinimizedDockOrIme = task != null
1711 && (task.mStack.isAdjustedForMinimizedDockedStack()
1712 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001713 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001714 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1715 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001716 && getWindowConfiguration().hasMovementAnimations()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001717 && !mWinAnimator.mLastHidden) {
1718 mWinAnimator.setMoveAnimation(left, top);
1719 }
1720
1721 //TODO (multidisplay): Accessibility supported only for the default display.
1722 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001723 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001724 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1725 }
1726
1727 try {
1728 mClient.moved(left, top);
1729 } catch (RemoteException e) {
1730 }
1731 mMovedByResize = false;
1732 }
1733
1734 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001735 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001736 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1737 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001738 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001739 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001740 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001741 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001742 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001743 }
1744
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001745 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001746 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001747 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001748 return false;
1749 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001750 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001751 }
1752
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001753 boolean fillsDisplay() {
1754 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001755 return mFrame.left <= 0 && mFrame.top <= 0
1756 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001757 }
1758
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001759 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001760 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001761 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001762 }
1763
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001764 void onWindowReplacementTimeout() {
1765 if (mWillReplaceWindow) {
1766 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001767 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001768 // delays removal on certain conditions, which will leave the stale window in the
1769 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1770 //
1771 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001772 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001773 } else {
1774 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001775 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001776 c.onWindowReplacementTimeout();
1777 }
1778 }
1779 }
1780
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001781 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001782 void forceWindowsScaleableInTransaction(boolean force) {
1783 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1784 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1785 }
1786
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001787 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001788 }
1789
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001790 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001791 void removeImmediately() {
1792 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001793
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001794 if (mRemoved) {
1795 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001796 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1797 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001798 return;
1799 }
1800
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001801 mRemoved = true;
1802
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001803 mWillReplaceWindow = false;
1804 if (mReplacementWindow != null) {
1805 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1806 }
1807
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001808 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001809 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001810 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001811 }
1812
1813 final int type = mAttrs.type;
1814 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001815 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001816 }
1817 mPolicy.removeWindowLw(this);
1818
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001819 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001820
Craig Mautner96868332012-12-04 14:29:11 -08001821 mWinAnimator.destroyDeferredSurfaceLocked();
1822 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001823 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001824 try {
1825 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1826 } catch (RuntimeException e) {
1827 // Ignore if it has already been removed (usually because
1828 // we are doing this as part of processing a death note.)
1829 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001830
1831 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001832 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001833
Wale Ogunwale571771c2016-08-26 13:18:50 -07001834 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001835 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001836 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001837 removeIfPossible(false /*keepVisibleDeadWindow*/);
1838 }
1839
Wale Ogunwale571771c2016-08-26 13:18:50 -07001840 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001841 mWindowRemovalAllowed = true;
1842 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1843 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1844
1845 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1846 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1847 "Starting window removed " + this);
1848
1849 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1850 Slog.v(TAG_WM, "Remove " + this + " client="
1851 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1852 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1853 + Debug.getCallers(5));
1854
1855 final long origId = Binder.clearCallingIdentity();
1856
1857 disposeInputChannel();
1858
1859 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1860 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1861 + " mAnimatingExit=" + mAnimatingExit
1862 + " mRemoveOnExit=" + mRemoveOnExit
1863 + " mHasSurface=" + mHasSurface
1864 + " surfaceShowing=" + mWinAnimator.getShown()
1865 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1866 + " app-animation="
1867 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1868 + " mWillReplaceWindow=" + mWillReplaceWindow
1869 + " inPendingTransaction="
1870 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1871 + " mDisplayFrozen=" + mService.mDisplayFrozen
1872 + " callers=" + Debug.getCallers(6));
1873
1874 // Visibility of the removed window. Will be used later to update orientation later on.
1875 boolean wasVisible = false;
1876
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001877 final int displayId = getDisplayId();
1878
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001879 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1880 // window until the animation is done. If the display is frozen, just remove immediately,
1881 // since the animation wouldn't be seen.
David Stevens9440dc82017-03-16 19:00:20 -07001882 if (mHasSurface && mToken.okToAnimate()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001883 if (mWillReplaceWindow) {
1884 // This window is going to be replaced. We need to keep it around until the new one
1885 // gets added, then we will get rid of this one.
1886 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1887 "Preserving " + this + " until the new one is " + "added");
1888 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1889 // been removed. We probably need another flag to indicate that window removal
1890 // should be deffered vs. overloading the flag that says we are playing an exit
1891 // animation.
1892 mAnimatingExit = true;
1893 mReplacingRemoveRequested = true;
1894 Binder.restoreCallingIdentity(origId);
1895 return;
1896 }
1897
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001898 // If we are not currently running the exit animation, we need to see about starting one
1899 wasVisible = isWinVisibleLw();
1900
1901 if (keepVisibleDeadWindow) {
1902 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1903 "Not removing " + this + " because app died while it's visible");
1904
1905 mAppDied = true;
1906 setDisplayLayoutNeeded();
1907 mService.mWindowPlacerLocked.performSurfacePlacement();
1908
1909 // Set up a replacement input channel since the app is now dead.
1910 // We need to catch tapping on the dead window to restart the app.
1911 openInputChannel(null);
1912 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1913
1914 Binder.restoreCallingIdentity(origId);
1915 return;
1916 }
1917
1918 if (wasVisible) {
1919 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1920
1921 // Try starting an animation.
1922 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1923 mAnimatingExit = true;
1924 }
1925 //TODO (multidisplay): Magnification is supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001926 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001927 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1928 }
1929 }
1930 final boolean isAnimating =
1931 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1932 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001933 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001934 // We delay the removal of a window if it has a showing surface that can be used to run
1935 // exit animation and it is marked as exiting.
1936 // Also, If isn't the an animating starting window that is the last window in the app.
1937 // We allow the removal of the non-animating starting window now as there is no
1938 // additional window or animation that will trigger its removal.
1939 if (mWinAnimator.getShown() && mAnimatingExit
1940 && (!lastWindowIsStartingWindow || isAnimating)) {
1941 // The exit animation is running or should run... wait for it!
1942 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1943 "Not removing " + this + " due to exit animation ");
1944 setupWindowForRemoveOnExit();
1945 if (mAppToken != null) {
1946 mAppToken.updateReportedVisibilityLocked();
1947 }
1948 Binder.restoreCallingIdentity(origId);
1949 return;
1950 }
1951 }
1952
Wale Ogunwale571771c2016-08-26 13:18:50 -07001953 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001954 // Removing a visible window will effect the computed orientation
1955 // So just update orientation if needed.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001956 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1957 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001958 }
1959 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1960 Binder.restoreCallingIdentity(origId);
1961 }
1962
1963 private void setupWindowForRemoveOnExit() {
1964 mRemoveOnExit = true;
1965 setDisplayLayoutNeeded();
1966 // Request a focus update as this window's input channel is already gone. Otherwise
1967 // we could have no focused window in input manager.
1968 final boolean focusChanged = mService.updateFocusedWindowLocked(
1969 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1970 mService.mWindowPlacerLocked.performSurfacePlacement();
1971 if (focusChanged) {
1972 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1973 }
1974 }
1975
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001976 void setHasSurface(boolean hasSurface) {
1977 mHasSurface = hasSurface;
1978 }
1979
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001980 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001981 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001982 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1983 if (appToken != null) {
Robert Carrdee1b3f2017-02-27 11:33:33 -08001984 return appToken.getAnimLayerAdjustment();
Wale Ogunwale455fac52016-07-21 07:24:49 -07001985 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001986 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07001987
Robert Carrdee1b3f2017-02-27 11:33:33 -08001988 return mToken.getAnimLayerAdjustment();
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001989 }
1990
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001991 int getSpecialWindowAnimLayerAdjustment() {
1992 int specialAdjustment = 0;
1993 if (mIsImWindow) {
1994 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
1995 } else if (mIsWallpaper) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07001996 specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment();
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001997 }
1998
1999 return mLayer + specialAdjustment;
2000 }
2001
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002002 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002003 if (mIsImWindow) {
2004 // IME windows can't be IME targets. IME targets are required to be below the IME
2005 // windows and that wouldn't be possible if the IME window is its own target...silly.
2006 return false;
2007 }
2008
Winson Chung3d0a74a2017-07-12 12:37:19 -07002009 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002010 if (!windowsAreFocusable) {
2011 // This window can't be an IME target if the app's windows should not be focusable.
2012 return false;
2013 }
2014
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002015 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002016 final int type = mAttrs.type;
2017
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002018 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2019 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002020 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2021 && type != TYPE_APPLICATION_STARTING) {
2022 return false;
2023 }
2024
2025 if (DEBUG_INPUT_METHOD) {
2026 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2027 if (!isVisibleOrAdding()) {
2028 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2029 + " relayoutCalled=" + mRelayoutCalled
2030 + " viewVis=" + mViewVisibility
2031 + " policyVis=" + mPolicyVisibility
2032 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2033 + " parentHidden=" + isParentWindowHidden()
2034 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2035 if (mAppToken != null) {
2036 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2037 }
2038 }
2039 }
2040 return isVisibleOrAdding();
2041 }
2042
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002043 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002044 final DisplayContent dc = getDisplayContent();
2045 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002046 return;
2047 }
Jorim Jaggi1f833082017-08-04 18:06:56 +02002048
2049 // If layout is currently deferred, we want to hold of with updating the layers.
2050 if (mService.mWindowPlacerLocked.isLayoutDeferred()) {
2051 return;
2052 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002053 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002054 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002055 // Force an animation pass just to update the mDimLayer layer.
2056 mService.scheduleAnimationLocked();
2057 }
2058 }
2059
Chong Zhangacf11402015-11-04 16:23:10 -08002060 private final class DeadWindowEventReceiver extends InputEventReceiver {
2061 DeadWindowEventReceiver(InputChannel inputChannel) {
2062 super(inputChannel, mService.mH.getLooper());
2063 }
2064 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002065 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002066 finishInputEvent(event, true);
2067 }
2068 }
2069 /**
2070 * Dummy event receiver for windows that died visible.
2071 */
2072 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2073
Chong Zhang112eb8c2015-11-02 11:17:00 -08002074 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002075 if (mInputChannel != null) {
2076 throw new IllegalStateException("Window already has an input channel.");
2077 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002078 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002079 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2080 mInputChannel = inputChannels[0];
2081 mClientChannel = inputChannels[1];
2082 mInputWindowHandle.inputChannel = inputChannels[0];
2083 if (outInputChannel != null) {
2084 mClientChannel.transferTo(outInputChannel);
2085 mClientChannel.dispose();
2086 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002087 } else {
2088 // If the window died visible, we setup a dummy input channel, so that taps
2089 // can still detected by input monitor channel, and we can relaunch the app.
2090 // Create dummy event receiver that simply reports all events as handled.
2091 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002092 }
2093 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002094 }
2095
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002096 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002097 if (mDeadWindowEventReceiver != null) {
2098 mDeadWindowEventReceiver.dispose();
2099 mDeadWindowEventReceiver = null;
2100 }
2101
2102 // unregister server channel first otherwise it complains about broken channel
2103 if (mInputChannel != null) {
2104 mService.mInputManager.unregisterInputChannel(mInputChannel);
2105 mInputChannel.dispose();
2106 mInputChannel = null;
2107 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002108 if (mClientChannel != null) {
2109 mClientChannel.dispose();
2110 mClientChannel = null;
2111 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002112 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002113 }
2114
Chong Zhang112eb8c2015-11-02 11:17:00 -08002115 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002116 // When the app is terminated (eg. from Recents), the task might have already been
2117 // removed with the window pending removal. Don't apply dim in such cases, as there
2118 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2119 final AppWindowToken token = mAppToken;
2120 if (token != null && token.removed) {
2121 return;
2122 }
2123
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002124 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002125 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002126 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002127 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002128 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002129 && dc != null && !mAnimatingExit && isVisible()) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002130 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002131 }
2132 }
2133
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002134 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002135 Task task = getTask();
2136 if (task != null) {
2137 return task;
2138 }
2139 return getStack();
2140 }
2141
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002142 /** Returns true if the replacement window was removed. */
2143 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2144 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2145 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2146 removeReplacedWindow();
2147 return true;
2148 }
2149
2150 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002151 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002152 if (c.removeReplacedWindowIfNeeded(replacement)) {
2153 return true;
2154 }
2155 }
2156 return false;
2157 }
2158
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002159 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002160 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2161 if (isDimming()) {
2162 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002163 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002164 mWillReplaceWindow = false;
2165 mAnimateReplacingWindow = false;
2166 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002167 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002168 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002169 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002170 }
2171 }
2172
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002173 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2174 boolean replacementSet = false;
2175
2176 if (mWillReplaceWindow && mReplacementWindow == null
2177 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2178
2179 mReplacementWindow = replacementCandidate;
2180 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2181 replacementSet = true;
2182 }
2183
2184 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002185 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002186 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2187 }
2188
2189 return replacementSet;
2190 }
2191
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002192 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002193 final DisplayContent dc = getDisplayContent();
2194 if (dc != null) {
2195 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002196 }
2197 }
2198
Robert Carrfed10072016-05-26 11:48:49 -07002199 // TODO: Strange usage of word workspace here and above.
2200 boolean inPinnedWorkspace() {
2201 final Task task = getTask();
2202 return task != null && task.inPinnedWorkspace();
2203 }
2204
Chong Zhang5117e272016-05-03 12:47:34 -07002205 void applyAdjustForImeIfNeeded() {
2206 final Task task = getTask();
2207 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2208 task.mStack.applyAdjustForImeIfNeeded(task);
2209 }
2210 }
2211
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002212 @Override
2213 void switchUser() {
2214 super.switchUser();
2215 if (isHiddenFromUserLocked()) {
2216 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2217 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2218 hideLw(false);
2219 }
2220 }
2221
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002222 int getTouchableRegion(Region region, int flags) {
2223 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002224 if (modal && mAppToken != null) {
2225 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002226 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002227 // If this is a modal window we need to dismiss it if it's not full screen and the
2228 // touch happens outside of the frame that displays the content. This means we
2229 // need to intercept touches outside of that window. The dim layer user
2230 // associated with the window (task or stack) will give us the good bounds, as
2231 // they would be used to display the dim layer.
2232 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2233 if (dimLayerUser != null) {
2234 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002235 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002236 getVisibleBounds(mTmpRect);
2237 }
2238 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002239 // For freeform windows we the touch region to include the whole surface for the
2240 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002241 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2242 final int delta = WindowManagerService.dipToPixel(
2243 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2244 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002245 }
2246 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002247 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002248 } else {
2249 // Not modal or full screen modal
2250 getTouchableRegion(region);
2251 }
2252 return flags;
2253 }
2254
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002255 void checkPolicyVisibilityChange() {
2256 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2257 if (DEBUG_VISIBILITY) {
2258 Slog.v(TAG, "Policy visibility changing after anim in " +
2259 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2260 }
2261 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002262 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002263 if (!mPolicyVisibility) {
2264 if (mService.mCurrentFocus == this) {
2265 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2266 "setAnimationLocked: setting mFocusMayChange true");
2267 mService.mFocusMayChange = true;
2268 }
2269 // Window is no longer visible -- make sure if we were waiting
2270 // for it to be displayed before enabling the display, that
2271 // we allow the display to be enabled now.
2272 mService.enableScreenIfNeededLocked();
2273 }
2274 }
2275 }
2276
2277 void setRequestedSize(int requestedWidth, int requestedHeight) {
2278 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2279 mLayoutNeeded = true;
2280 mRequestedWidth = requestedWidth;
2281 mRequestedHeight = requestedHeight;
2282 }
2283 }
2284
Bryce Leef858b572017-06-29 14:03:33 -07002285 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002286 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002287 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2288 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2289 mTurnOnScreen = true;
2290 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002291
2292 // If we were already visible, skip rest of preparation.
2293 if (wasVisible) {
2294 if (DEBUG_VISIBILITY) Slog.v(TAG,
2295 "Already visible and does not turn on screen, skip preparing: " + this);
2296 return;
2297 }
2298
2299 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2300 == SOFT_INPUT_ADJUST_RESIZE) {
2301 mLayoutNeeded = true;
2302 }
2303
David Stevens9440dc82017-03-16 19:00:20 -07002304 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002305 mWinAnimator.applyEnterAnimationLocked();
2306 }
Bryce Leef858b572017-06-29 14:03:33 -07002307 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002308
Bryce Leef858b572017-06-29 14:03:33 -07002309 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2310 final Configuration globalConfig = mService.mRoot.getConfiguration();
2311 final Configuration overrideConfig = getMergedOverrideConfiguration();
2312 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2313 }
2314
2315 void setReportedConfiguration(MergedConfiguration config) {
2316 mLastReportedConfiguration.setTo(config.getMergedConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002317 }
2318
2319 void adjustStartingWindowFlags() {
2320 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2321 && mAppToken.startingWindow != null) {
2322 // Special handling of starting window over the base
2323 // window of the app: propagate lock screen flags to it,
2324 // to provide the correct semantics while starting.
2325 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2326 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2327 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2328 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2329 }
2330 }
2331
2332 void setWindowScale(int requestedWidth, int requestedHeight) {
2333 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2334
2335 if (scaledWindow) {
2336 // requested{Width|Height} Surface's physical size
2337 // attrs.{width|height} Size on screen
2338 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2339 mHScale = (mAttrs.width != requestedWidth) ?
2340 (mAttrs.width / (float)requestedWidth) : 1.0f;
2341 mVScale = (mAttrs.height != requestedHeight) ?
2342 (mAttrs.height / (float)requestedHeight) : 1.0f;
2343 } else {
2344 mHScale = mVScale = 1;
2345 }
2346 }
2347
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002348 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002349 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002350 public void binderDied() {
2351 try {
2352 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002353 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002354 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002355 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002356 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002357 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2358 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2359 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002360 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002361 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2362 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002363 // just in case they have the divider at an unstable position. Better
2364 // also reset drag resizing state, because the owner can't do it
2365 // anymore.
Wale Ogunwale1666e312016-12-16 11:27:18 -08002366 final TaskStack stack = dc.getDockedStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002367 if (stack != null) {
2368 stack.resetDockedStackToMiddle();
2369 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002370 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002371 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002372 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002373 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002374 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002375 }
2376 }
2377 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002378 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002379 }
2380 }
2381 }
2382
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002383 /**
2384 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2385 * because we want to preserve its location on screen to be re-activated later when the user
2386 * interacts with it.
2387 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002388 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002389 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002390 // Not a visible app window or the app isn't dead.
2391 return false;
2392 }
2393
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002394 if (mAttrs.token != mClient.asBinder()) {
2395 // The window was add by a client using another client's app token. We don't want to
2396 // keep the dead window around for this case since this is meant for 'real' apps.
2397 return false;
2398 }
2399
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002400 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2401 // We don't keep starting windows since they were added by the window manager before
2402 // the app even launched.
2403 return false;
2404 }
2405
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002406 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002407 }
2408
Wale Ogunwaled045c822015-12-02 09:14:28 -08002409 /** @return true if this window desires key events. */
2410 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002411 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002412 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002413 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002414 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002415 && !canReceiveTouchInput();
2416 }
2417
2418 /** @return true if this window desires touch events. */
2419 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002420 return mAppToken != null && mAppToken.getTask() != null
2421 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002422 }
2423
Craig Mautner749a7bb2012-04-02 13:49:53 -07002424 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002425 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002426 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002427 }
2428
Craig Mautner749a7bb2012-04-02 13:49:53 -07002429 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002430 public boolean showLw(boolean doAnimation) {
2431 return showLw(doAnimation, true);
2432 }
2433
2434 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002435 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002436 return false;
2437 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002438 if (!mAppOpVisibility) {
2439 // Being hidden due to app op request.
2440 return false;
2441 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002442 if (mPermanentlyHidden) {
2443 // Permanently hidden until the app exists as apps aren't prepared
2444 // to handle their windows being removed from under them.
2445 return false;
2446 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002447 if (mForceHideNonSystemOverlayWindow) {
2448 // This is an alert window that is currently force hidden.
2449 return false;
2450 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002451 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002452 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002453 return false;
2454 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002455 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002456 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002457 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002458 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
David Stevens9440dc82017-03-16 19:00:20 -07002459 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002460 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002461 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002462 // Check for the case where we are currently visible and
2463 // not animating; we do not want to do animation at such a
2464 // point to become visible when we already are.
2465 doAnimation = false;
2466 }
2467 }
2468 mPolicyVisibility = true;
2469 mPolicyVisibilityAfterAnim = true;
2470 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002471 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002472 }
2473 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002474 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002475 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002476 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2477 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2478 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002479 return true;
2480 }
2481
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002482 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002483 public boolean hideLw(boolean doAnimation) {
2484 return hideLw(doAnimation, true);
2485 }
2486
2487 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2488 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002489 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002490 doAnimation = false;
2491 }
2492 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002493 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002494 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002495 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002496 return false;
2497 }
2498 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002499 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002500 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002501 doAnimation = false;
2502 }
2503 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002504 mPolicyVisibilityAfterAnim = false;
2505 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002506 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002507 mPolicyVisibility = false;
2508 // Window is no longer visible -- make sure if we were waiting
2509 // for it to be displayed before enabling the display, that
2510 // we allow the display to be enabled now.
2511 mService.enableScreenIfNeededLocked();
2512 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002513 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002514 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002515 mService.mFocusMayChange = true;
2516 }
2517 }
2518 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002519 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002520 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002521 if (mService.mCurrentFocus == this) {
2522 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2523 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002524 return true;
2525 }
2526
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002527 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2528 if (mOwnerCanAddInternalSystemWindow
2529 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2530 return;
2531 }
2532 if (mForceHideNonSystemOverlayWindow == forceHide) {
2533 return;
2534 }
2535 mForceHideNonSystemOverlayWindow = forceHide;
2536 if (forceHide) {
2537 hideLw(true /* doAnimation */, true /* requestAnim */);
2538 } else {
2539 showLw(true /* doAnimation */, true /* requestAnim */);
2540 }
2541 }
2542
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002543 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002544 if (mAppOpVisibility != state) {
2545 mAppOpVisibility = state;
2546 if (state) {
2547 // If the policy visibility had last been to hide, then this
2548 // will incorrectly show at this point since we lost that
2549 // information. Not a big deal -- for the windows that have app
2550 // ops modifies they should only be hidden by policy due to the
2551 // lock screen, and the user won't be changing this if locked.
2552 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002553 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002554 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002555 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002556 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002557 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002558 }
2559
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002560 public void hidePermanentlyLw() {
2561 if (!mPermanentlyHidden) {
2562 mPermanentlyHidden = true;
2563 hideLw(true, true);
2564 }
2565 }
2566
Jeff Brownc2932a12014-11-20 18:04:05 -08002567 public void pokeDrawLockLw(long timeout) {
2568 if (isVisibleOrAdding()) {
2569 if (mDrawLock == null) {
2570 // We want the tag name to be somewhat stable so that it is easier to correlate
2571 // in wake lock statistics. So in particular, we don't want to include the
2572 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002573 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002574 mDrawLock = mService.mPowerManager.newWakeLock(
2575 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2576 mDrawLock.setReferenceCounted(false);
2577 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2578 }
2579 // Each call to acquire resets the timeout.
2580 if (DEBUG_POWER) {
2581 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2582 + mAttrs.packageName);
2583 }
2584 mDrawLock.acquire(timeout);
2585 } else if (DEBUG_POWER) {
2586 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2587 + "owned by " + mAttrs.packageName);
2588 }
2589 }
2590
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002591 @Override
2592 public boolean isAlive() {
2593 return mClient.asBinder().isBinderAlive();
2594 }
2595
Craig Mautnera987d432012-10-11 14:07:58 -07002596 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002597 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002598 }
2599
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002600 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002601 boolean isAnimating() {
2602 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2603 return true;
2604 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002605 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002606 }
2607
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002608 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2609 animators.add(mWinAnimator);
2610
2611 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002612 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002613 c.addWinAnimatorToList(animators);
2614 }
2615 }
2616
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002617 void sendAppVisibilityToClients() {
2618 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002619
Wale Ogunwale89973222017-04-23 18:39:45 -07002620 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002621 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2622 // Don't hide the starting window.
2623 return;
2624 }
2625
Wale Ogunwale89973222017-04-23 18:39:45 -07002626 if (clientHidden) {
2627 // Once we are notifying the client that it's visibility has changed, we need to prevent
2628 // it from destroying child surfaces until the animation has finished. We do this by
2629 // detaching any surface control the client added from the client.
2630 for (int i = mChildren.size() - 1; i >= 0; --i) {
2631 final WindowState c = mChildren.get(i);
2632 c.mWinAnimator.detachChildren();
2633 }
2634
2635 mWinAnimator.detachChildren();
2636 }
2637
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002638 try {
2639 if (DEBUG_VISIBILITY) Slog.v(TAG,
2640 "Setting visibility of " + this + ": " + (!clientHidden));
2641 mClient.dispatchAppVisibility(!clientHidden);
2642 } catch (RemoteException e) {
2643 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002644 }
2645
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002646 void onStartFreezingScreen() {
2647 mAppFreezing = true;
2648 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002649 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002650 c.onStartFreezingScreen();
2651 }
2652 }
2653
2654 boolean onStopFreezingScreen() {
2655 boolean unfrozeWindows = false;
2656 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002657 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002658 unfrozeWindows |= c.onStopFreezingScreen();
2659 }
2660
2661 if (!mAppFreezing) {
2662 return unfrozeWindows;
2663 }
2664
Wale Ogunwale953171d2016-09-30 09:17:30 -07002665 mAppFreezing = false;
2666
Bryce Lee8c3cf382017-07-06 19:47:10 -07002667 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002668 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2669 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002670 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002671 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002672 }
2673 mLastFreezeDuration = 0;
2674 setDisplayLayoutNeeded();
2675 return true;
2676 }
2677
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002678 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2679 boolean destroyedSomething = false;
2680 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002681 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002682 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2683 }
2684
Robert Carrdb2f6e62017-03-01 20:17:58 -08002685 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2686 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002687 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002688
2689 if (appStopped || mWindowRemovalAllowed) {
2690 mWinAnimator.destroyPreservedSurfaceLocked();
2691 }
2692
2693 if (mDestroying) {
2694 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2695 + " destroySurfaces: appStopped=" + appStopped
2696 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2697 + " win.mRemoveOnExit=" + mRemoveOnExit);
2698 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002699 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002700 }
2701 if (mRemoveOnExit) {
2702 removeImmediately();
2703 }
2704 if (cleanupOnResume) {
2705 requestUpdateWallpaperIfNeeded();
2706 }
2707 mDestroying = false;
2708 destroyedSomething = true;
2709 }
2710
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002711 return destroyedSomething;
2712 }
Chris Craik3131bde2016-05-06 13:39:08 -07002713
Robert Carr89a28ab2017-04-24 15:33:11 -07002714 // Destroy or save the application surface without checking
2715 // various indicators of whether the client has released the surface.
2716 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002717 void destroySurfaceUnchecked() {
2718 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002719
Chong Zhang92147042016-05-09 12:47:11 -07002720 // Clear animating flags now, since the surface is now gone. (Note this is true even
2721 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2722 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002723 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002724
Craig Mautner69b08182012-09-05 13:07:13 -07002725 @Override
2726 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002727 final DisplayContent displayContent = getDisplayContent();
2728 if (displayContent == null) {
2729 // Only a window that was on a non-default display can be detached from it.
2730 return false;
2731 }
Winson Chung47a3e652014-05-21 16:03:42 -07002732 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002733 }
2734
Adrian Rooscd3884d2015-02-18 17:25:23 +01002735 @Override
2736 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002737 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002738 final DisplayContent dc = getDisplayContent();
2739 return dimLayerUser != null && dc != null
2740 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002741 }
2742
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002743 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002744 mShowToOwnerOnly = showToOwnerOnly;
2745 }
2746
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002747 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002748 // Child windows are evaluated based on their parent window.
2749 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002750 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002751 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002752
2753 // All window frames that are fullscreen extend above status bar, but some don't extend
2754 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2755 // bottom right.
2756 if (win.mFrame.left <= win.mDisplayFrame.left
2757 && win.mFrame.top <= win.mDisplayFrame.top
2758 && win.mFrame.right >= win.mStableFrame.right
2759 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002760 // Is a fullscreen window, like the clock alarm. Show to everyone.
2761 return false;
2762 }
2763 }
2764
Craig Mautner341220f2012-10-16 15:20:09 -07002765 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002766 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002767 }
2768
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002769 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2770 outRegion.set(
2771 frame.left + inset.left, frame.top + inset.top,
2772 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002773 }
2774
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002775 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002776 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002777 switch (mTouchableInsets) {
2778 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002779 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002780 outRegion.set(frame);
2781 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002782 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002783 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002784 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002785 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002786 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002787 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002788 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002789 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002790 outRegion.translate(frame.left, frame.top);
2791 break;
2792 }
2793 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002794 cropRegionToStackBoundsIfNeeded(outRegion);
2795 }
2796
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002797 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002798 final Task task = getTask();
2799 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002800 return;
2801 }
2802
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002803 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002804 if (stack == null) {
2805 return;
2806 }
2807
2808 stack.getDimBounds(mTmpRect);
2809 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002810 }
2811
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002812 /**
2813 * Report a focus change. Must be called with no locks held, and consistently
2814 * from the same serialized thread (such as dispatched from a handler).
2815 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002816 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002817 try {
2818 mClient.windowFocusChanged(focused, inTouchMode);
2819 } catch (RemoteException e) {
2820 }
2821 if (mFocusCallbacks != null) {
2822 final int N = mFocusCallbacks.beginBroadcast();
2823 for (int i=0; i<N; i++) {
2824 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2825 try {
2826 if (focused) {
2827 obs.focusGained(mWindowId.asBinder());
2828 } else {
2829 obs.focusLost(mWindowId.asBinder());
2830 }
2831 } catch (RemoteException e) {
2832 }
2833 }
2834 mFocusCallbacks.finishBroadcast();
2835 }
2836 }
2837
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002838 @Override
2839 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002840 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002841 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002842 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002843
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002844 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002845 }
2846
Craig Mautnerdf88d732014-01-27 09:21:32 -08002847 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002848 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002849 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002850 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2851 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002852 final MergedConfiguration mergedConfiguration =
2853 new MergedConfiguration(mService.mRoot.getConfiguration(),
2854 getMergedOverrideConfiguration());
2855
2856 setReportedConfiguration(mergedConfiguration);
2857
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002858 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002859 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2860
Craig Mautnerdf88d732014-01-27 09:21:32 -08002861 final Rect frame = mFrame;
2862 final Rect overscanInsets = mLastOverscanInsets;
2863 final Rect contentInsets = mLastContentInsets;
2864 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002865 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002866 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002867 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002868 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002869 final int displayId = getDisplayId();
Chet Haase8eb48d22014-09-24 07:31:29 -07002870 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2871 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002872 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2873 mService.mH.post(new Runnable() {
2874 @Override
2875 public void run() {
2876 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002877 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002878 stableInsets, outsets, reportDraw, mergedConfiguration,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002879 reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002880 } catch (RemoteException e) {
2881 // Not a remote call, RemoteException won't be raised.
2882 }
2883 }
2884 });
2885 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002886 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002887 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002888 }
Svetoslav4604abc2014-06-10 18:59:30 -07002889
2890 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002891 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002892 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002893 }
2894
Craig Mautnerdf88d732014-01-27 09:21:32 -08002895 mOverscanInsetsChanged = false;
2896 mContentInsetsChanged = false;
2897 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002898 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002899 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07002900 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002901 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002902 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002903 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002904 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002905 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002906 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2907 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002908 // We are assuming the hosting process is dead or in a zombie state.
2909 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2910 + ", removing this window.");
2911 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002912 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002913 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002914 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002915 }
2916
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002917 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002918 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2919 // start even if we haven't received the relayout window, so that the client requests
2920 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2921 // until the window to small size, otherwise the multithread renderer will shift last
2922 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2923 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002924 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002925 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002926 return frame;
2927 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002928 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002929 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002930 return mTmpRect;
2931 }
2932
Jorim Jaggi86905582016-02-09 21:36:09 -08002933 @Override
2934 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002935 final TaskStack stack = getStack();
2936 if (stack == null) {
2937 return INVALID_STACK_ID;
2938 }
2939 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002940 }
2941
2942 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2943 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Andrii Kulian44607962017-03-16 11:06:24 -07002944 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002945 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08002946 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
2947 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07002948
Jorim Jaggidc249c42015-12-15 14:57:31 -08002949 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002950 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
2951 mPolicy.isNavBarForcedShownLw(this), displayId);
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002952 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002953 }
2954
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002955 public void registerFocusObserver(IWindowFocusObserver observer) {
2956 synchronized(mService.mWindowMap) {
2957 if (mFocusCallbacks == null) {
2958 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2959 }
2960 mFocusCallbacks.register(observer);
2961 }
2962 }
2963
2964 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2965 synchronized(mService.mWindowMap) {
2966 if (mFocusCallbacks != null) {
2967 mFocusCallbacks.unregister(observer);
2968 }
2969 }
2970 }
2971
2972 public boolean isFocused() {
2973 synchronized(mService.mWindowMap) {
2974 return mService.mCurrentFocus == this;
2975 }
2976 }
2977
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07002978 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002979 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07002980 return task != null && task.inFreeformWorkspace();
2981 }
2982
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002983 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002984 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002985 final Task task = getTask();
2986 return task != null && !task.isFullscreen();
2987 }
2988
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002989 /** Is this window in a container that takes up the entire screen space? */
2990 private boolean inFullscreenContainer() {
2991 if (mAppToken == null) {
2992 return true;
2993 }
2994 if (mAppToken.hasBounds()) {
2995 return false;
2996 }
2997 return !isInMultiWindowMode();
2998 }
2999
Andrii Kulian283acd22017-08-03 04:03:51 -07003000 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3001 boolean isLetterboxedAppWindow() {
3002 final Task task = getTask();
3003 final boolean taskIsFullscreen = task != null && task.isFullscreen();
3004 final boolean appWindowIsFullscreen = mAppToken != null && !mAppToken.hasBounds();
3005
3006 return taskIsFullscreen && !appWindowIsFullscreen;
3007 }
3008
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003009 /** Returns the appropriate bounds to use for computing frames. */
3010 private void getContainerBounds(Rect outBounds) {
3011 if (isInMultiWindowMode()) {
3012 getTask().getBounds(outBounds);
3013 } else if (mAppToken != null){
3014 mAppToken.getBounds(outBounds);
3015 } else {
3016 outBounds.setEmpty();
3017 }
3018 }
3019
Chong Zhang3005e752015-09-18 18:46:28 -07003020 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003021 return mDragResizing != computeDragResizing();
3022 }
3023
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003024 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003025 void setWaitingForDrawnIfResizingChanged() {
3026 if (isDragResizeChanged()) {
3027 mService.mWaitingForDrawn.add(this);
3028 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003029 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003030 }
3031
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003032 /**
3033 * @return Whether we reported a drag resize change to the application or not already.
3034 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003035 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003036 return mDragResizingChangeReported;
3037 }
3038
3039 /**
3040 * Resets the state whether we reported a drag resize change to the app.
3041 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003042 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003043 void resetDragResizingChangeReported() {
3044 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003045 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003046 }
3047
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003048 /**
3049 * Set whether we got resized but drag resizing flag was false.
3050 * @see #isResizedWhileNotDragResizing().
3051 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003052 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003053 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3054 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3055 }
3056
3057 /**
3058 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3059 * need to recreate the surface and defer surface bound updates in order to make sure the
3060 * buffer contents and the positioning/size stay in sync.
3061 */
3062 boolean isResizedWhileNotDragResizing() {
3063 return mResizedWhileNotDragResizing;
3064 }
3065
3066 /**
3067 * @return Whether we reported "resize while not drag resizing" to the application.
3068 * @see #isResizedWhileNotDragResizing()
3069 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003070 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003071 return mResizedWhileNotDragResizingReported;
3072 }
3073
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003074 int getResizeMode() {
3075 return mResizeMode;
3076 }
3077
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003078 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003079 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003080 if (task == null) {
3081 return false;
3082 }
Winson Chung2af04b32017-01-24 16:21:13 -08003083 if (!StackId.isStackAffectedByDragResizing(getStackId())) {
3084 return false;
3085 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003086 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003087 // Floating windows never enter drag resize mode.
3088 return false;
3089 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003090 if (task.isDragResizing()) {
3091 return true;
3092 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003093
3094 // If the bounds are currently frozen, it means that the layout size that the app sees
3095 // and the bounds we clip this window to might be different. In order to avoid holes, we
3096 // simulate that we are still resizing so the app fills the hole with the resizing
3097 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003098 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003099 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003100 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003101
Chong Zhang3005e752015-09-18 18:46:28 -07003102 }
3103
3104 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003105 final boolean resizing = computeDragResizing();
3106 if (resizing == mDragResizing) {
3107 return;
3108 }
3109 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003110 final Task task = getTask();
3111 if (task != null && task.isDragResizing()) {
3112 mResizeMode = task.getDragResizeMode();
3113 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003114 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003115 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3116 : DRAG_RESIZE_MODE_FREEFORM;
3117 }
Chong Zhang3005e752015-09-18 18:46:28 -07003118 }
3119
3120 boolean isDragResizing() {
3121 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003122 }
3123
Robert Carr2487ce72016-04-07 15:18:45 -07003124 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003125 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3126 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003127 }
3128
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003129 @CallSuper
3130 @Override
3131 public void writeToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003132 final long token = proto.start(fieldId);
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003133 super.writeToProto(proto, WINDOW_CONTAINER);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003134 writeIdentifierToProto(proto, IDENTIFIER);
3135 proto.write(DISPLAY_ID, getDisplayId());
3136 proto.write(STACK_ID, getStackId());
3137 mAttrs.writeToProto(proto, ATTRIBUTES);
3138 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3139 mFrame.writeToProto(proto, FRAME);
3140 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3141 mParentFrame.writeToProto(proto, PARENT_FRAME);
3142 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3143 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3144 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
3145 mWinAnimator.writeToProto(proto, ANIMATOR);
3146 proto.write(ANIMATING_EXIT, mAnimatingExit);
3147 for (int i = 0; i < mChildren.size(); i++) {
3148 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS);
3149 }
3150 proto.end(token);
3151 }
3152
3153 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
3154 final long token = proto.start(fieldId);
3155 proto.write(HASH_CODE, System.identityHashCode(this));
3156 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3157 final CharSequence title = getWindowTag();
3158 if (title != null) {
3159 proto.write(TITLE, title.toString());
3160 }
3161 proto.end(token);
3162 }
3163
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003164 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003165 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003166 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003167 if (stack != null) {
3168 pw.print(" stackId="); pw.print(stack.mStackId);
3169 }
Craig Mautner59c00972012-07-30 12:10:24 -07003170 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003171 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003172 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003173 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3174 pw.print(" package="); pw.print(mAttrs.packageName);
3175 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003176 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003177 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3178 pw.print(" h="); pw.print(mRequestedHeight);
3179 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003180 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3181 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3182 pw.print(" h="); pw.println(mLastRequestedHeight);
3183 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003184 if (mIsChildWindow || mLayoutAttached) {
3185 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003186 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3187 }
3188 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3189 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3190 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3191 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3192 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3193 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003194 if (dumpAll) {
3195 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3196 pw.print(" mSubLayer="); pw.print(mSubLayer);
3197 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003198 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003199 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3200 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003201 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003202 if (dumpAll) {
3203 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003204 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003205 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3206 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003207 pw.print(" mAppDied=");pw.print(mAppDied);
3208 pw.print(prefix); pw.print("drawnStateEvaluated=");
3209 pw.print(getDrawnStateEvaluated());
3210 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003211 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003212 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003213 pw.print(prefix); pw.print("mViewVisibility=0x");
3214 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003215 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3216 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003217 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3218 pw.print(" mSystemUiVisibility=0x");
3219 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003220 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003221 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003222 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003223 pw.print(prefix); pw.print("mPolicyVisibility=");
3224 pw.print(mPolicyVisibility);
3225 pw.print(" mPolicyVisibilityAfterAnim=");
3226 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003227 pw.print(" mAppOpVisibility=");
3228 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003229 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003230 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
3231 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3232 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003233 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003234 if (!mRelayoutCalled || mLayoutNeeded) {
3235 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3236 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003237 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003238 if (mXOffset != 0 || mYOffset != 0) {
3239 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3240 pw.print(" y="); pw.println(mYOffset);
3241 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003242 if (dumpAll) {
3243 pw.print(prefix); pw.print("mGivenContentInsets=");
3244 mGivenContentInsets.printShortString(pw);
3245 pw.print(" mGivenVisibleInsets=");
3246 mGivenVisibleInsets.printShortString(pw);
3247 pw.println();
3248 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3249 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3250 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003251 Region region = new Region();
3252 getTouchableRegion(region);
3253 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003254 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003255 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3256 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3257 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003258 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003259 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003260 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003261 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003262 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003263 if (dumpAll) {
3264 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3265 pw.print(" last="); mLastFrame.printShortString(pw);
3266 pw.println();
3267 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003268 if (mEnforceSizeCompat) {
3269 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003270 pw.println();
3271 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003272 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003273 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003274 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003275 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003276 pw.println();
3277 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3278 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003279 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003280 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003281 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003282 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003283 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3284 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003285 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3286 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003287 pw.print(prefix); pw.print("Cur insets: overscan=");
3288 mOverscanInsets.printShortString(pw);
3289 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003290 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003291 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003292 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003293 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003294 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003295 pw.print(prefix); pw.print("Lst insets: overscan=");
3296 mLastOverscanInsets.printShortString(pw);
3297 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003298 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003299 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003300 pw.print(" physical="); mLastOutsets.printShortString(pw);
3301 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003302 pw.println();
3303 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003304 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3305 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003306 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3307 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003308 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3309 pw.print(" mDestroying="); pw.print(mDestroying);
3310 pw.print(" mRemoved="); pw.println(mRemoved);
3311 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003312 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003313 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003314 pw.print(prefix); pw.print("mOrientationChanging=");
3315 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003316 pw.print(" configOrientationChanging=");
3317 pw.print(mLastReportedConfiguration.orientation
3318 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003319 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003320 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003321 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003322 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003323 if (mLastFreezeDuration != 0) {
3324 pw.print(prefix); pw.print("mLastFreezeDuration=");
3325 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3326 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003327 if (mHScale != 1 || mVScale != 1) {
3328 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3329 pw.print(" mVScale="); pw.println(mVScale);
3330 }
3331 if (mWallpaperX != -1 || mWallpaperY != -1) {
3332 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3333 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3334 }
3335 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3336 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3337 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3338 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003339 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3340 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3341 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3342 pw.print(mWallpaperDisplayOffsetX);
3343 pw.print(" mWallpaperDisplayOffsetY=");
3344 pw.println(mWallpaperDisplayOffsetY);
3345 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003346 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003347 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003348 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003349 if (isDragResizing()) {
3350 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3351 }
3352 if (computeDragResizing()) {
3353 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3354 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003355 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3356 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003357 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003358
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003359 @Override
3360 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003361 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003362 + " " + getWindowTag();
3363 }
3364
Robert Carra1eb4392015-12-10 12:43:51 -08003365 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003366 CharSequence tag = mAttrs.getTitle();
3367 if (tag == null || tag.length() <= 0) {
3368 tag = mAttrs.packageName;
3369 }
3370 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003371 }
3372
3373 @Override
3374 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003375 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003376 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003377 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003378 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003379 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003380 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003381 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003382 }
3383 return mStringNameCache;
3384 }
Robert Carr58f29132015-10-29 14:19:05 -07003385
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003386 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003387 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003388 clipRect.left = (int) (clipRect.left / mHScale);
3389 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003390 }
3391 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003392 clipRect.top = (int) (clipRect.top / mVScale);
3393 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003394 }
3395 }
Robert Carr31e28482015-12-02 16:53:18 -08003396
Jorim Jaggif5834272016-04-04 20:25:41 -07003397 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3398 final int pw = containingFrame.width();
3399 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003400 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003401 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003402 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3403
3404 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003405 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3406 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003407 // 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 -07003408 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3409 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3410 // the display.
3411 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003412 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003413 float x, y;
3414 int w,h;
3415
3416 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3417 if (mAttrs.width < 0) {
3418 w = pw;
3419 } else if (mEnforceSizeCompat) {
3420 w = (int)(mAttrs.width * mGlobalScale + .5f);
3421 } else {
3422 w = mAttrs.width;
3423 }
3424 if (mAttrs.height < 0) {
3425 h = ph;
3426 } else if (mEnforceSizeCompat) {
3427 h = (int)(mAttrs.height * mGlobalScale + .5f);
3428 } else {
3429 h = mAttrs.height;
3430 }
3431 } else {
3432 if (mAttrs.width == MATCH_PARENT) {
3433 w = pw;
3434 } else if (mEnforceSizeCompat) {
3435 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3436 } else {
3437 w = mRequestedWidth;
3438 }
3439 if (mAttrs.height == MATCH_PARENT) {
3440 h = ph;
3441 } else if (mEnforceSizeCompat) {
3442 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3443 } else {
3444 h = mRequestedHeight;
3445 }
3446 }
3447
3448 if (mEnforceSizeCompat) {
3449 x = mAttrs.x * mGlobalScale;
3450 y = mAttrs.y * mGlobalScale;
3451 } else {
3452 x = mAttrs.x;
3453 y = mAttrs.y;
3454 }
3455
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003456 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003457 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003458 // required by {@link Gravity#apply} call.
3459 w = Math.min(w, pw);
3460 h = Math.min(h, ph);
3461 }
3462
3463 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003464 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003465 (int) (x + mAttrs.horizontalMargin * pw),
3466 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3467
3468 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003469 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003470 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003471 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003472
3473 // We need to make sure we update the CompatFrame as it is used for
3474 // cropping decisions, etc, on systems where we lack a decor layer.
3475 mCompatFrame.set(mFrame);
3476 if (mEnforceSizeCompat) {
3477 // See comparable block in computeFrameLw.
3478 mCompatFrame.scale(mInvGlobalScale);
3479 }
Robert Carr31e28482015-12-02 16:53:18 -08003480 }
Robert Carr51a1b872015-12-08 14:03:13 -08003481
3482 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003483 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003484 }
3485
Robert Carrf3b72c72016-03-21 18:16:39 -07003486 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003487 return mIsChildWindow
3488 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003489 }
3490
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003491 /**
3492 * Returns true if any window added by an application process that if of type
3493 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3494 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3495 * this window is visible.
3496 */
3497 boolean hideNonSystemOverlayWindowsWhenVisible() {
3498 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3499 && mSession.mCanHideNonSystemOverlayWindows;
3500 }
3501
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003502 /** Returns the parent window if this is a child of another window, else null. */
3503 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003504 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3505 // WindowContainer that isn't a WindowState.
3506 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003507 }
3508
3509 /** Returns the topmost parent window if this is a child of another window, else this. */
3510 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003511 WindowState current = this;
3512 WindowState topParent = current;
3513 while (current != null && current.mIsChildWindow) {
3514 current = current.getParentWindow();
3515 // Parent window can be null if the child is detached from it's parent already, but
3516 // someone still has a reference to access it. So, we return the top parent value we
3517 // already have instead of null.
3518 if (current != null) {
3519 topParent = current;
3520 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003521 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003522 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003523 }
3524
Wale Ogunwale9d147902016-07-16 11:58:55 -07003525 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003526 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003527 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003528 }
3529
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003530 void setWillReplaceWindow(boolean animate) {
3531 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003532 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003533 c.setWillReplaceWindow(animate);
3534 }
3535
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003536 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3537 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3538 // We don't set replacing on starting windows since they are added by window manager and
3539 // not the client so won't be replaced by the client.
3540 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003541 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003542
3543 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003544 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003545 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003546 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003547
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003548 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003549 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003550 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003551 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003552
3553 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003554 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003555 c.clearWillReplaceWindow();
3556 }
3557 }
3558
3559 boolean waitingForReplacement() {
3560 if (mWillReplaceWindow) {
3561 return true;
3562 }
3563
3564 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003565 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003566 if (c.waitingForReplacement()) {
3567 return true;
3568 }
3569 }
3570 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003571 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003572
Chong Zhang4d7369a2016-04-25 16:09:14 -07003573 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003574 final DisplayContent dc = getDisplayContent();
3575 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3576 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3577 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003578 mService.mWindowPlacerLocked.requestTraversal();
3579 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003580
3581 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003582 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003583 c.requestUpdateWallpaperIfNeeded();
3584 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003585 }
3586
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003587 float translateToWindowX(float x) {
3588 float winX = x - mFrame.left;
3589 if (mEnforceSizeCompat) {
3590 winX *= mGlobalScale;
3591 }
3592 return winX;
3593 }
3594
3595 float translateToWindowY(float y) {
3596 float winY = y - mFrame.top;
3597 if (mEnforceSizeCompat) {
3598 winY *= mGlobalScale;
3599 }
3600 return winY;
3601 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003602
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003603 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003604 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003605 final DisplayContent dc = getDisplayContent();
3606 if (dimLayerUser != null && dc != null) {
3607 dc.mDimLayerController.applyDim(dimLayerUser,
3608 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003609 }
3610 }
3611
Robert Carrd1a010f2016-04-07 22:36:22 -07003612 // During activity relaunch due to resize, we sometimes use window replacement
3613 // for only child windows (as the main window is handled by window preservation)
3614 // and the big surface.
3615 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003616 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3617 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3618 // we also want to replace them at such phases, as they won't be covered by window
3619 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003620 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003621 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003622 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003623 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003624
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003625 void setWillReplaceChildWindows() {
3626 if (shouldBeReplacedWithChildren()) {
3627 setWillReplaceWindow(false /* animate */);
3628 }
3629 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003630 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003631 c.setWillReplaceChildWindows();
3632 }
3633 }
3634
3635 WindowState getReplacingWindow() {
3636 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3637 return this;
3638 }
3639 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003640 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003641 final WindowState replacing = c.getReplacingWindow();
3642 if (replacing != null) {
3643 return replacing;
3644 }
3645 }
3646 return null;
3647 }
3648
Jorim Jaggife762342016-10-13 14:33:27 +02003649 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003650 public int getRotationAnimationHint() {
3651 if (mAppToken != null) {
3652 return mAppToken.mRotationAnimationHint;
3653 } else {
3654 return -1;
3655 }
3656 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003657
Jorim Jaggife762342016-10-13 14:33:27 +02003658 @Override
3659 public boolean isInputMethodWindow() {
3660 return mIsImWindow;
3661 }
3662
Wale Ogunwale9d147902016-07-16 11:58:55 -07003663 // This must be called while inside a transaction.
3664 boolean performShowLocked() {
3665 if (isHiddenFromUserLocked()) {
3666 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3667 hideLw(false);
3668 return false;
3669 }
3670
3671 logPerformShow("performShow on ");
3672
Jorim Jaggia50da602016-12-29 11:51:42 +01003673 final int drawState = mWinAnimator.mDrawState;
3674 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3675 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3676 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3677 }
3678
Jorim Jaggib0d27342016-11-01 16:10:42 -07003679 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003680 return false;
3681 }
3682
3683 logPerformShow("Showing ");
3684
3685 mService.enableScreenIfNeededLocked();
3686 mWinAnimator.applyEnterAnimationLocked();
3687
3688 // Force the show in the next prepareSurfaceLocked() call.
3689 mWinAnimator.mLastAlpha = -1;
3690 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3691 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3692 mWinAnimator.mDrawState = HAS_DRAWN;
3693 mService.scheduleAnimationLocked();
3694
3695 if (mHidden) {
3696 mHidden = false;
3697 final DisplayContent displayContent = getDisplayContent();
3698
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003699 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003700 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003701 if (c.mWinAnimator.mSurfaceController != null) {
3702 c.performShowLocked();
3703 // It hadn't been shown, which means layout not performed on it, so now we
3704 // want to make sure to do a layout. If called from within the transaction
3705 // loop, this will cause it to restart with a new layout.
3706 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003707 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003708 }
3709 }
3710 }
3711 }
3712
Wale Ogunwale9d147902016-07-16 11:58:55 -07003713 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003714 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003715 }
3716
3717 return true;
3718 }
3719
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003720 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003721 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003722 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003723 Slog.v(TAG, prefix + this
3724 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003725 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003726 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3727 + " during animation: policyVis=" + mPolicyVisibility
3728 + " parentHidden=" + isParentWindowHidden()
3729 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003730 + (mAppToken != null && mAppToken.hiddenRequested)
3731 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003732 + " animating=" + mWinAnimator.mAnimating
3733 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003734 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003735 + " Callers=" + Debug.getCallers(4));
3736 }
3737 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003738
3739 WindowInfo getWindowInfo() {
3740 WindowInfo windowInfo = WindowInfo.obtain();
3741 windowInfo.type = mAttrs.type;
3742 windowInfo.layer = mLayer;
3743 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003744 if (mAppToken != null) {
3745 windowInfo.activityToken = mAppToken.appToken.asBinder();
3746 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003747 windowInfo.title = mAttrs.accessibilityTitle;
3748 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3749 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003750 Task task = getTask();
3751 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWorkspace();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003752
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003753 if (mIsChildWindow) {
3754 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003755 }
3756
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003757 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003758 if (childCount > 0) {
3759 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003760 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003761 }
3762 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003763 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003764 windowInfo.childTokens.add(child.mClient.asBinder());
3765 }
3766 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003767 return windowInfo;
3768 }
3769
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003770 int getHighestAnimLayer() {
3771 int highest = mWinAnimator.mAnimLayer;
3772 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003773 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003774 final int childLayer = c.getHighestAnimLayer();
3775 if (childLayer > highest) {
3776 highest = childLayer;
3777 }
3778 }
3779 return highest;
3780 }
3781
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003782 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003783 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003784 if (mChildren.isEmpty()) {
3785 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003786 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003787 }
3788
3789 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003790 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003791 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003792 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003793 }
3794 }
3795
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003796 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003797 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003798 // below the parent, then this window (the parent), and then the positive sublayer children
3799 // because they need to appear above the parent.
3800 int i = 0;
3801 final int count = mChildren.size();
3802 WindowState child = mChildren.get(i);
3803
3804 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003805 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003806 return true;
3807 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003808 i++;
3809 if (i >= count) {
3810 break;
3811 }
3812 child = mChildren.get(i);
3813 }
3814
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003815 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003816 return true;
3817 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003818
3819 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003820 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003821 return true;
3822 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003823 i++;
3824 if (i >= count) {
3825 break;
3826 }
3827 child = mChildren.get(i);
3828 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003829
3830 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003831 }
3832
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003833 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003834 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003835 // 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) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003841 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003842 return true;
3843 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003844 --i;
3845 if (i < 0) {
3846 break;
3847 }
3848 child = mChildren.get(i);
3849 }
3850
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003851 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003852 return true;
3853 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003854
3855 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003856 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003857 return true;
3858 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003859 --i;
3860 if (i < 0) {
3861 break;
3862 }
3863 child = mChildren.get(i);
3864 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003865
3866 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003867 }
3868
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003869 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3870 boolean traverseTopToBottom) {
3871 if (traverseTopToBottom) {
3872 if (mService.mInputMethodTarget == this) {
3873 // This window is the current IME target, so we need to process the IME windows
3874 // directly above it.
3875 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3876 return true;
3877 }
3878 }
3879 if (callback.apply(this)) {
3880 return true;
3881 }
3882 } else {
3883 if (callback.apply(this)) {
3884 return true;
3885 }
3886 if (mService.mInputMethodTarget == this) {
3887 // This window is the current IME target, so we need to process the IME windows
3888 // directly above it.
3889 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3890 return true;
3891 }
3892 }
3893 }
3894
3895 return false;
3896 }
3897
Wale Ogunwaled1880962016-11-08 10:31:59 -08003898 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003899 if (mChildren.isEmpty()) {
3900 return callback.test(this) ? this : null;
3901 }
3902
3903 // We want to consume the positive sublayer children first because they need to appear
3904 // above the parent, then this window (the parent), and then the negative sublayer children
3905 // because they need to appear above the parent.
3906 int i = mChildren.size() - 1;
3907 WindowState child = mChildren.get(i);
3908
3909 while (i >= 0 && child.mSubLayer >= 0) {
3910 if (callback.test(child)) {
3911 return child;
3912 }
3913 --i;
3914 if (i < 0) {
3915 break;
3916 }
3917 child = mChildren.get(i);
3918 }
3919
Wale Ogunwaled1880962016-11-08 10:31:59 -08003920 if (callback.test(this)) {
3921 return this;
3922 }
Wale Ogunwale34247952017-02-19 11:57:53 -08003923
3924 while (i >= 0) {
3925 if (callback.test(child)) {
3926 return child;
3927 }
3928 --i;
3929 if (i < 0) {
3930 break;
3931 }
3932 child = mChildren.get(i);
3933 }
3934
3935 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08003936 }
3937
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003938 boolean isWindowAnimationSet() {
3939 if (mWinAnimator.isWindowAnimationSet()) {
3940 return true;
3941 }
3942 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003943 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003944 if (c.isWindowAnimationSet()) {
3945 return true;
3946 }
3947 }
3948 return false;
3949 }
3950
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003951 void onExitAnimationDone() {
3952 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3953 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
3954 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
3955
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003956 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003957 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003958 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003959 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003960 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003961 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003962 }
3963 }
3964
3965 if (mWinAnimator.mEnteringAnimation) {
3966 mWinAnimator.mEnteringAnimation = false;
3967 mService.requestTraversal();
3968 // System windows don't have an activity and an app token as a result, but need a way
3969 // to be informed about their entrance animation end.
3970 if (mAppToken == null) {
3971 try {
3972 mClient.dispatchWindowShown();
3973 } catch (RemoteException e) {
3974 }
3975 }
3976 }
3977
3978 if (!mWinAnimator.isWindowAnimationSet()) {
3979 //TODO (multidisplay): Accessibility is supported only for the default display.
3980 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3981 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3982 }
3983 }
3984
3985 if (!mAnimatingExit) {
3986 return;
3987 }
3988
3989 if (mWinAnimator.isWindowAnimationSet()) {
3990 return;
3991 }
3992
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003993 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003994 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3995
3996 mDestroying = true;
3997
3998 final boolean hasSurface = mWinAnimator.hasSurface();
3999 if (hasSurface) {
4000 mWinAnimator.hide("onExitAnimationDone");
4001 }
4002
4003 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4004 // care to ensure the activity has actually stopped and the surface is not still in use.
4005 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4006 // transaction.
4007 if (mAppToken != null) {
4008 mAppToken.destroySurfaces();
4009 } else {
4010 if (hasSurface) {
4011 mService.mDestroySurface.add(this);
4012 }
4013 if (mRemoveOnExit) {
4014 mService.mPendingRemove.add(this);
4015 mRemoveOnExit = false;
4016 }
4017 }
4018 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004019 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004020 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004021
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004022 boolean clearAnimatingFlags() {
4023 boolean didSomething = false;
4024 // We don't want to clear it out for windows that get replaced, because the
4025 // animation depends on the flag to remove the replaced window.
4026 //
4027 // We also don't clear the mAnimatingExit flag for windows which have the
4028 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4029 // by the client. We should let animation proceed and not clear this flag or
4030 // they won't eventually be removed by WindowStateAnimator#finishExit.
4031 if (!mWillReplaceWindow && !mRemoveOnExit) {
4032 // Clear mAnimating flag together with mAnimatingExit. When animation
4033 // changes from exiting to entering, we need to clear this flag until the
4034 // new animation gets applied, so that isAnimationStarting() becomes true
4035 // until then.
4036 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4037 // placement for this window during this period, one or more frame will
4038 // show up with wrong position or scale.
4039 if (mAnimatingExit) {
4040 mAnimatingExit = false;
4041 didSomething = true;
4042 }
4043 if (mWinAnimator.mAnimating) {
4044 mWinAnimator.mAnimating = false;
4045 didSomething = true;
4046 }
4047 if (mDestroying) {
4048 mDestroying = false;
4049 mService.mDestroySurface.remove(this);
4050 didSomething = true;
4051 }
4052 }
4053
4054 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004055 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004056 }
4057
4058 return didSomething;
4059 }
4060
Winson4b4ba902016-07-27 19:45:52 -07004061 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004062 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004063 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004064
4065 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004066 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004067 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004068 c.hideWallpaperWindow(wasDeferred, reason);
4069 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004070 if (!mWinAnimator.mLastHidden || wasDeferred) {
4071 mWinAnimator.hide(reason);
4072 dispatchWallpaperVisibility(false);
4073 final DisplayContent displayContent = getDisplayContent();
4074 if (displayContent != null) {
4075 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4076 }
4077 }
4078 }
4079
4080 /**
4081 * Check wallpaper window for visibility change and notify window if so.
4082 * @param visible Current visibility.
4083 */
4084 void dispatchWallpaperVisibility(final boolean visible) {
4085 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004086 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004087
4088 // Only send notification if the visibility actually changed and we are not trying to hide
4089 // the wallpaper when we are deferring hiding of the wallpaper.
4090 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4091 mWallpaperVisible = visible;
4092 try {
4093 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4094 "Updating vis of wallpaper " + this
4095 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4096 mClient.dispatchAppVisibility(visible);
4097 } catch (RemoteException e) {
4098 }
4099 }
4100 }
4101
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004102 boolean hasVisibleNotDrawnWallpaper() {
4103 if (mWallpaperVisible && !isDrawnLw()) {
4104 return true;
4105 }
4106 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004107 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004108 if (c.hasVisibleNotDrawnWallpaper()) {
4109 return true;
4110 }
4111 }
4112 return false;
4113 }
4114
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004115 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4116 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004117 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004118 c.updateReportedVisibility(results);
4119 }
4120
4121 if (mAppFreezing || mViewVisibility != View.VISIBLE
4122 || mAttrs.type == TYPE_APPLICATION_STARTING
4123 || mDestroying) {
4124 return;
4125 }
4126 if (DEBUG_VISIBILITY) {
4127 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4128 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4129 if (!isDrawnLw()) {
4130 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4131 + " pv=" + mPolicyVisibility
4132 + " mDrawState=" + mWinAnimator.mDrawState
4133 + " ph=" + isParentWindowHidden()
4134 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4135 + " a=" + mWinAnimator.mAnimating);
4136 }
4137 }
4138
4139 results.numInteresting++;
4140 if (isDrawnLw()) {
4141 results.numDrawn++;
4142 if (!mWinAnimator.isAnimationSet()) {
4143 results.numVisible++;
4144 }
4145 results.nowGone = false;
4146 } else if (mWinAnimator.isAnimationSet()) {
4147 results.nowGone = false;
4148 }
4149 }
4150
Robert Carrfbbde852016-10-18 11:02:28 -07004151 /**
4152 * Calculate the window crop according to system decor policy. In general this is
4153 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4154 * special cases. This rectangle is in screen space.
4155 */
4156 void calculatePolicyCrop(Rect policyCrop) {
4157 final DisplayContent displayContent = getDisplayContent();
4158 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4159
4160 if (!isDefaultDisplay()) {
4161 // On a different display there is no system decor. Crop the window
4162 // by the screen boundaries.
4163 // TODO(multi-display)
4164 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4165 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4166 displayInfo.logicalWidth - mCompatFrame.left,
4167 displayInfo.logicalHeight - mCompatFrame.top);
4168 } else if (mLayer >= mService.mSystemDecorLayer) {
4169 // Above the decor layer is easy, just use the entire window
4170 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4171 } else if (mDecorFrame.isEmpty()) {
4172 // Windows without policy decor aren't cropped.
4173 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4174 } else {
4175 // Crop to the system decor specified by policy.
4176 calculateSystemDecorRect(policyCrop);
4177 }
4178 }
4179
4180 /**
4181 * The system decor rect is the region of the window which is not covered
4182 * by system decorations.
4183 */
4184 private void calculateSystemDecorRect(Rect systemDecorRect) {
4185 final Rect decorRect = mDecorFrame;
4186 final int width = mFrame.width();
4187 final int height = mFrame.height();
4188
4189 // Compute the offset of the window in relation to the decor rect.
4190 final int left = mXOffset + mFrame.left;
4191 final int top = mYOffset + mFrame.top;
4192
4193 // Initialize the decor rect to the entire frame.
4194 if (isDockedResizing()) {
4195 // If we are resizing with the divider, the task bounds might be smaller than the
4196 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4197 // want in this case in order to avoid holes.
4198 //
4199 // We take care to not shrink the width, for surfaces which are larger than
4200 // the display region. Of course this area will not eventually be visible
4201 // but if we truncate the width now, we will calculate incorrectly
4202 // when adjusting to the stack bounds.
4203 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4204 systemDecorRect.set(0, 0,
4205 Math.max(width, displayInfo.logicalWidth),
4206 Math.max(height, displayInfo.logicalHeight));
4207 } else {
4208 systemDecorRect.set(0, 0, width, height);
4209 }
4210
4211 // If a freeform window is animating from a position where it would be cutoff, it would be
4212 // cutoff during the animation. We don't want that, so for the duration of the animation
4213 // we ignore the decor cropping and depend on layering to position windows correctly.
4214 final boolean cropToDecor = !(inFreeformWorkspace() && isAnimatingLw());
4215 if (cropToDecor) {
4216 // Intersect with the decor rect, offsetted by window position.
4217 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4218 decorRect.right - left, decorRect.bottom - top);
4219 }
4220
4221 // If size compatibility is being applied to the window, the
4222 // surface is scaled relative to the screen. Also apply this
4223 // scaling to the crop rect. We aren't using the standard rect
4224 // scale function because we want to round things to make the crop
4225 // always round to a larger rect to ensure we don't crop too
4226 // much and hide part of the window that should be seen.
4227 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4228 final float scale = mInvGlobalScale;
4229 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4230 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4231 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4232 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4233 }
4234
4235 }
4236
4237 /**
4238 * Expand the given rectangle by this windows surface insets. This
4239 * takes you from the 'window size' to the 'surface size'.
4240 * The surface insets are positive in each direction, so we inset by
4241 * the inverse.
4242 */
4243 void expandForSurfaceInsets(Rect r) {
4244 r.inset(-mAttrs.surfaceInsets.left,
4245 -mAttrs.surfaceInsets.top,
4246 -mAttrs.surfaceInsets.right,
4247 -mAttrs.surfaceInsets.bottom);
4248 }
4249
Robert Carrc91d1c32017-02-15 19:37:46 -08004250 boolean surfaceInsetsChanging() {
4251 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4252 }
4253
Bryce Leef858b572017-06-29 14:03:33 -07004254 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004255 final boolean wasVisible = isVisibleLw();
4256
4257 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004258 if (mAnimatingExit) {
4259 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4260 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4261
4262 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4263 mAnimatingExit = false;
4264 }
4265 if (mDestroying) {
4266 mDestroying = false;
4267 mService.mDestroySurface.remove(this);
4268 }
4269 if (oldVisibility == View.GONE) {
4270 mWinAnimator.mEnterAnimationPending = true;
4271 }
4272
Andrii Kulian8ee72852017-03-10 10:36:45 -08004273 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004274
4275 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004276
Bryce Leef858b572017-06-29 14:03:33 -07004277 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004278
Robert Carrc91d1c32017-02-15 19:37:46 -08004279 if ((attrChanges & FORMAT_CHANGED) != 0) {
4280 // If the format can't be changed in place, preserve the old surface until the app draws
4281 // on the new one. This prevents blinking when we change elevation of freeform and
4282 // pinned windows.
4283 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4284 mWinAnimator.preserveSurfaceLocked();
4285 result |= RELAYOUT_RES_SURFACE_CHANGED
4286 | RELAYOUT_RES_FIRST_TIME;
4287 }
4288 }
4289
4290 // When we change the Surface size, in scenarios which may require changing
4291 // the surface position in sync with the resize, we use a preserved surface
4292 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004293 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4294 // stack since it can lead to issues if a new surface is created while calculating the
4295 // scale for the animation using the source hint rect
4296 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004297 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Winson Chung8bca9e42017-04-16 15:59:43 -07004298 || (surfaceInsetsChanging() && !inPinnedWorkspace())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004299 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4300
4301 setDragResizing();
4302 setResizedWhileNotDragResizing(false);
4303 // We can only change top level windows to the full-screen surface when
4304 // resizing (as we only have one full-screen surface). So there is no need
4305 // to preserve and destroy windows which are attached to another, they
4306 // will keep their surface and its size may change over time.
4307 if (mHasSurface && !isChildWindow()) {
4308 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004309 result |= RELAYOUT_RES_SURFACE_CHANGED |
4310 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004311 }
4312 }
4313 final boolean freeformResizing = isDragResizing()
4314 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4315 final boolean dockedResizing = isDragResizing()
4316 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4317 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4318 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004319 return result;
4320 }
4321
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004322 /**
4323 * @return True if this window has been laid out at least once; false otherwise.
4324 */
4325 boolean isLaidOut() {
4326 return mLayoutSeq != -1;
4327 }
4328
4329 /**
4330 * Updates the last inset values to the current ones.
4331 */
4332 void updateLastInsetValues() {
4333 mLastOverscanInsets.set(mOverscanInsets);
4334 mLastContentInsets.set(mContentInsets);
4335 mLastVisibleInsets.set(mVisibleInsets);
4336 mLastStableInsets.set(mStableInsets);
4337 mLastOutsets.set(mOutsets);
4338 }
4339
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004340 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4341 // access to its windows children. Need to investigate re-writing
4342 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4343 static final class UpdateReportedVisibilityResults {
4344 int numInteresting;
4345 int numVisible;
4346 int numDrawn;
4347 boolean nowGone = true;
4348
4349 void reset() {
4350 numInteresting = 0;
4351 numVisible = 0;
4352 numDrawn = 0;
4353 nowGone = true;
4354 }
4355 }
Robert Carraf422a82017-04-10 18:34:33 -07004356
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004357 private static final class WindowId extends IWindowId.Stub {
4358 private final WeakReference<WindowState> mOuter;
4359
4360 private WindowId(WindowState outer) {
4361
4362 // Use a weak reference for the outer class. This is important to prevent the following
4363 // leak: Since we send this class to the client process, binder will keep it alive as
4364 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4365 // out our reference so even though this class is kept alive we don't leak WindowState,
4366 // which can keep a whole lot of classes alive.
4367 mOuter = new WeakReference<>(outer);
4368 }
4369
4370 @Override
4371 public void registerFocusObserver(IWindowFocusObserver observer) {
4372 final WindowState outer = mOuter.get();
4373 if (outer != null) {
4374 outer.registerFocusObserver(observer);
4375 }
4376 }
4377 @Override
4378 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4379 final WindowState outer = mOuter.get();
4380 if (outer != null) {
4381 outer.unregisterFocusObserver(observer);
4382 }
4383 }
4384 @Override
4385 public boolean isFocused() {
4386 final WindowState outer = mOuter.get();
4387 return outer != null && outer.isFocused();
4388 }
4389 }
4390
Robert Carraf422a82017-04-10 18:34:33 -07004391 boolean usesRelativeZOrdering() {
4392 if (!isChildWindow()) {
4393 return false;
4394 } else if (mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4395 return true;
4396 } else {
4397 return false;
4398 }
4399 }
satokcef37fb2011-10-24 21:49:38 +09004400}