blob: 5a181f1077d3c253f051fbdd27a034b9f0cb80ed [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;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700105import static com.android.server.wm.proto.IdentifierProto.HASH_CODE;
106import static com.android.server.wm.proto.IdentifierProto.TITLE;
107import static com.android.server.wm.proto.IdentifierProto.USER_ID;
108import static com.android.server.wm.proto.WindowStateProto.ANIMATING_EXIT;
109import static com.android.server.wm.proto.WindowStateProto.ANIMATOR;
110import static com.android.server.wm.proto.WindowStateProto.ATTRIBUTES;
111import static com.android.server.wm.proto.WindowStateProto.CHILD_WINDOWS;
112import static com.android.server.wm.proto.WindowStateProto.CONTAINING_FRAME;
113import static com.android.server.wm.proto.WindowStateProto.CONTENT_FRAME;
114import static com.android.server.wm.proto.WindowStateProto.CONTENT_INSETS;
115import static com.android.server.wm.proto.WindowStateProto.DISPLAY_ID;
116import static com.android.server.wm.proto.WindowStateProto.FRAME;
117import static com.android.server.wm.proto.WindowStateProto.GIVEN_CONTENT_INSETS;
118import static com.android.server.wm.proto.WindowStateProto.IDENTIFIER;
119import static com.android.server.wm.proto.WindowStateProto.PARENT_FRAME;
120import static com.android.server.wm.proto.WindowStateProto.STACK_ID;
121import static com.android.server.wm.proto.WindowStateProto.SURFACE_INSETS;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800122
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800123import android.app.AppOpsManager;
124import android.content.Context;
125import android.content.res.Configuration;
126import android.graphics.Matrix;
127import android.graphics.PixelFormat;
128import android.graphics.Point;
129import android.graphics.Rect;
130import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700131import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700132import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800133import android.os.IBinder;
134import android.os.PowerManager;
135import android.os.RemoteCallbackList;
136import android.os.RemoteException;
137import android.os.SystemClock;
138import android.os.Trace;
139import android.os.UserHandle;
140import android.os.WorkSource;
Andrii Kulian44607962017-03-16 11:06:24 -0700141import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800142import android.util.DisplayMetrics;
143import android.util.Slog;
144import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700145import android.util.proto.ProtoOutputStream;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800146import android.view.DisplayInfo;
147import android.view.Gravity;
148import android.view.IApplicationToken;
149import android.view.IWindow;
150import android.view.IWindowFocusObserver;
151import android.view.IWindowId;
152import android.view.InputChannel;
153import android.view.InputEvent;
154import android.view.InputEventReceiver;
155import android.view.View;
156import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700157import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800158import android.view.WindowManager;
159import android.view.WindowManagerPolicy;
160
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800161import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800162import com.android.server.input.InputWindowHandle;
163
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800164import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200165import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800166import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700167import java.util.Comparator;
168import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800169import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800170
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700171/** A window in the window manager. */
172class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800173 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800174
Skuhne81c524a2015-08-12 13:34:14 -0700175 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700176 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
177 // use hard-coded min sizes for now.
178 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
179 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700180
181 // The thickness of a window resize handle outside the window bounds on the free form workspace
182 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700183 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700184
Jorim Jaggi02886a82016-12-06 09:10:06 -0800185 private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false ||
186 ENABLE_TASK_SNAPSHOTS;
Robert Carr7098dbd2016-02-01 12:31:01 -0800187
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800188 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700189 final WindowManagerPolicy mPolicy;
190 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 final Session mSession;
192 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800193 final int mAppOp;
194 // UserId and appId of the owner. Don't display windows of non-current user.
195 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800196 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
197 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200198 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700200 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700202
203 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
204 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800205 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
206 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700207 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 final int mBaseLayer;
209 final int mSubLayer;
210 final boolean mLayoutAttached;
211 final boolean mIsImWindow;
212 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700213 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700214 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700215 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800216 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700217 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700218 /**
219 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
220 * Normally set by calling {@link #showLw} and {@link #hideLw}.
221 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700223 /**
224 * What {@link #mPolicyVisibility} should be set to after a transition animation.
225 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
226 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
227 * animation is done.
228 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700230 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700231 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700232 // This is a non-system overlay window that is currently force hidden.
233 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700235 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700237 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200238 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700239 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700240
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700241 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800242
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700243 /**
244 * The window size that was requested by the application. These are in
245 * the application's coordinate space (without compatibility scale applied).
246 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 int mRequestedWidth;
248 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700249 private int mLastRequestedWidth;
250 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700251
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800253 boolean mHaveFrame;
254 boolean mObscured;
255 boolean mTurnOnScreen;
256
257 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700258
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700259 /**
260 * Used to store last reported to client configuration and check if we have newer available.
261 * We'll send configuration to client only if it is different from the last applied one and
262 * client won't perform unnecessary updates.
263 */
264 private final Configuration mLastReportedConfiguration = new Configuration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700265
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700266 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700267 * Actual position of the surface shown on-screen (may be modified by animation). These are
268 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700269 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700270 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271
272 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700273 * Insets that determine the actually visible area. These are in the application's
274 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 */
276 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700277 private final Rect mLastVisibleInsets = new Rect();
278 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800279
280 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700281 * Insets that are covered by system windows (such as the status bar) and
282 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700283 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 */
285 final Rect mContentInsets = new Rect();
286 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700287
288 /**
289 * The last content insets returned to the client in relayout. We use
290 * these in the bounds animation to ensure we only observe inset changes
291 * at the same time that a client resizes it's surface so that we may use
292 * the geometryAppliesWithResize synchronization mechanism to keep
293 * the contents in place.
294 */
295 final Rect mLastRelayoutContentInsets = new Rect();
296
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700297 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298
299 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800300 * Insets that determine the area covered by the display overscan region. These are in the
301 * application's coordinate space (without compatibility scale applied).
302 */
303 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700304 private final Rect mLastOverscanInsets = new Rect();
305 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800306
307 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700308 * Insets that determine the area covered by the stable system windows. These are in the
309 * application's coordinate space (without compatibility scale applied).
310 */
311 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700312 private final Rect mLastStableInsets = new Rect();
313 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700314
315 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700316 * Outsets determine the area outside of the surface where we want to pretend that it's possible
317 * to draw anyway.
318 */
319 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700320 private final Rect mLastOutsets = new Rect();
321 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700322
323 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 * Set to true if we are waiting for this window to receive its
325 * given internal insets before laying out other windows based on it.
326 */
327 boolean mGivenInsetsPending;
328
329 /**
330 * These are the content insets that were given during layout for
331 * this window, to be applied to windows behind it.
332 */
333 final Rect mGivenContentInsets = new Rect();
334
335 /**
336 * These are the visible insets that were given during layout for
337 * this window, to be applied to windows behind it.
338 */
339 final Rect mGivenVisibleInsets = new Rect();
340
341 /**
342 * This is the given touchable area relative to the window frame, or null if none.
343 */
344 final Region mGivenTouchableRegion = new Region();
345
346 /**
347 * Flag indicating whether the touchable region should be adjusted by
348 * the visible insets; if false the area outside the visible insets is
349 * NOT touchable, so we must use those to adjust the frame during hit
350 * tests.
351 */
352 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
353
354 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400355 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700356 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800357 float mHScale=1, mVScale=1;
358 float mLastHScale=1, mLastVScale=1;
359 final Matrix mTmpMatrix = new Matrix();
360
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700361 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 final Rect mFrame = new Rect();
363 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700364 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700365 // Frame that is scaled to the application's coordinate space when in
366 // screen size compatibility mode.
367 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368
369 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700370
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700371 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700372
Wale Ogunwale94596652015-02-06 19:27:34 -0800373 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
374 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700375 final Rect mDisplayFrame = new Rect();
376
377 // The region of the display frame that the display type supports displaying content on. This
378 // is mostly a special case for TV where some displays don’t have the entire display usable.
379 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
380 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700381 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700382
383 // The display frame minus the stable insets. This value is always constant regardless of if
384 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700385 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800386
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700387 // The area not occupied by the status and navigation bars. So, if both status and navigation
388 // bars are visible, the decor frame is equal to the stable frame.
389 final Rect mDecorFrame = new Rect();
390
391 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
392 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700393 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700394
395 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
396 // displays hint text.
397 final Rect mVisibleFrame = new Rect();
398
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700399 // Frame that includes dead area outside of the surface but where we want to pretend that it's
400 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700401 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700402
Jorim Jaggidc249c42015-12-15 14:57:31 -0800403 /**
404 * Usually empty. Set to the task's tempInsetFrame. See
405 *{@link android.app.IActivityManager#resizeDockedStack}.
406 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700407 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800408
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800409 boolean mContentChanged;
410
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800411 // If a window showing a wallpaper: the requested offset for the
412 // wallpaper; if a wallpaper window: the currently applied offset.
413 float mWallpaperX = -1;
414 float mWallpaperY = -1;
415
416 // If a window showing a wallpaper: what fraction of the offset
417 // range corresponds to a full virtual screen.
418 float mWallpaperXStep = -1;
419 float mWallpaperYStep = -1;
420
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700421 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
422 // to its window; if a wallpaper window: not used.
423 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
424 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
425
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800426 // Wallpaper windows: pixels offset based on above variables.
427 int mXOffset;
428 int mYOffset;
429
Craig Mautner2268e7e2012-12-13 15:40:00 -0800430 /**
431 * This is set after IWindowSession.relayout() has been called at
432 * least once for the window. It allows us to detect the situation
433 * where we don't yet have a surface, but should have one soon, so
434 * we can give the window focus before waiting for the relayout.
435 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800436 boolean mRelayoutCalled;
437
Robert Carrfed10072016-05-26 11:48:49 -0700438 boolean mInRelayout;
439
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800440 /**
441 * If the application has called relayout() with changes that can
442 * impact its window's size, we need to perform a layout pass on it
443 * even if it is not currently visible for layout. This is set
444 * when in that case until the layout is done.
445 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800446 boolean mLayoutNeeded;
447
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800448 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800449 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800450
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800451 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800452 boolean mDestroying;
453
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800454 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800455 boolean mRemoveOnExit;
456
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800457 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800458 * Whether the app died while it was visible, if true we might need
459 * to continue to show it until it's restarted.
460 */
461 boolean mAppDied;
462
463 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800464 * Set when the orientation is changing and this window has not yet
465 * been updated for the new orientation.
466 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700467 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800468
Dianne Hackborna57c6952013-03-29 14:46:40 -0700469 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700470 * Sometimes in addition to the mOrientationChanging
471 * flag we report that the orientation is changing
472 * due to a mismatch in current and reported configuration.
473 *
474 * In the case of timeout we still need to make sure we
475 * leave the orientation changing state though, so we
476 * use this as a special time out escape hatch.
477 */
478 private boolean mOrientationChangeTimedOut;
479
480 /**
Robert Carr237028a2016-07-26 10:39:45 -0700481 * The orientation during the last visible call to relayout. If our
482 * current orientation is different, the window can't be ready
483 * to be shown.
484 */
485 int mLastVisibleLayoutRotation = -1;
486
487 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800488 * Set when we need to report the orientation change to client to trigger a relayout.
489 */
490 boolean mReportOrientationChanged;
491
492 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700493 * How long we last kept the screen frozen.
494 */
495 int mLastFreezeDuration;
496
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800497 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800498 boolean mRemoved;
499
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800500 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800501 * It is save to remove the window and destroy the surface because the client requested removal
502 * or some other higher level component said so (e.g. activity manager).
503 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800504 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700505 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800506
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800507 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700508 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800509 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700510 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800511
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800512 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700513 private String mStringNameCache;
514 private CharSequence mLastTitle;
515 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800516
Craig Mautnera2c77052012-03-26 12:14:43 -0700517 final WindowStateAnimator mWinAnimator;
518
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700519 boolean mHasSurface = false;
520
Craig Mautner88400d32012-09-30 12:35:45 -0700521 /** When true this window can be displayed on screens owther than mOwnerUid's */
522 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700523
Robert Carr13f7be9e2015-12-02 18:39:45 -0800524 // Whether the window has a saved surface from last pause, which can be
525 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700526 private boolean mSurfaceSaved = false;
527
Chong Zhang8e4bda92016-05-04 15:08:18 -0700528 // Whether we're performing an entering animation with a saved surface. This flag is
529 // true during the time we're showing a window with a previously saved surface. It's
530 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700531 private boolean mAnimatingWithSavedSurface;
532
533 // Whether the window was visible when we set the app to invisible last time. WM uses
534 // this as a hint to restore the surface (if available) for early animation next time
535 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700536 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800537
Robert Carra1eb4392015-12-10 12:43:51 -0800538 // This window will be replaced due to relaunch. This allows window manager
539 // to differentiate between simple removal of a window and replacement. In the latter case it
540 // will preserve the old window until the new one is drawn.
541 boolean mWillReplaceWindow = false;
542 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700543 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800544 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700545 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800546 // If not null, the window that will be used to replace the old one. This is being set when
547 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700548 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700549 // For the new window in the replacement transition, if we have
550 // requested to replace without animation, then we should
551 // make sure we also don't apply an enter animation for
552 // the new window.
553 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800554 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700555 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800556
Jeff Brownc2932a12014-11-20 18:04:05 -0800557 /**
558 * Wake lock for drawing.
559 * Even though it's slightly more expensive to do so, we will use a separate wake lock
560 * for each app that is requesting to draw while dozing so that we can accurately track
561 * who is preventing the system from suspending.
562 * This lock is only acquired on first use.
563 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700564 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800565
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700566 final private Rect mTmpRect = new Rect();
567
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800568 /**
569 * Whether the window was resized by us while it was gone for layout.
570 */
571 boolean mResizedWhileGone = false;
572
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700573 /** @see #isResizedWhileNotDragResizing(). */
574 private boolean mResizedWhileNotDragResizing;
575
576 /** @see #isResizedWhileNotDragResizingReported(). */
577 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700578
Robert Carr6da3cc02016-06-16 15:17:07 -0700579 /**
580 * During seamless rotation we have two phases, first the old window contents
581 * are rotated to look as if they didn't move in the new coordinate system. Then we
582 * have to freeze updates to this layer (to preserve the transformation) until
583 * the resize actually occurs. This is true from when the transformation is set
584 * and false until the transaction to resize is sent.
585 */
586 boolean mSeamlesslyRotated = false;
587
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700588 private static final Region sEmptyRegion = new Region();
589
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700590 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800591 * Surface insets from the previous call to relayout(), used to track
592 * if we are changing the Surface insets.
593 */
594 final Rect mLastSurfaceInsets = new Rect();
595
596 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700597 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
598 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
599 * make sure all children have been considered.
600 */
601 private boolean mDrawnStateEvaluated;
602
603 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700604 * 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 -0700605 * of z-order and 1 otherwise.
606 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800607 private static final Comparator<WindowState> sWindowSubLayerComparator =
608 new Comparator<WindowState>() {
609 @Override
610 public int compare(WindowState w1, WindowState w2) {
611 final int layer1 = w1.mSubLayer;
612 final int layer2 = w2.mSubLayer;
613 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
614 // We insert the child window into the list ordered by
615 // the sub-layer. For same sub-layers, the negative one
616 // should go below others; the positive one should go
617 // above others.
618 return -1;
619 }
620 return 1;
621 };
622 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700623
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800624 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700625 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800626 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800627 mService = service;
628 mSession = s;
629 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800630 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800631 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700632 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700633 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800634 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200635 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636 mAttrs.copyFrom(a);
637 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700638 mPolicy = mService.mPolicy;
639 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800640 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700641 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700642 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700643 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700644 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700645 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800646 try {
647 c.asBinder().linkToDeath(deathRecipient, 0);
648 } catch (RemoteException e) {
649 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700650 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651 mLayoutAttached = false;
652 mIsImWindow = false;
653 mIsWallpaper = false;
654 mIsFloatingLayer = false;
655 mBaseLayer = 0;
656 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700657 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700658 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800659 return;
660 }
661 mDeathRecipient = deathRecipient;
662
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700663 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664 // The multiplier here is to reserve space for multiple
665 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800666 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700667 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800668 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700669 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900670
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700671 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
672 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900673
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800674 mLayoutAttached = mAttrs.type !=
675 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700676 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
677 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
678 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800679 } else {
680 // The multiplier here is to reserve space for multiple
681 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800682 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700683 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800684 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700685 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800686 mLayoutAttached = false;
687 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
688 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
689 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800690 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700691 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800692
Wale Ogunwale72919d22016-12-08 18:58:50 -0800693 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700694 // Windows for apps that can show for all users should also show when the device is
695 // locked.
696 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700697 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800698
Craig Mautner322e4032012-07-13 13:35:20 -0700699 mWinAnimator = new WindowStateAnimator(this);
700 mWinAnimator.mAlpha = a.alpha;
701
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800702 mRequestedWidth = 0;
703 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700704 mLastRequestedWidth = 0;
705 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800706 mXOffset = 0;
707 mYOffset = 0;
708 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800709 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800710 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
711 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800712 }
713
714 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700715 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800716 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800717 }
718
Bryce Leed390deb2017-06-22 13:14:28 -0700719 /**
720 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
721 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700722 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700723 return mDrawnStateEvaluated;
724 }
725
726 /**
727 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
728 * be cleared when detached from parent.
729 */
730 void setDrawnStateEvaluated(boolean evaluated) {
731 mDrawnStateEvaluated = evaluated;
732 }
733
734 @Override
735 void onParentSet() {
736 super.onParentSet();
737 setDrawnStateEvaluated(false /*evaluated*/);
738 }
739
Craig Mautnera2c77052012-03-26 12:14:43 -0700740 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800741 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800742 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800743 }
744
745 @Override
746 public String getOwningPackage() {
747 return mAttrs.packageName;
748 }
749
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800750 @Override
751 public boolean canAddInternalSystemWindow() {
752 return mOwnerCanAddInternalSystemWindow;
753 }
754
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200755 @Override
756 public boolean canAcquireSleepToken() {
757 return mSession.mCanAcquireSleepToken;
758 }
759
Jorim Jaggif5834272016-04-04 20:25:41 -0700760 /**
761 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
762 * from {@param frame}. In other words, it applies the insets that would result if
763 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700764 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
765 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700766 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700767 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
768 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
769 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
770 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
771 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700772 frame.inset(left, top, right, bottom);
773 }
774
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800775 @Override
Robert Carr43521762016-10-28 13:15:04 -0700776 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
777 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
778 Rect outsetFrame) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800779 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700780 // This window is being replaced and either already got information that it's being
781 // removed or we are still waiting for some information. Because of this we don't
782 // want to apply any more changes to it, so it remains in this state until new window
783 // appears.
784 return;
785 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800786 mHaveFrame = true;
787
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700788 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700789 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800790 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700791 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800792
Chong Zhangae35fef2016-03-16 15:56:55 -0700793 // If the task has temp inset bounds set, we have to make sure all its windows uses
794 // the temp inset frame. Otherwise different display frames get applied to the main
795 // window and the child window, making them misaligned.
Andrii Kulianc24f3732017-08-08 19:35:17 -0700796 if (inFullscreenContainer || isLetterboxedAppWindow()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700797 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700798 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700799 task.getTempInsetBounds(mInsetFrame);
800 }
801
Jorim Jaggif5834272016-04-04 20:25:41 -0700802 // Denotes the actual frame used to calculate the insets and to perform the layout. When
803 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
804 // insets temporarily. By the notion of a task having a different layout frame, we can
805 // achieve that while still moving the task around.
806 final Rect layoutContainingFrame;
807 final Rect layoutDisplayFrame;
808
809 // The offset from the layout containing frame to the actual containing frame.
810 final int layoutXDiff;
811 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700812 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800813 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700814 mContainingFrame.set(parentFrame);
815 mDisplayFrame.set(displayFrame);
816 layoutDisplayFrame = displayFrame;
817 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700818 layoutXDiff = 0;
819 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800820 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700821 getContainerBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100822 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
823
824 // If the bounds are frozen, we still want to translate the window freely and only
825 // freeze the size.
826 Rect frozen = mAppToken.mFrozenBounds.peek();
827 mContainingFrame.right = mContainingFrame.left + frozen.width();
828 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
829 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800830 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700831 // IME is up and obscuring this window. Adjust the window position so it is visible.
832 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700833 final int stackId = getStackId();
834 if (stackId == FREEFORM_WORKSPACE_STACK_ID
835 && mContainingFrame.bottom > contentFrame.bottom) {
836 // In freeform we want to move the top up directly.
837 // TODO: Investigate why this is contentFrame not parentFrame.
838 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
839 } else if (stackId != PINNED_STACK_ID
840 && mContainingFrame.bottom > parentFrame.bottom) {
841 // But in docked we want to behave like fullscreen and behave as if the task
842 // were given smaller bounds for the purposes of layout. Skip adjustments for
843 // the pinned stack, they are handled separately in the PinnedStackController.
844 mContainingFrame.bottom = parentFrame.bottom;
845 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700846 }
Skuhne81c524a2015-08-12 13:34:14 -0700847
Robert Carre6275582016-02-29 15:45:45 -0800848 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700849 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
850 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800851 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700852 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700853 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700854 }
Doris Liu06d582d2015-06-01 13:18:43 -0700855 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800856 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700857 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
858 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
859 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700860 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700861 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700862 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700863 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
864 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700865 }
Robert Carr43521762016-10-28 13:15:04 -0700866 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700867 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700868 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800869
Craig Mautner967212c2013-04-13 21:10:58 -0700870 final int pw = mContainingFrame.width();
871 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800872
Robert Carr43521762016-10-28 13:15:04 -0700873 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800874 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700875 // + " to " + parentFrame);
876 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800877 mContentChanged = true;
878 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700879 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
880 mLastRequestedWidth = mRequestedWidth;
881 mLastRequestedHeight = mRequestedHeight;
882 mContentChanged = true;
883 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800884
Robert Carr43521762016-10-28 13:15:04 -0700885 mOverscanFrame.set(overscanFrame);
886 mContentFrame.set(contentFrame);
887 mVisibleFrame.set(visibleFrame);
888 mDecorFrame.set(decorFrame);
889 mStableFrame.set(stableFrame);
890 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700891 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700892 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700893 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800894
Craig Mautnereda67292013-04-28 13:50:14 -0700895 final int fw = mFrame.width();
896 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800897
Jorim Jaggif5834272016-04-04 20:25:41 -0700898 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
899
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700900 // Calculate the outsets before the content frame gets shrinked to the window frame.
901 if (hasOutsets) {
902 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
903 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
904 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
905 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
906 } else {
907 mOutsets.set(0, 0, 0, 0);
908 }
909
Craig Mautnera248eee2013-05-07 11:41:27 -0700910 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800911 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800912 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800913 // For pinned workspace the frame isn't limited in any particular
914 // way since SystemUI controls the bounds. For freeform however
915 // we want to keep things inside the content frame.
916 final Rect limitFrame = task.inPinnedWorkspace() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700917 // Keep the frame out of the blocked system area, limit it in size to the content area
918 // and make sure that there is always a minimum visible so that the user can drag it
919 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800920 final int height = Math.min(mFrame.height(), limitFrame.height());
921 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700922 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900923 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
924 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
925 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
926 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800927 final int top = Math.max(limitFrame.top,
928 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
929 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
930 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700931 mFrame.set(left, top, left + width, top + height);
932 mContentFrame.set(mFrame);
933 mVisibleFrame.set(mContentFrame);
934 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700935 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700936 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100937 mContentFrame.set(mFrame);
938 if (!mFrame.equals(mLastFrame)) {
939 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800940 }
Skuhne81c524a2015-08-12 13:34:14 -0700941 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700942 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
943 Math.max(mContentFrame.top, mFrame.top),
944 Math.min(mContentFrame.right, mFrame.right),
945 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800946
Jorim Jaggi656f6502016-04-11 21:08:17 -0700947 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
948 Math.max(mVisibleFrame.top, mFrame.top),
949 Math.min(mVisibleFrame.right, mFrame.right),
950 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800951
Jorim Jaggi656f6502016-04-11 21:08:17 -0700952 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
953 Math.max(mStableFrame.top, mFrame.top),
954 Math.min(mStableFrame.right, mFrame.right),
955 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700956 }
Adrian Roosfa104232014-06-20 16:10:14 -0700957
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700958 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500959 // Windows that are not fullscreen can be positioned outside of the display frame,
960 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700961 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
962 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
963 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
964 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800965 }
Craig Mautnereda67292013-04-28 13:50:14 -0700966
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100967 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100968 // For the docked divider, we calculate the stable insets like a full-screen window
969 // so it can use it to calculate the snap positions.
970 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
971 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
972 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
973 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800974
975 // The divider doesn't care about insets in any case, so set it to empty so we don't
976 // trigger a relayout when moving it.
977 mContentInsets.setEmpty();
978 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100979 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700980 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700981 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
982 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700983 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
984 && mFrame.right > mTmpRect.right;
985 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
986 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700987 mContentInsets.set(mContentFrame.left - mFrame.left,
988 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700989 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700990 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700991 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700992 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800993
Jorim Jaggi656f6502016-04-11 21:08:17 -0700994 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
995 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700996 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700997 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700998 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700999 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001000
Jorim Jaggi656f6502016-04-11 21:08:17 -07001001 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
1002 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001003 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001004 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001005 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001006 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001007 }
Adrian Roosfa104232014-06-20 16:10:14 -07001008
Jorim Jaggi656f6502016-04-11 21:08:17 -07001009 // Offset the actual frame by the amount layout frame is off.
1010 mFrame.offset(-layoutXDiff, -layoutYDiff);
1011 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001012 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
1013 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
1014 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1015
Craig Mautnereda67292013-04-28 13:50:14 -07001016 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001017 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001018 // If there is a size compatibility scale being applied to the
1019 // window, we need to apply this to its insets so that they are
1020 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001021 mOverscanInsets.scale(mInvGlobalScale);
1022 mContentInsets.scale(mInvGlobalScale);
1023 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001024 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001025 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001026
1027 // Also the scaled frame that we report to the app needs to be
1028 // adjusted to be in its coordinate space.
1029 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001030 }
1031
Craig Mautnereda67292013-04-28 13:50:14 -07001032 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001033 final DisplayContent displayContent = getDisplayContent();
1034 if (displayContent != null) {
1035 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001036 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001037 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001038 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001039 }
1040
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001041 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001042 "Resolving (mRequestedWidth="
1043 + mRequestedWidth + ", mRequestedheight="
1044 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1045 + "): frame=" + mFrame.toShortString()
1046 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001047 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001048 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001049 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001050 }
1051
Craig Mautnera2c77052012-03-26 12:14:43 -07001052 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001053 public Rect getFrameLw() {
1054 return mFrame;
1055 }
1056
Craig Mautnera2c77052012-03-26 12:14:43 -07001057 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001058 public Point getShownPositionLw() {
1059 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001060 }
1061
Craig Mautnera2c77052012-03-26 12:14:43 -07001062 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001063 public Rect getDisplayFrameLw() {
1064 return mDisplayFrame;
1065 }
1066
Craig Mautnera2c77052012-03-26 12:14:43 -07001067 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001068 public Rect getOverscanFrameLw() {
1069 return mOverscanFrame;
1070 }
1071
1072 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001073 public Rect getContentFrameLw() {
1074 return mContentFrame;
1075 }
1076
Craig Mautnera2c77052012-03-26 12:14:43 -07001077 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001078 public Rect getVisibleFrameLw() {
1079 return mVisibleFrame;
1080 }
1081
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001082 Rect getStableFrameLw() {
1083 return mStableFrame;
1084 }
1085
Craig Mautnera2c77052012-03-26 12:14:43 -07001086 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001087 public boolean getGivenInsetsPendingLw() {
1088 return mGivenInsetsPending;
1089 }
1090
Craig Mautnera2c77052012-03-26 12:14:43 -07001091 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001092 public Rect getGivenContentInsetsLw() {
1093 return mGivenContentInsets;
1094 }
1095
Craig Mautnera2c77052012-03-26 12:14:43 -07001096 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001097 public Rect getGivenVisibleInsetsLw() {
1098 return mGivenVisibleInsets;
1099 }
1100
Craig Mautnera2c77052012-03-26 12:14:43 -07001101 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001102 public WindowManager.LayoutParams getAttrs() {
1103 return mAttrs;
1104 }
1105
Craig Mautner812d2ca2012-09-27 15:35:34 -07001106 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001107 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001108 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001109 }
1110
Craig Mautner19d59bc2012-09-04 11:15:56 -07001111 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001112 public int getSystemUiVisibility() {
1113 return mSystemUiVisibility;
1114 }
1115
Craig Mautner19d59bc2012-09-04 11:15:56 -07001116 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001117 public int getSurfaceLayer() {
1118 return mLayer;
1119 }
1120
Craig Mautner812d2ca2012-09-27 15:35:34 -07001121 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001122 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001123 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001124 }
1125
1126 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001127 public IApplicationToken getAppToken() {
1128 return mAppToken != null ? mAppToken.appToken : null;
1129 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001130
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001131 @Override
1132 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001133 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001134 }
1135
Robert Carr31aa98b2016-07-20 15:29:03 -07001136 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001137 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1138 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1139 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001140 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001141 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001142 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1143 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001144 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001145 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001146 }
1147
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001148 /**
1149 * Adds the window to the resizing list if any of the parameters we use to track the window
1150 * dimensions or insets have changed.
1151 */
1152 void updateResizingWindowIfNeeded() {
1153 final WindowStateAnimator winAnimator = mWinAnimator;
1154 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1155 return;
1156 }
1157
1158 final Task task = getTask();
1159 // In the case of stack bound animations, the window frames will update (unlike other
1160 // animations which just modify various transformation properties). We don't want to
1161 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1162 // the frame may not correspond to the surface size or the onscreen area at various
1163 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001164 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001165 return;
1166 }
1167
1168 setReportResizeHints();
1169 boolean configChanged = isConfigChanged();
1170 if (DEBUG_CONFIGURATION && configChanged) {
1171 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1172 }
1173
1174 final boolean dragResizingChanged = isDragResizeChanged()
1175 && !isDragResizingChangeReported();
1176
1177 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1178 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1179 + " frame=" + mFrame);
1180
1181 // We update mLastFrame always rather than in the conditional with the last inset
1182 // variables, because mFrameSizeChanged only tracks the width and height changing.
1183 mLastFrame.set(mFrame);
1184
1185 if (mContentInsetsChanged
1186 || mVisibleInsetsChanged
1187 || winAnimator.mSurfaceResized
1188 || mOutsetsChanged
1189 || mFrameSizeChanged
1190 || configChanged
1191 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001192 || !isResizedWhileNotDragResizingReported()
1193 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001194 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1195 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1196 + " contentInsetsChanged=" + mContentInsetsChanged
1197 + " " + mContentInsets.toShortString()
1198 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1199 + " " + mVisibleInsets.toShortString()
1200 + " stableInsetsChanged=" + mStableInsetsChanged
1201 + " " + mStableInsets.toShortString()
1202 + " outsetsChanged=" + mOutsetsChanged
1203 + " " + mOutsets.toShortString()
1204 + " surfaceResized=" + winAnimator.mSurfaceResized
1205 + " configChanged=" + configChanged
1206 + " dragResizingChanged=" + dragResizingChanged
1207 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001208 + isResizedWhileNotDragResizingReported()
1209 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001210 }
1211
1212 // If it's a dead window left on screen, and the configuration changed, there is nothing
1213 // we can do about it. Remove the window now.
1214 if (mAppToken != null && mAppDied) {
1215 mAppToken.removeDeadWindows();
1216 return;
1217 }
1218
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001219 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001220 mService.makeWindowFreezingScreenIfNeededLocked(this);
1221
1222 // If the orientation is changing, or we're starting or ending a drag resizing action,
1223 // then we need to hold off on unfreezing the display until this window has been
1224 // redrawn; to do that, we need to go through the process of getting informed by the
1225 // application when it has finished drawing.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001226 if (getOrientationChanging() || dragResizingChanged
1227 || isResizedWhileNotDragResizing()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001228 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1229 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1230 + ", mDrawState=DRAW_PENDING in " + this
1231 + ", surfaceController " + winAnimator.mSurfaceController);
1232 }
1233 winAnimator.mDrawState = DRAW_PENDING;
1234 if (mAppToken != null) {
1235 mAppToken.clearAllDrawn();
1236 }
1237 }
1238 if (!mService.mResizingWindows.contains(this)) {
1239 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1240 mService.mResizingWindows.add(this);
1241 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001242 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001243 if (isDrawnLw()) {
1244 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1245 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001246 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001247 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1248 - mService.mDisplayFreezeTime);
1249 }
1250 }
1251 }
1252
Bryce Lee8c3cf382017-07-06 19:47:10 -07001253 boolean getOrientationChanging() {
1254 // In addition to the local state flag, we must also consider the difference in the last
1255 // reported configuration vs. the current state. If the client code has not been informed of
1256 // the change, logic dependent on having finished processing the orientation, such as
1257 // unfreezing, could be improperly triggered.
1258 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1259 // this is not necessarily what the client has processed yet. Find a
1260 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001261 return (mOrientationChanging || (isVisible()
1262 && getConfiguration().orientation != mLastReportedConfiguration.orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001263 && !mSeamlesslyRotated
1264 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001265 }
1266
1267 void setOrientationChanging(boolean changing) {
1268 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001269 mOrientationChangeTimedOut = false;
1270 }
1271
1272 void orientationChangeTimedOut() {
1273 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001274 }
1275
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001276 DisplayContent getDisplayContent() {
1277 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001278 }
1279
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001280 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001281 final DisplayContent displayContent = getDisplayContent();
1282 return displayContent != null ? displayContent.getDisplayInfo() : null;
1283 }
1284
Jorim Jaggife762342016-10-13 14:33:27 +02001285 @Override
1286 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001287 final DisplayContent displayContent = getDisplayContent();
1288 if (displayContent == null) {
1289 return -1;
1290 }
1291 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001292 }
1293
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001294 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001295 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001296 }
1297
1298 TaskStack getStack() {
1299 Task task = getTask();
1300 if (task != null) {
1301 if (task.mStack != null) {
1302 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001303 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001304 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001305 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1306 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001307 final DisplayContent dc = getDisplayContent();
1308 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001309 }
1310
Skuhnef932e562015-08-20 12:07:30 -07001311 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001312 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001313 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001314 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001315 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001316 final Task task = getTask();
1317 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001318 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001319 mTmpRect.setEmpty();
1320 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001321 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001322 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001323 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001324 } else {
1325 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001326 }
1327 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001328
Chong Zhang9184ec62015-09-24 12:32:21 -07001329 bounds.set(mVisibleFrame);
1330 if (intersectWithStackBounds) {
1331 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001332 }
1333
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001334 if (bounds.isEmpty()) {
1335 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001336 if (intersectWithStackBounds) {
1337 bounds.intersect(mTmpRect);
1338 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001339 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001340 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001341 }
1342
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001343 public long getInputDispatchingTimeoutNanos() {
1344 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001345 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001346 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1347 }
1348
Craig Mautnere8552142012-11-07 13:55:47 -08001349 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001350 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001351 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001352 }
1353
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001354 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1355 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1356 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1357 if (dtdx < -.000001f || dtdx > .000001f) return false;
1358 if (dsdy < -.000001f || dsdy > .000001f) return false;
1359 return true;
1360 }
1361
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001362 void prelayout() {
1363 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001364 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1365 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001366 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001367 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001368 }
1369 }
1370
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001371 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001372 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001373 // If we're animating with a saved surface, we're already visible.
1374 // Return true so that the alpha doesn't get cleared.
1375 if (!mAppFreezing && isDrawnLw()
1376 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1377 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1378 return true;
1379 }
1380
Wale Ogunwale44f21802016-09-02 12:49:48 -07001381 return super.hasContentToDisplay();
1382 }
1383
1384 @Override
1385 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001386 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001387 }
1388
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001389 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001390 * @return True if the window would be visible if we'd ignore policy visibility, false
1391 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001392 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001393 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001394 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001395 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001396 }
1397
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001398 @Override
1399 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001400 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001401 }
1402
1403 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001404 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1405 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001406 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001407 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1408 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001409 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001410 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001411 }
1412
1413 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001414 * The same as isVisible(), but follows the current hidden state of the associated app token,
1415 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001416 */
1417 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001418 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001419 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001420 }
1421
1422 /**
1423 * Can this window possibly be a drag/drop target? The test here is
1424 * a combination of the above "visible now" with the check that the
1425 * Input Manager uses when discarding windows from input consideration.
1426 */
1427 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001428 return isVisibleNow() && !mRemoved
1429 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001430 }
1431
1432 /**
1433 * Same as isVisible(), but we also count it as visible between the
1434 * call to IWindowSession.add() and the first relayout().
1435 */
1436 boolean isVisibleOrAdding() {
1437 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001438 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001439 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001440 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001441 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001442 }
1443
1444 /**
1445 * Is this window currently on-screen? It is on-screen either if it
1446 * is visible or it is currently running an animation before no longer
1447 * being visible.
1448 */
1449 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001450 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001451 return false;
1452 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001453 final AppWindowToken atoken = mAppToken;
1454 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001455 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001456 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001457 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001458 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001459 }
1460
1461 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001462 * Whether this window's drawn state might affect the drawn states of the app token.
1463 *
1464 * @param visibleOnly Whether we should consider only the windows that's currently
1465 * visible in layout. If true, windows that has not relayout to VISIBLE
1466 * would always return false.
1467 *
1468 * @return true if the window should be considered while evaluating allDrawn flags.
1469 */
1470 boolean mightAffectAllDrawn(boolean visibleOnly) {
Wale Ogunwale89973222017-04-23 18:39:45 -07001471 final boolean isViewVisible = (mAppToken == null || !mAppToken.isClientHidden())
Chong Zhange292eb32016-05-21 09:23:55 -07001472 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Jorim Jaggib0d27342016-11-01 16:10:42 -07001473 return (isOnScreen() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001474 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1475 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001476 && !mAnimatingExit && !mDestroying;
1477 }
1478
1479 /**
1480 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1481 * it must be drawn before allDrawn can become true.
1482 */
1483 boolean isInteresting() {
1484 return mAppToken != null && !mAppDied
1485 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1486 }
1487
1488 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 * Like isOnScreen(), but we don't return true if the window is part
1490 * of a transition that has not yet been started.
1491 */
1492 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001493 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001494 return false;
1495 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001496 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001497 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001498 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001499 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001500 }
1501
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001502 // TODO: Another visibility method that was added late in the release to minimize risk.
1503 @Override
1504 public boolean canAffectSystemUiFlags() {
Jorim Jaggi07a7b962017-08-03 16:59:44 +02001505 final boolean shown = mWinAnimator.getShown() && mWinAnimator.mShownAlpha > 0f;
Jorim Jaggic0c93242017-08-04 16:05:02 +02001506
1507 // We only consider the app to be exiting when the animation has started. After the app
1508 // transition is executed the windows are marked exiting before the new windows have been
1509 // shown. Thus, wait considering a window to be exiting after the animation has actually
1510 // started.
1511 final boolean appAnimationStarting = mAppToken != null
1512 && mAppToken.mAppAnimator.isAnimationStarting();
1513 final boolean exitingSelf = mAnimatingExit && (!mWinAnimator.isAnimationStarting()
1514 && !appAnimationStarting);
1515 final boolean appExiting = mAppToken != null && mAppToken.hidden && !appAnimationStarting;
1516
1517 final boolean exiting = exitingSelf || mDestroying || appExiting;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001518 final boolean translucent = mAttrs.alpha == 0.0f;
1519 return shown && !exiting && !translucent;
1520 }
1521
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001522 /**
1523 * Like isOnScreen, but returns false if the surface hasn't yet
1524 * been drawn.
1525 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001526 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001527 public boolean isDisplayedLw() {
1528 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001529 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001530 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001531 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001532 || mWinAnimator.mAnimating
1533 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001534 }
1535
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001536 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001537 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001538 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001539 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001540 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001541 return mWinAnimator.mAnimation != null
1542 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001543 }
1544
Craig Mautner812d2ca2012-09-27 15:35:34 -07001545 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001546 public boolean isGoneForLayoutLw() {
1547 final AppWindowToken atoken = mAppToken;
1548 return mViewVisibility == View.GONE
1549 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001550 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001551 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001552 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001553 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001554 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001555 }
1556
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001557 /**
1558 * Returns true if the window has a surface that it has drawn a
1559 * complete UI in to.
1560 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001561 public boolean isDrawFinishedLw() {
1562 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001563 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1564 || mWinAnimator.mDrawState == READY_TO_SHOW
1565 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001566 }
1567
1568 /**
1569 * Returns true if the window has a surface that it has drawn a
1570 * complete UI in to.
1571 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001572 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001573 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001574 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001575 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001576 }
1577
1578 /**
1579 * Return true if the window is opaque and fully drawn. This indicates
1580 * it may obscure windows behind it.
1581 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001582 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001583 // When there is keyguard, wallpaper could be placed over the secure app
1584 // window but invisible. We need to check wallpaper visibility explicitly
1585 // to determine if it's occluding apps.
1586 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1587 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001588 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001589 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001590 }
1591
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001592 @Override
1593 void onMovedByResize() {
1594 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001595 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001596 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001597 }
1598
1599 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1600 boolean changed = false;
1601
1602 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001603 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001604 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1605 }
1606
1607 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1608 // Starting window that's exiting will be removed when the animation finishes.
1609 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1610 // to actually remove it.
1611 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1612 mAnimatingExit = true;
1613 mRemoveOnExit = true;
1614 mWindowRemovalAllowed = true;
1615 }
1616 return changed;
1617 }
1618
Robert Carrd5c7dd62017-03-08 10:39:30 -08001619 // Next up we will notify the client that it's visibility has changed.
1620 // We need to prevent it from destroying child surfaces until
1621 // the animation has finished.
1622 if (!visible && isVisibleNow()) {
1623 mWinAnimator.detachChildren();
1624 }
1625
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001626 if (visible != isVisibleNow()) {
1627 if (!runningAppAnimation) {
1628 final AccessibilityController accessibilityController =
1629 mService.mAccessibilityController;
1630 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1631 mWinAnimator.applyAnimationLocked(winTransit, visible);
1632 //TODO (multidisplay): Magnification is supported only for the default
1633 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1634 accessibilityController.onWindowTransitionLocked(this, winTransit);
1635 }
1636 }
1637 changed = true;
1638 setDisplayLayoutNeeded();
1639 }
1640
1641 return changed;
1642 }
1643
1644 boolean onSetAppExiting() {
1645 final DisplayContent displayContent = getDisplayContent();
1646 boolean changed = false;
1647
1648 if (isVisibleNow()) {
1649 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1650 //TODO (multidisplay): Magnification is supported only for the default
1651 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1652 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1653 }
1654 changed = true;
1655 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001656 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001657 }
1658 }
1659
1660 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001661 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001662 changed |= c.onSetAppExiting();
1663 }
1664
1665 return changed;
1666 }
1667
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001668 @Override
1669 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001670 // Some windows won't go through the resizing process, if they don't have a surface, so
1671 // destroy all saved surfaces here.
1672 destroySavedSurface();
1673
1674 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1675 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001676 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001677 resizingWindows.add(this);
1678
1679 // If we are not drag resizing, force recreating of a new surface so updating
1680 // the content and positioning that surface will be in sync.
1681 //
1682 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1683 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1684 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1685 // their frame to update crop, etc...
1686 //
1687 // Anyway we don't need to synchronize position and content updates for these
1688 // windows since they aren't at the base layer and could be moved around anyway.
1689 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001690 !mWinAnimator.isForceScaled() && !isGoneForLayoutLw() &&
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001691 !getTask().inPinnedWorkspace()) {
1692 setResizedWhileNotDragResizing(true);
1693 }
1694 }
1695 if (isGoneForLayoutLw()) {
1696 mResizedWhileGone = true;
1697 }
1698
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001699 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001700 }
1701
1702 void onUnfreezeBounds() {
1703 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001704 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001705 c.onUnfreezeBounds();
1706 }
1707
1708 if (!mHasSurface) {
1709 return;
1710 }
1711
1712 mLayoutNeeded = true;
1713 setDisplayLayoutNeeded();
1714 if (!mService.mResizingWindows.contains(this)) {
1715 mService.mResizingWindows.add(this);
1716 }
1717 }
1718
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001719 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001720 * If the window has moved due to its containing content frame changing, then notify the
1721 * listeners and optionally animate it. Simply checking a change of position is not enough,
1722 * because being move due to dock divider is not a trigger for animation.
1723 */
1724 void handleWindowMovedIfNeeded() {
1725 if (!hasMoved()) {
1726 return;
1727 }
1728
1729 // Frame has moved, containing content frame has also moved, and we're not currently
1730 // animating... let's do something.
1731 final int left = mFrame.left;
1732 final int top = mFrame.top;
1733 final Task task = getTask();
1734 final boolean adjustedForMinimizedDockOrIme = task != null
1735 && (task.mStack.isAdjustedForMinimizedDockedStack()
1736 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001737 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001738 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1739 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1740 && (task == null || getTask().mStack.hasMovementAnimations())
1741 && !mWinAnimator.mLastHidden) {
1742 mWinAnimator.setMoveAnimation(left, top);
1743 }
1744
1745 //TODO (multidisplay): Accessibility supported only for the default display.
1746 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001747 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001748 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1749 }
1750
1751 try {
1752 mClient.moved(left, top);
1753 } catch (RemoteException e) {
1754 }
1755 mMovedByResize = false;
1756 }
1757
1758 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001759 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001760 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1761 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001762 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001763 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001764 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001765 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001766 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001767 }
1768
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001769 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001770 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001771 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001772 return false;
1773 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001774 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001775 }
1776
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001777 boolean fillsDisplay() {
1778 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001779 return mFrame.left <= 0 && mFrame.top <= 0
1780 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001781 }
1782
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001783 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001784 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001785 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001786 }
1787
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001788 void onWindowReplacementTimeout() {
1789 if (mWillReplaceWindow) {
1790 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001791 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001792 // delays removal on certain conditions, which will leave the stale window in the
1793 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1794 //
1795 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001796 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001797 } else {
1798 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001799 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001800 c.onWindowReplacementTimeout();
1801 }
1802 }
1803 }
1804
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001805 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001806 void forceWindowsScaleableInTransaction(boolean force) {
1807 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1808 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1809 }
1810
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001811 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001812 }
1813
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001814 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001815 void removeImmediately() {
1816 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001817
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001818 if (mRemoved) {
1819 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001820 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1821 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001822 return;
1823 }
1824
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001825 mRemoved = true;
1826
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001827 mWillReplaceWindow = false;
1828 if (mReplacementWindow != null) {
1829 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1830 }
1831
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001832 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001833 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001834 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001835 }
1836
1837 final int type = mAttrs.type;
1838 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001839 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001840 }
1841 mPolicy.removeWindowLw(this);
1842
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001843 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001844
Craig Mautner96868332012-12-04 14:29:11 -08001845 mWinAnimator.destroyDeferredSurfaceLocked();
1846 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001847 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001848 try {
1849 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1850 } catch (RuntimeException e) {
1851 // Ignore if it has already been removed (usually because
1852 // we are doing this as part of processing a death note.)
1853 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001854
1855 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001856 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001857
Wale Ogunwale571771c2016-08-26 13:18:50 -07001858 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001859 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001860 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001861 removeIfPossible(false /*keepVisibleDeadWindow*/);
1862 }
1863
Wale Ogunwale571771c2016-08-26 13:18:50 -07001864 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001865 mWindowRemovalAllowed = true;
1866 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1867 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1868
1869 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1870 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1871 "Starting window removed " + this);
1872
1873 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1874 Slog.v(TAG_WM, "Remove " + this + " client="
1875 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1876 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1877 + Debug.getCallers(5));
1878
1879 final long origId = Binder.clearCallingIdentity();
1880
1881 disposeInputChannel();
1882
1883 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1884 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1885 + " mAnimatingExit=" + mAnimatingExit
1886 + " mRemoveOnExit=" + mRemoveOnExit
1887 + " mHasSurface=" + mHasSurface
1888 + " surfaceShowing=" + mWinAnimator.getShown()
1889 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1890 + " app-animation="
1891 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1892 + " mWillReplaceWindow=" + mWillReplaceWindow
1893 + " inPendingTransaction="
1894 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1895 + " mDisplayFrozen=" + mService.mDisplayFrozen
1896 + " callers=" + Debug.getCallers(6));
1897
1898 // Visibility of the removed window. Will be used later to update orientation later on.
1899 boolean wasVisible = false;
1900
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001901 final int displayId = getDisplayId();
1902
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001903 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1904 // window until the animation is done. If the display is frozen, just remove immediately,
1905 // since the animation wouldn't be seen.
David Stevens9440dc82017-03-16 19:00:20 -07001906 if (mHasSurface && mToken.okToAnimate()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001907 if (mWillReplaceWindow) {
1908 // This window is going to be replaced. We need to keep it around until the new one
1909 // gets added, then we will get rid of this one.
1910 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1911 "Preserving " + this + " until the new one is " + "added");
1912 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1913 // been removed. We probably need another flag to indicate that window removal
1914 // should be deffered vs. overloading the flag that says we are playing an exit
1915 // animation.
1916 mAnimatingExit = true;
1917 mReplacingRemoveRequested = true;
1918 Binder.restoreCallingIdentity(origId);
1919 return;
1920 }
1921
1922 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1923 // We started enter animation early with a saved surface, now the app asks to remove
1924 // this window. If we remove it now and the app is not yet drawn, we'll show a
1925 // flicker. Delay the removal now until it's really drawn.
1926 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1927 "removeWindowLocked: delay removal of " + this + " due to early animation");
1928 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1929 // immediately after the enter animation is done. If the app is not yet drawn then
1930 // it will show up as a flicker.
1931 setupWindowForRemoveOnExit();
1932 Binder.restoreCallingIdentity(origId);
1933 return;
1934 }
1935 // If we are not currently running the exit animation, we need to see about starting one
1936 wasVisible = isWinVisibleLw();
1937
1938 if (keepVisibleDeadWindow) {
1939 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1940 "Not removing " + this + " because app died while it's visible");
1941
1942 mAppDied = true;
1943 setDisplayLayoutNeeded();
1944 mService.mWindowPlacerLocked.performSurfacePlacement();
1945
1946 // Set up a replacement input channel since the app is now dead.
1947 // We need to catch tapping on the dead window to restart the app.
1948 openInputChannel(null);
1949 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1950
1951 Binder.restoreCallingIdentity(origId);
1952 return;
1953 }
1954
1955 if (wasVisible) {
1956 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1957
1958 // Try starting an animation.
1959 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1960 mAnimatingExit = true;
1961 }
1962 //TODO (multidisplay): Magnification is supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001963 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001964 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1965 }
1966 }
1967 final boolean isAnimating =
1968 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1969 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001970 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001971 // We delay the removal of a window if it has a showing surface that can be used to run
1972 // exit animation and it is marked as exiting.
1973 // Also, If isn't the an animating starting window that is the last window in the app.
1974 // We allow the removal of the non-animating starting window now as there is no
1975 // additional window or animation that will trigger its removal.
1976 if (mWinAnimator.getShown() && mAnimatingExit
1977 && (!lastWindowIsStartingWindow || isAnimating)) {
1978 // The exit animation is running or should run... wait for it!
1979 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1980 "Not removing " + this + " due to exit animation ");
1981 setupWindowForRemoveOnExit();
1982 if (mAppToken != null) {
1983 mAppToken.updateReportedVisibilityLocked();
1984 }
1985 Binder.restoreCallingIdentity(origId);
1986 return;
1987 }
1988 }
1989
Wale Ogunwale571771c2016-08-26 13:18:50 -07001990 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001991 // Removing a visible window will effect the computed orientation
1992 // So just update orientation if needed.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001993 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1994 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001995 }
1996 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1997 Binder.restoreCallingIdentity(origId);
1998 }
1999
2000 private void setupWindowForRemoveOnExit() {
2001 mRemoveOnExit = true;
2002 setDisplayLayoutNeeded();
2003 // Request a focus update as this window's input channel is already gone. Otherwise
2004 // we could have no focused window in input manager.
2005 final boolean focusChanged = mService.updateFocusedWindowLocked(
2006 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
2007 mService.mWindowPlacerLocked.performSurfacePlacement();
2008 if (focusChanged) {
2009 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2010 }
2011 }
2012
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002013 void setHasSurface(boolean hasSurface) {
2014 mHasSurface = hasSurface;
2015 }
2016
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002017 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08002018 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07002019 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
2020 if (appToken != null) {
Robert Carrdee1b3f2017-02-27 11:33:33 -08002021 return appToken.getAnimLayerAdjustment();
Wale Ogunwale455fac52016-07-21 07:24:49 -07002022 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002023 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07002024
Robert Carrdee1b3f2017-02-27 11:33:33 -08002025 return mToken.getAnimLayerAdjustment();
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002026 }
2027
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002028 int getSpecialWindowAnimLayerAdjustment() {
2029 int specialAdjustment = 0;
2030 if (mIsImWindow) {
2031 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
2032 } else if (mIsWallpaper) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07002033 specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment();
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002034 }
2035
2036 return mLayer + specialAdjustment;
2037 }
2038
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002039 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002040 if (mIsImWindow) {
2041 // IME windows can't be IME targets. IME targets are required to be below the IME
2042 // windows and that wouldn't be possible if the IME window is its own target...silly.
2043 return false;
2044 }
2045
Winson Chung3d0a74a2017-07-12 12:37:19 -07002046 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002047 if (!windowsAreFocusable) {
2048 // This window can't be an IME target if the app's windows should not be focusable.
2049 return false;
2050 }
2051
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002052 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002053 final int type = mAttrs.type;
2054
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002055 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2056 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002057 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2058 && type != TYPE_APPLICATION_STARTING) {
2059 return false;
2060 }
2061
2062 if (DEBUG_INPUT_METHOD) {
2063 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2064 if (!isVisibleOrAdding()) {
2065 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2066 + " relayoutCalled=" + mRelayoutCalled
2067 + " viewVis=" + mViewVisibility
2068 + " policyVis=" + mPolicyVisibility
2069 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2070 + " parentHidden=" + isParentWindowHidden()
2071 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2072 if (mAppToken != null) {
2073 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2074 }
2075 }
2076 }
2077 return isVisibleOrAdding();
2078 }
2079
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002080 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002081 final DisplayContent dc = getDisplayContent();
2082 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002083 return;
2084 }
Jorim Jaggi1f833082017-08-04 18:06:56 +02002085
2086 // If layout is currently deferred, we want to hold of with updating the layers.
2087 if (mService.mWindowPlacerLocked.isLayoutDeferred()) {
2088 return;
2089 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002090 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002091 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002092 // Force an animation pass just to update the mDimLayer layer.
2093 mService.scheduleAnimationLocked();
2094 }
2095 }
2096
Chong Zhangacf11402015-11-04 16:23:10 -08002097 private final class DeadWindowEventReceiver extends InputEventReceiver {
2098 DeadWindowEventReceiver(InputChannel inputChannel) {
2099 super(inputChannel, mService.mH.getLooper());
2100 }
2101 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002102 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002103 finishInputEvent(event, true);
2104 }
2105 }
2106 /**
2107 * Dummy event receiver for windows that died visible.
2108 */
2109 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2110
Chong Zhang112eb8c2015-11-02 11:17:00 -08002111 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002112 if (mInputChannel != null) {
2113 throw new IllegalStateException("Window already has an input channel.");
2114 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002115 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002116 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2117 mInputChannel = inputChannels[0];
2118 mClientChannel = inputChannels[1];
2119 mInputWindowHandle.inputChannel = inputChannels[0];
2120 if (outInputChannel != null) {
2121 mClientChannel.transferTo(outInputChannel);
2122 mClientChannel.dispose();
2123 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002124 } else {
2125 // If the window died visible, we setup a dummy input channel, so that taps
2126 // can still detected by input monitor channel, and we can relaunch the app.
2127 // Create dummy event receiver that simply reports all events as handled.
2128 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002129 }
2130 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002131 }
2132
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002133 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002134 if (mDeadWindowEventReceiver != null) {
2135 mDeadWindowEventReceiver.dispose();
2136 mDeadWindowEventReceiver = null;
2137 }
2138
2139 // unregister server channel first otherwise it complains about broken channel
2140 if (mInputChannel != null) {
2141 mService.mInputManager.unregisterInputChannel(mInputChannel);
2142 mInputChannel.dispose();
2143 mInputChannel = null;
2144 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002145 if (mClientChannel != null) {
2146 mClientChannel.dispose();
2147 mClientChannel = null;
2148 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002149 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002150 }
2151
Chong Zhang112eb8c2015-11-02 11:17:00 -08002152 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002153 // When the app is terminated (eg. from Recents), the task might have already been
2154 // removed with the window pending removal. Don't apply dim in such cases, as there
2155 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2156 final AppWindowToken token = mAppToken;
2157 if (token != null && token.removed) {
2158 return;
2159 }
2160
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002161 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002162 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002163 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002164 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002165 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002166 && dc != null && !mAnimatingExit && isVisible()) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002167 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002168 }
2169 }
2170
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002171 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002172 Task task = getTask();
2173 if (task != null) {
2174 return task;
2175 }
2176 return getStack();
2177 }
2178
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002179 /** Returns true if the replacement window was removed. */
2180 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2181 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2182 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2183 removeReplacedWindow();
2184 return true;
2185 }
2186
2187 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002188 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002189 if (c.removeReplacedWindowIfNeeded(replacement)) {
2190 return true;
2191 }
2192 }
2193 return false;
2194 }
2195
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002196 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002197 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2198 if (isDimming()) {
2199 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002200 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002201 mWillReplaceWindow = false;
2202 mAnimateReplacingWindow = false;
2203 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002204 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002205 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002206 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002207 }
2208 }
2209
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002210 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2211 boolean replacementSet = false;
2212
2213 if (mWillReplaceWindow && mReplacementWindow == null
2214 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2215
2216 mReplacementWindow = replacementCandidate;
2217 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2218 replacementSet = true;
2219 }
2220
2221 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002222 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002223 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2224 }
2225
2226 return replacementSet;
2227 }
2228
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002229 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002230 final DisplayContent dc = getDisplayContent();
2231 if (dc != null) {
2232 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002233 }
2234 }
2235
Robert Carrfed10072016-05-26 11:48:49 -07002236 // TODO: Strange usage of word workspace here and above.
2237 boolean inPinnedWorkspace() {
2238 final Task task = getTask();
2239 return task != null && task.inPinnedWorkspace();
2240 }
2241
Chong Zhang5117e272016-05-03 12:47:34 -07002242 void applyAdjustForImeIfNeeded() {
2243 final Task task = getTask();
2244 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2245 task.mStack.applyAdjustForImeIfNeeded(task);
2246 }
2247 }
2248
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002249 @Override
2250 void switchUser() {
2251 super.switchUser();
2252 if (isHiddenFromUserLocked()) {
2253 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2254 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2255 hideLw(false);
2256 }
2257 }
2258
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002259 int getTouchableRegion(Region region, int flags) {
2260 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002261 if (modal && mAppToken != null) {
2262 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002263 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002264 // If this is a modal window we need to dismiss it if it's not full screen and the
2265 // touch happens outside of the frame that displays the content. This means we
2266 // need to intercept touches outside of that window. The dim layer user
2267 // associated with the window (task or stack) will give us the good bounds, as
2268 // they would be used to display the dim layer.
2269 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2270 if (dimLayerUser != null) {
2271 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002272 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002273 getVisibleBounds(mTmpRect);
2274 }
2275 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002276 // For freeform windows we the touch region to include the whole surface for the
2277 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002278 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2279 final int delta = WindowManagerService.dipToPixel(
2280 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2281 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002282 }
2283 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002284 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002285 } else {
2286 // Not modal or full screen modal
2287 getTouchableRegion(region);
2288 }
2289 return flags;
2290 }
2291
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002292 void checkPolicyVisibilityChange() {
2293 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2294 if (DEBUG_VISIBILITY) {
2295 Slog.v(TAG, "Policy visibility changing after anim in " +
2296 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2297 }
2298 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002299 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002300 if (!mPolicyVisibility) {
2301 if (mService.mCurrentFocus == this) {
2302 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2303 "setAnimationLocked: setting mFocusMayChange true");
2304 mService.mFocusMayChange = true;
2305 }
2306 // Window is no longer visible -- make sure if we were waiting
2307 // for it to be displayed before enabling the display, that
2308 // we allow the display to be enabled now.
2309 mService.enableScreenIfNeededLocked();
2310 }
2311 }
2312 }
2313
2314 void setRequestedSize(int requestedWidth, int requestedHeight) {
2315 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2316 mLayoutNeeded = true;
2317 mRequestedWidth = requestedWidth;
2318 mRequestedHeight = requestedHeight;
2319 }
2320 }
2321
Bryce Leef858b572017-06-29 14:03:33 -07002322 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002323 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002324 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2325 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2326 mTurnOnScreen = true;
2327 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002328
2329 // If we were already visible, skip rest of preparation.
2330 if (wasVisible) {
2331 if (DEBUG_VISIBILITY) Slog.v(TAG,
2332 "Already visible and does not turn on screen, skip preparing: " + this);
2333 return;
2334 }
2335
2336 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2337 == SOFT_INPUT_ADJUST_RESIZE) {
2338 mLayoutNeeded = true;
2339 }
2340
David Stevens9440dc82017-03-16 19:00:20 -07002341 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002342 mWinAnimator.applyEnterAnimationLocked();
2343 }
Bryce Leef858b572017-06-29 14:03:33 -07002344 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002345
Bryce Leef858b572017-06-29 14:03:33 -07002346 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2347 final Configuration globalConfig = mService.mRoot.getConfiguration();
2348 final Configuration overrideConfig = getMergedOverrideConfiguration();
2349 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2350 }
2351
2352 void setReportedConfiguration(MergedConfiguration config) {
2353 mLastReportedConfiguration.setTo(config.getMergedConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002354 }
2355
2356 void adjustStartingWindowFlags() {
2357 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2358 && mAppToken.startingWindow != null) {
2359 // Special handling of starting window over the base
2360 // window of the app: propagate lock screen flags to it,
2361 // to provide the correct semantics while starting.
2362 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2363 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2364 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2365 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2366 }
2367 }
2368
2369 void setWindowScale(int requestedWidth, int requestedHeight) {
2370 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2371
2372 if (scaledWindow) {
2373 // requested{Width|Height} Surface's physical size
2374 // attrs.{width|height} Size on screen
2375 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2376 mHScale = (mAttrs.width != requestedWidth) ?
2377 (mAttrs.width / (float)requestedWidth) : 1.0f;
2378 mVScale = (mAttrs.height != requestedHeight) ?
2379 (mAttrs.height / (float)requestedHeight) : 1.0f;
2380 } else {
2381 mHScale = mVScale = 1;
2382 }
2383 }
2384
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002385 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002386 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002387 public void binderDied() {
2388 try {
2389 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002390 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002391 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002392 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002393 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002394 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2395 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2396 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002397 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002398 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2399 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002400 // just in case they have the divider at an unstable position. Better
2401 // also reset drag resizing state, because the owner can't do it
2402 // anymore.
Wale Ogunwale1666e312016-12-16 11:27:18 -08002403 final TaskStack stack = dc.getDockedStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002404 if (stack != null) {
2405 stack.resetDockedStackToMiddle();
2406 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002407 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002408 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002409 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002410 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002411 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002412 }
2413 }
2414 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002415 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002416 }
2417 }
2418 }
2419
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002420 /**
2421 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2422 * because we want to preserve its location on screen to be re-activated later when the user
2423 * interacts with it.
2424 */
2425 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002426 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002427 // Not a visible app window or the app isn't dead.
2428 return false;
2429 }
2430
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002431 if (mAttrs.token != mClient.asBinder()) {
2432 // The window was add by a client using another client's app token. We don't want to
2433 // keep the dead window around for this case since this is meant for 'real' apps.
2434 return false;
2435 }
2436
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002437 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2438 // We don't keep starting windows since they were added by the window manager before
2439 // the app even launched.
2440 return false;
2441 }
2442
2443 final TaskStack stack = getStack();
2444 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2445 }
2446
Wale Ogunwaled045c822015-12-02 09:14:28 -08002447 /** @return true if this window desires key events. */
2448 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002449 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002450 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002451 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002452 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002453 && !canReceiveTouchInput();
2454 }
2455
2456 /** @return true if this window desires touch events. */
2457 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002458 return mAppToken != null && mAppToken.getTask() != null
2459 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002460 }
2461
Craig Mautner749a7bb2012-04-02 13:49:53 -07002462 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002463 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002464 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002465 }
2466
Craig Mautner749a7bb2012-04-02 13:49:53 -07002467 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002468 public boolean showLw(boolean doAnimation) {
2469 return showLw(doAnimation, true);
2470 }
2471
2472 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002473 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002474 return false;
2475 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002476 if (!mAppOpVisibility) {
2477 // Being hidden due to app op request.
2478 return false;
2479 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002480 if (mPermanentlyHidden) {
2481 // Permanently hidden until the app exists as apps aren't prepared
2482 // to handle their windows being removed from under them.
2483 return false;
2484 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002485 if (mForceHideNonSystemOverlayWindow) {
2486 // This is an alert window that is currently force hidden.
2487 return false;
2488 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002489 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002490 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002491 return false;
2492 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002493 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002494 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002495 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002496 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
David Stevens9440dc82017-03-16 19:00:20 -07002497 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002498 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002499 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002500 // Check for the case where we are currently visible and
2501 // not animating; we do not want to do animation at such a
2502 // point to become visible when we already are.
2503 doAnimation = false;
2504 }
2505 }
2506 mPolicyVisibility = true;
2507 mPolicyVisibilityAfterAnim = true;
2508 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002509 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002510 }
2511 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002512 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002513 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002514 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2515 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2516 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002517 return true;
2518 }
2519
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002520 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002521 public boolean hideLw(boolean doAnimation) {
2522 return hideLw(doAnimation, true);
2523 }
2524
2525 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2526 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002527 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002528 doAnimation = false;
2529 }
2530 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002531 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002532 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002533 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002534 return false;
2535 }
2536 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002537 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002538 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002539 doAnimation = false;
2540 }
2541 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002542 mPolicyVisibilityAfterAnim = false;
2543 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002544 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002545 mPolicyVisibility = false;
2546 // Window is no longer visible -- make sure if we were waiting
2547 // for it to be displayed before enabling the display, that
2548 // we allow the display to be enabled now.
2549 mService.enableScreenIfNeededLocked();
2550 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002551 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002552 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002553 mService.mFocusMayChange = true;
2554 }
2555 }
2556 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002557 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002558 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002559 if (mService.mCurrentFocus == this) {
2560 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2561 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002562 return true;
2563 }
2564
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002565 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2566 if (mOwnerCanAddInternalSystemWindow
2567 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2568 return;
2569 }
2570 if (mForceHideNonSystemOverlayWindow == forceHide) {
2571 return;
2572 }
2573 mForceHideNonSystemOverlayWindow = forceHide;
2574 if (forceHide) {
2575 hideLw(true /* doAnimation */, true /* requestAnim */);
2576 } else {
2577 showLw(true /* doAnimation */, true /* requestAnim */);
2578 }
2579 }
2580
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002581 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002582 if (mAppOpVisibility != state) {
2583 mAppOpVisibility = state;
2584 if (state) {
2585 // If the policy visibility had last been to hide, then this
2586 // will incorrectly show at this point since we lost that
2587 // information. Not a big deal -- for the windows that have app
2588 // ops modifies they should only be hidden by policy due to the
2589 // lock screen, and the user won't be changing this if locked.
2590 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002591 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002592 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002593 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002594 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002595 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002596 }
2597
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002598 public void hidePermanentlyLw() {
2599 if (!mPermanentlyHidden) {
2600 mPermanentlyHidden = true;
2601 hideLw(true, true);
2602 }
2603 }
2604
Jeff Brownc2932a12014-11-20 18:04:05 -08002605 public void pokeDrawLockLw(long timeout) {
2606 if (isVisibleOrAdding()) {
2607 if (mDrawLock == null) {
2608 // We want the tag name to be somewhat stable so that it is easier to correlate
2609 // in wake lock statistics. So in particular, we don't want to include the
2610 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002611 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002612 mDrawLock = mService.mPowerManager.newWakeLock(
2613 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2614 mDrawLock.setReferenceCounted(false);
2615 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2616 }
2617 // Each call to acquire resets the timeout.
2618 if (DEBUG_POWER) {
2619 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2620 + mAttrs.packageName);
2621 }
2622 mDrawLock.acquire(timeout);
2623 } else if (DEBUG_POWER) {
2624 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2625 + "owned by " + mAttrs.packageName);
2626 }
2627 }
2628
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002629 @Override
2630 public boolean isAlive() {
2631 return mClient.asBinder().isBinderAlive();
2632 }
2633
Craig Mautnera987d432012-10-11 14:07:58 -07002634 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002635 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002636 }
2637
Chong Zhangbef461f2015-10-27 11:38:24 -07002638 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002639 return mAnimatingWithSavedSurface;
2640 }
2641
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002642 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002643 boolean isAnimating() {
2644 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2645 return true;
2646 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002647 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002648 }
2649
Chong Zhang8e4bda92016-05-04 15:08:18 -07002650 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002651 if (mAnimatingWithSavedSurface
2652 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2653 return true;
2654 }
2655 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002656 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002657 if (c.isAnimatingInvisibleWithSavedSurface()) {
2658 return true;
2659 }
2660 }
2661 return false;
2662 }
2663
2664 void stopUsingSavedSurface() {
2665 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002666 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002667 c.stopUsingSavedSurface();
2668 }
2669
2670 if (!isAnimatingInvisibleWithSavedSurface()) {
2671 return;
2672 }
2673
2674 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2675 clearAnimatingWithSavedSurface();
2676 mDestroying = true;
2677 mWinAnimator.hide("stopUsingSavedSurface");
Wale Ogunwale0303c572016-10-20 10:16:29 -07002678 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002679 }
2680
2681 void markSavedSurfaceExiting() {
2682 if (isAnimatingInvisibleWithSavedSurface()) {
2683 mAnimatingExit = true;
2684 mWinAnimator.mAnimating = true;
2685 }
2686 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002687 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002688 c.markSavedSurfaceExiting();
2689 }
2690 }
2691
2692 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2693 animators.add(mWinAnimator);
2694
2695 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002696 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002697 c.addWinAnimatorToList(animators);
2698 }
2699 }
2700
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002701 void sendAppVisibilityToClients() {
2702 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002703
Wale Ogunwale89973222017-04-23 18:39:45 -07002704 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002705 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2706 // Don't hide the starting window.
2707 return;
2708 }
2709
Wale Ogunwale89973222017-04-23 18:39:45 -07002710 if (clientHidden) {
2711 // Once we are notifying the client that it's visibility has changed, we need to prevent
2712 // it from destroying child surfaces until the animation has finished. We do this by
2713 // detaching any surface control the client added from the client.
2714 for (int i = mChildren.size() - 1; i >= 0; --i) {
2715 final WindowState c = mChildren.get(i);
2716 c.mWinAnimator.detachChildren();
2717 }
2718
2719 mWinAnimator.detachChildren();
2720 }
2721
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002722 try {
2723 if (DEBUG_VISIBILITY) Slog.v(TAG,
2724 "Setting visibility of " + this + ": " + (!clientHidden));
2725 mClient.dispatchAppVisibility(!clientHidden);
2726 } catch (RemoteException e) {
2727 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002728 }
2729
Chong Zhang92147042016-05-09 12:47:11 -07002730 public void setVisibleBeforeClientHidden() {
2731 mWasVisibleBeforeClientHidden |=
2732 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002733
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002734 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002735 }
2736
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002737 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002738 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002739 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002740 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002741 c.clearWasVisibleBeforeClientHidden();
2742 }
Chong Zhang92147042016-05-09 12:47:11 -07002743 }
2744
2745 public boolean wasVisibleBeforeClientHidden() {
2746 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002747 }
2748
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002749 void onStartFreezingScreen() {
2750 mAppFreezing = true;
2751 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002752 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002753 c.onStartFreezingScreen();
2754 }
2755 }
2756
2757 boolean onStopFreezingScreen() {
2758 boolean unfrozeWindows = false;
2759 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002760 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002761 unfrozeWindows |= c.onStopFreezingScreen();
2762 }
2763
2764 if (!mAppFreezing) {
2765 return unfrozeWindows;
2766 }
2767
Wale Ogunwale953171d2016-09-30 09:17:30 -07002768 mAppFreezing = false;
2769
Bryce Lee8c3cf382017-07-06 19:47:10 -07002770 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002771 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2772 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002773 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002774 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002775 }
2776 mLastFreezeDuration = 0;
2777 setDisplayLayoutNeeded();
2778 return true;
2779 }
2780
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002781 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002782 if (mWinAnimator.mSurfaceController == null) {
2783 // Don't bother if the surface controller is gone for any reason.
2784 return false;
2785 }
2786
Chong Zhang92147042016-05-09 12:47:11 -07002787 if (!mWasVisibleBeforeClientHidden) {
2788 return false;
2789 }
2790
Wale Ogunwale945d1972016-03-23 13:16:41 -07002791 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2792 // We don't save secure surfaces since their content shouldn't be shown while the app
2793 // isn't on screen and content might leak through during the transition animation with
2794 // saved surface.
2795 return false;
2796 }
2797
Jorim Jaggi02886a82016-12-06 09:10:06 -08002798 if (isLowRamDeviceStatic()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002799 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002800 return false;
2801 }
2802
Jorim Jaggiab7ad382016-10-26 18:22:04 -07002803 final Task task = getTask();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002804 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2805 if (taskTop != null && taskTop != mAppToken) {
2806 // Don't save if the window is not the topmost window.
2807 return false;
2808 }
2809
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002810 if (mResizedWhileGone) {
2811 // Somebody resized our window while we were gone for layout, which means that the
2812 // client got an old size, so we have an outdated surface here.
2813 return false;
2814 }
2815
Robert Carr7098dbd2016-02-01 12:31:01 -08002816 if (DEBUG_DISABLE_SAVING_SURFACES) {
2817 return false;
2818 }
2819
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002820 return mAppToken.shouldSaveSurface();
2821 }
2822
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002823 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2824 boolean destroyedSomething = false;
2825 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002826 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002827 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2828 }
2829
Robert Carrdb2f6e62017-03-01 20:17:58 -08002830 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2831 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002832 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002833
2834 if (appStopped || mWindowRemovalAllowed) {
2835 mWinAnimator.destroyPreservedSurfaceLocked();
2836 }
2837
2838 if (mDestroying) {
2839 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2840 + " destroySurfaces: appStopped=" + appStopped
2841 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2842 + " win.mRemoveOnExit=" + mRemoveOnExit);
2843 if (!cleanupOnResume || mRemoveOnExit) {
Robert Carr89a28ab2017-04-24 15:33:11 -07002844 destroyOrSaveSurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002845 }
2846 if (mRemoveOnExit) {
2847 removeImmediately();
2848 }
2849 if (cleanupOnResume) {
2850 requestUpdateWallpaperIfNeeded();
2851 }
2852 mDestroying = false;
2853 destroyedSomething = true;
2854 }
2855
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002856 return destroyedSomething;
2857 }
Chris Craik3131bde2016-05-06 13:39:08 -07002858
Robert Carr89a28ab2017-04-24 15:33:11 -07002859 // Destroy or save the application surface without checking
2860 // various indicators of whether the client has released the surface.
2861 // This is in general unsafe, and most callers should use {@link #destroySurface}
2862 void destroyOrSaveSurfaceUnchecked() {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002863 mSurfaceSaved = shouldSaveSurface();
2864 if (mSurfaceSaved) {
2865 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2866 Slog.v(TAG, "Saving surface: " + this);
2867 }
Chris Craik3131bde2016-05-06 13:39:08 -07002868 // Previous user of the surface may have set a transparent region signaling a portion
2869 // doesn't need to be composited, so reset to default empty state.
2870 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002871
2872 mWinAnimator.hide("saved surface");
2873 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2874 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002875 // The client should have disconnected at this point, but if it doesn't,
2876 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2877 // the client can't reconnect to the buffer queue, and rendering will fail.
2878 if (mWinAnimator.mSurfaceController != null) {
2879 mWinAnimator.mSurfaceController.disconnectInTransaction();
2880 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002881 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002882 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002883 mWinAnimator.destroySurfaceLocked();
2884 }
Chong Zhang92147042016-05-09 12:47:11 -07002885 // Clear animating flags now, since the surface is now gone. (Note this is true even
2886 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2887 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002888 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002889
Chong Zhang92147042016-05-09 12:47:11 -07002890 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002891 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002892 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002893 c.destroySavedSurface();
2894 }
2895
Robert Carr13f7be9e2015-12-02 18:39:45 -08002896 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002897 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002898 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002899 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002900 }
Chong Zhang92147042016-05-09 12:47:11 -07002901 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002902 }
2903
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002904 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2905 int restoreSavedSurfaceForInterestingWindow() {
2906 int interestingNotDrawn = -1;
2907 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002908 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002909 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2910 if (childInterestingNotDrawn != -1) {
2911 if (interestingNotDrawn == -1) {
2912 interestingNotDrawn = childInterestingNotDrawn;
2913 } else {
2914 interestingNotDrawn += childInterestingNotDrawn;
2915 }
2916 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002917 }
Robert Carr237028a2016-07-26 10:39:45 -07002918
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002919 if (mAttrs.type == TYPE_APPLICATION_STARTING
2920 || mAppDied || !wasVisibleBeforeClientHidden()
2921 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2922 // Window isn't interesting...
2923 return interestingNotDrawn;
2924 }
2925
2926 restoreSavedSurface();
2927
2928 if (!isDrawnLw()) {
2929 if (interestingNotDrawn == -1) {
2930 interestingNotDrawn = 1;
2931 } else {
2932 interestingNotDrawn++;
2933 }
2934 }
2935 return interestingNotDrawn;
2936 }
2937
2938 /** Returns true if the saved surface was restored. */
2939 boolean restoreSavedSurface() {
2940 if (!mSurfaceSaved) {
2941 return false;
2942 }
2943
2944 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2945 // However this means the surface was never laid out in the new orientation.
2946 // We can only restore to the last rotation we were laid out as visible in.
Andrii Kulian8ee72852017-03-10 10:36:45 -08002947 if (mLastVisibleLayoutRotation != getDisplayContent().getRotation()) {
Robert Carr237028a2016-07-26 10:39:45 -07002948 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002949 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002950 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002951 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002952
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002953 if (mWinAnimator.mSurfaceController != null) {
2954 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002955 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002956 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002957
Chong Zhang6e9872b2016-08-17 10:19:05 -07002958 requestUpdateWallpaperIfNeeded();
2959
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002960 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2961 Slog.v(TAG, "Restoring saved surface: " + this);
2962 }
2963 } else {
2964 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2965 // this point. Even if we destroyed the saved surface because of rotation
2966 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2967 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002968 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002969
2970 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002971 }
2972
Chong Zhang92147042016-05-09 12:47:11 -07002973 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002974 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2975 return true;
2976 }
2977
2978 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002979 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002980 if (c.canRestoreSurface()) {
2981 return true;
2982 }
2983 }
2984
2985 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002986 }
2987
2988 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002989 return mSurfaceSaved;
2990 }
2991
Chong Zhang92147042016-05-09 12:47:11 -07002992 void clearHasSavedSurface() {
2993 mSurfaceSaved = false;
2994 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002995 if (mWasVisibleBeforeClientHidden) {
2996 mAppToken.destroySavedSurfaces();
2997 }
Chong Zhang92147042016-05-09 12:47:11 -07002998 }
2999
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07003000 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07003001 if (mAnimatingWithSavedSurface) {
3002 // App has drawn something to its windows, we're no longer animating with
3003 // the saved surfaces.
3004 if (DEBUG_ANIM) Slog.d(TAG,
3005 "clearAnimatingWithSavedSurface(): win=" + this);
3006 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07003007 return true;
Chong Zhang92147042016-05-09 12:47:11 -07003008 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07003009 return false;
Chong Zhang92147042016-05-09 12:47:11 -07003010 }
3011
Craig Mautner69b08182012-09-05 13:07:13 -07003012 @Override
3013 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003014 final DisplayContent displayContent = getDisplayContent();
3015 if (displayContent == null) {
3016 // Only a window that was on a non-default display can be detached from it.
3017 return false;
3018 }
Winson Chung47a3e652014-05-21 16:03:42 -07003019 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07003020 }
3021
Adrian Rooscd3884d2015-02-18 17:25:23 +01003022 @Override
3023 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07003024 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003025 final DisplayContent dc = getDisplayContent();
3026 return dimLayerUser != null && dc != null
3027 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01003028 }
3029
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003030 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07003031 mShowToOwnerOnly = showToOwnerOnly;
3032 }
3033
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003034 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003035 // Child windows are evaluated based on their parent window.
3036 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003037 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08003038 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07003039
3040 // All window frames that are fullscreen extend above status bar, but some don't extend
3041 // below navigation bar. Thus, check for display frame for top/left and stable frame for
3042 // bottom right.
3043 if (win.mFrame.left <= win.mDisplayFrame.left
3044 && win.mFrame.top <= win.mDisplayFrame.top
3045 && win.mFrame.right >= win.mStableFrame.right
3046 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07003047 // Is a fullscreen window, like the clock alarm. Show to everyone.
3048 return false;
3049 }
3050 }
3051
Craig Mautner341220f2012-10-16 15:20:09 -07003052 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01003053 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07003054 }
3055
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003056 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
3057 outRegion.set(
3058 frame.left + inset.left, frame.top + inset.top,
3059 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04003060 }
3061
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003062 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003063 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003064 switch (mTouchableInsets) {
3065 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003066 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003067 outRegion.set(frame);
3068 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003069 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003070 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003071 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003072 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003073 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003074 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003075 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003076 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003077 outRegion.translate(frame.left, frame.top);
3078 break;
3079 }
3080 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003081 cropRegionToStackBoundsIfNeeded(outRegion);
3082 }
3083
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003084 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003085 final Task task = getTask();
3086 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003087 return;
3088 }
3089
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003090 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003091 if (stack == null) {
3092 return;
3093 }
3094
3095 stack.getDimBounds(mTmpRect);
3096 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003097 }
3098
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003099 /**
3100 * Report a focus change. Must be called with no locks held, and consistently
3101 * from the same serialized thread (such as dispatched from a handler).
3102 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003103 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003104 try {
3105 mClient.windowFocusChanged(focused, inTouchMode);
3106 } catch (RemoteException e) {
3107 }
3108 if (mFocusCallbacks != null) {
3109 final int N = mFocusCallbacks.beginBroadcast();
3110 for (int i=0; i<N; i++) {
3111 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
3112 try {
3113 if (focused) {
3114 obs.focusGained(mWindowId.asBinder());
3115 } else {
3116 obs.focusLost(mWindowId.asBinder());
3117 }
3118 } catch (RemoteException e) {
3119 }
3120 }
3121 mFocusCallbacks.finishBroadcast();
3122 }
3123 }
3124
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003125 @Override
3126 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003127 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003128 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003129 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003130
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003131 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003132 }
3133
Craig Mautnerdf88d732014-01-27 09:21:32 -08003134 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003135 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003136 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003137 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3138 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07003139 final MergedConfiguration mergedConfiguration =
3140 new MergedConfiguration(mService.mRoot.getConfiguration(),
3141 getMergedOverrideConfiguration());
3142
3143 setReportedConfiguration(mergedConfiguration);
3144
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003145 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003146 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3147
Craig Mautnerdf88d732014-01-27 09:21:32 -08003148 final Rect frame = mFrame;
3149 final Rect overscanInsets = mLastOverscanInsets;
3150 final Rect contentInsets = mLastContentInsets;
3151 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003152 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003153 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003154 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003155 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003156 final int displayId = getDisplayId();
Chet Haase8eb48d22014-09-24 07:31:29 -07003157 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3158 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003159 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3160 mService.mH.post(new Runnable() {
3161 @Override
3162 public void run() {
3163 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003164 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003165 stableInsets, outsets, reportDraw, mergedConfiguration,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003166 reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003167 } catch (RemoteException e) {
3168 // Not a remote call, RemoteException won't be raised.
3169 }
3170 }
3171 });
3172 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003173 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003174 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003175 }
Svetoslav4604abc2014-06-10 18:59:30 -07003176
3177 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003178 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003179 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003180 }
3181
Craig Mautnerdf88d732014-01-27 09:21:32 -08003182 mOverscanInsetsChanged = false;
3183 mContentInsetsChanged = false;
3184 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003185 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003186 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003187 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003188 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003189 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003190 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003191 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003192 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003193 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3194 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003195 // We are assuming the hosting process is dead or in a zombie state.
3196 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3197 + ", removing this window.");
3198 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003199 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003200 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003201 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003202 }
3203
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003204 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003205 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3206 // start even if we haven't received the relayout window, so that the client requests
3207 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3208 // until the window to small size, otherwise the multithread renderer will shift last
3209 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3210 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003211 boolean resizing = isDragResizing() || isDragResizeChanged();
3212 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3213 return frame;
3214 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003215 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003216 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003217 return mTmpRect;
3218 }
3219
Jorim Jaggi86905582016-02-09 21:36:09 -08003220 @Override
3221 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003222 final TaskStack stack = getStack();
3223 if (stack == null) {
3224 return INVALID_STACK_ID;
3225 }
3226 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003227 }
3228
3229 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3230 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Andrii Kulian44607962017-03-16 11:06:24 -07003231 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003232 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08003233 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
3234 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003235
Jorim Jaggidc249c42015-12-15 14:57:31 -08003236 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003237 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
3238 mPolicy.isNavBarForcedShownLw(this), displayId);
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003239 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003240 }
3241
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003242 public void registerFocusObserver(IWindowFocusObserver observer) {
3243 synchronized(mService.mWindowMap) {
3244 if (mFocusCallbacks == null) {
3245 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3246 }
3247 mFocusCallbacks.register(observer);
3248 }
3249 }
3250
3251 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3252 synchronized(mService.mWindowMap) {
3253 if (mFocusCallbacks != null) {
3254 mFocusCallbacks.unregister(observer);
3255 }
3256 }
3257 }
3258
3259 public boolean isFocused() {
3260 synchronized(mService.mWindowMap) {
3261 return mService.mCurrentFocus == this;
3262 }
3263 }
3264
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003265 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003266 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003267 return task != null && task.inFreeformWorkspace();
3268 }
3269
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003270 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003271 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003272 final Task task = getTask();
3273 return task != null && !task.isFullscreen();
3274 }
3275
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003276 /** Is this window in a container that takes up the entire screen space? */
3277 private boolean inFullscreenContainer() {
3278 if (mAppToken == null) {
3279 return true;
3280 }
3281 if (mAppToken.hasBounds()) {
3282 return false;
3283 }
3284 return !isInMultiWindowMode();
3285 }
3286
Andrii Kulian283acd22017-08-03 04:03:51 -07003287 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3288 boolean isLetterboxedAppWindow() {
3289 final Task task = getTask();
3290 final boolean taskIsFullscreen = task != null && task.isFullscreen();
3291 final boolean appWindowIsFullscreen = mAppToken != null && !mAppToken.hasBounds();
3292
3293 return taskIsFullscreen && !appWindowIsFullscreen;
3294 }
3295
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003296 /** Returns the appropriate bounds to use for computing frames. */
3297 private void getContainerBounds(Rect outBounds) {
3298 if (isInMultiWindowMode()) {
3299 getTask().getBounds(outBounds);
3300 } else if (mAppToken != null){
3301 mAppToken.getBounds(outBounds);
3302 } else {
3303 outBounds.setEmpty();
3304 }
3305 }
3306
Chong Zhang3005e752015-09-18 18:46:28 -07003307 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003308 return mDragResizing != computeDragResizing();
3309 }
3310
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003311 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003312 void setWaitingForDrawnIfResizingChanged() {
3313 if (isDragResizeChanged()) {
3314 mService.mWaitingForDrawn.add(this);
3315 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003316 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003317 }
3318
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003319 /**
3320 * @return Whether we reported a drag resize change to the application or not already.
3321 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003322 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003323 return mDragResizingChangeReported;
3324 }
3325
3326 /**
3327 * Resets the state whether we reported a drag resize change to the app.
3328 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003329 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003330 void resetDragResizingChangeReported() {
3331 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003332 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003333 }
3334
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003335 /**
3336 * Set whether we got resized but drag resizing flag was false.
3337 * @see #isResizedWhileNotDragResizing().
3338 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003339 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003340 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3341 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3342 }
3343
3344 /**
3345 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3346 * need to recreate the surface and defer surface bound updates in order to make sure the
3347 * buffer contents and the positioning/size stay in sync.
3348 */
3349 boolean isResizedWhileNotDragResizing() {
3350 return mResizedWhileNotDragResizing;
3351 }
3352
3353 /**
3354 * @return Whether we reported "resize while not drag resizing" to the application.
3355 * @see #isResizedWhileNotDragResizing()
3356 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003357 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003358 return mResizedWhileNotDragResizingReported;
3359 }
3360
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003361 int getResizeMode() {
3362 return mResizeMode;
3363 }
3364
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003365 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003366 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003367 if (task == null) {
3368 return false;
3369 }
Winson Chung2af04b32017-01-24 16:21:13 -08003370 if (!StackId.isStackAffectedByDragResizing(getStackId())) {
3371 return false;
3372 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003373 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003374 // Floating windows never enter drag resize mode.
3375 return false;
3376 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003377 if (task.isDragResizing()) {
3378 return true;
3379 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003380
3381 // If the bounds are currently frozen, it means that the layout size that the app sees
3382 // and the bounds we clip this window to might be different. In order to avoid holes, we
3383 // simulate that we are still resizing so the app fills the hole with the resizing
3384 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003385 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003386 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003387 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003388
Chong Zhang3005e752015-09-18 18:46:28 -07003389 }
3390
3391 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003392 final boolean resizing = computeDragResizing();
3393 if (resizing == mDragResizing) {
3394 return;
3395 }
3396 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003397 final Task task = getTask();
3398 if (task != null && task.isDragResizing()) {
3399 mResizeMode = task.getDragResizeMode();
3400 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003401 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003402 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3403 : DRAG_RESIZE_MODE_FREEFORM;
3404 }
Chong Zhang3005e752015-09-18 18:46:28 -07003405 }
3406
3407 boolean isDragResizing() {
3408 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003409 }
3410
Robert Carr2487ce72016-04-07 15:18:45 -07003411 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003412 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3413 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003414 }
3415
Steven Timotiusaf03df62017-07-18 16:56:43 -07003416 void writeToProto(ProtoOutputStream proto, long fieldId) {
3417 final long token = proto.start(fieldId);
3418 writeIdentifierToProto(proto, IDENTIFIER);
3419 proto.write(DISPLAY_ID, getDisplayId());
3420 proto.write(STACK_ID, getStackId());
3421 mAttrs.writeToProto(proto, ATTRIBUTES);
3422 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3423 mFrame.writeToProto(proto, FRAME);
3424 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3425 mParentFrame.writeToProto(proto, PARENT_FRAME);
3426 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3427 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3428 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
3429 mWinAnimator.writeToProto(proto, ANIMATOR);
3430 proto.write(ANIMATING_EXIT, mAnimatingExit);
3431 for (int i = 0; i < mChildren.size(); i++) {
3432 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS);
3433 }
3434 proto.end(token);
3435 }
3436
3437 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
3438 final long token = proto.start(fieldId);
3439 proto.write(HASH_CODE, System.identityHashCode(this));
3440 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3441 final CharSequence title = getWindowTag();
3442 if (title != null) {
3443 proto.write(TITLE, title.toString());
3444 }
3445 proto.end(token);
3446 }
3447
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003448 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003449 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003450 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003451 if (stack != null) {
3452 pw.print(" stackId="); pw.print(stack.mStackId);
3453 }
Craig Mautner59c00972012-07-30 12:10:24 -07003454 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003455 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003456 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003457 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3458 pw.print(" package="); pw.print(mAttrs.packageName);
3459 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003460 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003461 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3462 pw.print(" h="); pw.print(mRequestedHeight);
3463 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003464 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3465 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3466 pw.print(" h="); pw.println(mLastRequestedHeight);
3467 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003468 if (mIsChildWindow || mLayoutAttached) {
3469 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003470 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3471 }
3472 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3473 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3474 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3475 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3476 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3477 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003478 if (dumpAll) {
3479 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3480 pw.print(" mSubLayer="); pw.print(mSubLayer);
3481 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003482 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003483 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3484 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003485 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003486 if (dumpAll) {
3487 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003488 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003489 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3490 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003491 pw.print(isAnimatingWithSavedSurface());
Bryce Lee6311c4b2017-07-06 14:09:29 -07003492 pw.print(" mAppDied=");pw.print(mAppDied);
3493 pw.print(prefix); pw.print("drawnStateEvaluated=");
3494 pw.print(getDrawnStateEvaluated());
3495 pw.print(prefix); pw.print("mightAffectAllDrawn=");
3496 pw.println(mightAffectAllDrawn(false /*visibleOnly*/));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003497 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003498 pw.print(prefix); pw.print("mViewVisibility=0x");
3499 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003500 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3501 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003502 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3503 pw.print(" mSystemUiVisibility=0x");
3504 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003505 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003506 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003507 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003508 pw.print(prefix); pw.print("mPolicyVisibility=");
3509 pw.print(mPolicyVisibility);
3510 pw.print(" mPolicyVisibilityAfterAnim=");
3511 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003512 pw.print(" mAppOpVisibility=");
3513 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003514 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003515 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
3516 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3517 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003518 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003519 if (!mRelayoutCalled || mLayoutNeeded) {
3520 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3521 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003522 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003523 if (mXOffset != 0 || mYOffset != 0) {
3524 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3525 pw.print(" y="); pw.println(mYOffset);
3526 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003527 if (dumpAll) {
3528 pw.print(prefix); pw.print("mGivenContentInsets=");
3529 mGivenContentInsets.printShortString(pw);
3530 pw.print(" mGivenVisibleInsets=");
3531 mGivenVisibleInsets.printShortString(pw);
3532 pw.println();
3533 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3534 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3535 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003536 Region region = new Region();
3537 getTouchableRegion(region);
3538 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003539 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003540 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3541 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3542 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003543 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003544 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003545 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003546 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003547 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3548 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003549 if (dumpAll) {
3550 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3551 pw.print(" last="); mLastFrame.printShortString(pw);
3552 pw.println();
3553 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003554 if (mEnforceSizeCompat) {
3555 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003556 pw.println();
3557 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003558 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003559 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003560 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003561 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003562 pw.println();
3563 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3564 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003565 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003566 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003567 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003568 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003569 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3570 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003571 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3572 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003573 pw.print(prefix); pw.print("Cur insets: overscan=");
3574 mOverscanInsets.printShortString(pw);
3575 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003576 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003577 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003578 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003579 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003580 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003581 pw.print(prefix); pw.print("Lst insets: overscan=");
3582 mLastOverscanInsets.printShortString(pw);
3583 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003584 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003585 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003586 pw.print(" physical="); mLastOutsets.printShortString(pw);
3587 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003588 pw.println();
3589 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003590 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3591 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003592 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3593 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003594 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3595 pw.print(" mDestroying="); pw.print(mDestroying);
3596 pw.print(" mRemoved="); pw.println(mRemoved);
3597 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003598 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003599 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003600 pw.print(prefix); pw.print("mOrientationChanging=");
3601 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003602 pw.print(" configOrientationChanging=");
3603 pw.print(mLastReportedConfiguration.orientation
3604 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003605 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003606 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003607 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003608 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003609 if (mLastFreezeDuration != 0) {
3610 pw.print(prefix); pw.print("mLastFreezeDuration=");
3611 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3612 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003613 if (mHScale != 1 || mVScale != 1) {
3614 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3615 pw.print(" mVScale="); pw.println(mVScale);
3616 }
3617 if (mWallpaperX != -1 || mWallpaperY != -1) {
3618 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3619 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3620 }
3621 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3622 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3623 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3624 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003625 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3626 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3627 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3628 pw.print(mWallpaperDisplayOffsetX);
3629 pw.print(" mWallpaperDisplayOffsetY=");
3630 pw.println(mWallpaperDisplayOffsetY);
3631 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003632 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003633 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003634 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003635 if (isDragResizing()) {
3636 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3637 }
3638 if (computeDragResizing()) {
3639 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3640 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003641 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3642 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003643 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003644
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003645 @Override
3646 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003647 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003648 + " " + getWindowTag();
3649 }
3650
Robert Carra1eb4392015-12-10 12:43:51 -08003651 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003652 CharSequence tag = mAttrs.getTitle();
3653 if (tag == null || tag.length() <= 0) {
3654 tag = mAttrs.packageName;
3655 }
3656 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003657 }
3658
3659 @Override
3660 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003661 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003662 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003663 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003664 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003665 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003666 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003667 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003668 }
3669 return mStringNameCache;
3670 }
Robert Carr58f29132015-10-29 14:19:05 -07003671
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003672 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003673 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003674 clipRect.left = (int) (clipRect.left / mHScale);
3675 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003676 }
3677 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003678 clipRect.top = (int) (clipRect.top / mVScale);
3679 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003680 }
3681 }
Robert Carr31e28482015-12-02 16:53:18 -08003682
Jorim Jaggif5834272016-04-04 20:25:41 -07003683 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3684 final int pw = containingFrame.width();
3685 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003686 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003687 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003688 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3689
3690 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003691 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3692 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003693 // 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 -07003694 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3695 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3696 // the display.
3697 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003698 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003699 float x, y;
3700 int w,h;
3701
3702 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3703 if (mAttrs.width < 0) {
3704 w = pw;
3705 } else if (mEnforceSizeCompat) {
3706 w = (int)(mAttrs.width * mGlobalScale + .5f);
3707 } else {
3708 w = mAttrs.width;
3709 }
3710 if (mAttrs.height < 0) {
3711 h = ph;
3712 } else if (mEnforceSizeCompat) {
3713 h = (int)(mAttrs.height * mGlobalScale + .5f);
3714 } else {
3715 h = mAttrs.height;
3716 }
3717 } else {
3718 if (mAttrs.width == MATCH_PARENT) {
3719 w = pw;
3720 } else if (mEnforceSizeCompat) {
3721 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3722 } else {
3723 w = mRequestedWidth;
3724 }
3725 if (mAttrs.height == MATCH_PARENT) {
3726 h = ph;
3727 } else if (mEnforceSizeCompat) {
3728 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3729 } else {
3730 h = mRequestedHeight;
3731 }
3732 }
3733
3734 if (mEnforceSizeCompat) {
3735 x = mAttrs.x * mGlobalScale;
3736 y = mAttrs.y * mGlobalScale;
3737 } else {
3738 x = mAttrs.x;
3739 y = mAttrs.y;
3740 }
3741
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003742 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003743 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003744 // required by {@link Gravity#apply} call.
3745 w = Math.min(w, pw);
3746 h = Math.min(h, ph);
3747 }
3748
3749 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003750 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003751 (int) (x + mAttrs.horizontalMargin * pw),
3752 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3753
3754 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003755 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003756 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003757 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003758
3759 // We need to make sure we update the CompatFrame as it is used for
3760 // cropping decisions, etc, on systems where we lack a decor layer.
3761 mCompatFrame.set(mFrame);
3762 if (mEnforceSizeCompat) {
3763 // See comparable block in computeFrameLw.
3764 mCompatFrame.scale(mInvGlobalScale);
3765 }
Robert Carr31e28482015-12-02 16:53:18 -08003766 }
Robert Carr51a1b872015-12-08 14:03:13 -08003767
3768 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003769 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003770 }
3771
Robert Carrf3b72c72016-03-21 18:16:39 -07003772 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003773 return mIsChildWindow
3774 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003775 }
3776
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003777 /**
3778 * Returns true if any window added by an application process that if of type
3779 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3780 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3781 * this window is visible.
3782 */
3783 boolean hideNonSystemOverlayWindowsWhenVisible() {
3784 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3785 && mSession.mCanHideNonSystemOverlayWindows;
3786 }
3787
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003788 /** Returns the parent window if this is a child of another window, else null. */
3789 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003790 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3791 // WindowContainer that isn't a WindowState.
3792 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003793 }
3794
3795 /** Returns the topmost parent window if this is a child of another window, else this. */
3796 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003797 WindowState current = this;
3798 WindowState topParent = current;
3799 while (current != null && current.mIsChildWindow) {
3800 current = current.getParentWindow();
3801 // Parent window can be null if the child is detached from it's parent already, but
3802 // someone still has a reference to access it. So, we return the top parent value we
3803 // already have instead of null.
3804 if (current != null) {
3805 topParent = current;
3806 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003807 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003808 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003809 }
3810
Wale Ogunwale9d147902016-07-16 11:58:55 -07003811 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003812 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003813 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003814 }
3815
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003816 void setWillReplaceWindow(boolean animate) {
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.setWillReplaceWindow(animate);
3820 }
3821
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003822 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3823 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3824 // We don't set replacing on starting windows since they are added by window manager and
3825 // not the client so won't be replaced by the client.
3826 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003827 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003828
3829 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003830 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003831 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003832 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003833
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003834 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003835 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003836 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003837 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003838
3839 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003840 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003841 c.clearWillReplaceWindow();
3842 }
3843 }
3844
3845 boolean waitingForReplacement() {
3846 if (mWillReplaceWindow) {
3847 return true;
3848 }
3849
3850 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003851 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003852 if (c.waitingForReplacement()) {
3853 return true;
3854 }
3855 }
3856 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003857 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003858
Chong Zhang4d7369a2016-04-25 16:09:14 -07003859 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003860 final DisplayContent dc = getDisplayContent();
3861 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3862 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3863 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003864 mService.mWindowPlacerLocked.requestTraversal();
3865 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003866
3867 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003868 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003869 c.requestUpdateWallpaperIfNeeded();
3870 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003871 }
3872
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003873 float translateToWindowX(float x) {
3874 float winX = x - mFrame.left;
3875 if (mEnforceSizeCompat) {
3876 winX *= mGlobalScale;
3877 }
3878 return winX;
3879 }
3880
3881 float translateToWindowY(float y) {
3882 float winY = y - mFrame.top;
3883 if (mEnforceSizeCompat) {
3884 winY *= mGlobalScale;
3885 }
3886 return winY;
3887 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003888
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003889 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003890 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003891 final DisplayContent dc = getDisplayContent();
3892 if (dimLayerUser != null && dc != null) {
3893 dc.mDimLayerController.applyDim(dimLayerUser,
3894 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003895 }
3896 }
3897
Robert Carrd1a010f2016-04-07 22:36:22 -07003898 // During activity relaunch due to resize, we sometimes use window replacement
3899 // for only child windows (as the main window is handled by window preservation)
3900 // and the big surface.
3901 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003902 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3903 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3904 // we also want to replace them at such phases, as they won't be covered by window
3905 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003906 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003907 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003908 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003909 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003910
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003911 void setWillReplaceChildWindows() {
3912 if (shouldBeReplacedWithChildren()) {
3913 setWillReplaceWindow(false /* animate */);
3914 }
3915 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003916 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003917 c.setWillReplaceChildWindows();
3918 }
3919 }
3920
3921 WindowState getReplacingWindow() {
3922 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3923 return this;
3924 }
3925 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003926 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003927 final WindowState replacing = c.getReplacingWindow();
3928 if (replacing != null) {
3929 return replacing;
3930 }
3931 }
3932 return null;
3933 }
3934
Jorim Jaggife762342016-10-13 14:33:27 +02003935 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003936 public int getRotationAnimationHint() {
3937 if (mAppToken != null) {
3938 return mAppToken.mRotationAnimationHint;
3939 } else {
3940 return -1;
3941 }
3942 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003943
Jorim Jaggife762342016-10-13 14:33:27 +02003944 @Override
3945 public boolean isInputMethodWindow() {
3946 return mIsImWindow;
3947 }
3948
Wale Ogunwale9d147902016-07-16 11:58:55 -07003949 // This must be called while inside a transaction.
3950 boolean performShowLocked() {
3951 if (isHiddenFromUserLocked()) {
3952 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3953 hideLw(false);
3954 return false;
3955 }
3956
3957 logPerformShow("performShow on ");
3958
Jorim Jaggia50da602016-12-29 11:51:42 +01003959 final int drawState = mWinAnimator.mDrawState;
3960 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3961 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3962 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3963 }
3964
Jorim Jaggib0d27342016-11-01 16:10:42 -07003965 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003966 return false;
3967 }
3968
3969 logPerformShow("Showing ");
3970
3971 mService.enableScreenIfNeededLocked();
3972 mWinAnimator.applyEnterAnimationLocked();
3973
3974 // Force the show in the next prepareSurfaceLocked() call.
3975 mWinAnimator.mLastAlpha = -1;
3976 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3977 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3978 mWinAnimator.mDrawState = HAS_DRAWN;
3979 mService.scheduleAnimationLocked();
3980
3981 if (mHidden) {
3982 mHidden = false;
3983 final DisplayContent displayContent = getDisplayContent();
3984
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003985 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003986 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003987 if (c.mWinAnimator.mSurfaceController != null) {
3988 c.performShowLocked();
3989 // It hadn't been shown, which means layout not performed on it, so now we
3990 // want to make sure to do a layout. If called from within the transaction
3991 // loop, this will cause it to restart with a new layout.
3992 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003993 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003994 }
3995 }
3996 }
3997 }
3998
Wale Ogunwale9d147902016-07-16 11:58:55 -07003999 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07004000 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07004001 }
4002
4003 return true;
4004 }
4005
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07004006 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07004007 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02004008 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07004009 Slog.v(TAG, prefix + this
4010 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07004011 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07004012 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
4013 + " during animation: policyVis=" + mPolicyVisibility
4014 + " parentHidden=" + isParentWindowHidden()
4015 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07004016 + (mAppToken != null && mAppToken.hiddenRequested)
4017 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07004018 + " animating=" + mWinAnimator.mAnimating
4019 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07004020 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07004021 + " Callers=" + Debug.getCallers(4));
4022 }
4023 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004024
4025 WindowInfo getWindowInfo() {
4026 WindowInfo windowInfo = WindowInfo.obtain();
4027 windowInfo.type = mAttrs.type;
4028 windowInfo.layer = mLayer;
4029 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07004030 if (mAppToken != null) {
4031 windowInfo.activityToken = mAppToken.appToken.asBinder();
4032 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004033 windowInfo.title = mAttrs.accessibilityTitle;
4034 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
4035 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08004036 Task task = getTask();
4037 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWorkspace();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004038
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004039 if (mIsChildWindow) {
4040 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004041 }
4042
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004043 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004044 if (childCount > 0) {
4045 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004046 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004047 }
4048 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004049 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004050 windowInfo.childTokens.add(child.mClient.asBinder());
4051 }
4052 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004053 return windowInfo;
4054 }
4055
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004056 int getHighestAnimLayer() {
4057 int highest = mWinAnimator.mAnimLayer;
4058 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004059 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004060 final int childLayer = c.getHighestAnimLayer();
4061 if (childLayer > highest) {
4062 highest = childLayer;
4063 }
4064 }
4065 return highest;
4066 }
4067
Wale Ogunwale9adfe572016-09-08 20:43:58 -07004068 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004069 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004070 if (mChildren.isEmpty()) {
4071 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004072 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004073 }
4074
4075 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004076 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004077 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004078 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004079 }
4080 }
4081
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004082 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004083 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004084 // below the parent, then this window (the parent), and then the positive sublayer children
4085 // because they need to appear above the parent.
4086 int i = 0;
4087 final int count = mChildren.size();
4088 WindowState child = mChildren.get(i);
4089
4090 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004091 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004092 return true;
4093 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004094 i++;
4095 if (i >= count) {
4096 break;
4097 }
4098 child = mChildren.get(i);
4099 }
4100
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004101 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004102 return true;
4103 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004104
4105 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004106 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004107 return true;
4108 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004109 i++;
4110 if (i >= count) {
4111 break;
4112 }
4113 child = mChildren.get(i);
4114 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004115
4116 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004117 }
4118
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004119 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004120 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004121 // above the parent, then this window (the parent), and then the negative sublayer children
4122 // because they need to appear above the parent.
4123 int i = mChildren.size() - 1;
4124 WindowState child = mChildren.get(i);
4125
4126 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004127 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004128 return true;
4129 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004130 --i;
4131 if (i < 0) {
4132 break;
4133 }
4134 child = mChildren.get(i);
4135 }
4136
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004137 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004138 return true;
4139 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004140
4141 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004142 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004143 return true;
4144 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004145 --i;
4146 if (i < 0) {
4147 break;
4148 }
4149 child = mChildren.get(i);
4150 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004151
4152 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004153 }
4154
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004155 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4156 boolean traverseTopToBottom) {
4157 if (traverseTopToBottom) {
4158 if (mService.mInputMethodTarget == this) {
4159 // This window is the current IME target, so we need to process the IME windows
4160 // directly above it.
4161 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4162 return true;
4163 }
4164 }
4165 if (callback.apply(this)) {
4166 return true;
4167 }
4168 } else {
4169 if (callback.apply(this)) {
4170 return true;
4171 }
4172 if (mService.mInputMethodTarget == this) {
4173 // This window is the current IME target, so we need to process the IME windows
4174 // directly above it.
4175 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4176 return true;
4177 }
4178 }
4179 }
4180
4181 return false;
4182 }
4183
Wale Ogunwaled1880962016-11-08 10:31:59 -08004184 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004185 if (mChildren.isEmpty()) {
4186 return callback.test(this) ? this : null;
4187 }
4188
4189 // We want to consume the positive sublayer children first because they need to appear
4190 // above the parent, then this window (the parent), and then the negative sublayer children
4191 // because they need to appear above the parent.
4192 int i = mChildren.size() - 1;
4193 WindowState child = mChildren.get(i);
4194
4195 while (i >= 0 && child.mSubLayer >= 0) {
4196 if (callback.test(child)) {
4197 return child;
4198 }
4199 --i;
4200 if (i < 0) {
4201 break;
4202 }
4203 child = mChildren.get(i);
4204 }
4205
Wale Ogunwaled1880962016-11-08 10:31:59 -08004206 if (callback.test(this)) {
4207 return this;
4208 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004209
4210 while (i >= 0) {
4211 if (callback.test(child)) {
4212 return child;
4213 }
4214 --i;
4215 if (i < 0) {
4216 break;
4217 }
4218 child = mChildren.get(i);
4219 }
4220
4221 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004222 }
4223
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004224 boolean isWindowAnimationSet() {
4225 if (mWinAnimator.isWindowAnimationSet()) {
4226 return true;
4227 }
4228 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004229 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004230 if (c.isWindowAnimationSet()) {
4231 return true;
4232 }
4233 }
4234 return false;
4235 }
4236
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004237 void onExitAnimationDone() {
4238 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4239 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
4240 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
4241
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004242 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004243 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004244 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004245 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004246 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004247 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004248 }
4249 }
4250
4251 if (mWinAnimator.mEnteringAnimation) {
4252 mWinAnimator.mEnteringAnimation = false;
4253 mService.requestTraversal();
4254 // System windows don't have an activity and an app token as a result, but need a way
4255 // to be informed about their entrance animation end.
4256 if (mAppToken == null) {
4257 try {
4258 mClient.dispatchWindowShown();
4259 } catch (RemoteException e) {
4260 }
4261 }
4262 }
4263
4264 if (!mWinAnimator.isWindowAnimationSet()) {
4265 //TODO (multidisplay): Accessibility is supported only for the default display.
4266 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4267 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4268 }
4269 }
4270
4271 if (!mAnimatingExit) {
4272 return;
4273 }
4274
4275 if (mWinAnimator.isWindowAnimationSet()) {
4276 return;
4277 }
4278
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004279 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004280 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4281
4282 mDestroying = true;
4283
4284 final boolean hasSurface = mWinAnimator.hasSurface();
4285 if (hasSurface) {
4286 mWinAnimator.hide("onExitAnimationDone");
4287 }
4288
4289 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4290 // care to ensure the activity has actually stopped and the surface is not still in use.
4291 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4292 // transaction.
4293 if (mAppToken != null) {
4294 mAppToken.destroySurfaces();
4295 } else {
4296 if (hasSurface) {
4297 mService.mDestroySurface.add(this);
4298 }
4299 if (mRemoveOnExit) {
4300 mService.mPendingRemove.add(this);
4301 mRemoveOnExit = false;
4302 }
4303 }
4304 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004305 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004306 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004307
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004308 boolean clearAnimatingFlags() {
4309 boolean didSomething = false;
4310 // We don't want to clear it out for windows that get replaced, because the
4311 // animation depends on the flag to remove the replaced window.
4312 //
4313 // We also don't clear the mAnimatingExit flag for windows which have the
4314 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4315 // by the client. We should let animation proceed and not clear this flag or
4316 // they won't eventually be removed by WindowStateAnimator#finishExit.
4317 if (!mWillReplaceWindow && !mRemoveOnExit) {
4318 // Clear mAnimating flag together with mAnimatingExit. When animation
4319 // changes from exiting to entering, we need to clear this flag until the
4320 // new animation gets applied, so that isAnimationStarting() becomes true
4321 // until then.
4322 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4323 // placement for this window during this period, one or more frame will
4324 // show up with wrong position or scale.
4325 if (mAnimatingExit) {
4326 mAnimatingExit = false;
4327 didSomething = true;
4328 }
4329 if (mWinAnimator.mAnimating) {
4330 mWinAnimator.mAnimating = false;
4331 didSomething = true;
4332 }
4333 if (mDestroying) {
4334 mDestroying = false;
4335 mService.mDestroySurface.remove(this);
4336 didSomething = true;
4337 }
4338 }
4339
4340 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004341 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004342 }
4343
4344 return didSomething;
4345 }
4346
Winson4b4ba902016-07-27 19:45:52 -07004347 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004348 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004349 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004350
4351 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004352 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004353 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004354 c.hideWallpaperWindow(wasDeferred, reason);
4355 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004356 if (!mWinAnimator.mLastHidden || wasDeferred) {
4357 mWinAnimator.hide(reason);
4358 dispatchWallpaperVisibility(false);
4359 final DisplayContent displayContent = getDisplayContent();
4360 if (displayContent != null) {
4361 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4362 }
4363 }
4364 }
4365
4366 /**
4367 * Check wallpaper window for visibility change and notify window if so.
4368 * @param visible Current visibility.
4369 */
4370 void dispatchWallpaperVisibility(final boolean visible) {
4371 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004372 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004373
4374 // Only send notification if the visibility actually changed and we are not trying to hide
4375 // the wallpaper when we are deferring hiding of the wallpaper.
4376 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4377 mWallpaperVisible = visible;
4378 try {
4379 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4380 "Updating vis of wallpaper " + this
4381 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4382 mClient.dispatchAppVisibility(visible);
4383 } catch (RemoteException e) {
4384 }
4385 }
4386 }
4387
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004388 boolean hasVisibleNotDrawnWallpaper() {
4389 if (mWallpaperVisible && !isDrawnLw()) {
4390 return true;
4391 }
4392 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004393 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004394 if (c.hasVisibleNotDrawnWallpaper()) {
4395 return true;
4396 }
4397 }
4398 return false;
4399 }
4400
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004401 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4402 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004403 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004404 c.updateReportedVisibility(results);
4405 }
4406
4407 if (mAppFreezing || mViewVisibility != View.VISIBLE
4408 || mAttrs.type == TYPE_APPLICATION_STARTING
4409 || mDestroying) {
4410 return;
4411 }
4412 if (DEBUG_VISIBILITY) {
4413 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4414 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4415 if (!isDrawnLw()) {
4416 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4417 + " pv=" + mPolicyVisibility
4418 + " mDrawState=" + mWinAnimator.mDrawState
4419 + " ph=" + isParentWindowHidden()
4420 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4421 + " a=" + mWinAnimator.mAnimating);
4422 }
4423 }
4424
4425 results.numInteresting++;
4426 if (isDrawnLw()) {
4427 results.numDrawn++;
4428 if (!mWinAnimator.isAnimationSet()) {
4429 results.numVisible++;
4430 }
4431 results.nowGone = false;
4432 } else if (mWinAnimator.isAnimationSet()) {
4433 results.nowGone = false;
4434 }
4435 }
4436
Robert Carrfbbde852016-10-18 11:02:28 -07004437 /**
4438 * Calculate the window crop according to system decor policy. In general this is
4439 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4440 * special cases. This rectangle is in screen space.
4441 */
4442 void calculatePolicyCrop(Rect policyCrop) {
4443 final DisplayContent displayContent = getDisplayContent();
4444 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4445
4446 if (!isDefaultDisplay()) {
4447 // On a different display there is no system decor. Crop the window
4448 // by the screen boundaries.
4449 // TODO(multi-display)
4450 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4451 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4452 displayInfo.logicalWidth - mCompatFrame.left,
4453 displayInfo.logicalHeight - mCompatFrame.top);
4454 } else if (mLayer >= mService.mSystemDecorLayer) {
4455 // Above the decor layer is easy, just use the entire window
4456 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4457 } else if (mDecorFrame.isEmpty()) {
4458 // Windows without policy decor aren't cropped.
4459 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4460 } else {
4461 // Crop to the system decor specified by policy.
4462 calculateSystemDecorRect(policyCrop);
4463 }
4464 }
4465
4466 /**
4467 * The system decor rect is the region of the window which is not covered
4468 * by system decorations.
4469 */
4470 private void calculateSystemDecorRect(Rect systemDecorRect) {
4471 final Rect decorRect = mDecorFrame;
4472 final int width = mFrame.width();
4473 final int height = mFrame.height();
4474
4475 // Compute the offset of the window in relation to the decor rect.
4476 final int left = mXOffset + mFrame.left;
4477 final int top = mYOffset + mFrame.top;
4478
4479 // Initialize the decor rect to the entire frame.
4480 if (isDockedResizing()) {
4481 // If we are resizing with the divider, the task bounds might be smaller than the
4482 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4483 // want in this case in order to avoid holes.
4484 //
4485 // We take care to not shrink the width, for surfaces which are larger than
4486 // the display region. Of course this area will not eventually be visible
4487 // but if we truncate the width now, we will calculate incorrectly
4488 // when adjusting to the stack bounds.
4489 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4490 systemDecorRect.set(0, 0,
4491 Math.max(width, displayInfo.logicalWidth),
4492 Math.max(height, displayInfo.logicalHeight));
4493 } else {
4494 systemDecorRect.set(0, 0, width, height);
4495 }
4496
4497 // If a freeform window is animating from a position where it would be cutoff, it would be
4498 // cutoff during the animation. We don't want that, so for the duration of the animation
4499 // we ignore the decor cropping and depend on layering to position windows correctly.
4500 final boolean cropToDecor = !(inFreeformWorkspace() && isAnimatingLw());
4501 if (cropToDecor) {
4502 // Intersect with the decor rect, offsetted by window position.
4503 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4504 decorRect.right - left, decorRect.bottom - top);
4505 }
4506
4507 // If size compatibility is being applied to the window, the
4508 // surface is scaled relative to the screen. Also apply this
4509 // scaling to the crop rect. We aren't using the standard rect
4510 // scale function because we want to round things to make the crop
4511 // always round to a larger rect to ensure we don't crop too
4512 // much and hide part of the window that should be seen.
4513 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4514 final float scale = mInvGlobalScale;
4515 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4516 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4517 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4518 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4519 }
4520
4521 }
4522
4523 /**
4524 * Expand the given rectangle by this windows surface insets. This
4525 * takes you from the 'window size' to the 'surface size'.
4526 * The surface insets are positive in each direction, so we inset by
4527 * the inverse.
4528 */
4529 void expandForSurfaceInsets(Rect r) {
4530 r.inset(-mAttrs.surfaceInsets.left,
4531 -mAttrs.surfaceInsets.top,
4532 -mAttrs.surfaceInsets.right,
4533 -mAttrs.surfaceInsets.bottom);
4534 }
4535
Robert Carrc91d1c32017-02-15 19:37:46 -08004536 boolean surfaceInsetsChanging() {
4537 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4538 }
4539
Bryce Leef858b572017-06-29 14:03:33 -07004540 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004541 final boolean wasVisible = isVisibleLw();
4542
4543 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004544 if (mAnimatingExit) {
4545 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4546 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4547
4548 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4549 mAnimatingExit = false;
4550 }
4551 if (mDestroying) {
4552 mDestroying = false;
4553 mService.mDestroySurface.remove(this);
4554 }
4555 if (oldVisibility == View.GONE) {
4556 mWinAnimator.mEnterAnimationPending = true;
4557 }
4558
Andrii Kulian8ee72852017-03-10 10:36:45 -08004559 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004560
4561 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004562
Bryce Leef858b572017-06-29 14:03:33 -07004563 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004564
Robert Carrc91d1c32017-02-15 19:37:46 -08004565 if ((attrChanges & FORMAT_CHANGED) != 0) {
4566 // If the format can't be changed in place, preserve the old surface until the app draws
4567 // on the new one. This prevents blinking when we change elevation of freeform and
4568 // pinned windows.
4569 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4570 mWinAnimator.preserveSurfaceLocked();
4571 result |= RELAYOUT_RES_SURFACE_CHANGED
4572 | RELAYOUT_RES_FIRST_TIME;
4573 }
4574 }
4575
4576 // When we change the Surface size, in scenarios which may require changing
4577 // the surface position in sync with the resize, we use a preserved surface
4578 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004579 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4580 // stack since it can lead to issues if a new surface is created while calculating the
4581 // scale for the animation using the source hint rect
4582 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004583 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Winson Chung8bca9e42017-04-16 15:59:43 -07004584 || (surfaceInsetsChanging() && !inPinnedWorkspace())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004585 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4586
4587 setDragResizing();
4588 setResizedWhileNotDragResizing(false);
4589 // We can only change top level windows to the full-screen surface when
4590 // resizing (as we only have one full-screen surface). So there is no need
4591 // to preserve and destroy windows which are attached to another, they
4592 // will keep their surface and its size may change over time.
4593 if (mHasSurface && !isChildWindow()) {
4594 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004595 result |= RELAYOUT_RES_SURFACE_CHANGED |
4596 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004597 }
4598 }
4599 final boolean freeformResizing = isDragResizing()
4600 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4601 final boolean dockedResizing = isDragResizing()
4602 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4603 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4604 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
4605 if (isAnimatingWithSavedSurface()) {
4606 // If we're animating with a saved surface now, request client to report draw.
4607 // We still need to know when the real thing is drawn.
4608 result |= RELAYOUT_RES_FIRST_TIME;
4609 }
4610 return result;
4611 }
4612
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004613 /**
4614 * @return True if this window has been laid out at least once; false otherwise.
4615 */
4616 boolean isLaidOut() {
4617 return mLayoutSeq != -1;
4618 }
4619
4620 /**
4621 * Updates the last inset values to the current ones.
4622 */
4623 void updateLastInsetValues() {
4624 mLastOverscanInsets.set(mOverscanInsets);
4625 mLastContentInsets.set(mContentInsets);
4626 mLastVisibleInsets.set(mVisibleInsets);
4627 mLastStableInsets.set(mStableInsets);
4628 mLastOutsets.set(mOutsets);
4629 }
4630
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004631 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4632 // access to its windows children. Need to investigate re-writing
4633 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4634 static final class UpdateReportedVisibilityResults {
4635 int numInteresting;
4636 int numVisible;
4637 int numDrawn;
4638 boolean nowGone = true;
4639
4640 void reset() {
4641 numInteresting = 0;
4642 numVisible = 0;
4643 numDrawn = 0;
4644 nowGone = true;
4645 }
4646 }
Robert Carraf422a82017-04-10 18:34:33 -07004647
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004648 private static final class WindowId extends IWindowId.Stub {
4649 private final WeakReference<WindowState> mOuter;
4650
4651 private WindowId(WindowState outer) {
4652
4653 // Use a weak reference for the outer class. This is important to prevent the following
4654 // leak: Since we send this class to the client process, binder will keep it alive as
4655 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4656 // out our reference so even though this class is kept alive we don't leak WindowState,
4657 // which can keep a whole lot of classes alive.
4658 mOuter = new WeakReference<>(outer);
4659 }
4660
4661 @Override
4662 public void registerFocusObserver(IWindowFocusObserver observer) {
4663 final WindowState outer = mOuter.get();
4664 if (outer != null) {
4665 outer.registerFocusObserver(observer);
4666 }
4667 }
4668 @Override
4669 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4670 final WindowState outer = mOuter.get();
4671 if (outer != null) {
4672 outer.unregisterFocusObserver(observer);
4673 }
4674 }
4675 @Override
4676 public boolean isFocused() {
4677 final WindowState outer = mOuter.get();
4678 return outer != null && outer.isFocused();
4679 }
4680 }
4681
Robert Carraf422a82017-04-10 18:34:33 -07004682 boolean usesRelativeZOrdering() {
4683 if (!isChildWindow()) {
4684 return false;
4685 } else if (mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4686 return true;
4687 } else {
4688 return false;
4689 }
4690 }
satokcef37fb2011-10-24 21:49:38 +09004691}