blob: b61a873ea0362e57be49e839004b7eea7bc686b3 [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.ENABLE_TASK_SNAPSHOTS;
20import static android.app.ActivityManager.StackId;
Winson Chungd73e94b2017-05-31 16:25:30 -070021import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080022import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Winson Chungd73e94b2017-05-31 16:25:30 -070023import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080024import static android.app.ActivityManager.isLowRamDeviceStatic;
25import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
26import static android.view.Display.DEFAULT_DISPLAY;
27import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
29import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
30import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
31import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
32import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
33import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
34import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
35import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
36import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
37import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
38import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
39import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
40import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
41import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
42import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
43import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
44import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080045import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080046import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
47import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
48import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070049import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080050import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
52import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
53import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
54import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
55import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carraf422a82017-04-10 18:34:33 -070056import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080057import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
58import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
59import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
60import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
61import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
62import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070063import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080064import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070065import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080066import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
67import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
68import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
69import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080070import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
71import static android.view.WindowManagerPolicy.TRANSIT_ENTER;
72import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
73import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
74import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
75import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
76import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
77import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
78import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
79import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
80import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080083import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
85import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
86import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
87import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080091import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
92import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
93import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
94import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
95import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
96import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
97import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
98import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
99import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
100import static com.android.server.wm.WindowManagerService.localLOGV;
101import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
102import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
103import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
104import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
105
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800106import android.app.AppOpsManager;
107import android.content.Context;
108import android.content.res.Configuration;
109import android.graphics.Matrix;
110import android.graphics.PixelFormat;
111import android.graphics.Point;
112import android.graphics.Rect;
113import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700114import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700115import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800116import android.os.IBinder;
117import android.os.PowerManager;
118import android.os.RemoteCallbackList;
119import android.os.RemoteException;
120import android.os.SystemClock;
121import android.os.Trace;
122import android.os.UserHandle;
123import android.os.WorkSource;
Andrii Kulian44607962017-03-16 11:06:24 -0700124import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800125import android.util.DisplayMetrics;
126import android.util.Slog;
127import android.util.TimeUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800128import android.view.DisplayInfo;
129import android.view.Gravity;
130import android.view.IApplicationToken;
131import android.view.IWindow;
132import android.view.IWindowFocusObserver;
133import android.view.IWindowId;
134import android.view.InputChannel;
135import android.view.InputEvent;
136import android.view.InputEventReceiver;
137import android.view.View;
138import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700139import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800140import android.view.WindowManager;
141import android.view.WindowManagerPolicy;
142
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800143import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800144import com.android.server.input.InputWindowHandle;
145
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800146import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200147import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800148import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700149import java.util.Comparator;
150import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800151import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800152
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700153/** A window in the window manager. */
154class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800155 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800156
Skuhne81c524a2015-08-12 13:34:14 -0700157 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700158 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
159 // use hard-coded min sizes for now.
160 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
161 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700162
163 // The thickness of a window resize handle outside the window bounds on the free form workspace
164 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700165 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700166
Jorim Jaggi02886a82016-12-06 09:10:06 -0800167 private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false ||
168 ENABLE_TASK_SNAPSHOTS;
Robert Carr7098dbd2016-02-01 12:31:01 -0800169
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700171 final WindowManagerPolicy mPolicy;
172 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 final Session mSession;
174 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800175 final int mAppOp;
176 // UserId and appId of the owner. Don't display windows of non-current user.
177 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800178 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
179 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200180 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800181 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700182 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700184
185 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
186 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
188 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700189 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 final int mBaseLayer;
191 final int mSubLayer;
192 final boolean mLayoutAttached;
193 final boolean mIsImWindow;
194 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700195 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700196 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700197 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700199 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700200 /**
201 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
202 * Normally set by calling {@link #showLw} and {@link #hideLw}.
203 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700205 /**
206 * What {@link #mPolicyVisibility} should be set to after a transition animation.
207 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
208 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
209 * animation is done.
210 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800211 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700212 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700213 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700214 // This is a non-system overlay window that is currently force hidden.
215 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800216 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700217 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800218 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700219 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200220 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700221 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700222
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700223 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800224
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700225 /**
226 * The window size that was requested by the application. These are in
227 * the application's coordinate space (without compatibility scale applied).
228 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229 int mRequestedWidth;
230 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700231 private int mLastRequestedWidth;
232 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700233
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 boolean mHaveFrame;
236 boolean mObscured;
237 boolean mTurnOnScreen;
238
239 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700240
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700241 /**
242 * Used to store last reported to client configuration and check if we have newer available.
243 * We'll send configuration to client only if it is different from the last applied one and
244 * client won't perform unnecessary updates.
245 */
246 private final Configuration mLastReportedConfiguration = new Configuration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700247
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700248 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700249 * Actual position of the surface shown on-screen (may be modified by animation). These are
250 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700251 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700252 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800253
254 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700255 * Insets that determine the actually visible area. These are in the application's
256 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 */
258 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700259 private final Rect mLastVisibleInsets = new Rect();
260 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261
262 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700263 * Insets that are covered by system windows (such as the status bar) and
264 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700265 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 */
267 final Rect mContentInsets = new Rect();
268 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700269
270 /**
271 * The last content insets returned to the client in relayout. We use
272 * these in the bounds animation to ensure we only observe inset changes
273 * at the same time that a client resizes it's surface so that we may use
274 * the geometryAppliesWithResize synchronization mechanism to keep
275 * the contents in place.
276 */
277 final Rect mLastRelayoutContentInsets = new Rect();
278
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700279 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280
281 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800282 * Insets that determine the area covered by the display overscan region. These are in the
283 * application's coordinate space (without compatibility scale applied).
284 */
285 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700286 private final Rect mLastOverscanInsets = new Rect();
287 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800288
289 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700290 * Insets that determine the area covered by the stable system windows. These are in the
291 * application's coordinate space (without compatibility scale applied).
292 */
293 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700294 private final Rect mLastStableInsets = new Rect();
295 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700296
297 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700298 * Outsets determine the area outside of the surface where we want to pretend that it's possible
299 * to draw anyway.
300 */
301 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700302 private final Rect mLastOutsets = new Rect();
303 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700304
305 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 * Set to true if we are waiting for this window to receive its
307 * given internal insets before laying out other windows based on it.
308 */
309 boolean mGivenInsetsPending;
310
311 /**
312 * These are the content insets that were given during layout for
313 * this window, to be applied to windows behind it.
314 */
315 final Rect mGivenContentInsets = new Rect();
316
317 /**
318 * These are the visible insets that were given during layout for
319 * this window, to be applied to windows behind it.
320 */
321 final Rect mGivenVisibleInsets = new Rect();
322
323 /**
324 * This is the given touchable area relative to the window frame, or null if none.
325 */
326 final Region mGivenTouchableRegion = new Region();
327
328 /**
329 * Flag indicating whether the touchable region should be adjusted by
330 * the visible insets; if false the area outside the visible insets is
331 * NOT touchable, so we must use those to adjust the frame during hit
332 * tests.
333 */
334 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
335
336 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400337 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700338 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339 float mHScale=1, mVScale=1;
340 float mLastHScale=1, mLastVScale=1;
341 final Matrix mTmpMatrix = new Matrix();
342
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700343 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344 final Rect mFrame = new Rect();
345 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700346 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700347 // Frame that is scaled to the application's coordinate space when in
348 // screen size compatibility mode.
349 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350
351 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700352
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700353 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700354
Wale Ogunwale94596652015-02-06 19:27:34 -0800355 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
356 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700357 final Rect mDisplayFrame = new Rect();
358
359 // The region of the display frame that the display type supports displaying content on. This
360 // is mostly a special case for TV where some displays don’t have the entire display usable.
361 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
362 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700363 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700364
365 // The display frame minus the stable insets. This value is always constant regardless of if
366 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700367 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700369 // The area not occupied by the status and navigation bars. So, if both status and navigation
370 // bars are visible, the decor frame is equal to the stable frame.
371 final Rect mDecorFrame = new Rect();
372
373 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
374 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700375 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700376
377 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
378 // displays hint text.
379 final Rect mVisibleFrame = new Rect();
380
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700381 // Frame that includes dead area outside of the surface but where we want to pretend that it's
382 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700383 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700384
Jorim Jaggidc249c42015-12-15 14:57:31 -0800385 /**
386 * Usually empty. Set to the task's tempInsetFrame. See
387 *{@link android.app.IActivityManager#resizeDockedStack}.
388 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700389 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800390
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800391 boolean mContentChanged;
392
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800393 // If a window showing a wallpaper: the requested offset for the
394 // wallpaper; if a wallpaper window: the currently applied offset.
395 float mWallpaperX = -1;
396 float mWallpaperY = -1;
397
398 // If a window showing a wallpaper: what fraction of the offset
399 // range corresponds to a full virtual screen.
400 float mWallpaperXStep = -1;
401 float mWallpaperYStep = -1;
402
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700403 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
404 // to its window; if a wallpaper window: not used.
405 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
406 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
407
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408 // Wallpaper windows: pixels offset based on above variables.
409 int mXOffset;
410 int mYOffset;
411
Craig Mautner2268e7e2012-12-13 15:40:00 -0800412 /**
413 * This is set after IWindowSession.relayout() has been called at
414 * least once for the window. It allows us to detect the situation
415 * where we don't yet have a surface, but should have one soon, so
416 * we can give the window focus before waiting for the relayout.
417 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800418 boolean mRelayoutCalled;
419
Robert Carrfed10072016-05-26 11:48:49 -0700420 boolean mInRelayout;
421
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800422 /**
423 * If the application has called relayout() with changes that can
424 * impact its window's size, we need to perform a layout pass on it
425 * even if it is not currently visible for layout. This is set
426 * when in that case until the layout is done.
427 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800428 boolean mLayoutNeeded;
429
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800430 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800431 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800432
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800433 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800434 boolean mDestroying;
435
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800436 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800437 boolean mRemoveOnExit;
438
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800439 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800440 * Whether the app died while it was visible, if true we might need
441 * to continue to show it until it's restarted.
442 */
443 boolean mAppDied;
444
445 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800446 * Set when the orientation is changing and this window has not yet
447 * been updated for the new orientation.
448 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700449 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800450
Dianne Hackborna57c6952013-03-29 14:46:40 -0700451 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700452 * Sometimes in addition to the mOrientationChanging
453 * flag we report that the orientation is changing
454 * due to a mismatch in current and reported configuration.
455 *
456 * In the case of timeout we still need to make sure we
457 * leave the orientation changing state though, so we
458 * use this as a special time out escape hatch.
459 */
460 private boolean mOrientationChangeTimedOut;
461
462 /**
Robert Carr237028a2016-07-26 10:39:45 -0700463 * The orientation during the last visible call to relayout. If our
464 * current orientation is different, the window can't be ready
465 * to be shown.
466 */
467 int mLastVisibleLayoutRotation = -1;
468
469 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800470 * Set when we need to report the orientation change to client to trigger a relayout.
471 */
472 boolean mReportOrientationChanged;
473
474 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700475 * How long we last kept the screen frozen.
476 */
477 int mLastFreezeDuration;
478
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800479 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800480 boolean mRemoved;
481
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800482 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800483 * It is save to remove the window and destroy the surface because the client requested removal
484 * or some other higher level component said so (e.g. activity manager).
485 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800486 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700487 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800488
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700490 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800491 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700492 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800493
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800494 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700495 private String mStringNameCache;
496 private CharSequence mLastTitle;
497 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800498
Craig Mautnera2c77052012-03-26 12:14:43 -0700499 final WindowStateAnimator mWinAnimator;
500
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700501 boolean mHasSurface = false;
502
Craig Mautner88400d32012-09-30 12:35:45 -0700503 /** When true this window can be displayed on screens owther than mOwnerUid's */
504 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700505
Robert Carr13f7be9e2015-12-02 18:39:45 -0800506 // Whether the window has a saved surface from last pause, which can be
507 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700508 private boolean mSurfaceSaved = false;
509
Chong Zhang8e4bda92016-05-04 15:08:18 -0700510 // Whether we're performing an entering animation with a saved surface. This flag is
511 // true during the time we're showing a window with a previously saved surface. It's
512 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700513 private boolean mAnimatingWithSavedSurface;
514
515 // Whether the window was visible when we set the app to invisible last time. WM uses
516 // this as a hint to restore the surface (if available) for early animation next time
517 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700518 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800519
Robert Carra1eb4392015-12-10 12:43:51 -0800520 // This window will be replaced due to relaunch. This allows window manager
521 // to differentiate between simple removal of a window and replacement. In the latter case it
522 // will preserve the old window until the new one is drawn.
523 boolean mWillReplaceWindow = false;
524 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700525 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800526 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700527 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800528 // If not null, the window that will be used to replace the old one. This is being set when
529 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700530 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700531 // For the new window in the replacement transition, if we have
532 // requested to replace without animation, then we should
533 // make sure we also don't apply an enter animation for
534 // the new window.
535 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800536 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700537 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800538
Jeff Brownc2932a12014-11-20 18:04:05 -0800539 /**
540 * Wake lock for drawing.
541 * Even though it's slightly more expensive to do so, we will use a separate wake lock
542 * for each app that is requesting to draw while dozing so that we can accurately track
543 * who is preventing the system from suspending.
544 * This lock is only acquired on first use.
545 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700546 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800547
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700548 final private Rect mTmpRect = new Rect();
549
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800550 /**
551 * Whether the window was resized by us while it was gone for layout.
552 */
553 boolean mResizedWhileGone = false;
554
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700555 /** @see #isResizedWhileNotDragResizing(). */
556 private boolean mResizedWhileNotDragResizing;
557
558 /** @see #isResizedWhileNotDragResizingReported(). */
559 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700560
Robert Carr6da3cc02016-06-16 15:17:07 -0700561 /**
562 * During seamless rotation we have two phases, first the old window contents
563 * are rotated to look as if they didn't move in the new coordinate system. Then we
564 * have to freeze updates to this layer (to preserve the transformation) until
565 * the resize actually occurs. This is true from when the transformation is set
566 * and false until the transaction to resize is sent.
567 */
568 boolean mSeamlesslyRotated = false;
569
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700570 private static final Region sEmptyRegion = new Region();
571
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700572 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800573 * Surface insets from the previous call to relayout(), used to track
574 * if we are changing the Surface insets.
575 */
576 final Rect mLastSurfaceInsets = new Rect();
577
578 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700579 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
580 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
581 * make sure all children have been considered.
582 */
583 private boolean mDrawnStateEvaluated;
584
585 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700586 * 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 -0700587 * of z-order and 1 otherwise.
588 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800589 private static final Comparator<WindowState> sWindowSubLayerComparator =
590 new Comparator<WindowState>() {
591 @Override
592 public int compare(WindowState w1, WindowState w2) {
593 final int layer1 = w1.mSubLayer;
594 final int layer2 = w2.mSubLayer;
595 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
596 // We insert the child window into the list ordered by
597 // the sub-layer. For same sub-layers, the negative one
598 // should go below others; the positive one should go
599 // above others.
600 return -1;
601 }
602 return 1;
603 };
604 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700605
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800606 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700607 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800608 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800609 mService = service;
610 mSession = s;
611 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800612 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800613 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700614 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700615 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800616 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200617 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800618 mAttrs.copyFrom(a);
619 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700620 mPolicy = mService.mPolicy;
621 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800622 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700623 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700624 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700625 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700626 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700627 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800628 try {
629 c.asBinder().linkToDeath(deathRecipient, 0);
630 } catch (RemoteException e) {
631 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700632 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800633 mLayoutAttached = false;
634 mIsImWindow = false;
635 mIsWallpaper = false;
636 mIsFloatingLayer = false;
637 mBaseLayer = 0;
638 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700639 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700640 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800641 return;
642 }
643 mDeathRecipient = deathRecipient;
644
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700645 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800646 // The multiplier here is to reserve space for multiple
647 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800648 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700649 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800650 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700651 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900652
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700653 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
654 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900655
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800656 mLayoutAttached = mAttrs.type !=
657 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700658 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
659 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
660 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800661 } else {
662 // The multiplier here is to reserve space for multiple
663 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800664 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700665 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800666 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700667 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800668 mLayoutAttached = false;
669 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
670 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
671 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700673 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800674
Wale Ogunwale72919d22016-12-08 18:58:50 -0800675 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700676 // Windows for apps that can show for all users should also show when the device is
677 // locked.
678 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700679 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800680
Craig Mautner322e4032012-07-13 13:35:20 -0700681 mWinAnimator = new WindowStateAnimator(this);
682 mWinAnimator.mAlpha = a.alpha;
683
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800684 mRequestedWidth = 0;
685 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700686 mLastRequestedWidth = 0;
687 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800688 mXOffset = 0;
689 mYOffset = 0;
690 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800691 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800692 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
693 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800694 }
695
696 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700697 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800698 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800699 }
700
Bryce Leed390deb2017-06-22 13:14:28 -0700701 /**
702 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
703 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700704 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700705 return mDrawnStateEvaluated;
706 }
707
708 /**
709 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
710 * be cleared when detached from parent.
711 */
712 void setDrawnStateEvaluated(boolean evaluated) {
713 mDrawnStateEvaluated = evaluated;
714 }
715
716 @Override
717 void onParentSet() {
718 super.onParentSet();
719 setDrawnStateEvaluated(false /*evaluated*/);
720 }
721
Craig Mautnera2c77052012-03-26 12:14:43 -0700722 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800723 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800724 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800725 }
726
727 @Override
728 public String getOwningPackage() {
729 return mAttrs.packageName;
730 }
731
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800732 @Override
733 public boolean canAddInternalSystemWindow() {
734 return mOwnerCanAddInternalSystemWindow;
735 }
736
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200737 @Override
738 public boolean canAcquireSleepToken() {
739 return mSession.mCanAcquireSleepToken;
740 }
741
Jorim Jaggif5834272016-04-04 20:25:41 -0700742 /**
743 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
744 * from {@param frame}. In other words, it applies the insets that would result if
745 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700746 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
747 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700748 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700749 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
750 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
751 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
752 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
753 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700754 frame.inset(left, top, right, bottom);
755 }
756
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800757 @Override
Robert Carr43521762016-10-28 13:15:04 -0700758 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
759 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
760 Rect outsetFrame) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800761 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700762 // This window is being replaced and either already got information that it's being
763 // removed or we are still waiting for some information. Because of this we don't
764 // want to apply any more changes to it, so it remains in this state until new window
765 // appears.
766 return;
767 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800768 mHaveFrame = true;
769
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700770 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700771 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800772 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700773 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800774
Chong Zhangae35fef2016-03-16 15:56:55 -0700775 // If the task has temp inset bounds set, we have to make sure all its windows uses
776 // the temp inset frame. Otherwise different display frames get applied to the main
777 // window and the child window, making them misaligned.
Andrii Kulianc24f3732017-08-08 19:35:17 -0700778 if (inFullscreenContainer || isLetterboxedAppWindow()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700779 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700780 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700781 task.getTempInsetBounds(mInsetFrame);
782 }
783
Jorim Jaggif5834272016-04-04 20:25:41 -0700784 // Denotes the actual frame used to calculate the insets and to perform the layout. When
785 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
786 // insets temporarily. By the notion of a task having a different layout frame, we can
787 // achieve that while still moving the task around.
788 final Rect layoutContainingFrame;
789 final Rect layoutDisplayFrame;
790
791 // The offset from the layout containing frame to the actual containing frame.
792 final int layoutXDiff;
793 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700794 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800795 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700796 mContainingFrame.set(parentFrame);
797 mDisplayFrame.set(displayFrame);
798 layoutDisplayFrame = displayFrame;
799 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700800 layoutXDiff = 0;
801 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800802 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700803 getContainerBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100804 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
805
806 // If the bounds are frozen, we still want to translate the window freely and only
807 // freeze the size.
808 Rect frozen = mAppToken.mFrozenBounds.peek();
809 mContainingFrame.right = mContainingFrame.left + frozen.width();
810 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
811 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800812 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700813 // IME is up and obscuring this window. Adjust the window position so it is visible.
814 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700815 final int stackId = getStackId();
816 if (stackId == FREEFORM_WORKSPACE_STACK_ID
817 && mContainingFrame.bottom > contentFrame.bottom) {
818 // In freeform we want to move the top up directly.
819 // TODO: Investigate why this is contentFrame not parentFrame.
820 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
821 } else if (stackId != PINNED_STACK_ID
822 && mContainingFrame.bottom > parentFrame.bottom) {
823 // But in docked we want to behave like fullscreen and behave as if the task
824 // were given smaller bounds for the purposes of layout. Skip adjustments for
825 // the pinned stack, they are handled separately in the PinnedStackController.
826 mContainingFrame.bottom = parentFrame.bottom;
827 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700828 }
Skuhne81c524a2015-08-12 13:34:14 -0700829
Robert Carre6275582016-02-29 15:45:45 -0800830 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700831 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
832 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800833 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700834 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700835 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700836 }
Doris Liu06d582d2015-06-01 13:18:43 -0700837 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800838 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700839 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
840 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
841 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700842 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700843 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700844 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700845 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
846 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700847 }
Robert Carr43521762016-10-28 13:15:04 -0700848 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700849 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700850 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800851
Craig Mautner967212c2013-04-13 21:10:58 -0700852 final int pw = mContainingFrame.width();
853 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800854
Robert Carr43521762016-10-28 13:15:04 -0700855 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800856 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700857 // + " to " + parentFrame);
858 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800859 mContentChanged = true;
860 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700861 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
862 mLastRequestedWidth = mRequestedWidth;
863 mLastRequestedHeight = mRequestedHeight;
864 mContentChanged = true;
865 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800866
Robert Carr43521762016-10-28 13:15:04 -0700867 mOverscanFrame.set(overscanFrame);
868 mContentFrame.set(contentFrame);
869 mVisibleFrame.set(visibleFrame);
870 mDecorFrame.set(decorFrame);
871 mStableFrame.set(stableFrame);
872 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700873 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700874 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700875 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800876
Craig Mautnereda67292013-04-28 13:50:14 -0700877 final int fw = mFrame.width();
878 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800879
Jorim Jaggif5834272016-04-04 20:25:41 -0700880 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
881
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700882 // Calculate the outsets before the content frame gets shrinked to the window frame.
883 if (hasOutsets) {
884 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
885 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
886 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
887 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
888 } else {
889 mOutsets.set(0, 0, 0, 0);
890 }
891
Craig Mautnera248eee2013-05-07 11:41:27 -0700892 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800893 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800894 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800895 // For pinned workspace the frame isn't limited in any particular
896 // way since SystemUI controls the bounds. For freeform however
897 // we want to keep things inside the content frame.
898 final Rect limitFrame = task.inPinnedWorkspace() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700899 // Keep the frame out of the blocked system area, limit it in size to the content area
900 // and make sure that there is always a minimum visible so that the user can drag it
901 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800902 final int height = Math.min(mFrame.height(), limitFrame.height());
903 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700904 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900905 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
906 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
907 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
908 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800909 final int top = Math.max(limitFrame.top,
910 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
911 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
912 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700913 mFrame.set(left, top, left + width, top + height);
914 mContentFrame.set(mFrame);
915 mVisibleFrame.set(mContentFrame);
916 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700917 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700918 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100919 mContentFrame.set(mFrame);
920 if (!mFrame.equals(mLastFrame)) {
921 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800922 }
Skuhne81c524a2015-08-12 13:34:14 -0700923 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700924 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
925 Math.max(mContentFrame.top, mFrame.top),
926 Math.min(mContentFrame.right, mFrame.right),
927 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800928
Jorim Jaggi656f6502016-04-11 21:08:17 -0700929 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
930 Math.max(mVisibleFrame.top, mFrame.top),
931 Math.min(mVisibleFrame.right, mFrame.right),
932 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800933
Jorim Jaggi656f6502016-04-11 21:08:17 -0700934 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
935 Math.max(mStableFrame.top, mFrame.top),
936 Math.min(mStableFrame.right, mFrame.right),
937 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700938 }
Adrian Roosfa104232014-06-20 16:10:14 -0700939
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700940 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500941 // Windows that are not fullscreen can be positioned outside of the display frame,
942 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700943 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
944 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
945 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
946 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800947 }
Craig Mautnereda67292013-04-28 13:50:14 -0700948
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100949 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100950 // For the docked divider, we calculate the stable insets like a full-screen window
951 // so it can use it to calculate the snap positions.
952 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
953 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
954 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
955 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800956
957 // The divider doesn't care about insets in any case, so set it to empty so we don't
958 // trigger a relayout when moving it.
959 mContentInsets.setEmpty();
960 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100961 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700962 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700963 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
964 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700965 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
966 && mFrame.right > mTmpRect.right;
967 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
968 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700969 mContentInsets.set(mContentFrame.left - mFrame.left,
970 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700971 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700972 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700973 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700974 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800975
Jorim Jaggi656f6502016-04-11 21:08:17 -0700976 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
977 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700978 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700979 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700980 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700981 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800982
Jorim Jaggi656f6502016-04-11 21:08:17 -0700983 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
984 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700985 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700986 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700987 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700988 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100989 }
Adrian Roosfa104232014-06-20 16:10:14 -0700990
Jorim Jaggi656f6502016-04-11 21:08:17 -0700991 // Offset the actual frame by the amount layout frame is off.
992 mFrame.offset(-layoutXDiff, -layoutYDiff);
993 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700994 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
995 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
996 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
997
Craig Mautnereda67292013-04-28 13:50:14 -0700998 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400999 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001000 // If there is a size compatibility scale being applied to the
1001 // window, we need to apply this to its insets so that they are
1002 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001003 mOverscanInsets.scale(mInvGlobalScale);
1004 mContentInsets.scale(mInvGlobalScale);
1005 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001006 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001007 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001008
1009 // Also the scaled frame that we report to the app needs to be
1010 // adjusted to be in its coordinate space.
1011 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001012 }
1013
Craig Mautnereda67292013-04-28 13:50:14 -07001014 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001015 final DisplayContent displayContent = getDisplayContent();
1016 if (displayContent != null) {
1017 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001018 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001019 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001020 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001021 }
1022
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001023 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001024 "Resolving (mRequestedWidth="
1025 + mRequestedWidth + ", mRequestedheight="
1026 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1027 + "): frame=" + mFrame.toShortString()
1028 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001029 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001030 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001031 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001032 }
1033
Craig Mautnera2c77052012-03-26 12:14:43 -07001034 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001035 public Rect getFrameLw() {
1036 return mFrame;
1037 }
1038
Craig Mautnera2c77052012-03-26 12:14:43 -07001039 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001040 public Point getShownPositionLw() {
1041 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001042 }
1043
Craig Mautnera2c77052012-03-26 12:14:43 -07001044 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001045 public Rect getDisplayFrameLw() {
1046 return mDisplayFrame;
1047 }
1048
Craig Mautnera2c77052012-03-26 12:14:43 -07001049 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001050 public Rect getOverscanFrameLw() {
1051 return mOverscanFrame;
1052 }
1053
1054 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001055 public Rect getContentFrameLw() {
1056 return mContentFrame;
1057 }
1058
Craig Mautnera2c77052012-03-26 12:14:43 -07001059 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001060 public Rect getVisibleFrameLw() {
1061 return mVisibleFrame;
1062 }
1063
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001064 Rect getStableFrameLw() {
1065 return mStableFrame;
1066 }
1067
Craig Mautnera2c77052012-03-26 12:14:43 -07001068 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001069 public boolean getGivenInsetsPendingLw() {
1070 return mGivenInsetsPending;
1071 }
1072
Craig Mautnera2c77052012-03-26 12:14:43 -07001073 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001074 public Rect getGivenContentInsetsLw() {
1075 return mGivenContentInsets;
1076 }
1077
Craig Mautnera2c77052012-03-26 12:14:43 -07001078 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001079 public Rect getGivenVisibleInsetsLw() {
1080 return mGivenVisibleInsets;
1081 }
1082
Craig Mautnera2c77052012-03-26 12:14:43 -07001083 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001084 public WindowManager.LayoutParams getAttrs() {
1085 return mAttrs;
1086 }
1087
Craig Mautner812d2ca2012-09-27 15:35:34 -07001088 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001089 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001090 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001091 }
1092
Craig Mautner19d59bc2012-09-04 11:15:56 -07001093 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001094 public int getSystemUiVisibility() {
1095 return mSystemUiVisibility;
1096 }
1097
Craig Mautner19d59bc2012-09-04 11:15:56 -07001098 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001099 public int getSurfaceLayer() {
1100 return mLayer;
1101 }
1102
Craig Mautner812d2ca2012-09-27 15:35:34 -07001103 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001104 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001105 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001106 }
1107
1108 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001109 public IApplicationToken getAppToken() {
1110 return mAppToken != null ? mAppToken.appToken : null;
1111 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001112
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001113 @Override
1114 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001115 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001116 }
1117
Robert Carr31aa98b2016-07-20 15:29:03 -07001118 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001119 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1120 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1121 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001122 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001123 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001124 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1125 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001126 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001127 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001128 }
1129
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001130 /**
1131 * Adds the window to the resizing list if any of the parameters we use to track the window
1132 * dimensions or insets have changed.
1133 */
1134 void updateResizingWindowIfNeeded() {
1135 final WindowStateAnimator winAnimator = mWinAnimator;
1136 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1137 return;
1138 }
1139
1140 final Task task = getTask();
1141 // In the case of stack bound animations, the window frames will update (unlike other
1142 // animations which just modify various transformation properties). We don't want to
1143 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1144 // the frame may not correspond to the surface size or the onscreen area at various
1145 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001146 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001147 return;
1148 }
1149
1150 setReportResizeHints();
1151 boolean configChanged = isConfigChanged();
1152 if (DEBUG_CONFIGURATION && configChanged) {
1153 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1154 }
1155
1156 final boolean dragResizingChanged = isDragResizeChanged()
1157 && !isDragResizingChangeReported();
1158
1159 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1160 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1161 + " frame=" + mFrame);
1162
1163 // We update mLastFrame always rather than in the conditional with the last inset
1164 // variables, because mFrameSizeChanged only tracks the width and height changing.
1165 mLastFrame.set(mFrame);
1166
1167 if (mContentInsetsChanged
1168 || mVisibleInsetsChanged
1169 || winAnimator.mSurfaceResized
1170 || mOutsetsChanged
1171 || mFrameSizeChanged
1172 || configChanged
1173 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001174 || !isResizedWhileNotDragResizingReported()
1175 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001176 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1177 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1178 + " contentInsetsChanged=" + mContentInsetsChanged
1179 + " " + mContentInsets.toShortString()
1180 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1181 + " " + mVisibleInsets.toShortString()
1182 + " stableInsetsChanged=" + mStableInsetsChanged
1183 + " " + mStableInsets.toShortString()
1184 + " outsetsChanged=" + mOutsetsChanged
1185 + " " + mOutsets.toShortString()
1186 + " surfaceResized=" + winAnimator.mSurfaceResized
1187 + " configChanged=" + configChanged
1188 + " dragResizingChanged=" + dragResizingChanged
1189 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001190 + isResizedWhileNotDragResizingReported()
1191 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001192 }
1193
1194 // If it's a dead window left on screen, and the configuration changed, there is nothing
1195 // we can do about it. Remove the window now.
1196 if (mAppToken != null && mAppDied) {
1197 mAppToken.removeDeadWindows();
1198 return;
1199 }
1200
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001201 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001202 mService.makeWindowFreezingScreenIfNeededLocked(this);
1203
1204 // If the orientation is changing, or we're starting or ending a drag resizing action,
1205 // then we need to hold off on unfreezing the display until this window has been
1206 // redrawn; to do that, we need to go through the process of getting informed by the
1207 // application when it has finished drawing.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001208 if (getOrientationChanging() || dragResizingChanged
1209 || isResizedWhileNotDragResizing()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001210 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1211 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1212 + ", mDrawState=DRAW_PENDING in " + this
1213 + ", surfaceController " + winAnimator.mSurfaceController);
1214 }
1215 winAnimator.mDrawState = DRAW_PENDING;
1216 if (mAppToken != null) {
1217 mAppToken.clearAllDrawn();
1218 }
1219 }
1220 if (!mService.mResizingWindows.contains(this)) {
1221 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1222 mService.mResizingWindows.add(this);
1223 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001224 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001225 if (isDrawnLw()) {
1226 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1227 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001228 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001229 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1230 - mService.mDisplayFreezeTime);
1231 }
1232 }
1233 }
1234
Bryce Lee8c3cf382017-07-06 19:47:10 -07001235 boolean getOrientationChanging() {
1236 // In addition to the local state flag, we must also consider the difference in the last
1237 // reported configuration vs. the current state. If the client code has not been informed of
1238 // the change, logic dependent on having finished processing the orientation, such as
1239 // unfreezing, could be improperly triggered.
1240 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1241 // this is not necessarily what the client has processed yet. Find a
1242 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001243 return (mOrientationChanging || (isVisible()
1244 && getConfiguration().orientation != mLastReportedConfiguration.orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001245 && !mSeamlesslyRotated
1246 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001247 }
1248
1249 void setOrientationChanging(boolean changing) {
1250 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001251 mOrientationChangeTimedOut = false;
1252 }
1253
1254 void orientationChangeTimedOut() {
1255 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001256 }
1257
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001258 DisplayContent getDisplayContent() {
1259 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001260 }
1261
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001262 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001263 final DisplayContent displayContent = getDisplayContent();
1264 return displayContent != null ? displayContent.getDisplayInfo() : null;
1265 }
1266
Jorim Jaggife762342016-10-13 14:33:27 +02001267 @Override
1268 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001269 final DisplayContent displayContent = getDisplayContent();
1270 if (displayContent == null) {
1271 return -1;
1272 }
1273 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001274 }
1275
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001276 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001277 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001278 }
1279
1280 TaskStack getStack() {
1281 Task task = getTask();
1282 if (task != null) {
1283 if (task.mStack != null) {
1284 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001285 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001286 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001287 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1288 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001289 final DisplayContent dc = getDisplayContent();
1290 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001291 }
1292
Skuhnef932e562015-08-20 12:07:30 -07001293 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001294 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001295 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001296 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001297 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001298 final Task task = getTask();
1299 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001300 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001301 mTmpRect.setEmpty();
1302 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001303 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001304 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001305 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001306 } else {
1307 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001308 }
1309 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001310
Chong Zhang9184ec62015-09-24 12:32:21 -07001311 bounds.set(mVisibleFrame);
1312 if (intersectWithStackBounds) {
1313 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001314 }
1315
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001316 if (bounds.isEmpty()) {
1317 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001318 if (intersectWithStackBounds) {
1319 bounds.intersect(mTmpRect);
1320 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001321 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001322 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001323 }
1324
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001325 public long getInputDispatchingTimeoutNanos() {
1326 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001327 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001328 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1329 }
1330
Craig Mautnere8552142012-11-07 13:55:47 -08001331 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001332 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001333 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001334 }
1335
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001336 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1337 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1338 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1339 if (dtdx < -.000001f || dtdx > .000001f) return false;
1340 if (dsdy < -.000001f || dsdy > .000001f) return false;
1341 return true;
1342 }
1343
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001344 void prelayout() {
1345 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001346 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1347 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001348 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001349 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001350 }
1351 }
1352
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001353 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001354 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001355 // If we're animating with a saved surface, we're already visible.
1356 // Return true so that the alpha doesn't get cleared.
1357 if (!mAppFreezing && isDrawnLw()
1358 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1359 || (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 *
1446 * @param visibleOnly Whether we should consider only the windows that's currently
1447 * visible in layout. If true, windows that has not relayout to VISIBLE
1448 * would always return false.
1449 *
1450 * @return true if the window should be considered while evaluating allDrawn flags.
1451 */
1452 boolean mightAffectAllDrawn(boolean visibleOnly) {
Wale Ogunwale89973222017-04-23 18:39:45 -07001453 final boolean isViewVisible = (mAppToken == null || !mAppToken.isClientHidden())
Chong Zhange292eb32016-05-21 09:23:55 -07001454 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Jorim Jaggib0d27342016-11-01 16:10:42 -07001455 return (isOnScreen() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001456 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1457 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001458 && !mAnimatingExit && !mDestroying;
1459 }
1460
1461 /**
1462 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1463 * it must be drawn before allDrawn can become true.
1464 */
1465 boolean isInteresting() {
1466 return mAppToken != null && !mAppDied
1467 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1468 }
1469
1470 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001471 * Like isOnScreen(), but we don't return true if the window is part
1472 * of a transition that has not yet been started.
1473 */
1474 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001475 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001476 return false;
1477 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001478 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001479 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001480 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001481 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001482 }
1483
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001484 // TODO: Another visibility method that was added late in the release to minimize risk.
1485 @Override
1486 public boolean canAffectSystemUiFlags() {
Jorim Jaggi07a7b962017-08-03 16:59:44 +02001487 final boolean shown = mWinAnimator.getShown() && mWinAnimator.mShownAlpha > 0f;
Jorim Jaggic0c93242017-08-04 16:05:02 +02001488
1489 // We only consider the app to be exiting when the animation has started. After the app
1490 // transition is executed the windows are marked exiting before the new windows have been
1491 // shown. Thus, wait considering a window to be exiting after the animation has actually
1492 // started.
1493 final boolean appAnimationStarting = mAppToken != null
1494 && mAppToken.mAppAnimator.isAnimationStarting();
1495 final boolean exitingSelf = mAnimatingExit && (!mWinAnimator.isAnimationStarting()
1496 && !appAnimationStarting);
1497 final boolean appExiting = mAppToken != null && mAppToken.hidden && !appAnimationStarting;
1498
1499 final boolean exiting = exitingSelf || mDestroying || appExiting;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001500 final boolean translucent = mAttrs.alpha == 0.0f;
1501 return shown && !exiting && !translucent;
1502 }
1503
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001504 /**
1505 * Like isOnScreen, but returns false if the surface hasn't yet
1506 * been drawn.
1507 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001508 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001509 public boolean isDisplayedLw() {
1510 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001511 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001512 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001513 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001514 || mWinAnimator.mAnimating
1515 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001516 }
1517
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001518 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001519 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001520 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001521 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001522 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001523 return mWinAnimator.mAnimation != null
1524 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001525 }
1526
Craig Mautner812d2ca2012-09-27 15:35:34 -07001527 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001528 public boolean isGoneForLayoutLw() {
1529 final AppWindowToken atoken = mAppToken;
1530 return mViewVisibility == View.GONE
1531 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001532 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001533 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001534 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001535 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001536 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001537 }
1538
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001539 /**
1540 * Returns true if the window has a surface that it has drawn a
1541 * complete UI in to.
1542 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001543 public boolean isDrawFinishedLw() {
1544 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001545 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1546 || mWinAnimator.mDrawState == READY_TO_SHOW
1547 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001548 }
1549
1550 /**
1551 * Returns true if the window has a surface that it has drawn a
1552 * complete UI in to.
1553 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001554 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001555 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001556 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001557 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001558 }
1559
1560 /**
1561 * Return true if the window is opaque and fully drawn. This indicates
1562 * it may obscure windows behind it.
1563 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001564 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001565 // When there is keyguard, wallpaper could be placed over the secure app
1566 // window but invisible. We need to check wallpaper visibility explicitly
1567 // to determine if it's occluding apps.
1568 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1569 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001570 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001571 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001572 }
1573
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001574 @Override
1575 void onMovedByResize() {
1576 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001577 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001578 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001579 }
1580
1581 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1582 boolean changed = false;
1583
1584 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001585 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001586 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1587 }
1588
1589 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1590 // Starting window that's exiting will be removed when the animation finishes.
1591 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1592 // to actually remove it.
1593 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1594 mAnimatingExit = true;
1595 mRemoveOnExit = true;
1596 mWindowRemovalAllowed = true;
1597 }
1598 return changed;
1599 }
1600
Robert Carrd5c7dd62017-03-08 10:39:30 -08001601 // Next up we will notify the client that it's visibility has changed.
1602 // We need to prevent it from destroying child surfaces until
1603 // the animation has finished.
1604 if (!visible && isVisibleNow()) {
1605 mWinAnimator.detachChildren();
1606 }
1607
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001608 if (visible != isVisibleNow()) {
1609 if (!runningAppAnimation) {
1610 final AccessibilityController accessibilityController =
1611 mService.mAccessibilityController;
1612 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1613 mWinAnimator.applyAnimationLocked(winTransit, visible);
1614 //TODO (multidisplay): Magnification is supported only for the default
1615 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1616 accessibilityController.onWindowTransitionLocked(this, winTransit);
1617 }
1618 }
1619 changed = true;
1620 setDisplayLayoutNeeded();
1621 }
1622
1623 return changed;
1624 }
1625
1626 boolean onSetAppExiting() {
1627 final DisplayContent displayContent = getDisplayContent();
1628 boolean changed = false;
1629
1630 if (isVisibleNow()) {
1631 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1632 //TODO (multidisplay): Magnification is supported only for the default
1633 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1634 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1635 }
1636 changed = true;
1637 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001638 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001639 }
1640 }
1641
1642 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001643 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001644 changed |= c.onSetAppExiting();
1645 }
1646
1647 return changed;
1648 }
1649
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001650 @Override
1651 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001652 // Some windows won't go through the resizing process, if they don't have a surface, so
1653 // destroy all saved surfaces here.
1654 destroySavedSurface();
1655
1656 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1657 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001658 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001659 resizingWindows.add(this);
1660
1661 // If we are not drag resizing, force recreating of a new surface so updating
1662 // the content and positioning that surface will be in sync.
1663 //
1664 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1665 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1666 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1667 // their frame to update crop, etc...
1668 //
1669 // Anyway we don't need to synchronize position and content updates for these
1670 // windows since they aren't at the base layer and could be moved around anyway.
1671 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001672 !mWinAnimator.isForceScaled() && !isGoneForLayoutLw() &&
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001673 !getTask().inPinnedWorkspace()) {
1674 setResizedWhileNotDragResizing(true);
1675 }
1676 }
1677 if (isGoneForLayoutLw()) {
1678 mResizedWhileGone = true;
1679 }
1680
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001681 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001682 }
1683
1684 void onUnfreezeBounds() {
1685 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001686 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001687 c.onUnfreezeBounds();
1688 }
1689
1690 if (!mHasSurface) {
1691 return;
1692 }
1693
1694 mLayoutNeeded = true;
1695 setDisplayLayoutNeeded();
1696 if (!mService.mResizingWindows.contains(this)) {
1697 mService.mResizingWindows.add(this);
1698 }
1699 }
1700
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001701 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001702 * If the window has moved due to its containing content frame changing, then notify the
1703 * listeners and optionally animate it. Simply checking a change of position is not enough,
1704 * because being move due to dock divider is not a trigger for animation.
1705 */
1706 void handleWindowMovedIfNeeded() {
1707 if (!hasMoved()) {
1708 return;
1709 }
1710
1711 // Frame has moved, containing content frame has also moved, and we're not currently
1712 // animating... let's do something.
1713 final int left = mFrame.left;
1714 final int top = mFrame.top;
1715 final Task task = getTask();
1716 final boolean adjustedForMinimizedDockOrIme = task != null
1717 && (task.mStack.isAdjustedForMinimizedDockedStack()
1718 || task.mStack.isAdjustedForIme());
David Stevensf62360c2017-03-16 19:00:20 -07001719 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001720 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1721 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1722 && (task == null || getTask().mStack.hasMovementAnimations())
1723 && !mWinAnimator.mLastHidden) {
1724 mWinAnimator.setMoveAnimation(left, top);
1725 }
1726
1727 //TODO (multidisplay): Accessibility supported only for the default display.
1728 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001729 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001730 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1731 }
1732
1733 try {
1734 mClient.moved(left, top);
1735 } catch (RemoteException e) {
1736 }
1737 mMovedByResize = false;
1738 }
1739
1740 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001741 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001742 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1743 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001744 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001745 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001746 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001747 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001748 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001749 }
1750
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001751 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001752 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001753 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001754 return false;
1755 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001756 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001757 }
1758
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001759 boolean fillsDisplay() {
1760 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001761 return mFrame.left <= 0 && mFrame.top <= 0
1762 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001763 }
1764
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001765 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001766 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001767 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001768 }
1769
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001770 void onWindowReplacementTimeout() {
1771 if (mWillReplaceWindow) {
1772 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001773 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001774 // delays removal on certain conditions, which will leave the stale window in the
1775 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1776 //
1777 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001778 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001779 } else {
1780 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001781 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001782 c.onWindowReplacementTimeout();
1783 }
1784 }
1785 }
1786
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001787 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001788 void forceWindowsScaleableInTransaction(boolean force) {
1789 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1790 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1791 }
1792
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001793 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001794 }
1795
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001796 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001797 void removeImmediately() {
1798 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001799
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001800 if (mRemoved) {
1801 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001802 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1803 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001804 return;
1805 }
1806
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001807 mRemoved = true;
1808
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001809 mWillReplaceWindow = false;
1810 if (mReplacementWindow != null) {
1811 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1812 }
1813
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001814 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001815 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001816 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001817 }
1818
1819 final int type = mAttrs.type;
1820 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001821 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001822 }
1823 mPolicy.removeWindowLw(this);
1824
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001825 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001826
Craig Mautner96868332012-12-04 14:29:11 -08001827 mWinAnimator.destroyDeferredSurfaceLocked();
1828 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001829 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001830 try {
1831 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1832 } catch (RuntimeException e) {
1833 // Ignore if it has already been removed (usually because
1834 // we are doing this as part of processing a death note.)
1835 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001836
1837 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001838 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001839
Wale Ogunwale571771c2016-08-26 13:18:50 -07001840 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001841 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001842 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001843 removeIfPossible(false /*keepVisibleDeadWindow*/);
1844 }
1845
Wale Ogunwale571771c2016-08-26 13:18:50 -07001846 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001847 mWindowRemovalAllowed = true;
1848 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1849 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1850
1851 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1852 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1853 "Starting window removed " + this);
1854
1855 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1856 Slog.v(TAG_WM, "Remove " + this + " client="
1857 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1858 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1859 + Debug.getCallers(5));
1860
1861 final long origId = Binder.clearCallingIdentity();
1862
1863 disposeInputChannel();
1864
1865 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1866 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1867 + " mAnimatingExit=" + mAnimatingExit
1868 + " mRemoveOnExit=" + mRemoveOnExit
1869 + " mHasSurface=" + mHasSurface
1870 + " surfaceShowing=" + mWinAnimator.getShown()
1871 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1872 + " app-animation="
1873 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1874 + " mWillReplaceWindow=" + mWillReplaceWindow
1875 + " inPendingTransaction="
1876 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1877 + " mDisplayFrozen=" + mService.mDisplayFrozen
1878 + " callers=" + Debug.getCallers(6));
1879
1880 // Visibility of the removed window. Will be used later to update orientation later on.
1881 boolean wasVisible = false;
1882
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001883 final int displayId = getDisplayId();
1884
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001885 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1886 // window until the animation is done. If the display is frozen, just remove immediately,
1887 // since the animation wouldn't be seen.
David Stevensf62360c2017-03-16 19:00:20 -07001888 if (mHasSurface && mToken.okToAnimate()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001889 if (mWillReplaceWindow) {
1890 // This window is going to be replaced. We need to keep it around until the new one
1891 // gets added, then we will get rid of this one.
1892 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1893 "Preserving " + this + " until the new one is " + "added");
1894 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1895 // been removed. We probably need another flag to indicate that window removal
1896 // should be deffered vs. overloading the flag that says we are playing an exit
1897 // animation.
1898 mAnimatingExit = true;
1899 mReplacingRemoveRequested = true;
1900 Binder.restoreCallingIdentity(origId);
1901 return;
1902 }
1903
1904 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1905 // We started enter animation early with a saved surface, now the app asks to remove
1906 // this window. If we remove it now and the app is not yet drawn, we'll show a
1907 // flicker. Delay the removal now until it's really drawn.
1908 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1909 "removeWindowLocked: delay removal of " + this + " due to early animation");
1910 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1911 // immediately after the enter animation is done. If the app is not yet drawn then
1912 // it will show up as a flicker.
1913 setupWindowForRemoveOnExit();
1914 Binder.restoreCallingIdentity(origId);
1915 return;
1916 }
1917 // If we are not currently running the exit animation, we need to see about starting one
1918 wasVisible = isWinVisibleLw();
1919
1920 if (keepVisibleDeadWindow) {
1921 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1922 "Not removing " + this + " because app died while it's visible");
1923
1924 mAppDied = true;
1925 setDisplayLayoutNeeded();
1926 mService.mWindowPlacerLocked.performSurfacePlacement();
1927
1928 // Set up a replacement input channel since the app is now dead.
1929 // We need to catch tapping on the dead window to restart the app.
1930 openInputChannel(null);
1931 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1932
1933 Binder.restoreCallingIdentity(origId);
1934 return;
1935 }
1936
1937 if (wasVisible) {
1938 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1939
1940 // Try starting an animation.
1941 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1942 mAnimatingExit = true;
1943 }
1944 //TODO (multidisplay): Magnification is supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001945 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001946 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1947 }
1948 }
1949 final boolean isAnimating =
1950 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1951 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001952 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001953 // We delay the removal of a window if it has a showing surface that can be used to run
1954 // exit animation and it is marked as exiting.
1955 // Also, If isn't the an animating starting window that is the last window in the app.
1956 // We allow the removal of the non-animating starting window now as there is no
1957 // additional window or animation that will trigger its removal.
1958 if (mWinAnimator.getShown() && mAnimatingExit
1959 && (!lastWindowIsStartingWindow || isAnimating)) {
1960 // The exit animation is running or should run... wait for it!
1961 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1962 "Not removing " + this + " due to exit animation ");
1963 setupWindowForRemoveOnExit();
1964 if (mAppToken != null) {
1965 mAppToken.updateReportedVisibilityLocked();
1966 }
1967 Binder.restoreCallingIdentity(origId);
1968 return;
1969 }
1970 }
1971
Wale Ogunwale571771c2016-08-26 13:18:50 -07001972 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001973 // Removing a visible window will effect the computed orientation
1974 // So just update orientation if needed.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001975 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1976 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001977 }
1978 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1979 Binder.restoreCallingIdentity(origId);
1980 }
1981
1982 private void setupWindowForRemoveOnExit() {
1983 mRemoveOnExit = true;
1984 setDisplayLayoutNeeded();
1985 // Request a focus update as this window's input channel is already gone. Otherwise
1986 // we could have no focused window in input manager.
1987 final boolean focusChanged = mService.updateFocusedWindowLocked(
1988 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1989 mService.mWindowPlacerLocked.performSurfacePlacement();
1990 if (focusChanged) {
1991 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1992 }
1993 }
1994
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001995 void setHasSurface(boolean hasSurface) {
1996 mHasSurface = hasSurface;
1997 }
1998
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001999 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08002000 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07002001 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
2002 if (appToken != null) {
Robert Carrdee1b3f2017-02-27 11:33:33 -08002003 return appToken.getAnimLayerAdjustment();
Wale Ogunwale455fac52016-07-21 07:24:49 -07002004 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002005 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07002006
Robert Carrdee1b3f2017-02-27 11:33:33 -08002007 return mToken.getAnimLayerAdjustment();
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002008 }
2009
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002010 int getSpecialWindowAnimLayerAdjustment() {
2011 int specialAdjustment = 0;
2012 if (mIsImWindow) {
2013 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
2014 } else if (mIsWallpaper) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07002015 specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment();
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002016 }
2017
2018 return mLayer + specialAdjustment;
2019 }
2020
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002021 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002022 if (mIsImWindow) {
2023 // IME windows can't be IME targets. IME targets are required to be below the IME
2024 // windows and that wouldn't be possible if the IME window is its own target...silly.
2025 return false;
2026 }
2027
Winson Chung3d0a74a2017-07-12 12:37:19 -07002028 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002029 if (!windowsAreFocusable) {
2030 // This window can't be an IME target if the app's windows should not be focusable.
2031 return false;
2032 }
2033
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002034 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002035 final int type = mAttrs.type;
2036
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002037 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2038 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002039 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2040 && type != TYPE_APPLICATION_STARTING) {
2041 return false;
2042 }
2043
2044 if (DEBUG_INPUT_METHOD) {
2045 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2046 if (!isVisibleOrAdding()) {
2047 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2048 + " relayoutCalled=" + mRelayoutCalled
2049 + " viewVis=" + mViewVisibility
2050 + " policyVis=" + mPolicyVisibility
2051 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2052 + " parentHidden=" + isParentWindowHidden()
2053 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2054 if (mAppToken != null) {
2055 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2056 }
2057 }
2058 }
2059 return isVisibleOrAdding();
2060 }
2061
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002062 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002063 final DisplayContent dc = getDisplayContent();
2064 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002065 return;
2066 }
Jorim Jaggi1f833082017-08-04 18:06:56 +02002067
2068 // If layout is currently deferred, we want to hold of with updating the layers.
2069 if (mService.mWindowPlacerLocked.isLayoutDeferred()) {
2070 return;
2071 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002072 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002073 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002074 // Force an animation pass just to update the mDimLayer layer.
2075 mService.scheduleAnimationLocked();
2076 }
2077 }
2078
Chong Zhangacf11402015-11-04 16:23:10 -08002079 private final class DeadWindowEventReceiver extends InputEventReceiver {
2080 DeadWindowEventReceiver(InputChannel inputChannel) {
2081 super(inputChannel, mService.mH.getLooper());
2082 }
2083 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002084 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002085 finishInputEvent(event, true);
2086 }
2087 }
2088 /**
2089 * Dummy event receiver for windows that died visible.
2090 */
2091 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2092
Chong Zhang112eb8c2015-11-02 11:17:00 -08002093 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002094 if (mInputChannel != null) {
2095 throw new IllegalStateException("Window already has an input channel.");
2096 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002097 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002098 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2099 mInputChannel = inputChannels[0];
2100 mClientChannel = inputChannels[1];
2101 mInputWindowHandle.inputChannel = inputChannels[0];
2102 if (outInputChannel != null) {
2103 mClientChannel.transferTo(outInputChannel);
2104 mClientChannel.dispose();
2105 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002106 } else {
2107 // If the window died visible, we setup a dummy input channel, so that taps
2108 // can still detected by input monitor channel, and we can relaunch the app.
2109 // Create dummy event receiver that simply reports all events as handled.
2110 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002111 }
2112 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002113 }
2114
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002115 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002116 if (mDeadWindowEventReceiver != null) {
2117 mDeadWindowEventReceiver.dispose();
2118 mDeadWindowEventReceiver = null;
2119 }
2120
2121 // unregister server channel first otherwise it complains about broken channel
2122 if (mInputChannel != null) {
2123 mService.mInputManager.unregisterInputChannel(mInputChannel);
2124 mInputChannel.dispose();
2125 mInputChannel = null;
2126 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002127 if (mClientChannel != null) {
2128 mClientChannel.dispose();
2129 mClientChannel = null;
2130 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002131 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002132 }
2133
Chong Zhang112eb8c2015-11-02 11:17:00 -08002134 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002135 // When the app is terminated (eg. from Recents), the task might have already been
2136 // removed with the window pending removal. Don't apply dim in such cases, as there
2137 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2138 final AppWindowToken token = mAppToken;
2139 if (token != null && token.removed) {
2140 return;
2141 }
2142
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002143 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002144 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002145 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002146 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002147 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002148 && dc != null && !mAnimatingExit && isVisible()) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002149 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002150 }
2151 }
2152
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002153 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002154 Task task = getTask();
2155 if (task != null) {
2156 return task;
2157 }
2158 return getStack();
2159 }
2160
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002161 /** Returns true if the replacement window was removed. */
2162 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2163 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2164 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2165 removeReplacedWindow();
2166 return true;
2167 }
2168
2169 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002170 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002171 if (c.removeReplacedWindowIfNeeded(replacement)) {
2172 return true;
2173 }
2174 }
2175 return false;
2176 }
2177
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002178 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002179 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2180 if (isDimming()) {
2181 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002182 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002183 mWillReplaceWindow = false;
2184 mAnimateReplacingWindow = false;
2185 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002186 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002187 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002188 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002189 }
2190 }
2191
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002192 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2193 boolean replacementSet = false;
2194
2195 if (mWillReplaceWindow && mReplacementWindow == null
2196 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2197
2198 mReplacementWindow = replacementCandidate;
2199 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2200 replacementSet = true;
2201 }
2202
2203 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002204 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002205 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2206 }
2207
2208 return replacementSet;
2209 }
2210
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002211 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002212 final DisplayContent dc = getDisplayContent();
2213 if (dc != null) {
2214 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002215 }
2216 }
2217
Robert Carrfed10072016-05-26 11:48:49 -07002218 // TODO: Strange usage of word workspace here and above.
2219 boolean inPinnedWorkspace() {
2220 final Task task = getTask();
2221 return task != null && task.inPinnedWorkspace();
2222 }
2223
Chong Zhang5117e272016-05-03 12:47:34 -07002224 void applyAdjustForImeIfNeeded() {
2225 final Task task = getTask();
2226 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2227 task.mStack.applyAdjustForImeIfNeeded(task);
2228 }
2229 }
2230
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002231 @Override
2232 void switchUser() {
2233 super.switchUser();
2234 if (isHiddenFromUserLocked()) {
2235 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2236 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2237 hideLw(false);
2238 }
2239 }
2240
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002241 int getTouchableRegion(Region region, int flags) {
2242 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002243 if (modal && mAppToken != null) {
2244 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002245 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002246 // If this is a modal window we need to dismiss it if it's not full screen and the
2247 // touch happens outside of the frame that displays the content. This means we
2248 // need to intercept touches outside of that window. The dim layer user
2249 // associated with the window (task or stack) will give us the good bounds, as
2250 // they would be used to display the dim layer.
2251 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2252 if (dimLayerUser != null) {
2253 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002254 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002255 getVisibleBounds(mTmpRect);
2256 }
2257 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002258 // For freeform windows we the touch region to include the whole surface for the
2259 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002260 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2261 final int delta = WindowManagerService.dipToPixel(
2262 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2263 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002264 }
2265 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002266 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002267 } else {
2268 // Not modal or full screen modal
2269 getTouchableRegion(region);
2270 }
2271 return flags;
2272 }
2273
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002274 void checkPolicyVisibilityChange() {
2275 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2276 if (DEBUG_VISIBILITY) {
2277 Slog.v(TAG, "Policy visibility changing after anim in " +
2278 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2279 }
2280 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002281 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002282 if (!mPolicyVisibility) {
2283 if (mService.mCurrentFocus == this) {
2284 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2285 "setAnimationLocked: setting mFocusMayChange true");
2286 mService.mFocusMayChange = true;
2287 }
2288 // Window is no longer visible -- make sure if we were waiting
2289 // for it to be displayed before enabling the display, that
2290 // we allow the display to be enabled now.
2291 mService.enableScreenIfNeededLocked();
2292 }
2293 }
2294 }
2295
2296 void setRequestedSize(int requestedWidth, int requestedHeight) {
2297 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2298 mLayoutNeeded = true;
2299 mRequestedWidth = requestedWidth;
2300 mRequestedHeight = requestedHeight;
2301 }
2302 }
2303
Bryce Leef858b572017-06-29 14:03:33 -07002304 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002305 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002306 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2307 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2308 mTurnOnScreen = true;
2309 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002310
2311 // If we were already visible, skip rest of preparation.
2312 if (wasVisible) {
2313 if (DEBUG_VISIBILITY) Slog.v(TAG,
2314 "Already visible and does not turn on screen, skip preparing: " + this);
2315 return;
2316 }
2317
2318 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2319 == SOFT_INPUT_ADJUST_RESIZE) {
2320 mLayoutNeeded = true;
2321 }
2322
David Stevensf62360c2017-03-16 19:00:20 -07002323 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002324 mWinAnimator.applyEnterAnimationLocked();
2325 }
Bryce Leef858b572017-06-29 14:03:33 -07002326 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002327
Bryce Leef858b572017-06-29 14:03:33 -07002328 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2329 final Configuration globalConfig = mService.mRoot.getConfiguration();
2330 final Configuration overrideConfig = getMergedOverrideConfiguration();
2331 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2332 }
2333
2334 void setReportedConfiguration(MergedConfiguration config) {
2335 mLastReportedConfiguration.setTo(config.getMergedConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002336 }
2337
2338 void adjustStartingWindowFlags() {
2339 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2340 && mAppToken.startingWindow != null) {
2341 // Special handling of starting window over the base
2342 // window of the app: propagate lock screen flags to it,
2343 // to provide the correct semantics while starting.
2344 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2345 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2346 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2347 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2348 }
2349 }
2350
2351 void setWindowScale(int requestedWidth, int requestedHeight) {
2352 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2353
2354 if (scaledWindow) {
2355 // requested{Width|Height} Surface's physical size
2356 // attrs.{width|height} Size on screen
2357 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2358 mHScale = (mAttrs.width != requestedWidth) ?
2359 (mAttrs.width / (float)requestedWidth) : 1.0f;
2360 mVScale = (mAttrs.height != requestedHeight) ?
2361 (mAttrs.height / (float)requestedHeight) : 1.0f;
2362 } else {
2363 mHScale = mVScale = 1;
2364 }
2365 }
2366
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002367 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002368 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002369 public void binderDied() {
2370 try {
2371 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002372 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002373 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002374 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002375 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002376 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2377 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2378 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002379 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002380 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2381 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002382 // just in case they have the divider at an unstable position. Better
2383 // also reset drag resizing state, because the owner can't do it
2384 // anymore.
Wale Ogunwale1666e312016-12-16 11:27:18 -08002385 final TaskStack stack = dc.getDockedStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002386 if (stack != null) {
2387 stack.resetDockedStackToMiddle();
2388 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002389 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002390 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002391 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002392 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002393 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002394 }
2395 }
2396 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002397 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002398 }
2399 }
2400 }
2401
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002402 /**
2403 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2404 * because we want to preserve its location on screen to be re-activated later when the user
2405 * interacts with it.
2406 */
2407 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002408 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002409 // Not a visible app window or the app isn't dead.
2410 return false;
2411 }
2412
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002413 if (mAttrs.token != mClient.asBinder()) {
2414 // The window was add by a client using another client's app token. We don't want to
2415 // keep the dead window around for this case since this is meant for 'real' apps.
2416 return false;
2417 }
2418
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002419 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2420 // We don't keep starting windows since they were added by the window manager before
2421 // the app even launched.
2422 return false;
2423 }
2424
2425 final TaskStack stack = getStack();
2426 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2427 }
2428
Wale Ogunwaled045c822015-12-02 09:14:28 -08002429 /** @return true if this window desires key events. */
2430 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002431 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002432 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002433 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002434 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002435 && !canReceiveTouchInput();
2436 }
2437
2438 /** @return true if this window desires touch events. */
2439 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002440 return mAppToken != null && mAppToken.getTask() != null
2441 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002442 }
2443
Craig Mautner749a7bb2012-04-02 13:49:53 -07002444 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002445 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002446 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002447 }
2448
Craig Mautner749a7bb2012-04-02 13:49:53 -07002449 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002450 public boolean showLw(boolean doAnimation) {
2451 return showLw(doAnimation, true);
2452 }
2453
2454 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002455 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002456 return false;
2457 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002458 if (!mAppOpVisibility) {
2459 // Being hidden due to app op request.
2460 return false;
2461 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002462 if (mPermanentlyHidden) {
2463 // Permanently hidden until the app exists as apps aren't prepared
2464 // to handle their windows being removed from under them.
2465 return false;
2466 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002467 if (mForceHideNonSystemOverlayWindow) {
2468 // This is an alert window that is currently force hidden.
2469 return false;
2470 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002471 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002472 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002473 return false;
2474 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002475 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002476 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002477 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002478 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
David Stevensf62360c2017-03-16 19:00:20 -07002479 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002480 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002481 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002482 // Check for the case where we are currently visible and
2483 // not animating; we do not want to do animation at such a
2484 // point to become visible when we already are.
2485 doAnimation = false;
2486 }
2487 }
2488 mPolicyVisibility = true;
2489 mPolicyVisibilityAfterAnim = true;
2490 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002491 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002492 }
2493 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002494 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002495 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002496 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2497 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2498 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002499 return true;
2500 }
2501
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002502 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002503 public boolean hideLw(boolean doAnimation) {
2504 return hideLw(doAnimation, true);
2505 }
2506
2507 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2508 if (doAnimation) {
David Stevensf62360c2017-03-16 19:00:20 -07002509 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002510 doAnimation = false;
2511 }
2512 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002513 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002514 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002515 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002516 return false;
2517 }
2518 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002519 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002520 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002521 doAnimation = false;
2522 }
2523 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002524 mPolicyVisibilityAfterAnim = false;
2525 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002526 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002527 mPolicyVisibility = false;
2528 // Window is no longer visible -- make sure if we were waiting
2529 // for it to be displayed before enabling the display, that
2530 // we allow the display to be enabled now.
2531 mService.enableScreenIfNeededLocked();
2532 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002533 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002534 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002535 mService.mFocusMayChange = true;
2536 }
2537 }
2538 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002539 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002540 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002541 if (mService.mCurrentFocus == this) {
2542 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2543 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002544 return true;
2545 }
2546
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002547 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2548 if (mOwnerCanAddInternalSystemWindow
2549 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2550 return;
2551 }
2552 if (mForceHideNonSystemOverlayWindow == forceHide) {
2553 return;
2554 }
2555 mForceHideNonSystemOverlayWindow = forceHide;
2556 if (forceHide) {
2557 hideLw(true /* doAnimation */, true /* requestAnim */);
2558 } else {
2559 showLw(true /* doAnimation */, true /* requestAnim */);
2560 }
2561 }
2562
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002563 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002564 if (mAppOpVisibility != state) {
2565 mAppOpVisibility = state;
2566 if (state) {
2567 // If the policy visibility had last been to hide, then this
2568 // will incorrectly show at this point since we lost that
2569 // information. Not a big deal -- for the windows that have app
2570 // ops modifies they should only be hidden by policy due to the
2571 // lock screen, and the user won't be changing this if locked.
2572 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002573 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002574 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002575 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002576 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002577 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002578 }
2579
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002580 public void hidePermanentlyLw() {
2581 if (!mPermanentlyHidden) {
2582 mPermanentlyHidden = true;
2583 hideLw(true, true);
2584 }
2585 }
2586
Jeff Brownc2932a12014-11-20 18:04:05 -08002587 public void pokeDrawLockLw(long timeout) {
2588 if (isVisibleOrAdding()) {
2589 if (mDrawLock == null) {
2590 // We want the tag name to be somewhat stable so that it is easier to correlate
2591 // in wake lock statistics. So in particular, we don't want to include the
2592 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002593 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002594 mDrawLock = mService.mPowerManager.newWakeLock(
2595 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2596 mDrawLock.setReferenceCounted(false);
2597 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2598 }
2599 // Each call to acquire resets the timeout.
2600 if (DEBUG_POWER) {
2601 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2602 + mAttrs.packageName);
2603 }
2604 mDrawLock.acquire(timeout);
2605 } else if (DEBUG_POWER) {
2606 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2607 + "owned by " + mAttrs.packageName);
2608 }
2609 }
2610
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002611 @Override
2612 public boolean isAlive() {
2613 return mClient.asBinder().isBinderAlive();
2614 }
2615
Craig Mautnera987d432012-10-11 14:07:58 -07002616 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002617 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002618 }
2619
Chong Zhangbef461f2015-10-27 11:38:24 -07002620 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002621 return mAnimatingWithSavedSurface;
2622 }
2623
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002624 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002625 boolean isAnimating() {
2626 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2627 return true;
2628 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002629 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002630 }
2631
Chong Zhang8e4bda92016-05-04 15:08:18 -07002632 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002633 if (mAnimatingWithSavedSurface
2634 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2635 return true;
2636 }
2637 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002638 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002639 if (c.isAnimatingInvisibleWithSavedSurface()) {
2640 return true;
2641 }
2642 }
2643 return false;
2644 }
2645
2646 void stopUsingSavedSurface() {
2647 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002648 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002649 c.stopUsingSavedSurface();
2650 }
2651
2652 if (!isAnimatingInvisibleWithSavedSurface()) {
2653 return;
2654 }
2655
2656 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2657 clearAnimatingWithSavedSurface();
2658 mDestroying = true;
2659 mWinAnimator.hide("stopUsingSavedSurface");
Wale Ogunwale0303c572016-10-20 10:16:29 -07002660 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002661 }
2662
2663 void markSavedSurfaceExiting() {
2664 if (isAnimatingInvisibleWithSavedSurface()) {
2665 mAnimatingExit = true;
2666 mWinAnimator.mAnimating = true;
2667 }
2668 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002669 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002670 c.markSavedSurfaceExiting();
2671 }
2672 }
2673
2674 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2675 animators.add(mWinAnimator);
2676
2677 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002678 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002679 c.addWinAnimatorToList(animators);
2680 }
2681 }
2682
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002683 void sendAppVisibilityToClients() {
2684 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002685
Wale Ogunwale89973222017-04-23 18:39:45 -07002686 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002687 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2688 // Don't hide the starting window.
2689 return;
2690 }
2691
Wale Ogunwale89973222017-04-23 18:39:45 -07002692 if (clientHidden) {
2693 // Once we are notifying the client that it's visibility has changed, we need to prevent
2694 // it from destroying child surfaces until the animation has finished. We do this by
2695 // detaching any surface control the client added from the client.
2696 for (int i = mChildren.size() - 1; i >= 0; --i) {
2697 final WindowState c = mChildren.get(i);
2698 c.mWinAnimator.detachChildren();
2699 }
2700
2701 mWinAnimator.detachChildren();
2702 }
2703
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002704 try {
2705 if (DEBUG_VISIBILITY) Slog.v(TAG,
2706 "Setting visibility of " + this + ": " + (!clientHidden));
2707 mClient.dispatchAppVisibility(!clientHidden);
2708 } catch (RemoteException e) {
2709 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002710 }
2711
Chong Zhang92147042016-05-09 12:47:11 -07002712 public void setVisibleBeforeClientHidden() {
2713 mWasVisibleBeforeClientHidden |=
2714 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002715
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002716 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002717 }
2718
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002719 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002720 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002721 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002722 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002723 c.clearWasVisibleBeforeClientHidden();
2724 }
Chong Zhang92147042016-05-09 12:47:11 -07002725 }
2726
2727 public boolean wasVisibleBeforeClientHidden() {
2728 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002729 }
2730
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002731 void onStartFreezingScreen() {
2732 mAppFreezing = true;
2733 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002734 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002735 c.onStartFreezingScreen();
2736 }
2737 }
2738
2739 boolean onStopFreezingScreen() {
2740 boolean unfrozeWindows = false;
2741 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002742 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002743 unfrozeWindows |= c.onStopFreezingScreen();
2744 }
2745
2746 if (!mAppFreezing) {
2747 return unfrozeWindows;
2748 }
2749
Wale Ogunwale953171d2016-09-30 09:17:30 -07002750 mAppFreezing = false;
2751
Bryce Lee8c3cf382017-07-06 19:47:10 -07002752 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002753 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2754 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002755 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002756 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002757 }
2758 mLastFreezeDuration = 0;
2759 setDisplayLayoutNeeded();
2760 return true;
2761 }
2762
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002763 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002764 if (mWinAnimator.mSurfaceController == null) {
2765 // Don't bother if the surface controller is gone for any reason.
2766 return false;
2767 }
2768
Chong Zhang92147042016-05-09 12:47:11 -07002769 if (!mWasVisibleBeforeClientHidden) {
2770 return false;
2771 }
2772
Wale Ogunwale945d1972016-03-23 13:16:41 -07002773 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2774 // We don't save secure surfaces since their content shouldn't be shown while the app
2775 // isn't on screen and content might leak through during the transition animation with
2776 // saved surface.
2777 return false;
2778 }
2779
Jorim Jaggi02886a82016-12-06 09:10:06 -08002780 if (isLowRamDeviceStatic()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002781 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002782 return false;
2783 }
2784
Jorim Jaggiab7ad382016-10-26 18:22:04 -07002785 final Task task = getTask();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002786 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2787 if (taskTop != null && taskTop != mAppToken) {
2788 // Don't save if the window is not the topmost window.
2789 return false;
2790 }
2791
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002792 if (mResizedWhileGone) {
2793 // Somebody resized our window while we were gone for layout, which means that the
2794 // client got an old size, so we have an outdated surface here.
2795 return false;
2796 }
2797
Robert Carr7098dbd2016-02-01 12:31:01 -08002798 if (DEBUG_DISABLE_SAVING_SURFACES) {
2799 return false;
2800 }
2801
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002802 return mAppToken.shouldSaveSurface();
2803 }
2804
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002805 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2806 boolean destroyedSomething = false;
2807 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002808 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002809 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2810 }
2811
Robert Carrdb2f6e62017-03-01 20:17:58 -08002812 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2813 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002814 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002815
2816 if (appStopped || mWindowRemovalAllowed) {
2817 mWinAnimator.destroyPreservedSurfaceLocked();
2818 }
2819
2820 if (mDestroying) {
2821 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2822 + " destroySurfaces: appStopped=" + appStopped
2823 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2824 + " win.mRemoveOnExit=" + mRemoveOnExit);
2825 if (!cleanupOnResume || mRemoveOnExit) {
Robert Carr89a28ab2017-04-24 15:33:11 -07002826 destroyOrSaveSurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002827 }
2828 if (mRemoveOnExit) {
2829 removeImmediately();
2830 }
2831 if (cleanupOnResume) {
2832 requestUpdateWallpaperIfNeeded();
2833 }
2834 mDestroying = false;
2835 destroyedSomething = true;
2836 }
2837
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002838 return destroyedSomething;
2839 }
Chris Craik3131bde2016-05-06 13:39:08 -07002840
Robert Carr89a28ab2017-04-24 15:33:11 -07002841 // Destroy or save the application surface without checking
2842 // various indicators of whether the client has released the surface.
2843 // This is in general unsafe, and most callers should use {@link #destroySurface}
2844 void destroyOrSaveSurfaceUnchecked() {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002845 mSurfaceSaved = shouldSaveSurface();
2846 if (mSurfaceSaved) {
2847 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2848 Slog.v(TAG, "Saving surface: " + this);
2849 }
Chris Craik3131bde2016-05-06 13:39:08 -07002850 // Previous user of the surface may have set a transparent region signaling a portion
2851 // doesn't need to be composited, so reset to default empty state.
2852 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002853
2854 mWinAnimator.hide("saved surface");
2855 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2856 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002857 // The client should have disconnected at this point, but if it doesn't,
2858 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2859 // the client can't reconnect to the buffer queue, and rendering will fail.
2860 if (mWinAnimator.mSurfaceController != null) {
2861 mWinAnimator.mSurfaceController.disconnectInTransaction();
2862 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002863 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002864 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002865 mWinAnimator.destroySurfaceLocked();
2866 }
Chong Zhang92147042016-05-09 12:47:11 -07002867 // Clear animating flags now, since the surface is now gone. (Note this is true even
2868 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2869 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002870 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002871
Chong Zhang92147042016-05-09 12:47:11 -07002872 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002873 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002874 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002875 c.destroySavedSurface();
2876 }
2877
Robert Carr13f7be9e2015-12-02 18:39:45 -08002878 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002879 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002880 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002881 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002882 }
Chong Zhang92147042016-05-09 12:47:11 -07002883 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002884 }
2885
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002886 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2887 int restoreSavedSurfaceForInterestingWindow() {
2888 int interestingNotDrawn = -1;
2889 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002890 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002891 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2892 if (childInterestingNotDrawn != -1) {
2893 if (interestingNotDrawn == -1) {
2894 interestingNotDrawn = childInterestingNotDrawn;
2895 } else {
2896 interestingNotDrawn += childInterestingNotDrawn;
2897 }
2898 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002899 }
Robert Carr237028a2016-07-26 10:39:45 -07002900
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002901 if (mAttrs.type == TYPE_APPLICATION_STARTING
2902 || mAppDied || !wasVisibleBeforeClientHidden()
2903 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2904 // Window isn't interesting...
2905 return interestingNotDrawn;
2906 }
2907
2908 restoreSavedSurface();
2909
2910 if (!isDrawnLw()) {
2911 if (interestingNotDrawn == -1) {
2912 interestingNotDrawn = 1;
2913 } else {
2914 interestingNotDrawn++;
2915 }
2916 }
2917 return interestingNotDrawn;
2918 }
2919
2920 /** Returns true if the saved surface was restored. */
2921 boolean restoreSavedSurface() {
2922 if (!mSurfaceSaved) {
2923 return false;
2924 }
2925
2926 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2927 // However this means the surface was never laid out in the new orientation.
2928 // We can only restore to the last rotation we were laid out as visible in.
Andrii Kulian8ee72852017-03-10 10:36:45 -08002929 if (mLastVisibleLayoutRotation != getDisplayContent().getRotation()) {
Robert Carr237028a2016-07-26 10:39:45 -07002930 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002931 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002932 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002933 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002934
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002935 if (mWinAnimator.mSurfaceController != null) {
2936 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002937 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002938 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002939
Chong Zhang6e9872b2016-08-17 10:19:05 -07002940 requestUpdateWallpaperIfNeeded();
2941
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002942 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2943 Slog.v(TAG, "Restoring saved surface: " + this);
2944 }
2945 } else {
2946 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2947 // this point. Even if we destroyed the saved surface because of rotation
2948 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2949 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002950 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002951
2952 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002953 }
2954
Chong Zhang92147042016-05-09 12:47:11 -07002955 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002956 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2957 return true;
2958 }
2959
2960 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002961 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002962 if (c.canRestoreSurface()) {
2963 return true;
2964 }
2965 }
2966
2967 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002968 }
2969
2970 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002971 return mSurfaceSaved;
2972 }
2973
Chong Zhang92147042016-05-09 12:47:11 -07002974 void clearHasSavedSurface() {
2975 mSurfaceSaved = false;
2976 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002977 if (mWasVisibleBeforeClientHidden) {
2978 mAppToken.destroySavedSurfaces();
2979 }
Chong Zhang92147042016-05-09 12:47:11 -07002980 }
2981
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002982 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002983 if (mAnimatingWithSavedSurface) {
2984 // App has drawn something to its windows, we're no longer animating with
2985 // the saved surfaces.
2986 if (DEBUG_ANIM) Slog.d(TAG,
2987 "clearAnimatingWithSavedSurface(): win=" + this);
2988 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002989 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002990 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002991 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002992 }
2993
Craig Mautner69b08182012-09-05 13:07:13 -07002994 @Override
2995 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002996 final DisplayContent displayContent = getDisplayContent();
2997 if (displayContent == null) {
2998 // Only a window that was on a non-default display can be detached from it.
2999 return false;
3000 }
Winson Chung47a3e652014-05-21 16:03:42 -07003001 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07003002 }
3003
Adrian Rooscd3884d2015-02-18 17:25:23 +01003004 @Override
3005 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07003006 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003007 final DisplayContent dc = getDisplayContent();
3008 return dimLayerUser != null && dc != null
3009 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01003010 }
3011
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003012 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07003013 mShowToOwnerOnly = showToOwnerOnly;
3014 }
3015
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003016 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003017 // Child windows are evaluated based on their parent window.
3018 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003019 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08003020 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07003021
3022 // All window frames that are fullscreen extend above status bar, but some don't extend
3023 // below navigation bar. Thus, check for display frame for top/left and stable frame for
3024 // bottom right.
3025 if (win.mFrame.left <= win.mDisplayFrame.left
3026 && win.mFrame.top <= win.mDisplayFrame.top
3027 && win.mFrame.right >= win.mStableFrame.right
3028 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07003029 // Is a fullscreen window, like the clock alarm. Show to everyone.
3030 return false;
3031 }
3032 }
3033
Craig Mautner341220f2012-10-16 15:20:09 -07003034 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01003035 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07003036 }
3037
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003038 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
3039 outRegion.set(
3040 frame.left + inset.left, frame.top + inset.top,
3041 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04003042 }
3043
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003044 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003045 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003046 switch (mTouchableInsets) {
3047 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003048 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003049 outRegion.set(frame);
3050 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003051 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003052 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003053 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003054 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003055 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003056 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003057 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003058 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003059 outRegion.translate(frame.left, frame.top);
3060 break;
3061 }
3062 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003063 cropRegionToStackBoundsIfNeeded(outRegion);
3064 }
3065
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003066 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003067 final Task task = getTask();
3068 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003069 return;
3070 }
3071
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003072 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003073 if (stack == null) {
3074 return;
3075 }
3076
3077 stack.getDimBounds(mTmpRect);
3078 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003079 }
3080
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003081 /**
3082 * Report a focus change. Must be called with no locks held, and consistently
3083 * from the same serialized thread (such as dispatched from a handler).
3084 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003085 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003086 try {
3087 mClient.windowFocusChanged(focused, inTouchMode);
3088 } catch (RemoteException e) {
3089 }
3090 if (mFocusCallbacks != null) {
3091 final int N = mFocusCallbacks.beginBroadcast();
3092 for (int i=0; i<N; i++) {
3093 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
3094 try {
3095 if (focused) {
3096 obs.focusGained(mWindowId.asBinder());
3097 } else {
3098 obs.focusLost(mWindowId.asBinder());
3099 }
3100 } catch (RemoteException e) {
3101 }
3102 }
3103 mFocusCallbacks.finishBroadcast();
3104 }
3105 }
3106
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003107 @Override
3108 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003109 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003110 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003111 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003112
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003113 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003114 }
3115
Craig Mautnerdf88d732014-01-27 09:21:32 -08003116 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003117 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003118 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003119 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3120 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07003121 final MergedConfiguration mergedConfiguration =
3122 new MergedConfiguration(mService.mRoot.getConfiguration(),
3123 getMergedOverrideConfiguration());
3124
3125 setReportedConfiguration(mergedConfiguration);
3126
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003127 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003128 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3129
Craig Mautnerdf88d732014-01-27 09:21:32 -08003130 final Rect frame = mFrame;
3131 final Rect overscanInsets = mLastOverscanInsets;
3132 final Rect contentInsets = mLastContentInsets;
3133 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003134 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003135 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003136 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003137 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003138 final int displayId = getDisplayId();
Chet Haase8eb48d22014-09-24 07:31:29 -07003139 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3140 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003141 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3142 mService.mH.post(new Runnable() {
3143 @Override
3144 public void run() {
3145 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003146 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003147 stableInsets, outsets, reportDraw, mergedConfiguration,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003148 reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003149 } catch (RemoteException e) {
3150 // Not a remote call, RemoteException won't be raised.
3151 }
3152 }
3153 });
3154 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003155 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003156 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003157 }
Svetoslav4604abc2014-06-10 18:59:30 -07003158
3159 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003160 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003161 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003162 }
3163
Craig Mautnerdf88d732014-01-27 09:21:32 -08003164 mOverscanInsetsChanged = false;
3165 mContentInsetsChanged = false;
3166 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003167 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003168 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003169 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003170 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003171 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003172 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003173 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003174 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003175 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3176 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003177 // We are assuming the hosting process is dead or in a zombie state.
3178 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3179 + ", removing this window.");
3180 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003181 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003182 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003183 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003184 }
3185
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003186 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003187 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3188 // start even if we haven't received the relayout window, so that the client requests
3189 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3190 // until the window to small size, otherwise the multithread renderer will shift last
3191 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3192 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003193 boolean resizing = isDragResizing() || isDragResizeChanged();
3194 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3195 return frame;
3196 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003197 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003198 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003199 return mTmpRect;
3200 }
3201
Jorim Jaggi86905582016-02-09 21:36:09 -08003202 @Override
3203 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003204 final TaskStack stack = getStack();
3205 if (stack == null) {
3206 return INVALID_STACK_ID;
3207 }
3208 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003209 }
3210
3211 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3212 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Andrii Kulian44607962017-03-16 11:06:24 -07003213 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003214 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08003215 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
3216 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003217
Jorim Jaggidc249c42015-12-15 14:57:31 -08003218 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003219 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
3220 mPolicy.isNavBarForcedShownLw(this), displayId);
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003221 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003222 }
3223
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003224 public void registerFocusObserver(IWindowFocusObserver observer) {
3225 synchronized(mService.mWindowMap) {
3226 if (mFocusCallbacks == null) {
3227 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3228 }
3229 mFocusCallbacks.register(observer);
3230 }
3231 }
3232
3233 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3234 synchronized(mService.mWindowMap) {
3235 if (mFocusCallbacks != null) {
3236 mFocusCallbacks.unregister(observer);
3237 }
3238 }
3239 }
3240
3241 public boolean isFocused() {
3242 synchronized(mService.mWindowMap) {
3243 return mService.mCurrentFocus == this;
3244 }
3245 }
3246
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003247 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003248 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003249 return task != null && task.inFreeformWorkspace();
3250 }
3251
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003252 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003253 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003254 final Task task = getTask();
3255 return task != null && !task.isFullscreen();
3256 }
3257
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003258 /** Is this window in a container that takes up the entire screen space? */
3259 private boolean inFullscreenContainer() {
3260 if (mAppToken == null) {
3261 return true;
3262 }
3263 if (mAppToken.hasBounds()) {
3264 return false;
3265 }
3266 return !isInMultiWindowMode();
3267 }
3268
Andrii Kulian283acd22017-08-03 04:03:51 -07003269 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3270 boolean isLetterboxedAppWindow() {
3271 final Task task = getTask();
3272 final boolean taskIsFullscreen = task != null && task.isFullscreen();
3273 final boolean appWindowIsFullscreen = mAppToken != null && !mAppToken.hasBounds();
3274
3275 return taskIsFullscreen && !appWindowIsFullscreen;
3276 }
3277
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003278 /** Returns the appropriate bounds to use for computing frames. */
3279 private void getContainerBounds(Rect outBounds) {
3280 if (isInMultiWindowMode()) {
3281 getTask().getBounds(outBounds);
3282 } else if (mAppToken != null){
3283 mAppToken.getBounds(outBounds);
3284 } else {
3285 outBounds.setEmpty();
3286 }
3287 }
3288
Chong Zhang3005e752015-09-18 18:46:28 -07003289 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003290 return mDragResizing != computeDragResizing();
3291 }
3292
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003293 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003294 void setWaitingForDrawnIfResizingChanged() {
3295 if (isDragResizeChanged()) {
3296 mService.mWaitingForDrawn.add(this);
3297 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003298 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003299 }
3300
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003301 /**
3302 * @return Whether we reported a drag resize change to the application or not already.
3303 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003304 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003305 return mDragResizingChangeReported;
3306 }
3307
3308 /**
3309 * Resets the state whether we reported a drag resize change to the app.
3310 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003311 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003312 void resetDragResizingChangeReported() {
3313 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003314 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003315 }
3316
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003317 /**
3318 * Set whether we got resized but drag resizing flag was false.
3319 * @see #isResizedWhileNotDragResizing().
3320 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003321 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003322 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3323 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3324 }
3325
3326 /**
3327 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3328 * need to recreate the surface and defer surface bound updates in order to make sure the
3329 * buffer contents and the positioning/size stay in sync.
3330 */
3331 boolean isResizedWhileNotDragResizing() {
3332 return mResizedWhileNotDragResizing;
3333 }
3334
3335 /**
3336 * @return Whether we reported "resize while not drag resizing" to the application.
3337 * @see #isResizedWhileNotDragResizing()
3338 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003339 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003340 return mResizedWhileNotDragResizingReported;
3341 }
3342
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003343 int getResizeMode() {
3344 return mResizeMode;
3345 }
3346
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003347 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003348 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003349 if (task == null) {
3350 return false;
3351 }
Winson Chung2af04b32017-01-24 16:21:13 -08003352 if (!StackId.isStackAffectedByDragResizing(getStackId())) {
3353 return false;
3354 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003355 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003356 // Floating windows never enter drag resize mode.
3357 return false;
3358 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003359 if (task.isDragResizing()) {
3360 return true;
3361 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003362
3363 // If the bounds are currently frozen, it means that the layout size that the app sees
3364 // and the bounds we clip this window to might be different. In order to avoid holes, we
3365 // simulate that we are still resizing so the app fills the hole with the resizing
3366 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003367 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003368 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003369 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003370
Chong Zhang3005e752015-09-18 18:46:28 -07003371 }
3372
3373 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003374 final boolean resizing = computeDragResizing();
3375 if (resizing == mDragResizing) {
3376 return;
3377 }
3378 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003379 final Task task = getTask();
3380 if (task != null && task.isDragResizing()) {
3381 mResizeMode = task.getDragResizeMode();
3382 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003383 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003384 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3385 : DRAG_RESIZE_MODE_FREEFORM;
3386 }
Chong Zhang3005e752015-09-18 18:46:28 -07003387 }
3388
3389 boolean isDragResizing() {
3390 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003391 }
3392
Robert Carr2487ce72016-04-07 15:18:45 -07003393 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003394 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3395 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003396 }
3397
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003398 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003399 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003400 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003401 if (stack != null) {
3402 pw.print(" stackId="); pw.print(stack.mStackId);
3403 }
Craig Mautner59c00972012-07-30 12:10:24 -07003404 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003405 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003406 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003407 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3408 pw.print(" package="); pw.print(mAttrs.packageName);
3409 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003410 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003411 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3412 pw.print(" h="); pw.print(mRequestedHeight);
3413 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003414 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3415 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3416 pw.print(" h="); pw.println(mLastRequestedHeight);
3417 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003418 if (mIsChildWindow || mLayoutAttached) {
3419 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003420 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3421 }
3422 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3423 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3424 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3425 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3426 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3427 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003428 if (dumpAll) {
3429 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3430 pw.print(" mSubLayer="); pw.print(mSubLayer);
3431 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003432 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003433 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3434 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003435 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003436 if (dumpAll) {
3437 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003438 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003439 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3440 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003441 pw.print(isAnimatingWithSavedSurface());
Bryce Lee6311c4b2017-07-06 14:09:29 -07003442 pw.print(" mAppDied=");pw.print(mAppDied);
3443 pw.print(prefix); pw.print("drawnStateEvaluated=");
3444 pw.print(getDrawnStateEvaluated());
3445 pw.print(prefix); pw.print("mightAffectAllDrawn=");
3446 pw.println(mightAffectAllDrawn(false /*visibleOnly*/));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003447 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003448 pw.print(prefix); pw.print("mViewVisibility=0x");
3449 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003450 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3451 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003452 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3453 pw.print(" mSystemUiVisibility=0x");
3454 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003455 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003456 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003457 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003458 pw.print(prefix); pw.print("mPolicyVisibility=");
3459 pw.print(mPolicyVisibility);
3460 pw.print(" mPolicyVisibilityAfterAnim=");
3461 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003462 pw.print(" mAppOpVisibility=");
3463 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003464 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003465 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
3466 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3467 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003468 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003469 if (!mRelayoutCalled || mLayoutNeeded) {
3470 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3471 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003472 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003473 if (mXOffset != 0 || mYOffset != 0) {
3474 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3475 pw.print(" y="); pw.println(mYOffset);
3476 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003477 if (dumpAll) {
3478 pw.print(prefix); pw.print("mGivenContentInsets=");
3479 mGivenContentInsets.printShortString(pw);
3480 pw.print(" mGivenVisibleInsets=");
3481 mGivenVisibleInsets.printShortString(pw);
3482 pw.println();
3483 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3484 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3485 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003486 Region region = new Region();
3487 getTouchableRegion(region);
3488 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003489 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003490 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3491 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3492 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003493 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003494 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003495 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003496 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003497 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3498 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003499 if (dumpAll) {
3500 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3501 pw.print(" last="); mLastFrame.printShortString(pw);
3502 pw.println();
3503 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003504 if (mEnforceSizeCompat) {
3505 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003506 pw.println();
3507 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003508 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003509 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003510 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003511 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003512 pw.println();
3513 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3514 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003515 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003516 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003517 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003518 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003519 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3520 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003521 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3522 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003523 pw.print(prefix); pw.print("Cur insets: overscan=");
3524 mOverscanInsets.printShortString(pw);
3525 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003526 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003527 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003528 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003529 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003530 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003531 pw.print(prefix); pw.print("Lst insets: overscan=");
3532 mLastOverscanInsets.printShortString(pw);
3533 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003534 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003535 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003536 pw.print(" physical="); mLastOutsets.printShortString(pw);
3537 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003538 pw.println();
3539 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003540 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3541 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003542 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3543 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003544 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3545 pw.print(" mDestroying="); pw.print(mDestroying);
3546 pw.print(" mRemoved="); pw.println(mRemoved);
3547 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003548 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003549 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003550 pw.print(prefix); pw.print("mOrientationChanging=");
3551 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003552 pw.print(" configOrientationChanging=");
3553 pw.print(mLastReportedConfiguration.orientation
3554 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003555 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003556 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003557 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003558 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003559 if (mLastFreezeDuration != 0) {
3560 pw.print(prefix); pw.print("mLastFreezeDuration=");
3561 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3562 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003563 if (mHScale != 1 || mVScale != 1) {
3564 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3565 pw.print(" mVScale="); pw.println(mVScale);
3566 }
3567 if (mWallpaperX != -1 || mWallpaperY != -1) {
3568 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3569 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3570 }
3571 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3572 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3573 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3574 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003575 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3576 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3577 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3578 pw.print(mWallpaperDisplayOffsetX);
3579 pw.print(" mWallpaperDisplayOffsetY=");
3580 pw.println(mWallpaperDisplayOffsetY);
3581 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003582 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003583 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003584 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003585 if (isDragResizing()) {
3586 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3587 }
3588 if (computeDragResizing()) {
3589 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3590 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003591 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3592 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003593 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003594
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003595 @Override
3596 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003597 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003598 + " " + getWindowTag();
3599 }
3600
Robert Carra1eb4392015-12-10 12:43:51 -08003601 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003602 CharSequence tag = mAttrs.getTitle();
3603 if (tag == null || tag.length() <= 0) {
3604 tag = mAttrs.packageName;
3605 }
3606 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003607 }
3608
3609 @Override
3610 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003611 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003612 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003613 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003614 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003615 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003616 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003617 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003618 }
3619 return mStringNameCache;
3620 }
Robert Carr58f29132015-10-29 14:19:05 -07003621
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003622 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003623 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003624 clipRect.left = (int) (clipRect.left / mHScale);
3625 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003626 }
3627 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003628 clipRect.top = (int) (clipRect.top / mVScale);
3629 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003630 }
3631 }
Robert Carr31e28482015-12-02 16:53:18 -08003632
Jorim Jaggif5834272016-04-04 20:25:41 -07003633 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3634 final int pw = containingFrame.width();
3635 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003636 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003637 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003638 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3639
3640 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003641 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3642 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003643 // 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 -07003644 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3645 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3646 // the display.
3647 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003648 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003649 float x, y;
3650 int w,h;
3651
3652 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3653 if (mAttrs.width < 0) {
3654 w = pw;
3655 } else if (mEnforceSizeCompat) {
3656 w = (int)(mAttrs.width * mGlobalScale + .5f);
3657 } else {
3658 w = mAttrs.width;
3659 }
3660 if (mAttrs.height < 0) {
3661 h = ph;
3662 } else if (mEnforceSizeCompat) {
3663 h = (int)(mAttrs.height * mGlobalScale + .5f);
3664 } else {
3665 h = mAttrs.height;
3666 }
3667 } else {
3668 if (mAttrs.width == MATCH_PARENT) {
3669 w = pw;
3670 } else if (mEnforceSizeCompat) {
3671 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3672 } else {
3673 w = mRequestedWidth;
3674 }
3675 if (mAttrs.height == MATCH_PARENT) {
3676 h = ph;
3677 } else if (mEnforceSizeCompat) {
3678 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3679 } else {
3680 h = mRequestedHeight;
3681 }
3682 }
3683
3684 if (mEnforceSizeCompat) {
3685 x = mAttrs.x * mGlobalScale;
3686 y = mAttrs.y * mGlobalScale;
3687 } else {
3688 x = mAttrs.x;
3689 y = mAttrs.y;
3690 }
3691
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003692 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003693 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003694 // required by {@link Gravity#apply} call.
3695 w = Math.min(w, pw);
3696 h = Math.min(h, ph);
3697 }
3698
3699 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003700 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003701 (int) (x + mAttrs.horizontalMargin * pw),
3702 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3703
3704 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003705 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003706 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003707 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003708
3709 // We need to make sure we update the CompatFrame as it is used for
3710 // cropping decisions, etc, on systems where we lack a decor layer.
3711 mCompatFrame.set(mFrame);
3712 if (mEnforceSizeCompat) {
3713 // See comparable block in computeFrameLw.
3714 mCompatFrame.scale(mInvGlobalScale);
3715 }
Robert Carr31e28482015-12-02 16:53:18 -08003716 }
Robert Carr51a1b872015-12-08 14:03:13 -08003717
3718 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003719 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003720 }
3721
Robert Carrf3b72c72016-03-21 18:16:39 -07003722 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003723 return mIsChildWindow
3724 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003725 }
3726
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003727 /**
3728 * Returns true if any window added by an application process that if of type
3729 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3730 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3731 * this window is visible.
3732 */
3733 boolean hideNonSystemOverlayWindowsWhenVisible() {
3734 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3735 && mSession.mCanHideNonSystemOverlayWindows;
3736 }
3737
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003738 /** Returns the parent window if this is a child of another window, else null. */
3739 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003740 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3741 // WindowContainer that isn't a WindowState.
3742 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003743 }
3744
3745 /** Returns the topmost parent window if this is a child of another window, else this. */
3746 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003747 WindowState current = this;
3748 WindowState topParent = current;
3749 while (current != null && current.mIsChildWindow) {
3750 current = current.getParentWindow();
3751 // Parent window can be null if the child is detached from it's parent already, but
3752 // someone still has a reference to access it. So, we return the top parent value we
3753 // already have instead of null.
3754 if (current != null) {
3755 topParent = current;
3756 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003757 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003758 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003759 }
3760
Wale Ogunwale9d147902016-07-16 11:58:55 -07003761 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003762 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003763 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003764 }
3765
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003766 void setWillReplaceWindow(boolean animate) {
3767 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003768 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003769 c.setWillReplaceWindow(animate);
3770 }
3771
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003772 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3773 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3774 // We don't set replacing on starting windows since they are added by window manager and
3775 // not the client so won't be replaced by the client.
3776 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003777 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003778
3779 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003780 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003781 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003782 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003783
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003784 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003785 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003786 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003787 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003788
3789 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003790 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003791 c.clearWillReplaceWindow();
3792 }
3793 }
3794
3795 boolean waitingForReplacement() {
3796 if (mWillReplaceWindow) {
3797 return true;
3798 }
3799
3800 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003801 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003802 if (c.waitingForReplacement()) {
3803 return true;
3804 }
3805 }
3806 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003807 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003808
Chong Zhang4d7369a2016-04-25 16:09:14 -07003809 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003810 final DisplayContent dc = getDisplayContent();
3811 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3812 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3813 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003814 mService.mWindowPlacerLocked.requestTraversal();
3815 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003816
3817 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003818 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003819 c.requestUpdateWallpaperIfNeeded();
3820 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003821 }
3822
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003823 float translateToWindowX(float x) {
3824 float winX = x - mFrame.left;
3825 if (mEnforceSizeCompat) {
3826 winX *= mGlobalScale;
3827 }
3828 return winX;
3829 }
3830
3831 float translateToWindowY(float y) {
3832 float winY = y - mFrame.top;
3833 if (mEnforceSizeCompat) {
3834 winY *= mGlobalScale;
3835 }
3836 return winY;
3837 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003838
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003839 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003840 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003841 final DisplayContent dc = getDisplayContent();
3842 if (dimLayerUser != null && dc != null) {
3843 dc.mDimLayerController.applyDim(dimLayerUser,
3844 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003845 }
3846 }
3847
Robert Carrd1a010f2016-04-07 22:36:22 -07003848 // During activity relaunch due to resize, we sometimes use window replacement
3849 // for only child windows (as the main window is handled by window preservation)
3850 // and the big surface.
3851 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003852 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3853 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3854 // we also want to replace them at such phases, as they won't be covered by window
3855 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003856 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003857 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003858 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003859 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003860
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003861 void setWillReplaceChildWindows() {
3862 if (shouldBeReplacedWithChildren()) {
3863 setWillReplaceWindow(false /* animate */);
3864 }
3865 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003866 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003867 c.setWillReplaceChildWindows();
3868 }
3869 }
3870
3871 WindowState getReplacingWindow() {
3872 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3873 return this;
3874 }
3875 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003876 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003877 final WindowState replacing = c.getReplacingWindow();
3878 if (replacing != null) {
3879 return replacing;
3880 }
3881 }
3882 return null;
3883 }
3884
Jorim Jaggife762342016-10-13 14:33:27 +02003885 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003886 public int getRotationAnimationHint() {
3887 if (mAppToken != null) {
3888 return mAppToken.mRotationAnimationHint;
3889 } else {
3890 return -1;
3891 }
3892 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003893
Jorim Jaggife762342016-10-13 14:33:27 +02003894 @Override
3895 public boolean isInputMethodWindow() {
3896 return mIsImWindow;
3897 }
3898
Wale Ogunwale9d147902016-07-16 11:58:55 -07003899 // This must be called while inside a transaction.
3900 boolean performShowLocked() {
3901 if (isHiddenFromUserLocked()) {
3902 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3903 hideLw(false);
3904 return false;
3905 }
3906
3907 logPerformShow("performShow on ");
3908
Jorim Jaggia50da602016-12-29 11:51:42 +01003909 final int drawState = mWinAnimator.mDrawState;
3910 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3911 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3912 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3913 }
3914
Jorim Jaggib0d27342016-11-01 16:10:42 -07003915 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003916 return false;
3917 }
3918
3919 logPerformShow("Showing ");
3920
3921 mService.enableScreenIfNeededLocked();
3922 mWinAnimator.applyEnterAnimationLocked();
3923
3924 // Force the show in the next prepareSurfaceLocked() call.
3925 mWinAnimator.mLastAlpha = -1;
3926 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3927 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3928 mWinAnimator.mDrawState = HAS_DRAWN;
3929 mService.scheduleAnimationLocked();
3930
3931 if (mHidden) {
3932 mHidden = false;
3933 final DisplayContent displayContent = getDisplayContent();
3934
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003935 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003936 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003937 if (c.mWinAnimator.mSurfaceController != null) {
3938 c.performShowLocked();
3939 // It hadn't been shown, which means layout not performed on it, so now we
3940 // want to make sure to do a layout. If called from within the transaction
3941 // loop, this will cause it to restart with a new layout.
3942 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003943 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003944 }
3945 }
3946 }
3947 }
3948
Wale Ogunwale9d147902016-07-16 11:58:55 -07003949 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003950 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003951 }
3952
3953 return true;
3954 }
3955
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003956 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003957 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003958 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003959 Slog.v(TAG, prefix + this
3960 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003961 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003962 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3963 + " during animation: policyVis=" + mPolicyVisibility
3964 + " parentHidden=" + isParentWindowHidden()
3965 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003966 + (mAppToken != null && mAppToken.hiddenRequested)
3967 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003968 + " animating=" + mWinAnimator.mAnimating
3969 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003970 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003971 + " Callers=" + Debug.getCallers(4));
3972 }
3973 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003974
3975 WindowInfo getWindowInfo() {
3976 WindowInfo windowInfo = WindowInfo.obtain();
3977 windowInfo.type = mAttrs.type;
3978 windowInfo.layer = mLayer;
3979 windowInfo.token = mClient.asBinder();
3980 windowInfo.title = mAttrs.accessibilityTitle;
3981 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3982 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003983 Task task = getTask();
3984 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWorkspace();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003985
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003986 if (mIsChildWindow) {
3987 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003988 }
3989
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003990 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003991 if (childCount > 0) {
3992 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003993 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003994 }
3995 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003996 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003997 windowInfo.childTokens.add(child.mClient.asBinder());
3998 }
3999 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004000 return windowInfo;
4001 }
4002
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004003 int getHighestAnimLayer() {
4004 int highest = mWinAnimator.mAnimLayer;
4005 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004006 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004007 final int childLayer = c.getHighestAnimLayer();
4008 if (childLayer > highest) {
4009 highest = childLayer;
4010 }
4011 }
4012 return highest;
4013 }
4014
Wale Ogunwale9adfe572016-09-08 20:43:58 -07004015 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004016 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004017 if (mChildren.isEmpty()) {
4018 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004019 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004020 }
4021
4022 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004023 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004024 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004025 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004026 }
4027 }
4028
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004029 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004030 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004031 // below the parent, then this window (the parent), and then the positive sublayer children
4032 // because they need to appear above the parent.
4033 int i = 0;
4034 final int count = mChildren.size();
4035 WindowState child = mChildren.get(i);
4036
4037 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004038 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004039 return true;
4040 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004041 i++;
4042 if (i >= count) {
4043 break;
4044 }
4045 child = mChildren.get(i);
4046 }
4047
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004048 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004049 return true;
4050 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004051
4052 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004053 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004054 return true;
4055 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004056 i++;
4057 if (i >= count) {
4058 break;
4059 }
4060 child = mChildren.get(i);
4061 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004062
4063 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004064 }
4065
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004066 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004067 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004068 // above the parent, then this window (the parent), and then the negative sublayer children
4069 // because they need to appear above the parent.
4070 int i = mChildren.size() - 1;
4071 WindowState child = mChildren.get(i);
4072
4073 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004074 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004075 return true;
4076 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004077 --i;
4078 if (i < 0) {
4079 break;
4080 }
4081 child = mChildren.get(i);
4082 }
4083
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004084 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004085 return true;
4086 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004087
4088 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004089 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004090 return true;
4091 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004092 --i;
4093 if (i < 0) {
4094 break;
4095 }
4096 child = mChildren.get(i);
4097 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004098
4099 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004100 }
4101
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004102 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4103 boolean traverseTopToBottom) {
4104 if (traverseTopToBottom) {
4105 if (mService.mInputMethodTarget == this) {
4106 // This window is the current IME target, so we need to process the IME windows
4107 // directly above it.
4108 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4109 return true;
4110 }
4111 }
4112 if (callback.apply(this)) {
4113 return true;
4114 }
4115 } else {
4116 if (callback.apply(this)) {
4117 return true;
4118 }
4119 if (mService.mInputMethodTarget == this) {
4120 // This window is the current IME target, so we need to process the IME windows
4121 // directly above it.
4122 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4123 return true;
4124 }
4125 }
4126 }
4127
4128 return false;
4129 }
4130
Wale Ogunwaled1880962016-11-08 10:31:59 -08004131 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004132 if (mChildren.isEmpty()) {
4133 return callback.test(this) ? this : null;
4134 }
4135
4136 // We want to consume the positive sublayer children first because they need to appear
4137 // above the parent, then this window (the parent), and then the negative sublayer children
4138 // because they need to appear above the parent.
4139 int i = mChildren.size() - 1;
4140 WindowState child = mChildren.get(i);
4141
4142 while (i >= 0 && child.mSubLayer >= 0) {
4143 if (callback.test(child)) {
4144 return child;
4145 }
4146 --i;
4147 if (i < 0) {
4148 break;
4149 }
4150 child = mChildren.get(i);
4151 }
4152
Wale Ogunwaled1880962016-11-08 10:31:59 -08004153 if (callback.test(this)) {
4154 return this;
4155 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004156
4157 while (i >= 0) {
4158 if (callback.test(child)) {
4159 return child;
4160 }
4161 --i;
4162 if (i < 0) {
4163 break;
4164 }
4165 child = mChildren.get(i);
4166 }
4167
4168 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004169 }
4170
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004171 boolean isWindowAnimationSet() {
4172 if (mWinAnimator.isWindowAnimationSet()) {
4173 return true;
4174 }
4175 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004176 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004177 if (c.isWindowAnimationSet()) {
4178 return true;
4179 }
4180 }
4181 return false;
4182 }
4183
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004184 void onExitAnimationDone() {
4185 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4186 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
4187 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
4188
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004189 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004190 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004191 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004192 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004193 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004194 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004195 }
4196 }
4197
4198 if (mWinAnimator.mEnteringAnimation) {
4199 mWinAnimator.mEnteringAnimation = false;
4200 mService.requestTraversal();
4201 // System windows don't have an activity and an app token as a result, but need a way
4202 // to be informed about their entrance animation end.
4203 if (mAppToken == null) {
4204 try {
4205 mClient.dispatchWindowShown();
4206 } catch (RemoteException e) {
4207 }
4208 }
4209 }
4210
4211 if (!mWinAnimator.isWindowAnimationSet()) {
4212 //TODO (multidisplay): Accessibility is supported only for the default display.
4213 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4214 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4215 }
4216 }
4217
4218 if (!mAnimatingExit) {
4219 return;
4220 }
4221
4222 if (mWinAnimator.isWindowAnimationSet()) {
4223 return;
4224 }
4225
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004226 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004227 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4228
4229 mDestroying = true;
4230
4231 final boolean hasSurface = mWinAnimator.hasSurface();
4232 if (hasSurface) {
4233 mWinAnimator.hide("onExitAnimationDone");
4234 }
4235
4236 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4237 // care to ensure the activity has actually stopped and the surface is not still in use.
4238 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4239 // transaction.
4240 if (mAppToken != null) {
4241 mAppToken.destroySurfaces();
4242 } else {
4243 if (hasSurface) {
4244 mService.mDestroySurface.add(this);
4245 }
4246 if (mRemoveOnExit) {
4247 mService.mPendingRemove.add(this);
4248 mRemoveOnExit = false;
4249 }
4250 }
4251 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004252 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004253 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004254
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004255 boolean clearAnimatingFlags() {
4256 boolean didSomething = false;
4257 // We don't want to clear it out for windows that get replaced, because the
4258 // animation depends on the flag to remove the replaced window.
4259 //
4260 // We also don't clear the mAnimatingExit flag for windows which have the
4261 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4262 // by the client. We should let animation proceed and not clear this flag or
4263 // they won't eventually be removed by WindowStateAnimator#finishExit.
4264 if (!mWillReplaceWindow && !mRemoveOnExit) {
4265 // Clear mAnimating flag together with mAnimatingExit. When animation
4266 // changes from exiting to entering, we need to clear this flag until the
4267 // new animation gets applied, so that isAnimationStarting() becomes true
4268 // until then.
4269 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4270 // placement for this window during this period, one or more frame will
4271 // show up with wrong position or scale.
4272 if (mAnimatingExit) {
4273 mAnimatingExit = false;
4274 didSomething = true;
4275 }
4276 if (mWinAnimator.mAnimating) {
4277 mWinAnimator.mAnimating = false;
4278 didSomething = true;
4279 }
4280 if (mDestroying) {
4281 mDestroying = false;
4282 mService.mDestroySurface.remove(this);
4283 didSomething = true;
4284 }
4285 }
4286
4287 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004288 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004289 }
4290
4291 return didSomething;
4292 }
4293
Winson4b4ba902016-07-27 19:45:52 -07004294 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004295 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004296 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004297
4298 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004299 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004300 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004301 c.hideWallpaperWindow(wasDeferred, reason);
4302 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004303 if (!mWinAnimator.mLastHidden || wasDeferred) {
4304 mWinAnimator.hide(reason);
4305 dispatchWallpaperVisibility(false);
4306 final DisplayContent displayContent = getDisplayContent();
4307 if (displayContent != null) {
4308 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4309 }
4310 }
4311 }
4312
4313 /**
4314 * Check wallpaper window for visibility change and notify window if so.
4315 * @param visible Current visibility.
4316 */
4317 void dispatchWallpaperVisibility(final boolean visible) {
4318 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004319 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004320
4321 // Only send notification if the visibility actually changed and we are not trying to hide
4322 // the wallpaper when we are deferring hiding of the wallpaper.
4323 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4324 mWallpaperVisible = visible;
4325 try {
4326 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4327 "Updating vis of wallpaper " + this
4328 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4329 mClient.dispatchAppVisibility(visible);
4330 } catch (RemoteException e) {
4331 }
4332 }
4333 }
4334
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004335 boolean hasVisibleNotDrawnWallpaper() {
4336 if (mWallpaperVisible && !isDrawnLw()) {
4337 return true;
4338 }
4339 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004340 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004341 if (c.hasVisibleNotDrawnWallpaper()) {
4342 return true;
4343 }
4344 }
4345 return false;
4346 }
4347
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004348 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4349 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004350 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004351 c.updateReportedVisibility(results);
4352 }
4353
4354 if (mAppFreezing || mViewVisibility != View.VISIBLE
4355 || mAttrs.type == TYPE_APPLICATION_STARTING
4356 || mDestroying) {
4357 return;
4358 }
4359 if (DEBUG_VISIBILITY) {
4360 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4361 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4362 if (!isDrawnLw()) {
4363 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4364 + " pv=" + mPolicyVisibility
4365 + " mDrawState=" + mWinAnimator.mDrawState
4366 + " ph=" + isParentWindowHidden()
4367 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4368 + " a=" + mWinAnimator.mAnimating);
4369 }
4370 }
4371
4372 results.numInteresting++;
4373 if (isDrawnLw()) {
4374 results.numDrawn++;
4375 if (!mWinAnimator.isAnimationSet()) {
4376 results.numVisible++;
4377 }
4378 results.nowGone = false;
4379 } else if (mWinAnimator.isAnimationSet()) {
4380 results.nowGone = false;
4381 }
4382 }
4383
Robert Carrfbbde852016-10-18 11:02:28 -07004384 /**
4385 * Calculate the window crop according to system decor policy. In general this is
4386 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4387 * special cases. This rectangle is in screen space.
4388 */
4389 void calculatePolicyCrop(Rect policyCrop) {
4390 final DisplayContent displayContent = getDisplayContent();
4391 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4392
4393 if (!isDefaultDisplay()) {
4394 // On a different display there is no system decor. Crop the window
4395 // by the screen boundaries.
4396 // TODO(multi-display)
4397 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4398 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4399 displayInfo.logicalWidth - mCompatFrame.left,
4400 displayInfo.logicalHeight - mCompatFrame.top);
4401 } else if (mLayer >= mService.mSystemDecorLayer) {
4402 // Above the decor layer is easy, just use the entire window
4403 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4404 } else if (mDecorFrame.isEmpty()) {
4405 // Windows without policy decor aren't cropped.
4406 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4407 } else {
4408 // Crop to the system decor specified by policy.
4409 calculateSystemDecorRect(policyCrop);
4410 }
4411 }
4412
4413 /**
4414 * The system decor rect is the region of the window which is not covered
4415 * by system decorations.
4416 */
4417 private void calculateSystemDecorRect(Rect systemDecorRect) {
4418 final Rect decorRect = mDecorFrame;
4419 final int width = mFrame.width();
4420 final int height = mFrame.height();
4421
4422 // Compute the offset of the window in relation to the decor rect.
4423 final int left = mXOffset + mFrame.left;
4424 final int top = mYOffset + mFrame.top;
4425
4426 // Initialize the decor rect to the entire frame.
4427 if (isDockedResizing()) {
4428 // If we are resizing with the divider, the task bounds might be smaller than the
4429 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4430 // want in this case in order to avoid holes.
4431 //
4432 // We take care to not shrink the width, for surfaces which are larger than
4433 // the display region. Of course this area will not eventually be visible
4434 // but if we truncate the width now, we will calculate incorrectly
4435 // when adjusting to the stack bounds.
4436 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4437 systemDecorRect.set(0, 0,
4438 Math.max(width, displayInfo.logicalWidth),
4439 Math.max(height, displayInfo.logicalHeight));
4440 } else {
4441 systemDecorRect.set(0, 0, width, height);
4442 }
4443
4444 // If a freeform window is animating from a position where it would be cutoff, it would be
4445 // cutoff during the animation. We don't want that, so for the duration of the animation
4446 // we ignore the decor cropping and depend on layering to position windows correctly.
4447 final boolean cropToDecor = !(inFreeformWorkspace() && isAnimatingLw());
4448 if (cropToDecor) {
4449 // Intersect with the decor rect, offsetted by window position.
4450 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4451 decorRect.right - left, decorRect.bottom - top);
4452 }
4453
4454 // If size compatibility is being applied to the window, the
4455 // surface is scaled relative to the screen. Also apply this
4456 // scaling to the crop rect. We aren't using the standard rect
4457 // scale function because we want to round things to make the crop
4458 // always round to a larger rect to ensure we don't crop too
4459 // much and hide part of the window that should be seen.
4460 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4461 final float scale = mInvGlobalScale;
4462 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4463 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4464 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4465 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4466 }
4467
4468 }
4469
4470 /**
4471 * Expand the given rectangle by this windows surface insets. This
4472 * takes you from the 'window size' to the 'surface size'.
4473 * The surface insets are positive in each direction, so we inset by
4474 * the inverse.
4475 */
4476 void expandForSurfaceInsets(Rect r) {
4477 r.inset(-mAttrs.surfaceInsets.left,
4478 -mAttrs.surfaceInsets.top,
4479 -mAttrs.surfaceInsets.right,
4480 -mAttrs.surfaceInsets.bottom);
4481 }
4482
Robert Carrc91d1c32017-02-15 19:37:46 -08004483 boolean surfaceInsetsChanging() {
4484 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4485 }
4486
Bryce Leef858b572017-06-29 14:03:33 -07004487 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004488 final boolean wasVisible = isVisibleLw();
4489
4490 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004491 if (mAnimatingExit) {
4492 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4493 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4494
4495 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4496 mAnimatingExit = false;
4497 }
4498 if (mDestroying) {
4499 mDestroying = false;
4500 mService.mDestroySurface.remove(this);
4501 }
4502 if (oldVisibility == View.GONE) {
4503 mWinAnimator.mEnterAnimationPending = true;
4504 }
4505
Andrii Kulian8ee72852017-03-10 10:36:45 -08004506 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004507
4508 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004509
Bryce Leef858b572017-06-29 14:03:33 -07004510 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004511
Robert Carrc91d1c32017-02-15 19:37:46 -08004512 if ((attrChanges & FORMAT_CHANGED) != 0) {
4513 // If the format can't be changed in place, preserve the old surface until the app draws
4514 // on the new one. This prevents blinking when we change elevation of freeform and
4515 // pinned windows.
4516 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4517 mWinAnimator.preserveSurfaceLocked();
4518 result |= RELAYOUT_RES_SURFACE_CHANGED
4519 | RELAYOUT_RES_FIRST_TIME;
4520 }
4521 }
4522
4523 // When we change the Surface size, in scenarios which may require changing
4524 // the surface position in sync with the resize, we use a preserved surface
4525 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004526 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4527 // stack since it can lead to issues if a new surface is created while calculating the
4528 // scale for the animation using the source hint rect
4529 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004530 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Winson Chung8bca9e42017-04-16 15:59:43 -07004531 || (surfaceInsetsChanging() && !inPinnedWorkspace())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004532 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4533
4534 setDragResizing();
4535 setResizedWhileNotDragResizing(false);
4536 // We can only change top level windows to the full-screen surface when
4537 // resizing (as we only have one full-screen surface). So there is no need
4538 // to preserve and destroy windows which are attached to another, they
4539 // will keep their surface and its size may change over time.
4540 if (mHasSurface && !isChildWindow()) {
4541 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004542 result |= RELAYOUT_RES_SURFACE_CHANGED |
4543 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004544 }
4545 }
4546 final boolean freeformResizing = isDragResizing()
4547 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4548 final boolean dockedResizing = isDragResizing()
4549 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4550 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4551 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
4552 if (isAnimatingWithSavedSurface()) {
4553 // If we're animating with a saved surface now, request client to report draw.
4554 // We still need to know when the real thing is drawn.
4555 result |= RELAYOUT_RES_FIRST_TIME;
4556 }
4557 return result;
4558 }
4559
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004560 /**
4561 * @return True if this window has been laid out at least once; false otherwise.
4562 */
4563 boolean isLaidOut() {
4564 return mLayoutSeq != -1;
4565 }
4566
4567 /**
4568 * Updates the last inset values to the current ones.
4569 */
4570 void updateLastInsetValues() {
4571 mLastOverscanInsets.set(mOverscanInsets);
4572 mLastContentInsets.set(mContentInsets);
4573 mLastVisibleInsets.set(mVisibleInsets);
4574 mLastStableInsets.set(mStableInsets);
4575 mLastOutsets.set(mOutsets);
4576 }
4577
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004578 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4579 // access to its windows children. Need to investigate re-writing
4580 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4581 static final class UpdateReportedVisibilityResults {
4582 int numInteresting;
4583 int numVisible;
4584 int numDrawn;
4585 boolean nowGone = true;
4586
4587 void reset() {
4588 numInteresting = 0;
4589 numVisible = 0;
4590 numDrawn = 0;
4591 nowGone = true;
4592 }
4593 }
Robert Carraf422a82017-04-10 18:34:33 -07004594
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004595 private static final class WindowId extends IWindowId.Stub {
4596 private final WeakReference<WindowState> mOuter;
4597
4598 private WindowId(WindowState outer) {
4599
4600 // Use a weak reference for the outer class. This is important to prevent the following
4601 // leak: Since we send this class to the client process, binder will keep it alive as
4602 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4603 // out our reference so even though this class is kept alive we don't leak WindowState,
4604 // which can keep a whole lot of classes alive.
4605 mOuter = new WeakReference<>(outer);
4606 }
4607
4608 @Override
4609 public void registerFocusObserver(IWindowFocusObserver observer) {
4610 final WindowState outer = mOuter.get();
4611 if (outer != null) {
4612 outer.registerFocusObserver(observer);
4613 }
4614 }
4615 @Override
4616 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4617 final WindowState outer = mOuter.get();
4618 if (outer != null) {
4619 outer.unregisterFocusObserver(observer);
4620 }
4621 }
4622 @Override
4623 public boolean isFocused() {
4624 final WindowState outer = mOuter.get();
4625 return outer != null && outer.isFocused();
4626 }
4627 }
4628
Robert Carraf422a82017-04-10 18:34:33 -07004629 boolean usesRelativeZOrdering() {
4630 if (!isChildWindow()) {
4631 return false;
4632 } else if (mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4633 return true;
4634 } else {
4635 return false;
4636 }
4637 }
satokcef37fb2011-10-24 21:49:38 +09004638}