blob: e2027fd8764bd1927935e37c77da8dacd7dbeff9 [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
Wale Ogunwale053c8e42015-11-16 14:27:21 -080019import android.app.ActivityManager;
20import android.app.AppOpsManager;
21import android.content.Context;
22import android.content.res.Configuration;
23import android.graphics.Matrix;
24import android.graphics.PixelFormat;
25import android.graphics.Point;
26import android.graphics.Rect;
27import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070028import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -070029import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080030import android.os.IBinder;
31import android.os.PowerManager;
32import android.os.RemoteCallbackList;
33import android.os.RemoteException;
34import android.os.SystemClock;
35import android.os.Trace;
36import android.os.UserHandle;
37import android.os.WorkSource;
38import android.util.DisplayMetrics;
39import android.util.Slog;
40import android.util.TimeUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080041import android.view.DisplayInfo;
42import android.view.Gravity;
43import android.view.IApplicationToken;
44import android.view.IWindow;
45import android.view.IWindowFocusObserver;
46import android.view.IWindowId;
47import android.view.InputChannel;
48import android.view.InputEvent;
49import android.view.InputEventReceiver;
50import android.view.View;
51import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070052import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080053import android.view.WindowManager;
54import android.view.WindowManagerPolicy;
55
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -080056import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080057import com.android.server.input.InputWindowHandle;
58
Wale Ogunwale053c8e42015-11-16 14:27:21 -080059import java.io.PrintWriter;
60import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -070061import java.util.Comparator;
62import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -080063import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080064
Wale Ogunwaled045c822015-12-02 09:14:28 -080065import static android.app.ActivityManager.StackId;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -080066import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -080067import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070068import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070069import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080070import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
71import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
72import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
73import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080074import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -070075import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080076import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Wale Ogunwale6213caa2016-12-02 16:47:15 +000077import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070078import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080079import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggi5f23a572016-04-22 15:05:50 -070080import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080081import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
82import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080083import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale945d1972016-03-23 13:16:41 -070084import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Chong Zhang4d7369a2016-04-25 16:09:14 -070085import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070086import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080087import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080088import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080089import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080090import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080091import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070092import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
Robert Carra1eb4392015-12-10 12:43:51 -080093import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080094import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
95import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Robert Carrd1a010f2016-04-07 22:36:22 -070096import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080097import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080098import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Chong Zhangfea963e2016-08-15 17:14:16 -070099import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700100import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800101import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
102import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
103import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Chong Zhang4d7369a2016-04-25 16:09:14 -0700104import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700105import static android.view.WindowManagerPolicy.TRANSIT_ENTER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700106import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
107import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100108import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
109import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800110import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
111import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
112import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
113import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700114import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800115import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000116import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700117import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800118import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
119import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
120import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
121import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700122import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
123import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800124import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700125import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700126import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700127import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800128import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
129import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700130import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700131import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
132import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700133import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
134import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700135import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700136import static com.android.server.wm.WindowManagerService.localLOGV;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700137import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700138import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700139import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
140import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700142/** A window in the window manager. */
143class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800144 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800145
Skuhne81c524a2015-08-12 13:34:14 -0700146 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700147 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
148 // use hard-coded min sizes for now.
149 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
150 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700151
152 // The thickness of a window resize handle outside the window bounds on the free form workspace
153 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700154 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700155
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700156 private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
Robert Carr7098dbd2016-02-01 12:31:01 -0800157
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700159 final WindowManagerPolicy mPolicy;
160 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 final Session mSession;
162 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800163 final int mAppOp;
164 // UserId and appId of the owner. Don't display windows of non-current user.
165 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800166 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700168 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700170
171 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
172 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
174 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700175 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800176 final int mBaseLayer;
177 final int mSubLayer;
178 final boolean mLayoutAttached;
179 final boolean mIsImWindow;
180 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700181 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700182 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700183 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700185 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700186 /**
187 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
188 * Normally set by calling {@link #showLw} and {@link #hideLw}.
189 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700191 /**
192 * What {@link #mPolicyVisibility} should be set to after a transition animation.
193 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
194 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
195 * animation is done.
196 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700198 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700199 boolean mPermanentlyHidden; // the window should never be shown again
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800200 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700201 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700203 private boolean mDragResizing;
204 private boolean mDragResizingChangeReported;
205 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700206
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700207 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800208
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700209 /**
210 * The window size that was requested by the application. These are in
211 * the application's coordinate space (without compatibility scale applied).
212 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800213 int mRequestedWidth;
214 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700215 private int mLastRequestedWidth;
216 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700217
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800218 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800219 boolean mHaveFrame;
220 boolean mObscured;
221 boolean mTurnOnScreen;
222
223 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700224
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700225 /**
226 * Used to store last reported to client configuration and check if we have newer available.
227 * We'll send configuration to client only if it is different from the last applied one and
228 * client won't perform unnecessary updates.
229 */
230 private final Configuration mLastReportedConfiguration = new Configuration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700231
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700232 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700233 * Actual position of the surface shown on-screen (may be modified by animation). These are
234 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700235 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700236 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237
238 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700239 * Insets that determine the actually visible area. These are in the application's
240 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241 */
242 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700243 private final Rect mLastVisibleInsets = new Rect();
244 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245
246 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700247 * Insets that are covered by system windows (such as the status bar) and
248 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700249 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800250 */
251 final Rect mContentInsets = new Rect();
252 final Rect mLastContentInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700253 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254
255 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800256 * Insets that determine the area covered by the display overscan region. These are in the
257 * application's coordinate space (without compatibility scale applied).
258 */
259 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700260 private final Rect mLastOverscanInsets = new Rect();
261 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800262
263 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700264 * Insets that determine the area covered by the stable system windows. These are in the
265 * application's coordinate space (without compatibility scale applied).
266 */
267 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700268 private final Rect mLastStableInsets = new Rect();
269 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700270
271 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700272 * Outsets determine the area outside of the surface where we want to pretend that it's possible
273 * to draw anyway.
274 */
275 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700276 private final Rect mLastOutsets = new Rect();
277 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700278
279 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280 * Set to true if we are waiting for this window to receive its
281 * given internal insets before laying out other windows based on it.
282 */
283 boolean mGivenInsetsPending;
284
285 /**
286 * These are the content insets that were given during layout for
287 * this window, to be applied to windows behind it.
288 */
289 final Rect mGivenContentInsets = new Rect();
290
291 /**
292 * These are the visible insets that were given during layout for
293 * this window, to be applied to windows behind it.
294 */
295 final Rect mGivenVisibleInsets = new Rect();
296
297 /**
298 * This is the given touchable area relative to the window frame, or null if none.
299 */
300 final Region mGivenTouchableRegion = new Region();
301
302 /**
303 * Flag indicating whether the touchable region should be adjusted by
304 * the visible insets; if false the area outside the visible insets is
305 * NOT touchable, so we must use those to adjust the frame during hit
306 * tests.
307 */
308 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
309
310 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400311 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700312 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313 float mHScale=1, mVScale=1;
314 float mLastHScale=1, mLastVScale=1;
315 final Matrix mTmpMatrix = new Matrix();
316
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700317 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 final Rect mFrame = new Rect();
319 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700320 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700321 // Frame that is scaled to the application's coordinate space when in
322 // screen size compatibility mode.
323 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324
325 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700326
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700327 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700328
Wale Ogunwale94596652015-02-06 19:27:34 -0800329 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
330 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700331 final Rect mDisplayFrame = new Rect();
332
333 // The region of the display frame that the display type supports displaying content on. This
334 // is mostly a special case for TV where some displays don’t have the entire display usable.
335 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
336 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700337 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700338
339 // The display frame minus the stable insets. This value is always constant regardless of if
340 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700341 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800342
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700343 // The area not occupied by the status and navigation bars. So, if both status and navigation
344 // bars are visible, the decor frame is equal to the stable frame.
345 final Rect mDecorFrame = new Rect();
346
347 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
348 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700349 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700350
351 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
352 // displays hint text.
353 final Rect mVisibleFrame = new Rect();
354
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700355 // Frame that includes dead area outside of the surface but where we want to pretend that it's
356 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700357 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700358
Jorim Jaggidc249c42015-12-15 14:57:31 -0800359 /**
360 * Usually empty. Set to the task's tempInsetFrame. See
361 *{@link android.app.IActivityManager#resizeDockedStack}.
362 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700363 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800364
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800365 boolean mContentChanged;
366
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 // If a window showing a wallpaper: the requested offset for the
368 // wallpaper; if a wallpaper window: the currently applied offset.
369 float mWallpaperX = -1;
370 float mWallpaperY = -1;
371
372 // If a window showing a wallpaper: what fraction of the offset
373 // range corresponds to a full virtual screen.
374 float mWallpaperXStep = -1;
375 float mWallpaperYStep = -1;
376
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700377 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
378 // to its window; if a wallpaper window: not used.
379 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
380 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
381
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800382 // Wallpaper windows: pixels offset based on above variables.
383 int mXOffset;
384 int mYOffset;
385
Craig Mautner2268e7e2012-12-13 15:40:00 -0800386 /**
387 * This is set after IWindowSession.relayout() has been called at
388 * least once for the window. It allows us to detect the situation
389 * where we don't yet have a surface, but should have one soon, so
390 * we can give the window focus before waiting for the relayout.
391 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392 boolean mRelayoutCalled;
393
Robert Carrfed10072016-05-26 11:48:49 -0700394 boolean mInRelayout;
395
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800396 /**
397 * If the application has called relayout() with changes that can
398 * impact its window's size, we need to perform a layout pass on it
399 * even if it is not currently visible for layout. This is set
400 * when in that case until the layout is done.
401 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800402 boolean mLayoutNeeded;
403
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800404 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800405 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800406
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800407 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408 boolean mDestroying;
409
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800410 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800411 boolean mRemoveOnExit;
412
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800413 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800414 * Whether the app died while it was visible, if true we might need
415 * to continue to show it until it's restarted.
416 */
417 boolean mAppDied;
418
419 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800420 * Set when the orientation is changing and this window has not yet
421 * been updated for the new orientation.
422 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800423 boolean mOrientationChanging;
424
Dianne Hackborna57c6952013-03-29 14:46:40 -0700425 /**
Robert Carr237028a2016-07-26 10:39:45 -0700426 * The orientation during the last visible call to relayout. If our
427 * current orientation is different, the window can't be ready
428 * to be shown.
429 */
430 int mLastVisibleLayoutRotation = -1;
431
432 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700433 * How long we last kept the screen frozen.
434 */
435 int mLastFreezeDuration;
436
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800437 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800438 boolean mRemoved;
439
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800440 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800441 * It is save to remove the window and destroy the surface because the client requested removal
442 * or some other higher level component said so (e.g. activity manager).
443 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800444 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700445 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800446
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800447 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700448 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800449 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700450 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800451
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800452 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700453 private String mStringNameCache;
454 private CharSequence mLastTitle;
455 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456
Craig Mautnera2c77052012-03-26 12:14:43 -0700457 final WindowStateAnimator mWinAnimator;
458
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700459 boolean mHasSurface = false;
460
Craig Mautner88400d32012-09-30 12:35:45 -0700461 /** When true this window can be displayed on screens owther than mOwnerUid's */
462 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700463
Robert Carr13f7be9e2015-12-02 18:39:45 -0800464 // Whether the window has a saved surface from last pause, which can be
465 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700466 private boolean mSurfaceSaved = false;
467
Chong Zhang8e4bda92016-05-04 15:08:18 -0700468 // Whether we're performing an entering animation with a saved surface. This flag is
469 // true during the time we're showing a window with a previously saved surface. It's
470 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700471 private boolean mAnimatingWithSavedSurface;
472
473 // Whether the window was visible when we set the app to invisible last time. WM uses
474 // this as a hint to restore the surface (if available) for early animation next time
475 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700476 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800477
Robert Carra1eb4392015-12-10 12:43:51 -0800478 // This window will be replaced due to relaunch. This allows window manager
479 // to differentiate between simple removal of a window and replacement. In the latter case it
480 // will preserve the old window until the new one is drawn.
481 boolean mWillReplaceWindow = false;
482 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700483 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800484 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700485 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800486 // If not null, the window that will be used to replace the old one. This is being set when
487 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700488 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700489 // For the new window in the replacement transition, if we have
490 // requested to replace without animation, then we should
491 // make sure we also don't apply an enter animation for
492 // the new window.
493 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800494 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700495 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800496
Jeff Brownc2932a12014-11-20 18:04:05 -0800497 /**
498 * Wake lock for drawing.
499 * Even though it's slightly more expensive to do so, we will use a separate wake lock
500 * for each app that is requesting to draw while dozing so that we can accurately track
501 * who is preventing the system from suspending.
502 * This lock is only acquired on first use.
503 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700504 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800505
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700506 final private Rect mTmpRect = new Rect();
507
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800508 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800509 * See {@link #notifyMovedInStack}.
510 */
511 private boolean mJustMovedInStack;
512
513 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800514 * Whether the window was resized by us while it was gone for layout.
515 */
516 boolean mResizedWhileGone = false;
517
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700518 /** @see #isResizedWhileNotDragResizing(). */
519 private boolean mResizedWhileNotDragResizing;
520
521 /** @see #isResizedWhileNotDragResizingReported(). */
522 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700523
Robert Carr6da3cc02016-06-16 15:17:07 -0700524 /**
525 * During seamless rotation we have two phases, first the old window contents
526 * are rotated to look as if they didn't move in the new coordinate system. Then we
527 * have to freeze updates to this layer (to preserve the transformation) until
528 * the resize actually occurs. This is true from when the transformation is set
529 * and false until the transaction to resize is sent.
530 */
531 boolean mSeamlesslyRotated = false;
532
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700533 private static final Region sEmptyRegion = new Region();
534
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700535 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700536 * 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 -0700537 * of z-order and 1 otherwise.
538 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800539 private static final Comparator<WindowState> sWindowSubLayerComparator =
540 new Comparator<WindowState>() {
541 @Override
542 public int compare(WindowState w1, WindowState w2) {
543 final int layer1 = w1.mSubLayer;
544 final int layer2 = w2.mSubLayer;
545 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
546 // We insert the child window into the list ordered by
547 // the sub-layer. For same sub-layers, the negative one
548 // should go below others; the positive one should go
549 // above others.
550 return -1;
551 }
552 return 1;
553 };
554 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700555
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800556 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700557 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700558 int viewVisibility, int ownerId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800559 mService = service;
560 mSession = s;
561 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800562 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800563 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700564 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700565 mOwnerUid = ownerId;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800566 mWindowId = new IWindowId.Stub() {
567 @Override
568 public void registerFocusObserver(IWindowFocusObserver observer) {
569 WindowState.this.registerFocusObserver(observer);
570 }
571 @Override
572 public void unregisterFocusObserver(IWindowFocusObserver observer) {
573 WindowState.this.unregisterFocusObserver(observer);
574 }
575 @Override
576 public boolean isFocused() {
577 return WindowState.this.isFocused();
578 }
579 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800580 mAttrs.copyFrom(a);
581 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700582 mPolicy = mService.mPolicy;
583 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800584 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700585 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700586 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700587 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700588 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700589 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800590 try {
591 c.asBinder().linkToDeath(deathRecipient, 0);
592 } catch (RemoteException e) {
593 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700594 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800595 mLayoutAttached = false;
596 mIsImWindow = false;
597 mIsWallpaper = false;
598 mIsFloatingLayer = false;
599 mBaseLayer = 0;
600 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700601 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700602 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800603 return;
604 }
605 mDeathRecipient = deathRecipient;
606
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700607 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800608 // The multiplier here is to reserve space for multiple
609 // windows in the same type layer.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700610 mBaseLayer = mPolicy.windowTypeToLayerLw(parentWindow.mAttrs.type)
611 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700612 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700613 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900614
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700615 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
616 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900617
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800618 mLayoutAttached = mAttrs.type !=
619 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700620 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
621 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
622 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800623 } else {
624 // The multiplier here is to reserve space for multiple
625 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700626 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700627 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800628 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700629 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800630 mLayoutAttached = false;
631 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
632 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
633 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800634 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700635 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700637 if (mAppToken != null && mAppToken.showForAllUsers) {
638 // Windows for apps that can show for all users should also show when the device is
639 // locked.
640 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700641 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642
Craig Mautner322e4032012-07-13 13:35:20 -0700643 mWinAnimator = new WindowStateAnimator(this);
644 mWinAnimator.mAlpha = a.alpha;
645
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800646 mRequestedWidth = 0;
647 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700648 mLastRequestedWidth = 0;
649 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800650 mXOffset = 0;
651 mYOffset = 0;
652 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800653 mInputWindowHandle = new InputWindowHandle(
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700654 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800655 }
656
657 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700658 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800659 mSession.windowAddedLocked();
660 }
661
Craig Mautnera2c77052012-03-26 12:14:43 -0700662 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800663 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800664 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800665 }
666
667 @Override
668 public String getOwningPackage() {
669 return mAttrs.packageName;
670 }
671
Jorim Jaggif5834272016-04-04 20:25:41 -0700672 /**
673 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
674 * from {@param frame}. In other words, it applies the insets that would result if
675 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700676 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
677 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700678 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700679 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
680 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
681 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
682 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
683 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700684 frame.inset(left, top, right, bottom);
685 }
686
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800687 @Override
Robert Carr43521762016-10-28 13:15:04 -0700688 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
689 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
690 Rect outsetFrame) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800691 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700692 // This window is being replaced and either already got information that it's being
693 // removed or we are still waiting for some information. Because of this we don't
694 // want to apply any more changes to it, so it remains in this state until new window
695 // appears.
696 return;
697 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800698 mHaveFrame = true;
699
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700700 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700701 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800702 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700703 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800704
Chong Zhangae35fef2016-03-16 15:56:55 -0700705 // If the task has temp inset bounds set, we have to make sure all its windows uses
706 // the temp inset frame. Otherwise different display frames get applied to the main
707 // window and the child window, making them misaligned.
708 if (fullscreenTask) {
709 mInsetFrame.setEmpty();
710 } else {
711 task.getTempInsetBounds(mInsetFrame);
712 }
713
Jorim Jaggif5834272016-04-04 20:25:41 -0700714 // Denotes the actual frame used to calculate the insets and to perform the layout. When
715 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
716 // insets temporarily. By the notion of a task having a different layout frame, we can
717 // achieve that while still moving the task around.
718 final Rect layoutContainingFrame;
719 final Rect layoutDisplayFrame;
720
721 // The offset from the layout containing frame to the actual containing frame.
722 final int layoutXDiff;
723 final int layoutYDiff;
Wale Ogunwale7cd4b012016-05-07 12:41:22 -0700724 if (fullscreenTask || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800725 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700726 mContainingFrame.set(parentFrame);
727 mDisplayFrame.set(displayFrame);
728 layoutDisplayFrame = displayFrame;
729 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700730 layoutXDiff = 0;
731 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800732 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700733 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100734 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
735
736 // If the bounds are frozen, we still want to translate the window freely and only
737 // freeze the size.
738 Rect frozen = mAppToken.mFrozenBounds.peek();
739 mContainingFrame.right = mContainingFrame.left + frozen.width();
740 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
741 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800742 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700743 // IME is up and obscuring this window. Adjust the window position so it is visible.
744 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Robert Carr43521762016-10-28 13:15:04 -0700745 if (windowsAreFloating && mContainingFrame.bottom > contentFrame.bottom) {
Robert Carrfc03b2b2016-03-31 15:22:02 -0700746 // In freeform we want to move the top up directly.
Robert Carr43521762016-10-28 13:15:04 -0700747 // TODO: Investigate why this is contentFrame not parentFrame.
748 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
749 } else if (mContainingFrame.bottom > parentFrame.bottom) {
Robert Carrfc03b2b2016-03-31 15:22:02 -0700750 // But in docked we want to behave like fullscreen
751 // and behave as if the task were given smaller bounds
752 // for the purposes of layout.
Robert Carr43521762016-10-28 13:15:04 -0700753 mContainingFrame.bottom = parentFrame.bottom;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700754 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700755 }
Skuhne81c524a2015-08-12 13:34:14 -0700756
Robert Carre6275582016-02-29 15:45:45 -0800757 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700758 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
759 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800760 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700761 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700762 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700763 }
Doris Liu06d582d2015-06-01 13:18:43 -0700764 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800765 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700766 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
767 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
768 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700769 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700770 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700771 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700772 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
773 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700774 }
Robert Carr43521762016-10-28 13:15:04 -0700775 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700776 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700777 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800778
Craig Mautner967212c2013-04-13 21:10:58 -0700779 final int pw = mContainingFrame.width();
780 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800781
Robert Carr43521762016-10-28 13:15:04 -0700782 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800783 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700784 // + " to " + parentFrame);
785 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800786 mContentChanged = true;
787 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700788 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
789 mLastRequestedWidth = mRequestedWidth;
790 mLastRequestedHeight = mRequestedHeight;
791 mContentChanged = true;
792 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800793
Robert Carr43521762016-10-28 13:15:04 -0700794 mOverscanFrame.set(overscanFrame);
795 mContentFrame.set(contentFrame);
796 mVisibleFrame.set(visibleFrame);
797 mDecorFrame.set(decorFrame);
798 mStableFrame.set(stableFrame);
799 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700800 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700801 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700802 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800803
Craig Mautnereda67292013-04-28 13:50:14 -0700804 final int fw = mFrame.width();
805 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800806
Jorim Jaggif5834272016-04-04 20:25:41 -0700807 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
808
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700809 // Calculate the outsets before the content frame gets shrinked to the window frame.
810 if (hasOutsets) {
811 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
812 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
813 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
814 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
815 } else {
816 mOutsets.set(0, 0, 0, 0);
817 }
818
Craig Mautnera248eee2013-05-07 11:41:27 -0700819 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800820 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800821 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700822 // Keep the frame out of the blocked system area, limit it in size to the content area
823 // and make sure that there is always a minimum visible so that the user can drag it
824 // into a usable area..
825 final int height = Math.min(mFrame.height(), mContentFrame.height());
826 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700827 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900828 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
829 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
830 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
831 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Skuhne81c524a2015-08-12 13:34:14 -0700832 final int top = Math.max(mContentFrame.top,
833 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
834 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
835 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
836 mFrame.set(left, top, left + width, top + height);
837 mContentFrame.set(mFrame);
838 mVisibleFrame.set(mContentFrame);
839 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700840 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700841 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100842 mContentFrame.set(mFrame);
843 if (!mFrame.equals(mLastFrame)) {
844 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800845 }
Skuhne81c524a2015-08-12 13:34:14 -0700846 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700847 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
848 Math.max(mContentFrame.top, mFrame.top),
849 Math.min(mContentFrame.right, mFrame.right),
850 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800851
Jorim Jaggi656f6502016-04-11 21:08:17 -0700852 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
853 Math.max(mVisibleFrame.top, mFrame.top),
854 Math.min(mVisibleFrame.right, mFrame.right),
855 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800856
Jorim Jaggi656f6502016-04-11 21:08:17 -0700857 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
858 Math.max(mStableFrame.top, mFrame.top),
859 Math.min(mStableFrame.right, mFrame.right),
860 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700861 }
Adrian Roosfa104232014-06-20 16:10:14 -0700862
Jorim Jaggi899327f2016-02-25 20:44:18 -0500863 if (fullscreenTask && !windowsAreFloating) {
864 // Windows that are not fullscreen can be positioned outside of the display frame,
865 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700866 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
867 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
868 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
869 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800870 }
Craig Mautnereda67292013-04-28 13:50:14 -0700871
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100872 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100873 // For the docked divider, we calculate the stable insets like a full-screen window
874 // so it can use it to calculate the snap positions.
875 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
876 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
877 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
878 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800879
880 // The divider doesn't care about insets in any case, so set it to empty so we don't
881 // trigger a relayout when moving it.
882 mContentInsets.setEmpty();
883 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100884 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700885 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700886 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
887 // non-fullscreen mode.
Winsonbf1ed3d2016-10-19 17:30:26 -0700888 boolean overrideRightInset = !windowsAreFloating && !fullscreenTask &&
889 mFrame.right > mTmpRect.right;
890 boolean overrideBottomInset = !windowsAreFloating && !fullscreenTask &&
891 mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700892 mContentInsets.set(mContentFrame.left - mFrame.left,
893 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700894 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700895 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700896 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700897 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800898
Jorim Jaggi656f6502016-04-11 21:08:17 -0700899 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
900 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700901 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700902 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700903 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700904 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800905
Jorim Jaggi656f6502016-04-11 21:08:17 -0700906 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
907 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700908 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700909 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700910 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700911 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100912 }
Adrian Roosfa104232014-06-20 16:10:14 -0700913
Jorim Jaggi656f6502016-04-11 21:08:17 -0700914 // Offset the actual frame by the amount layout frame is off.
915 mFrame.offset(-layoutXDiff, -layoutYDiff);
916 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700917 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
918 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
919 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
920
Craig Mautnereda67292013-04-28 13:50:14 -0700921 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400922 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700923 // If there is a size compatibility scale being applied to the
924 // window, we need to apply this to its insets so that they are
925 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700926 mOverscanInsets.scale(mInvGlobalScale);
927 mContentInsets.scale(mInvGlobalScale);
928 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700929 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700930 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700931
932 // Also the scaled frame that we report to the app needs to be
933 // adjusted to be in its coordinate space.
934 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400935 }
936
Craig Mautnereda67292013-04-28 13:50:14 -0700937 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800938 final DisplayContent displayContent = getDisplayContent();
939 if (displayContent != null) {
940 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700941 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700942 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800943 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800944 }
945
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700946 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700947 "Resolving (mRequestedWidth="
948 + mRequestedWidth + ", mRequestedheight="
949 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
950 + "): frame=" + mFrame.toShortString()
951 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700952 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700953 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700954 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800955 }
956
Craig Mautnera2c77052012-03-26 12:14:43 -0700957 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800958 public Rect getFrameLw() {
959 return mFrame;
960 }
961
Craig Mautnera2c77052012-03-26 12:14:43 -0700962 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700963 public Point getShownPositionLw() {
964 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800965 }
966
Craig Mautnera2c77052012-03-26 12:14:43 -0700967 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800968 public Rect getDisplayFrameLw() {
969 return mDisplayFrame;
970 }
971
Craig Mautnera2c77052012-03-26 12:14:43 -0700972 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800973 public Rect getOverscanFrameLw() {
974 return mOverscanFrame;
975 }
976
977 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800978 public Rect getContentFrameLw() {
979 return mContentFrame;
980 }
981
Craig Mautnera2c77052012-03-26 12:14:43 -0700982 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800983 public Rect getVisibleFrameLw() {
984 return mVisibleFrame;
985 }
986
Robert Carre4ee8f8a2016-10-31 12:40:15 -0700987 Rect getStableFrameLw() {
988 return mStableFrame;
989 }
990
Craig Mautnera2c77052012-03-26 12:14:43 -0700991 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800992 public boolean getGivenInsetsPendingLw() {
993 return mGivenInsetsPending;
994 }
995
Craig Mautnera2c77052012-03-26 12:14:43 -0700996 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997 public Rect getGivenContentInsetsLw() {
998 return mGivenContentInsets;
999 }
1000
Craig Mautnera2c77052012-03-26 12:14:43 -07001001 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001002 public Rect getGivenVisibleInsetsLw() {
1003 return mGivenVisibleInsets;
1004 }
1005
Craig Mautnera2c77052012-03-26 12:14:43 -07001006 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001007 public WindowManager.LayoutParams getAttrs() {
1008 return mAttrs;
1009 }
1010
Craig Mautner812d2ca2012-09-27 15:35:34 -07001011 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001012 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001013 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001014 }
1015
Craig Mautner19d59bc2012-09-04 11:15:56 -07001016 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001017 public int getSystemUiVisibility() {
1018 return mSystemUiVisibility;
1019 }
1020
Craig Mautner19d59bc2012-09-04 11:15:56 -07001021 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001022 public int getSurfaceLayer() {
1023 return mLayer;
1024 }
1025
Craig Mautner812d2ca2012-09-27 15:35:34 -07001026 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001027 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001028 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001029 }
1030
1031 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001032 public IApplicationToken getAppToken() {
1033 return mAppToken != null ? mAppToken.appToken : null;
1034 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001035
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001036 @Override
1037 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001038 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001039 }
1040
Robert Carr31aa98b2016-07-20 15:29:03 -07001041 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001042 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1043 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1044 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001045 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001046 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001047 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1048 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001049 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001050 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001051 }
1052
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001053 /**
1054 * Adds the window to the resizing list if any of the parameters we use to track the window
1055 * dimensions or insets have changed.
1056 */
1057 void updateResizingWindowIfNeeded() {
1058 final WindowStateAnimator winAnimator = mWinAnimator;
1059 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1060 return;
1061 }
1062
1063 final Task task = getTask();
1064 // In the case of stack bound animations, the window frames will update (unlike other
1065 // animations which just modify various transformation properties). We don't want to
1066 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1067 // the frame may not correspond to the surface size or the onscreen area at various
1068 // phases in the animation, and the client will become sad and confused.
1069 if (task != null && task.mStack.getBoundsAnimating()) {
1070 return;
1071 }
1072
1073 setReportResizeHints();
1074 boolean configChanged = isConfigChanged();
1075 if (DEBUG_CONFIGURATION && configChanged) {
1076 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1077 }
1078
1079 final boolean dragResizingChanged = isDragResizeChanged()
1080 && !isDragResizingChangeReported();
1081
1082 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1083 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1084 + " frame=" + mFrame);
1085
1086 // We update mLastFrame always rather than in the conditional with the last inset
1087 // variables, because mFrameSizeChanged only tracks the width and height changing.
1088 mLastFrame.set(mFrame);
1089
1090 if (mContentInsetsChanged
1091 || mVisibleInsetsChanged
1092 || winAnimator.mSurfaceResized
1093 || mOutsetsChanged
1094 || mFrameSizeChanged
1095 || configChanged
1096 || dragResizingChanged
1097 || !isResizedWhileNotDragResizingReported()) {
1098 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1099 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1100 + " contentInsetsChanged=" + mContentInsetsChanged
1101 + " " + mContentInsets.toShortString()
1102 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1103 + " " + mVisibleInsets.toShortString()
1104 + " stableInsetsChanged=" + mStableInsetsChanged
1105 + " " + mStableInsets.toShortString()
1106 + " outsetsChanged=" + mOutsetsChanged
1107 + " " + mOutsets.toShortString()
1108 + " surfaceResized=" + winAnimator.mSurfaceResized
1109 + " configChanged=" + configChanged
1110 + " dragResizingChanged=" + dragResizingChanged
1111 + " resizedWhileNotDragResizingReported="
1112 + isResizedWhileNotDragResizingReported());
1113 }
1114
1115 // If it's a dead window left on screen, and the configuration changed, there is nothing
1116 // we can do about it. Remove the window now.
1117 if (mAppToken != null && mAppDied) {
1118 mAppToken.removeDeadWindows();
1119 return;
1120 }
1121
1122 mLastOverscanInsets.set(mOverscanInsets);
1123 mLastContentInsets.set(mContentInsets);
1124 mLastVisibleInsets.set(mVisibleInsets);
1125 mLastStableInsets.set(mStableInsets);
1126 mLastOutsets.set(mOutsets);
1127 mService.makeWindowFreezingScreenIfNeededLocked(this);
1128
1129 // If the orientation is changing, or we're starting or ending a drag resizing action,
1130 // then we need to hold off on unfreezing the display until this window has been
1131 // redrawn; to do that, we need to go through the process of getting informed by the
1132 // application when it has finished drawing.
1133 if (mOrientationChanging || dragResizingChanged || isResizedWhileNotDragResizing()) {
1134 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1135 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1136 + ", mDrawState=DRAW_PENDING in " + this
1137 + ", surfaceController " + winAnimator.mSurfaceController);
1138 }
1139 winAnimator.mDrawState = DRAW_PENDING;
1140 if (mAppToken != null) {
1141 mAppToken.clearAllDrawn();
1142 }
1143 }
1144 if (!mService.mResizingWindows.contains(this)) {
1145 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1146 mService.mResizingWindows.add(this);
1147 }
1148 } else if (mOrientationChanging) {
1149 if (isDrawnLw()) {
1150 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1151 + this + ", surfaceController " + winAnimator.mSurfaceController);
1152 mOrientationChanging = false;
1153 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1154 - mService.mDisplayFreezeTime);
1155 }
1156 }
1157 }
1158
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001159 DisplayContent getDisplayContent() {
1160 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001161 }
1162
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001163 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001164 final DisplayContent displayContent = getDisplayContent();
1165 return displayContent != null ? displayContent.getDisplayInfo() : null;
1166 }
1167
Jorim Jaggife762342016-10-13 14:33:27 +02001168 @Override
1169 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001170 final DisplayContent displayContent = getDisplayContent();
1171 if (displayContent == null) {
1172 return -1;
1173 }
1174 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001175 }
1176
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001177 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001178 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001179 }
1180
1181 TaskStack getStack() {
1182 Task task = getTask();
1183 if (task != null) {
1184 if (task.mStack != null) {
1185 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001186 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001187 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001188 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1189 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001190 final DisplayContent dc = getDisplayContent();
1191 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001192 }
1193
Skuhnef932e562015-08-20 12:07:30 -07001194 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001195 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001196 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001197 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001198 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001199 final Task task = getTask();
1200 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001201 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001202 mTmpRect.setEmpty();
1203 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001204 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001205 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001206 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001207 } else {
1208 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001209 }
1210 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001211
Chong Zhang9184ec62015-09-24 12:32:21 -07001212 bounds.set(mVisibleFrame);
1213 if (intersectWithStackBounds) {
1214 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001215 }
1216
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001217 if (bounds.isEmpty()) {
1218 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001219 if (intersectWithStackBounds) {
1220 bounds.intersect(mTmpRect);
1221 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001222 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001223 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001224 }
1225
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001226 public long getInputDispatchingTimeoutNanos() {
1227 return mAppToken != null
1228 ? mAppToken.inputDispatchingTimeoutNanos
1229 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1230 }
1231
Craig Mautnere8552142012-11-07 13:55:47 -08001232 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001233 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001234 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001235 }
1236
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001237 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1238 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1239 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1240 if (dtdx < -.000001f || dtdx > .000001f) return false;
1241 if (dsdy < -.000001f || dsdy > .000001f) return false;
1242 return true;
1243 }
1244
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001245 void prelayout() {
1246 if (mEnforceSizeCompat) {
1247 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001248 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001249 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001250 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001251 }
1252 }
1253
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001254 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001255 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001256 // If we're animating with a saved surface, we're already visible.
1257 // Return true so that the alpha doesn't get cleared.
1258 if (!mAppFreezing && isDrawnLw()
1259 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1260 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1261 return true;
1262 }
1263
Wale Ogunwale44f21802016-09-02 12:49:48 -07001264 return super.hasContentToDisplay();
1265 }
1266
1267 @Override
1268 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -07001269 // TODO: The check for hiddenRequested is commented out below, because the window can still
1270 // be visible on screen when the flag is true. We would like the isVisible() method to
1271 // return an answer closer to if the window is truly visible (can't be an exact answer
1272 // without checking the surface state), so comment out the check for now so we can test to
1273 // see what problem it causes.
1274 // If it doesn't cause any issues, then we can remove just before we lock down the current
1275 // release (O) and also consolidate this method with #isVisibleUnchecked() and possibly
1276 // other methods like isVisibleNow().
1277 // If it does cause problems, then we can look if there are other ways to solve the problem.
1278 // If there isn't then uncomment and document here why it is needed.
1279 if (/*(mAppToken == null || !mAppToken.hiddenRequested) && */isVisibleUnchecked()
1280 // TODO: The window isn't considered visible when the token is hidden, however
1281 // uncommenting the check below breaks the visual transition from an app to the launcher
1282 // if the home buttons is pressed. Need to investigate an fix that issue before
1283 // uncommenting.
1284 /* && !mToken.hidden*/) {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001285 // Is this window visible? It is not visible if there is no surface, or we are in the
1286 // process of running an exit animation that will remove the surface, or its app token
1287 // has been hidden.
1288 return true;
1289 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001290 return false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001291 }
1292
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001293 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001294 * Does the minimal check for visibility. Callers generally want to use one of the public
1295 * methods as they perform additional checks on the app token.
1296 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001297 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001298 private boolean isVisibleUnchecked() {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001299 return mHasSurface && mPolicyVisibility && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001300 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001301 }
1302
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001303 @Override
1304 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001305 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001306 }
1307
1308 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001309 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1310 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001311 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001312 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1313 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001314 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1315 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001316 }
1317
1318 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001319 * The same as isVisible(), but follows the current hidden state of the associated app token,
1320 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001321 */
1322 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001323 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001324 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001325 }
1326
1327 /**
1328 * Can this window possibly be a drag/drop target? The test here is
1329 * a combination of the above "visible now" with the check that the
1330 * Input Manager uses when discarding windows from input consideration.
1331 */
1332 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001333 return isVisibleNow() && !mRemoved
1334 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001335 }
1336
1337 /**
1338 * Same as isVisible(), but we also count it as visible between the
1339 * call to IWindowSession.add() and the first relayout().
1340 */
1341 boolean isVisibleOrAdding() {
1342 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001343 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001344 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001345 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001346 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001347 }
1348
1349 /**
1350 * Is this window currently on-screen? It is on-screen either if it
1351 * is visible or it is currently running an animation before no longer
1352 * being visible.
1353 */
1354 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001355 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001356 return false;
1357 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001358 final AppWindowToken atoken = mAppToken;
1359 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001360 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001361 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001362 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001363 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001364 }
1365
1366 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001367 * Whether this window's drawn state might affect the drawn states of the app token.
1368 *
1369 * @param visibleOnly Whether we should consider only the windows that's currently
1370 * visible in layout. If true, windows that has not relayout to VISIBLE
1371 * would always return false.
1372 *
1373 * @return true if the window should be considered while evaluating allDrawn flags.
1374 */
1375 boolean mightAffectAllDrawn(boolean visibleOnly) {
Chong Zhange292eb32016-05-21 09:23:55 -07001376 final boolean isViewVisible = (mAppToken == null || !mAppToken.clientHidden)
1377 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Jorim Jaggib0d27342016-11-01 16:10:42 -07001378 return (isOnScreen() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001379 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1380 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001381 && !mAnimatingExit && !mDestroying;
1382 }
1383
1384 /**
1385 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1386 * it must be drawn before allDrawn can become true.
1387 */
1388 boolean isInteresting() {
1389 return mAppToken != null && !mAppDied
1390 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1391 }
1392
1393 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001394 * Like isOnScreen(), but we don't return true if the window is part
1395 * of a transition that has not yet been started.
1396 */
1397 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001398 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001399 return false;
1400 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001401 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001402 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001403 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001404 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001405 }
1406
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001407 /**
1408 * Like isOnScreen, but returns false if the surface hasn't yet
1409 * been drawn.
1410 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001411 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 public boolean isDisplayedLw() {
1413 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001414 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001415 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001416 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001417 || mWinAnimator.mAnimating
1418 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001419 }
1420
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001421 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001422 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001423 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001424 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001425 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001426 return mWinAnimator.mAnimation != null
1427 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001428 }
1429
Craig Mautner812d2ca2012-09-27 15:35:34 -07001430 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001431 public boolean isGoneForLayoutLw() {
1432 final AppWindowToken atoken = mAppToken;
1433 return mViewVisibility == View.GONE
1434 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001435 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001436 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001437 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001438 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001439 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001440 }
1441
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001442 /**
1443 * Returns true if the window has a surface that it has drawn a
1444 * complete UI in to.
1445 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001446 public boolean isDrawFinishedLw() {
1447 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001448 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1449 || mWinAnimator.mDrawState == READY_TO_SHOW
1450 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001451 }
1452
1453 /**
1454 * Returns true if the window has a surface that it has drawn a
1455 * complete UI in to.
1456 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001457 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001458 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001459 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001460 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001461 }
1462
1463 /**
1464 * Return true if the window is opaque and fully drawn. This indicates
1465 * it may obscure windows behind it.
1466 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001467 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001468 // When there is keyguard, wallpaper could be placed over the secure app
1469 // window but invisible. We need to check wallpaper visibility explicitly
1470 // to determine if it's occluding apps.
1471 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1472 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001473 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001474 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001475 }
1476
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001477 @Override
1478 void onMovedByResize() {
1479 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001480 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001481 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001482 }
1483
1484 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1485 boolean changed = false;
1486
1487 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001488 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001489 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1490 }
1491
1492 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1493 // Starting window that's exiting will be removed when the animation finishes.
1494 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1495 // to actually remove it.
1496 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1497 mAnimatingExit = true;
1498 mRemoveOnExit = true;
1499 mWindowRemovalAllowed = true;
1500 }
1501 return changed;
1502 }
1503
1504 if (visible != isVisibleNow()) {
1505 if (!runningAppAnimation) {
1506 final AccessibilityController accessibilityController =
1507 mService.mAccessibilityController;
1508 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1509 mWinAnimator.applyAnimationLocked(winTransit, visible);
1510 //TODO (multidisplay): Magnification is supported only for the default
1511 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1512 accessibilityController.onWindowTransitionLocked(this, winTransit);
1513 }
1514 }
1515 changed = true;
1516 setDisplayLayoutNeeded();
1517 }
1518
1519 return changed;
1520 }
1521
1522 boolean onSetAppExiting() {
1523 final DisplayContent displayContent = getDisplayContent();
1524 boolean changed = false;
1525
1526 if (isVisibleNow()) {
1527 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1528 //TODO (multidisplay): Magnification is supported only for the default
1529 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1530 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1531 }
1532 changed = true;
1533 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001534 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001535 }
1536 }
1537
1538 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001539 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001540 changed |= c.onSetAppExiting();
1541 }
1542
1543 return changed;
1544 }
1545
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001546 @Override
1547 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001548 // Some windows won't go through the resizing process, if they don't have a surface, so
1549 // destroy all saved surfaces here.
1550 destroySavedSurface();
1551
1552 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1553 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001554 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001555 resizingWindows.add(this);
1556
1557 // If we are not drag resizing, force recreating of a new surface so updating
1558 // the content and positioning that surface will be in sync.
1559 //
1560 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1561 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1562 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1563 // their frame to update crop, etc...
1564 //
1565 // Anyway we don't need to synchronize position and content updates for these
1566 // windows since they aren't at the base layer and could be moved around anyway.
1567 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
1568 !getTask().mStack.getBoundsAnimating() && !isGoneForLayoutLw() &&
1569 !getTask().inPinnedWorkspace()) {
1570 setResizedWhileNotDragResizing(true);
1571 }
1572 }
1573 if (isGoneForLayoutLw()) {
1574 mResizedWhileGone = true;
1575 }
1576
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001577 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001578 }
1579
1580 void onUnfreezeBounds() {
1581 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001582 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001583 c.onUnfreezeBounds();
1584 }
1585
1586 if (!mHasSurface) {
1587 return;
1588 }
1589
1590 mLayoutNeeded = true;
1591 setDisplayLayoutNeeded();
1592 if (!mService.mResizingWindows.contains(this)) {
1593 mService.mResizingWindows.add(this);
1594 }
1595 }
1596
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001597 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001598 * If the window has moved due to its containing content frame changing, then notify the
1599 * listeners and optionally animate it. Simply checking a change of position is not enough,
1600 * because being move due to dock divider is not a trigger for animation.
1601 */
1602 void handleWindowMovedIfNeeded() {
1603 if (!hasMoved()) {
1604 return;
1605 }
1606
1607 // Frame has moved, containing content frame has also moved, and we're not currently
1608 // animating... let's do something.
1609 final int left = mFrame.left;
1610 final int top = mFrame.top;
1611 final Task task = getTask();
1612 final boolean adjustedForMinimizedDockOrIme = task != null
1613 && (task.mStack.isAdjustedForMinimizedDockedStack()
1614 || task.mStack.isAdjustedForIme());
1615 if (mService.okToDisplay()
1616 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1617 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1618 && (task == null || getTask().mStack.hasMovementAnimations())
1619 && !mWinAnimator.mLastHidden) {
1620 mWinAnimator.setMoveAnimation(left, top);
1621 }
1622
1623 //TODO (multidisplay): Accessibility supported only for the default display.
1624 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001625 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001626 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1627 }
1628
1629 try {
1630 mClient.moved(left, top);
1631 } catch (RemoteException e) {
1632 }
1633 mMovedByResize = false;
1634 }
1635
1636 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001637 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001638 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1639 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001640 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001641 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001642 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001643 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001644 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001645 }
1646
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001647 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001648 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001649 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001650 return false;
1651 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001652 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001653 }
1654
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001655 boolean fillsDisplay() {
1656 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001657 return mFrame.left <= 0 && mFrame.top <= 0
1658 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001659 }
1660
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001661 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001662 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001663 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001664 }
1665
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001666 boolean isAdjustedForMinimizedDock() {
1667 return mAppToken != null && mAppToken.mTask != null
1668 && mAppToken.mTask.mStack.isAdjustedForMinimizedDock();
1669 }
1670
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001671 void onWindowReplacementTimeout() {
1672 if (mWillReplaceWindow) {
1673 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001674 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001675 // delays removal on certain conditions, which will leave the stale window in the
1676 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1677 //
1678 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001679 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001680 } else {
1681 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001682 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001683 c.onWindowReplacementTimeout();
1684 }
1685 }
1686 }
1687
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001688 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001689 void forceWindowsScaleableInTransaction(boolean force) {
1690 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1691 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1692 }
1693
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001694 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001695 }
1696
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001697 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001698 void removeImmediately() {
1699 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001700
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001701 if (mRemoved) {
1702 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001703 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1704 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001705 return;
1706 }
1707
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001708 mRemoved = true;
1709
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001710 mWillReplaceWindow = false;
1711 if (mReplacementWindow != null) {
1712 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1713 }
1714
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001715 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001716 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001717 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001718 }
1719
1720 final int type = mAttrs.type;
1721 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001722 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001723 }
1724 mPolicy.removeWindowLw(this);
1725
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001726 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001727
Craig Mautner96868332012-12-04 14:29:11 -08001728 mWinAnimator.destroyDeferredSurfaceLocked();
1729 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001730 mSession.windowRemovedLocked();
1731 try {
1732 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1733 } catch (RuntimeException e) {
1734 // Ignore if it has already been removed (usually because
1735 // we are doing this as part of processing a death note.)
1736 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001737
1738 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001739 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001740
Wale Ogunwale571771c2016-08-26 13:18:50 -07001741 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001742 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001743 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001744 removeIfPossible(false /*keepVisibleDeadWindow*/);
1745 }
1746
Wale Ogunwale571771c2016-08-26 13:18:50 -07001747 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001748 mWindowRemovalAllowed = true;
1749 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1750 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1751
1752 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1753 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1754 "Starting window removed " + this);
1755
1756 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1757 Slog.v(TAG_WM, "Remove " + this + " client="
1758 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1759 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1760 + Debug.getCallers(5));
1761
1762 final long origId = Binder.clearCallingIdentity();
1763
1764 disposeInputChannel();
1765
1766 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1767 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1768 + " mAnimatingExit=" + mAnimatingExit
1769 + " mRemoveOnExit=" + mRemoveOnExit
1770 + " mHasSurface=" + mHasSurface
1771 + " surfaceShowing=" + mWinAnimator.getShown()
1772 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1773 + " app-animation="
1774 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1775 + " mWillReplaceWindow=" + mWillReplaceWindow
1776 + " inPendingTransaction="
1777 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1778 + " mDisplayFrozen=" + mService.mDisplayFrozen
1779 + " callers=" + Debug.getCallers(6));
1780
1781 // Visibility of the removed window. Will be used later to update orientation later on.
1782 boolean wasVisible = false;
1783
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001784 final int displayId = getDisplayId();
1785
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001786 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1787 // window until the animation is done. If the display is frozen, just remove immediately,
1788 // since the animation wouldn't be seen.
1789 if (mHasSurface && mService.okToDisplay()) {
1790 if (mWillReplaceWindow) {
1791 // This window is going to be replaced. We need to keep it around until the new one
1792 // gets added, then we will get rid of this one.
1793 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1794 "Preserving " + this + " until the new one is " + "added");
1795 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1796 // been removed. We probably need another flag to indicate that window removal
1797 // should be deffered vs. overloading the flag that says we are playing an exit
1798 // animation.
1799 mAnimatingExit = true;
1800 mReplacingRemoveRequested = true;
1801 Binder.restoreCallingIdentity(origId);
1802 return;
1803 }
1804
1805 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1806 // We started enter animation early with a saved surface, now the app asks to remove
1807 // this window. If we remove it now and the app is not yet drawn, we'll show a
1808 // flicker. Delay the removal now until it's really drawn.
1809 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1810 "removeWindowLocked: delay removal of " + this + " due to early animation");
1811 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1812 // immediately after the enter animation is done. If the app is not yet drawn then
1813 // it will show up as a flicker.
1814 setupWindowForRemoveOnExit();
1815 Binder.restoreCallingIdentity(origId);
1816 return;
1817 }
1818 // If we are not currently running the exit animation, we need to see about starting one
1819 wasVisible = isWinVisibleLw();
1820
1821 if (keepVisibleDeadWindow) {
1822 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1823 "Not removing " + this + " because app died while it's visible");
1824
1825 mAppDied = true;
1826 setDisplayLayoutNeeded();
1827 mService.mWindowPlacerLocked.performSurfacePlacement();
1828
1829 // Set up a replacement input channel since the app is now dead.
1830 // We need to catch tapping on the dead window to restart the app.
1831 openInputChannel(null);
1832 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1833
1834 Binder.restoreCallingIdentity(origId);
1835 return;
1836 }
1837
1838 if (wasVisible) {
1839 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1840
1841 // Try starting an animation.
1842 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1843 mAnimatingExit = true;
1844 }
1845 //TODO (multidisplay): Magnification is supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001846 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001847 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1848 }
1849 }
1850 final boolean isAnimating =
1851 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1852 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001853 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001854 // We delay the removal of a window if it has a showing surface that can be used to run
1855 // exit animation and it is marked as exiting.
1856 // Also, If isn't the an animating starting window that is the last window in the app.
1857 // We allow the removal of the non-animating starting window now as there is no
1858 // additional window or animation that will trigger its removal.
1859 if (mWinAnimator.getShown() && mAnimatingExit
1860 && (!lastWindowIsStartingWindow || isAnimating)) {
1861 // The exit animation is running or should run... wait for it!
1862 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1863 "Not removing " + this + " due to exit animation ");
1864 setupWindowForRemoveOnExit();
1865 if (mAppToken != null) {
1866 mAppToken.updateReportedVisibilityLocked();
1867 }
1868 Binder.restoreCallingIdentity(origId);
1869 return;
1870 }
1871 }
1872
Wale Ogunwale571771c2016-08-26 13:18:50 -07001873 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001874 // Removing a visible window will effect the computed orientation
1875 // So just update orientation if needed.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001876 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1877 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001878 }
1879 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1880 Binder.restoreCallingIdentity(origId);
1881 }
1882
1883 private void setupWindowForRemoveOnExit() {
1884 mRemoveOnExit = true;
1885 setDisplayLayoutNeeded();
1886 // Request a focus update as this window's input channel is already gone. Otherwise
1887 // we could have no focused window in input manager.
1888 final boolean focusChanged = mService.updateFocusedWindowLocked(
1889 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1890 mService.mWindowPlacerLocked.performSurfacePlacement();
1891 if (focusChanged) {
1892 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1893 }
1894 }
1895
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001896 void setHasSurface(boolean hasSurface) {
1897 mHasSurface = hasSurface;
1898 }
1899
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001900 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001901 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001902 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1903 if (appToken != null) {
1904 return appToken.mAppAnimator.animLayerAdjustment;
1905 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001906 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07001907
1908 if (mAppToken != null) {
1909 return mAppToken.mAppAnimator.animLayerAdjustment;
1910 }
1911
1912 // Nothing is animating, so there is no animation adjustment.
1913 return 0;
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001914 }
1915
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001916 int getSpecialWindowAnimLayerAdjustment() {
1917 int specialAdjustment = 0;
1918 if (mIsImWindow) {
1919 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
1920 } else if (mIsWallpaper) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07001921 specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment();
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001922 }
1923
1924 return mLayer + specialAdjustment;
1925 }
1926
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001927 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001928 if (mIsImWindow) {
1929 // IME windows can't be IME targets. IME targets are required to be below the IME
1930 // windows and that wouldn't be possible if the IME window is its own target...silly.
1931 return false;
1932 }
1933
1934 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001935 final int type = mAttrs.type;
1936
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001937 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
1938 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001939 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
1940 && type != TYPE_APPLICATION_STARTING) {
1941 return false;
1942 }
1943
1944 if (DEBUG_INPUT_METHOD) {
1945 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
1946 if (!isVisibleOrAdding()) {
1947 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
1948 + " relayoutCalled=" + mRelayoutCalled
1949 + " viewVis=" + mViewVisibility
1950 + " policyVis=" + mPolicyVisibility
1951 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
1952 + " parentHidden=" + isParentWindowHidden()
1953 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
1954 if (mAppToken != null) {
1955 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
1956 }
1957 }
1958 }
1959 return isVisibleOrAdding();
1960 }
1961
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001962 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001963 final DisplayContent dc = getDisplayContent();
1964 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001965 return;
1966 }
1967 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001968 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001969 // Force an animation pass just to update the mDimLayer layer.
1970 mService.scheduleAnimationLocked();
1971 }
1972 }
1973
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001974 /**
1975 * Notifies this window that the corresponding task has just moved in the stack.
1976 * <p>
1977 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
1978 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
1979 * the actual app transition that updates the visibility is delayed by a few transactions.
1980 * Instead of messing around with the ordering and timing how transitions and transactions are
1981 * executed, we introduce this little hack which prevents this window of getting visible again
1982 * with the wrong bounds until the app transitions has started.
1983 * <p>
1984 * This method notifies the window about that we just moved in the stack so we can apply this
1985 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
1986 */
1987 void notifyMovedInStack() {
1988 mJustMovedInStack = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001989
1990 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001991 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001992 c.notifyMovedInStack();
1993 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001994 }
1995
1996 /**
1997 * See {@link #notifyMovedInStack}.
1998 *
1999 * @return Whether we just got moved in the corresponding stack.
2000 */
2001 boolean hasJustMovedInStack() {
2002 return mJustMovedInStack;
2003 }
2004
2005 /**
2006 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
2007 */
2008 void resetJustMovedInStack() {
2009 mJustMovedInStack = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002010
2011 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002012 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002013 c.resetJustMovedInStack();
2014 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002015 }
2016
Chong Zhangacf11402015-11-04 16:23:10 -08002017 private final class DeadWindowEventReceiver extends InputEventReceiver {
2018 DeadWindowEventReceiver(InputChannel inputChannel) {
2019 super(inputChannel, mService.mH.getLooper());
2020 }
2021 @Override
2022 public void onInputEvent(InputEvent event) {
2023 finishInputEvent(event, true);
2024 }
2025 }
2026 /**
2027 * Dummy event receiver for windows that died visible.
2028 */
2029 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2030
Chong Zhang112eb8c2015-11-02 11:17:00 -08002031 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002032 if (mInputChannel != null) {
2033 throw new IllegalStateException("Window already has an input channel.");
2034 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002035 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002036 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2037 mInputChannel = inputChannels[0];
2038 mClientChannel = inputChannels[1];
2039 mInputWindowHandle.inputChannel = inputChannels[0];
2040 if (outInputChannel != null) {
2041 mClientChannel.transferTo(outInputChannel);
2042 mClientChannel.dispose();
2043 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002044 } else {
2045 // If the window died visible, we setup a dummy input channel, so that taps
2046 // can still detected by input monitor channel, and we can relaunch the app.
2047 // Create dummy event receiver that simply reports all events as handled.
2048 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002049 }
2050 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002051 }
2052
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002053 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002054 if (mDeadWindowEventReceiver != null) {
2055 mDeadWindowEventReceiver.dispose();
2056 mDeadWindowEventReceiver = null;
2057 }
2058
2059 // unregister server channel first otherwise it complains about broken channel
2060 if (mInputChannel != null) {
2061 mService.mInputManager.unregisterInputChannel(mInputChannel);
2062 mInputChannel.dispose();
2063 mInputChannel = null;
2064 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002065 if (mClientChannel != null) {
2066 mClientChannel.dispose();
2067 mClientChannel = null;
2068 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002069 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002070 }
2071
Chong Zhang112eb8c2015-11-02 11:17:00 -08002072 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002073 // When the app is terminated (eg. from Recents), the task might have already been
2074 // removed with the window pending removal. Don't apply dim in such cases, as there
2075 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2076 final AppWindowToken token = mAppToken;
2077 if (token != null && token.removed) {
2078 return;
2079 }
2080
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002081 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002082 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002083 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002084 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002085 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002086 && dc != null && !mAnimatingExit && isVisibleUnchecked()) {
2087 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002088 }
2089 }
2090
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002091 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002092 Task task = getTask();
2093 if (task != null) {
2094 return task;
2095 }
2096 return getStack();
2097 }
2098
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002099 /** Returns true if the replacement window was removed. */
2100 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2101 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2102 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2103 removeReplacedWindow();
2104 return true;
2105 }
2106
2107 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002108 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002109 if (c.removeReplacedWindowIfNeeded(replacement)) {
2110 return true;
2111 }
2112 }
2113 return false;
2114 }
2115
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002116 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002117 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2118 if (isDimming()) {
2119 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002120 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002121 mWillReplaceWindow = false;
2122 mAnimateReplacingWindow = false;
2123 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002124 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002125 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002126 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002127 }
2128 }
2129
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002130 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2131 boolean replacementSet = false;
2132
2133 if (mWillReplaceWindow && mReplacementWindow == null
2134 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2135
2136 mReplacementWindow = replacementCandidate;
2137 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2138 replacementSet = true;
2139 }
2140
2141 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002142 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002143 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2144 }
2145
2146 return replacementSet;
2147 }
2148
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002149 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002150 final DisplayContent dc = getDisplayContent();
2151 if (dc != null) {
2152 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002153 }
2154 }
2155
Robert Carrfed10072016-05-26 11:48:49 -07002156 // TODO: Strange usage of word workspace here and above.
2157 boolean inPinnedWorkspace() {
2158 final Task task = getTask();
2159 return task != null && task.inPinnedWorkspace();
2160 }
2161
Chong Zhang5117e272016-05-03 12:47:34 -07002162 void applyAdjustForImeIfNeeded() {
2163 final Task task = getTask();
2164 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2165 task.mStack.applyAdjustForImeIfNeeded(task);
2166 }
2167 }
2168
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002169 @Override
2170 void switchUser() {
2171 super.switchUser();
2172 if (isHiddenFromUserLocked()) {
2173 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2174 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2175 hideLw(false);
2176 }
2177 }
2178
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002179 int getTouchableRegion(Region region, int flags) {
2180 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002181 if (modal && mAppToken != null) {
2182 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002183 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002184 // If this is a modal window we need to dismiss it if it's not full screen and the
2185 // touch happens outside of the frame that displays the content. This means we
2186 // need to intercept touches outside of that window. The dim layer user
2187 // associated with the window (task or stack) will give us the good bounds, as
2188 // they would be used to display the dim layer.
2189 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2190 if (dimLayerUser != null) {
2191 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002192 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002193 getVisibleBounds(mTmpRect);
2194 }
2195 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002196 // For freeform windows we the touch region to include the whole surface for the
2197 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002198 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2199 final int delta = WindowManagerService.dipToPixel(
2200 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2201 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002202 }
2203 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002204 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002205 } else {
2206 // Not modal or full screen modal
2207 getTouchableRegion(region);
2208 }
2209 return flags;
2210 }
2211
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002212 void checkPolicyVisibilityChange() {
2213 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2214 if (DEBUG_VISIBILITY) {
2215 Slog.v(TAG, "Policy visibility changing after anim in " +
2216 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2217 }
2218 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002219 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002220 if (!mPolicyVisibility) {
2221 if (mService.mCurrentFocus == this) {
2222 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2223 "setAnimationLocked: setting mFocusMayChange true");
2224 mService.mFocusMayChange = true;
2225 }
2226 // Window is no longer visible -- make sure if we were waiting
2227 // for it to be displayed before enabling the display, that
2228 // we allow the display to be enabled now.
2229 mService.enableScreenIfNeededLocked();
2230 }
2231 }
2232 }
2233
2234 void setRequestedSize(int requestedWidth, int requestedHeight) {
2235 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2236 mLayoutNeeded = true;
2237 mRequestedWidth = requestedWidth;
2238 mRequestedHeight = requestedHeight;
2239 }
2240 }
2241
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002242 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
2243 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2244 == SOFT_INPUT_ADJUST_RESIZE) {
2245 mLayoutNeeded = true;
2246 }
2247 if (isDrawnLw() && mService.okToDisplay()) {
2248 mWinAnimator.applyEnterAnimationLocked();
2249 }
2250 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2251 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2252 mTurnOnScreen = true;
2253 }
2254 if (isConfigChanged()) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002255 outConfig.setTo(getConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002256 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002257 + outConfig);
2258 mLastReportedConfiguration.setTo(outConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002259 }
2260 }
2261
2262 void adjustStartingWindowFlags() {
2263 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2264 && mAppToken.startingWindow != null) {
2265 // Special handling of starting window over the base
2266 // window of the app: propagate lock screen flags to it,
2267 // to provide the correct semantics while starting.
2268 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2269 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2270 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2271 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2272 }
2273 }
2274
2275 void setWindowScale(int requestedWidth, int requestedHeight) {
2276 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2277
2278 if (scaledWindow) {
2279 // requested{Width|Height} Surface's physical size
2280 // attrs.{width|height} Size on screen
2281 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2282 mHScale = (mAttrs.width != requestedWidth) ?
2283 (mAttrs.width / (float)requestedWidth) : 1.0f;
2284 mVScale = (mAttrs.height != requestedHeight) ?
2285 (mAttrs.height / (float)requestedHeight) : 1.0f;
2286 } else {
2287 mHScale = mVScale = 1;
2288 }
2289 }
2290
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002291 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002292 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002293 public void binderDied() {
2294 try {
2295 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002296 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002297 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002298 if (win != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002299 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002300 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2301 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002302 // just in case they have the divider at an unstable position. Better
2303 // also reset drag resizing state, because the owner can't do it
2304 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002305 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
2306 if (stack != null) {
2307 stack.resetDockedStackToMiddle();
2308 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002309 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002310 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002311 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002312 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002313 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002314 }
2315 }
2316 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002317 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002318 }
2319 }
2320 }
2321
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002322 /**
2323 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2324 * because we want to preserve its location on screen to be re-activated later when the user
2325 * interacts with it.
2326 */
2327 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002328 if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002329 // Not a visible app window or the app isn't dead.
2330 return false;
2331 }
2332
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002333 if (mAttrs.token != mClient.asBinder()) {
2334 // The window was add by a client using another client's app token. We don't want to
2335 // keep the dead window around for this case since this is meant for 'real' apps.
2336 return false;
2337 }
2338
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002339 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2340 // We don't keep starting windows since they were added by the window manager before
2341 // the app even launched.
2342 return false;
2343 }
2344
2345 final TaskStack stack = getStack();
2346 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2347 }
2348
Wale Ogunwaled045c822015-12-02 09:14:28 -08002349 /** @return true if this window desires key events. */
2350 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002351 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002352 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002353 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002354 && (mAppToken == null || mAppToken.windowsAreFocusable())
2355 && !isAdjustedForMinimizedDock();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002356 }
2357
Craig Mautner749a7bb2012-04-02 13:49:53 -07002358 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002359 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002360 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002361 }
2362
Craig Mautner749a7bb2012-04-02 13:49:53 -07002363 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002364 public boolean showLw(boolean doAnimation) {
2365 return showLw(doAnimation, true);
2366 }
2367
2368 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002369 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002370 return false;
2371 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002372 if (!mAppOpVisibility) {
2373 // Being hidden due to app op request.
2374 return false;
2375 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002376 if (mPermanentlyHidden) {
2377 // Permanently hidden until the app exists as apps aren't prepared
2378 // to handle their windows being removed from under them.
2379 return false;
2380 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002381 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002382 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002383 return false;
2384 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002385 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002386 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002387 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002388 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07002389 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002390 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002391 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002392 // Check for the case where we are currently visible and
2393 // not animating; we do not want to do animation at such a
2394 // point to become visible when we already are.
2395 doAnimation = false;
2396 }
2397 }
2398 mPolicyVisibility = true;
2399 mPolicyVisibilityAfterAnim = true;
2400 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002401 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002402 }
2403 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002404 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002405 }
2406 return true;
2407 }
2408
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002409 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002410 public boolean hideLw(boolean doAnimation) {
2411 return hideLw(doAnimation, true);
2412 }
2413
2414 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2415 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07002416 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002417 doAnimation = false;
2418 }
2419 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002420 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002421 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002422 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002423 return false;
2424 }
2425 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002426 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002427 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002428 doAnimation = false;
2429 }
2430 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002431 mPolicyVisibilityAfterAnim = false;
2432 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002433 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002434 mPolicyVisibility = false;
2435 // Window is no longer visible -- make sure if we were waiting
2436 // for it to be displayed before enabling the display, that
2437 // we allow the display to be enabled now.
2438 mService.enableScreenIfNeededLocked();
2439 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002440 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002441 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002442 mService.mFocusMayChange = true;
2443 }
2444 }
2445 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002446 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002447 }
2448 return true;
2449 }
2450
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002451 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002452 if (mAppOpVisibility != state) {
2453 mAppOpVisibility = state;
2454 if (state) {
2455 // If the policy visibility had last been to hide, then this
2456 // will incorrectly show at this point since we lost that
2457 // information. Not a big deal -- for the windows that have app
2458 // ops modifies they should only be hidden by policy due to the
2459 // lock screen, and the user won't be changing this if locked.
2460 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002461 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002462 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002463 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002464 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002465 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002466 }
2467
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002468 public void hidePermanentlyLw() {
2469 if (!mPermanentlyHidden) {
2470 mPermanentlyHidden = true;
2471 hideLw(true, true);
2472 }
2473 }
2474
Jeff Brownc2932a12014-11-20 18:04:05 -08002475 public void pokeDrawLockLw(long timeout) {
2476 if (isVisibleOrAdding()) {
2477 if (mDrawLock == null) {
2478 // We want the tag name to be somewhat stable so that it is easier to correlate
2479 // in wake lock statistics. So in particular, we don't want to include the
2480 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002481 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002482 mDrawLock = mService.mPowerManager.newWakeLock(
2483 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2484 mDrawLock.setReferenceCounted(false);
2485 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2486 }
2487 // Each call to acquire resets the timeout.
2488 if (DEBUG_POWER) {
2489 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2490 + mAttrs.packageName);
2491 }
2492 mDrawLock.acquire(timeout);
2493 } else if (DEBUG_POWER) {
2494 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2495 + "owned by " + mAttrs.packageName);
2496 }
2497 }
2498
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002499 @Override
2500 public boolean isAlive() {
2501 return mClient.asBinder().isBinderAlive();
2502 }
2503
Craig Mautnera987d432012-10-11 14:07:58 -07002504 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002505 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002506 }
2507
Chong Zhangbef461f2015-10-27 11:38:24 -07002508 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002509 return mAnimatingWithSavedSurface;
2510 }
2511
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002512 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002513 boolean isAnimating() {
2514 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2515 return true;
2516 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002517 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002518 }
2519
Chong Zhang8e4bda92016-05-04 15:08:18 -07002520 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002521 if (mAnimatingWithSavedSurface
2522 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2523 return true;
2524 }
2525 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002526 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002527 if (c.isAnimatingInvisibleWithSavedSurface()) {
2528 return true;
2529 }
2530 }
2531 return false;
2532 }
2533
2534 void stopUsingSavedSurface() {
2535 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002536 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002537 c.stopUsingSavedSurface();
2538 }
2539
2540 if (!isAnimatingInvisibleWithSavedSurface()) {
2541 return;
2542 }
2543
2544 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2545 clearAnimatingWithSavedSurface();
2546 mDestroying = true;
2547 mWinAnimator.hide("stopUsingSavedSurface");
Wale Ogunwale0303c572016-10-20 10:16:29 -07002548 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002549 }
2550
2551 void markSavedSurfaceExiting() {
2552 if (isAnimatingInvisibleWithSavedSurface()) {
2553 mAnimatingExit = true;
2554 mWinAnimator.mAnimating = true;
2555 }
2556 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002557 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002558 c.markSavedSurfaceExiting();
2559 }
2560 }
2561
2562 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2563 animators.add(mWinAnimator);
2564
2565 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002566 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002567 c.addWinAnimatorToList(animators);
2568 }
2569 }
2570
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002571 void sendAppVisibilityToClients() {
2572 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002573
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002574 final boolean clientHidden = mAppToken.clientHidden;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002575 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2576 // Don't hide the starting window.
2577 return;
2578 }
2579
2580 try {
2581 if (DEBUG_VISIBILITY) Slog.v(TAG,
2582 "Setting visibility of " + this + ": " + (!clientHidden));
2583 mClient.dispatchAppVisibility(!clientHidden);
2584 } catch (RemoteException e) {
2585 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002586 }
2587
Chong Zhang92147042016-05-09 12:47:11 -07002588 public void setVisibleBeforeClientHidden() {
2589 mWasVisibleBeforeClientHidden |=
2590 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002591
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002592 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002593 }
2594
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002595 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002596 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002597 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002598 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002599 c.clearWasVisibleBeforeClientHidden();
2600 }
Chong Zhang92147042016-05-09 12:47:11 -07002601 }
2602
2603 public boolean wasVisibleBeforeClientHidden() {
2604 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002605 }
2606
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002607 void onStartFreezingScreen() {
2608 mAppFreezing = true;
2609 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002610 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002611 c.onStartFreezingScreen();
2612 }
2613 }
2614
2615 boolean onStopFreezingScreen() {
2616 boolean unfrozeWindows = false;
2617 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002618 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002619 unfrozeWindows |= c.onStopFreezingScreen();
2620 }
2621
2622 if (!mAppFreezing) {
2623 return unfrozeWindows;
2624 }
2625
Wale Ogunwale953171d2016-09-30 09:17:30 -07002626 mAppFreezing = false;
2627
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002628 if (mHasSurface && !mOrientationChanging
2629 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2630 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
2631 mOrientationChanging = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002632 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002633 }
2634 mLastFreezeDuration = 0;
2635 setDisplayLayoutNeeded();
2636 return true;
2637 }
2638
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002639 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002640 if (mWinAnimator.mSurfaceController == null) {
2641 // Don't bother if the surface controller is gone for any reason.
2642 return false;
2643 }
2644
Chong Zhang92147042016-05-09 12:47:11 -07002645 if (!mWasVisibleBeforeClientHidden) {
2646 return false;
2647 }
2648
Wale Ogunwale945d1972016-03-23 13:16:41 -07002649 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2650 // We don't save secure surfaces since their content shouldn't be shown while the app
2651 // isn't on screen and content might leak through during the transition animation with
2652 // saved surface.
2653 return false;
2654 }
2655
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002656 if (ActivityManager.isLowRamDeviceStatic()) {
2657 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002658 return false;
2659 }
2660
Jorim Jaggiab7ad382016-10-26 18:22:04 -07002661 final Task task = getTask();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002662 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2663 if (taskTop != null && taskTop != mAppToken) {
2664 // Don't save if the window is not the topmost window.
2665 return false;
2666 }
2667
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002668 if (mResizedWhileGone) {
2669 // Somebody resized our window while we were gone for layout, which means that the
2670 // client got an old size, so we have an outdated surface here.
2671 return false;
2672 }
2673
Robert Carr7098dbd2016-02-01 12:31:01 -08002674 if (DEBUG_DISABLE_SAVING_SURFACES) {
2675 return false;
2676 }
2677
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002678 return mAppToken.shouldSaveSurface();
2679 }
2680
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002681 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2682 boolean destroyedSomething = false;
2683 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002684 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002685 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2686 }
2687
2688 if (appStopped || mWindowRemovalAllowed || cleanupOnResume) {
2689
2690 mWinAnimator.destroyPreservedSurfaceLocked();
2691
2692 if (mDestroying) {
2693 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2694 + " destroySurfaces: appStopped=" + appStopped
2695 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2696 + " win.mRemoveOnExit=" + mRemoveOnExit);
2697
2698 if (!cleanupOnResume || mRemoveOnExit) {
2699 destroyOrSaveSurface();
2700 }
2701 if (mRemoveOnExit) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002702 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002703 }
2704 if (cleanupOnResume) {
2705 requestUpdateWallpaperIfNeeded();
2706 }
2707 mDestroying = false;
2708 destroyedSomething = true;
2709 }
2710 }
2711 return destroyedSomething;
2712 }
Chris Craik3131bde2016-05-06 13:39:08 -07002713
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002714 void destroyOrSaveSurface() {
2715 mSurfaceSaved = shouldSaveSurface();
2716 if (mSurfaceSaved) {
2717 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2718 Slog.v(TAG, "Saving surface: " + this);
2719 }
Chris Craik3131bde2016-05-06 13:39:08 -07002720 // Previous user of the surface may have set a transparent region signaling a portion
2721 // doesn't need to be composited, so reset to default empty state.
2722 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002723
2724 mWinAnimator.hide("saved surface");
2725 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2726 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002727 // The client should have disconnected at this point, but if it doesn't,
2728 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2729 // the client can't reconnect to the buffer queue, and rendering will fail.
2730 if (mWinAnimator.mSurfaceController != null) {
2731 mWinAnimator.mSurfaceController.disconnectInTransaction();
2732 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002733 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002734 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002735 mWinAnimator.destroySurfaceLocked();
2736 }
Chong Zhang92147042016-05-09 12:47:11 -07002737 // Clear animating flags now, since the surface is now gone. (Note this is true even
2738 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2739 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002740 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002741
Chong Zhang92147042016-05-09 12:47:11 -07002742 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002743 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002744 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002745 c.destroySavedSurface();
2746 }
2747
Robert Carr13f7be9e2015-12-02 18:39:45 -08002748 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002749 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002750 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002751 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002752 }
Chong Zhang92147042016-05-09 12:47:11 -07002753 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002754 }
2755
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002756 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2757 int restoreSavedSurfaceForInterestingWindow() {
2758 int interestingNotDrawn = -1;
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 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2762 if (childInterestingNotDrawn != -1) {
2763 if (interestingNotDrawn == -1) {
2764 interestingNotDrawn = childInterestingNotDrawn;
2765 } else {
2766 interestingNotDrawn += childInterestingNotDrawn;
2767 }
2768 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002769 }
Robert Carr237028a2016-07-26 10:39:45 -07002770
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002771 if (mAttrs.type == TYPE_APPLICATION_STARTING
2772 || mAppDied || !wasVisibleBeforeClientHidden()
2773 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2774 // Window isn't interesting...
2775 return interestingNotDrawn;
2776 }
2777
2778 restoreSavedSurface();
2779
2780 if (!isDrawnLw()) {
2781 if (interestingNotDrawn == -1) {
2782 interestingNotDrawn = 1;
2783 } else {
2784 interestingNotDrawn++;
2785 }
2786 }
2787 return interestingNotDrawn;
2788 }
2789
2790 /** Returns true if the saved surface was restored. */
2791 boolean restoreSavedSurface() {
2792 if (!mSurfaceSaved) {
2793 return false;
2794 }
2795
2796 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2797 // However this means the surface was never laid out in the new orientation.
2798 // We can only restore to the last rotation we were laid out as visible in.
Robert Carr237028a2016-07-26 10:39:45 -07002799 if (mLastVisibleLayoutRotation != mService.mRotation) {
2800 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002801 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002802 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002803 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002804
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002805 if (mWinAnimator.mSurfaceController != null) {
2806 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002807 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002808 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002809
Chong Zhang6e9872b2016-08-17 10:19:05 -07002810 requestUpdateWallpaperIfNeeded();
2811
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002812 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2813 Slog.v(TAG, "Restoring saved surface: " + this);
2814 }
2815 } else {
2816 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2817 // this point. Even if we destroyed the saved surface because of rotation
2818 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2819 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002820 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002821
2822 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002823 }
2824
Chong Zhang92147042016-05-09 12:47:11 -07002825 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002826 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2827 return true;
2828 }
2829
2830 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002831 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002832 if (c.canRestoreSurface()) {
2833 return true;
2834 }
2835 }
2836
2837 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002838 }
2839
2840 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002841 return mSurfaceSaved;
2842 }
2843
Chong Zhang92147042016-05-09 12:47:11 -07002844 void clearHasSavedSurface() {
2845 mSurfaceSaved = false;
2846 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002847 if (mWasVisibleBeforeClientHidden) {
2848 mAppToken.destroySavedSurfaces();
2849 }
Chong Zhang92147042016-05-09 12:47:11 -07002850 }
2851
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002852 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002853 if (mAnimatingWithSavedSurface) {
2854 // App has drawn something to its windows, we're no longer animating with
2855 // the saved surfaces.
2856 if (DEBUG_ANIM) Slog.d(TAG,
2857 "clearAnimatingWithSavedSurface(): win=" + this);
2858 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002859 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002860 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002861 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002862 }
2863
Craig Mautner69b08182012-09-05 13:07:13 -07002864 @Override
2865 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002866 final DisplayContent displayContent = getDisplayContent();
2867 if (displayContent == null) {
2868 // Only a window that was on a non-default display can be detached from it.
2869 return false;
2870 }
Winson Chung47a3e652014-05-21 16:03:42 -07002871 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002872 }
2873
Adrian Rooscd3884d2015-02-18 17:25:23 +01002874 @Override
2875 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002876 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002877 final DisplayContent dc = getDisplayContent();
2878 return dimLayerUser != null && dc != null
2879 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002880 }
2881
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002882 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002883 mShowToOwnerOnly = showToOwnerOnly;
2884 }
2885
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002886 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002887 // Child windows are evaluated based on their parent window.
2888 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002889 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07002890 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002891
2892 // All window frames that are fullscreen extend above status bar, but some don't extend
2893 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2894 // bottom right.
2895 if (win.mFrame.left <= win.mDisplayFrame.left
2896 && win.mFrame.top <= win.mDisplayFrame.top
2897 && win.mFrame.right >= win.mStableFrame.right
2898 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002899 // Is a fullscreen window, like the clock alarm. Show to everyone.
2900 return false;
2901 }
2902 }
2903
Craig Mautner341220f2012-10-16 15:20:09 -07002904 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002905 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002906 }
2907
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002908 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2909 outRegion.set(
2910 frame.left + inset.left, frame.top + inset.top,
2911 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002912 }
2913
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002914 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002915 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002916 switch (mTouchableInsets) {
2917 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002918 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002919 outRegion.set(frame);
2920 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002921 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002922 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002923 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002924 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002925 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002926 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002927 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002928 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002929 outRegion.translate(frame.left, frame.top);
2930 break;
2931 }
2932 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002933 cropRegionToStackBoundsIfNeeded(outRegion);
2934 }
2935
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002936 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002937 final Task task = getTask();
2938 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002939 return;
2940 }
2941
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002942 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002943 if (stack == null) {
2944 return;
2945 }
2946
2947 stack.getDimBounds(mTmpRect);
2948 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002949 }
2950
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002951 /**
2952 * Report a focus change. Must be called with no locks held, and consistently
2953 * from the same serialized thread (such as dispatched from a handler).
2954 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002955 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002956 try {
2957 mClient.windowFocusChanged(focused, inTouchMode);
2958 } catch (RemoteException e) {
2959 }
2960 if (mFocusCallbacks != null) {
2961 final int N = mFocusCallbacks.beginBroadcast();
2962 for (int i=0; i<N; i++) {
2963 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2964 try {
2965 if (focused) {
2966 obs.focusGained(mWindowId.asBinder());
2967 } else {
2968 obs.focusLost(mWindowId.asBinder());
2969 }
2970 } catch (RemoteException e) {
2971 }
2972 }
2973 mFocusCallbacks.finishBroadcast();
2974 }
2975 }
2976
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002977 @Override
2978 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002979 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002980 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002981 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002982
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002983 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002984 }
2985
Craig Mautnerdf88d732014-01-27 09:21:32 -08002986 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002987 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002988 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002989 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2990 + ": " + mCompatFrame);
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002991 final Configuration newConfig;
2992 if (isConfigChanged()) {
2993 newConfig = new Configuration(getConfiguration());
2994 mLastReportedConfiguration.setTo(newConfig);
2995 } else {
2996 newConfig = null;
2997 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002998 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002999 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3000
Craig Mautnerdf88d732014-01-27 09:21:32 -08003001 final Rect frame = mFrame;
3002 final Rect overscanInsets = mLastOverscanInsets;
3003 final Rect contentInsets = mLastContentInsets;
3004 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003005 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003006 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003007 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07003008 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3009 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003010 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3011 mService.mH.post(new Runnable() {
3012 @Override
3013 public void run() {
3014 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003015 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
3016 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003017 } catch (RemoteException e) {
3018 // Not a remote call, RemoteException won't be raised.
3019 }
3020 }
3021 });
3022 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003023 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003024 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003025 }
Svetoslav4604abc2014-06-10 18:59:30 -07003026
3027 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003028 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003029 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003030 }
3031
Craig Mautnerdf88d732014-01-27 09:21:32 -08003032 mOverscanInsetsChanged = false;
3033 mContentInsetsChanged = false;
3034 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003035 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003036 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003037 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003038 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003039 mWinAnimator.mSurfaceResized = false;
3040 } catch (RemoteException e) {
3041 mOrientationChanging = false;
3042 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3043 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003044 // We are assuming the hosting process is dead or in a zombie state.
3045 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3046 + ", removing this window.");
3047 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003048 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003049 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003050 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003051 }
3052
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003053 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003054 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3055 // start even if we haven't received the relayout window, so that the client requests
3056 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3057 // until the window to small size, otherwise the multithread renderer will shift last
3058 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3059 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003060 boolean resizing = isDragResizing() || isDragResizeChanged();
3061 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3062 return frame;
3063 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003064 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003065 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003066 return mTmpRect;
3067 }
3068
Jorim Jaggi86905582016-02-09 21:36:09 -08003069 @Override
3070 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003071 final TaskStack stack = getStack();
3072 if (stack == null) {
3073 return INVALID_STACK_ID;
3074 }
3075 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003076 }
3077
3078 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3079 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
3080 Configuration newConfig) throws RemoteException {
Chong Zhangedaf3052016-04-22 15:04:31 -07003081 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing;
3082
Jorim Jaggidc249c42015-12-15 14:57:31 -08003083 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08003084 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07003085 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003086 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003087 }
3088
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003089 public void registerFocusObserver(IWindowFocusObserver observer) {
3090 synchronized(mService.mWindowMap) {
3091 if (mFocusCallbacks == null) {
3092 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3093 }
3094 mFocusCallbacks.register(observer);
3095 }
3096 }
3097
3098 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3099 synchronized(mService.mWindowMap) {
3100 if (mFocusCallbacks != null) {
3101 mFocusCallbacks.unregister(observer);
3102 }
3103 }
3104 }
3105
3106 public boolean isFocused() {
3107 synchronized(mService.mWindowMap) {
3108 return mService.mCurrentFocus == this;
3109 }
3110 }
3111
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003112 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003113 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003114 return task != null && task.inFreeformWorkspace();
3115 }
3116
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003117 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003118 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003119 final Task task = getTask();
3120 return task != null && !task.isFullscreen();
3121 }
3122
Chong Zhang3005e752015-09-18 18:46:28 -07003123 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003124 return mDragResizing != computeDragResizing();
3125 }
3126
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003127 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003128 void setWaitingForDrawnIfResizingChanged() {
3129 if (isDragResizeChanged()) {
3130 mService.mWaitingForDrawn.add(this);
3131 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003132 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003133 }
3134
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003135 /**
3136 * @return Whether we reported a drag resize change to the application or not already.
3137 */
3138 boolean isDragResizingChangeReported() {
3139 return mDragResizingChangeReported;
3140 }
3141
3142 /**
3143 * Resets the state whether we reported a drag resize change to the app.
3144 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003145 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003146 void resetDragResizingChangeReported() {
3147 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003148 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003149 }
3150
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003151 /**
3152 * Set whether we got resized but drag resizing flag was false.
3153 * @see #isResizedWhileNotDragResizing().
3154 */
3155 void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
3156 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3157 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3158 }
3159
3160 /**
3161 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3162 * need to recreate the surface and defer surface bound updates in order to make sure the
3163 * buffer contents and the positioning/size stay in sync.
3164 */
3165 boolean isResizedWhileNotDragResizing() {
3166 return mResizedWhileNotDragResizing;
3167 }
3168
3169 /**
3170 * @return Whether we reported "resize while not drag resizing" to the application.
3171 * @see #isResizedWhileNotDragResizing()
3172 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003173 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003174 return mResizedWhileNotDragResizingReported;
3175 }
3176
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003177 int getResizeMode() {
3178 return mResizeMode;
3179 }
3180
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003181 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003182 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003183 if (task == null) {
3184 return false;
3185 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003186 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
3187
3188 // Floating windows never enter drag resize mode.
3189 return false;
3190 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003191 if (task.isDragResizing()) {
3192 return true;
3193 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003194
3195 // If the bounds are currently frozen, it means that the layout size that the app sees
3196 // and the bounds we clip this window to might be different. In order to avoid holes, we
3197 // simulate that we are still resizing so the app fills the hole with the resizing
3198 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003199 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003200 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003201 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003202
Chong Zhang3005e752015-09-18 18:46:28 -07003203 }
3204
3205 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003206 final boolean resizing = computeDragResizing();
3207 if (resizing == mDragResizing) {
3208 return;
3209 }
3210 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003211 final Task task = getTask();
3212 if (task != null && task.isDragResizing()) {
3213 mResizeMode = task.getDragResizeMode();
3214 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003215 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003216 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3217 : DRAG_RESIZE_MODE_FREEFORM;
3218 }
Chong Zhang3005e752015-09-18 18:46:28 -07003219 }
3220
3221 boolean isDragResizing() {
3222 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003223 }
3224
Robert Carr2487ce72016-04-07 15:18:45 -07003225 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003226 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3227 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003228 }
3229
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003230 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003231 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003232 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003233 if (stack != null) {
3234 pw.print(" stackId="); pw.print(stack.mStackId);
3235 }
Craig Mautner59c00972012-07-30 12:10:24 -07003236 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003237 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003238 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003239 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3240 pw.print(" package="); pw.print(mAttrs.packageName);
3241 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003242 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003243 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3244 pw.print(" h="); pw.print(mRequestedHeight);
3245 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003246 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3247 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3248 pw.print(" h="); pw.println(mLastRequestedHeight);
3249 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003250 if (mIsChildWindow || mLayoutAttached) {
3251 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003252 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3253 }
3254 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3255 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3256 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3257 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3258 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3259 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003260 if (dumpAll) {
3261 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3262 pw.print(" mSubLayer="); pw.print(mSubLayer);
3263 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003264 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003265 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3266 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003267 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003268 if (dumpAll) {
3269 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003270 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003271 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3272 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003273 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08003274 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003275 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003276 pw.print(prefix); pw.print("mViewVisibility=0x");
3277 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003278 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3279 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003280 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3281 pw.print(" mSystemUiVisibility=0x");
3282 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003283 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003284 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Svetoslav Ganov71c51022016-09-02 17:54:37 -07003285 || isParentWindowHidden()|| mPermanentlyHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003286 pw.print(prefix); pw.print("mPolicyVisibility=");
3287 pw.print(mPolicyVisibility);
3288 pw.print(" mPolicyVisibilityAfterAnim=");
3289 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003290 pw.print(" mAppOpVisibility=");
3291 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003292 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Svetoslav Ganovaa076532016-08-01 19:16:43 -07003293 pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003294 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003295 if (!mRelayoutCalled || mLayoutNeeded) {
3296 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3297 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003298 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003299 if (mXOffset != 0 || mYOffset != 0) {
3300 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3301 pw.print(" y="); pw.println(mYOffset);
3302 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003303 if (dumpAll) {
3304 pw.print(prefix); pw.print("mGivenContentInsets=");
3305 mGivenContentInsets.printShortString(pw);
3306 pw.print(" mGivenVisibleInsets=");
3307 mGivenVisibleInsets.printShortString(pw);
3308 pw.println();
3309 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3310 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3311 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003312 Region region = new Region();
3313 getTouchableRegion(region);
3314 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003315 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003316 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3317 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3318 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003319 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003320 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003321 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003322 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003323 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3324 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003325 if (dumpAll) {
3326 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3327 pw.print(" last="); mLastFrame.printShortString(pw);
3328 pw.println();
3329 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003330 if (mEnforceSizeCompat) {
3331 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003332 pw.println();
3333 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003334 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003335 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003336 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003337 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003338 pw.println();
3339 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3340 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003341 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003342 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003343 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003344 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003345 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3346 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003347 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3348 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003349 pw.print(prefix); pw.print("Cur insets: overscan=");
3350 mOverscanInsets.printShortString(pw);
3351 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003352 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003353 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003354 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003355 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003356 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003357 pw.print(prefix); pw.print("Lst insets: overscan=");
3358 mLastOverscanInsets.printShortString(pw);
3359 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003360 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003361 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003362 pw.print(" physical="); mLastOutsets.printShortString(pw);
3363 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003364 pw.println();
3365 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003366 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3367 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003368 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3369 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003370 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3371 pw.print(" mDestroying="); pw.print(mDestroying);
3372 pw.print(" mRemoved="); pw.println(mRemoved);
3373 }
3374 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
3375 pw.print(prefix); pw.print("mOrientationChanging=");
3376 pw.print(mOrientationChanging);
3377 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
3378 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
3379 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003380 if (mLastFreezeDuration != 0) {
3381 pw.print(prefix); pw.print("mLastFreezeDuration=");
3382 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3383 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003384 if (mHScale != 1 || mVScale != 1) {
3385 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3386 pw.print(" mVScale="); pw.println(mVScale);
3387 }
3388 if (mWallpaperX != -1 || mWallpaperY != -1) {
3389 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3390 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3391 }
3392 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3393 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3394 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3395 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003396 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3397 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3398 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3399 pw.print(mWallpaperDisplayOffsetX);
3400 pw.print(" mWallpaperDisplayOffsetY=");
3401 pw.println(mWallpaperDisplayOffsetY);
3402 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003403 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003404 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003405 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003406 if (isDragResizing()) {
3407 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3408 }
3409 if (computeDragResizing()) {
3410 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3411 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003412 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003413
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003414 @Override
3415 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003416 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003417 + " " + getWindowTag();
3418 }
3419
Robert Carra1eb4392015-12-10 12:43:51 -08003420 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003421 CharSequence tag = mAttrs.getTitle();
3422 if (tag == null || tag.length() <= 0) {
3423 tag = mAttrs.packageName;
3424 }
3425 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003426 }
3427
3428 @Override
3429 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003430 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003431 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003432 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003433 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003434 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003435 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003436 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003437 }
3438 return mStringNameCache;
3439 }
Robert Carr58f29132015-10-29 14:19:05 -07003440
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003441 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003442 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003443 clipRect.left = (int) (clipRect.left / mHScale);
3444 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003445 }
3446 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003447 clipRect.top = (int) (clipRect.top / mVScale);
3448 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003449 }
3450 }
Robert Carr31e28482015-12-02 16:53:18 -08003451
Jorim Jaggif5834272016-04-04 20:25:41 -07003452 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3453 final int pw = containingFrame.width();
3454 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003455 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07003456 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003457 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3458
3459 // We need to fit it to the display if either
3460 // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless
3461 // windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003462 // b) If it's a secondary app window, we also need to fit it to the display unless
3463 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on screen,
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003464 // but SurfaceViews want to be always at a specific location so we don't fit it to the
3465 // display.
3466 final boolean fitToDisplay = (task == null || !nonFullscreenTask)
Robert Carr6f44db12016-07-21 14:54:43 -07003467 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003468 float x, y;
3469 int w,h;
3470
3471 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3472 if (mAttrs.width < 0) {
3473 w = pw;
3474 } else if (mEnforceSizeCompat) {
3475 w = (int)(mAttrs.width * mGlobalScale + .5f);
3476 } else {
3477 w = mAttrs.width;
3478 }
3479 if (mAttrs.height < 0) {
3480 h = ph;
3481 } else if (mEnforceSizeCompat) {
3482 h = (int)(mAttrs.height * mGlobalScale + .5f);
3483 } else {
3484 h = mAttrs.height;
3485 }
3486 } else {
3487 if (mAttrs.width == MATCH_PARENT) {
3488 w = pw;
3489 } else if (mEnforceSizeCompat) {
3490 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3491 } else {
3492 w = mRequestedWidth;
3493 }
3494 if (mAttrs.height == MATCH_PARENT) {
3495 h = ph;
3496 } else if (mEnforceSizeCompat) {
3497 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3498 } else {
3499 h = mRequestedHeight;
3500 }
3501 }
3502
3503 if (mEnforceSizeCompat) {
3504 x = mAttrs.x * mGlobalScale;
3505 y = mAttrs.y * mGlobalScale;
3506 } else {
3507 x = mAttrs.x;
3508 y = mAttrs.y;
3509 }
3510
Robert Carr1d2bacb2016-03-30 14:29:35 -07003511 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003512 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003513 // required by {@link Gravity#apply} call.
3514 w = Math.min(w, pw);
3515 h = Math.min(h, ph);
3516 }
3517
3518 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003519 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003520 (int) (x + mAttrs.horizontalMargin * pw),
3521 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3522
3523 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003524 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003525 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003526 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003527
3528 // We need to make sure we update the CompatFrame as it is used for
3529 // cropping decisions, etc, on systems where we lack a decor layer.
3530 mCompatFrame.set(mFrame);
3531 if (mEnforceSizeCompat) {
3532 // See comparable block in computeFrameLw.
3533 mCompatFrame.scale(mInvGlobalScale);
3534 }
Robert Carr31e28482015-12-02 16:53:18 -08003535 }
Robert Carr51a1b872015-12-08 14:03:13 -08003536
3537 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003538 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003539 }
3540
Robert Carrf3b72c72016-03-21 18:16:39 -07003541 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003542 return mIsChildWindow
3543 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003544 }
3545
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003546 /** Returns the parent window if this is a child of another window, else null. */
3547 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003548 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3549 // WindowContainer that isn't a WindowState.
3550 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003551 }
3552
3553 /** Returns the topmost parent window if this is a child of another window, else this. */
3554 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003555 WindowState current = this;
3556 WindowState topParent = current;
3557 while (current != null && current.mIsChildWindow) {
3558 current = current.getParentWindow();
3559 // Parent window can be null if the child is detached from it's parent already, but
3560 // someone still has a reference to access it. So, we return the top parent value we
3561 // already have instead of null.
3562 if (current != null) {
3563 topParent = current;
3564 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003565 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003566 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003567 }
3568
Wale Ogunwale9d147902016-07-16 11:58:55 -07003569 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003570 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003571 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003572 }
3573
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003574 void setWillReplaceWindow(boolean animate) {
3575 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003576 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003577 c.setWillReplaceWindow(animate);
3578 }
3579
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003580 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3581 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3582 // We don't set replacing on starting windows since they are added by window manager and
3583 // not the client so won't be replaced by the client.
3584 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003585 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003586
3587 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003588 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003589 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003590 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003591
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003592 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003593 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003594 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003595 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003596
3597 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003598 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003599 c.clearWillReplaceWindow();
3600 }
3601 }
3602
3603 boolean waitingForReplacement() {
3604 if (mWillReplaceWindow) {
3605 return true;
3606 }
3607
3608 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003609 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003610 if (c.waitingForReplacement()) {
3611 return true;
3612 }
3613 }
3614 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003615 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003616
Chong Zhang4d7369a2016-04-25 16:09:14 -07003617 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003618 final DisplayContent dc = getDisplayContent();
3619 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3620 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3621 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003622 mService.mWindowPlacerLocked.requestTraversal();
3623 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003624
3625 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003626 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003627 c.requestUpdateWallpaperIfNeeded();
3628 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003629 }
3630
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003631 float translateToWindowX(float x) {
3632 float winX = x - mFrame.left;
3633 if (mEnforceSizeCompat) {
3634 winX *= mGlobalScale;
3635 }
3636 return winX;
3637 }
3638
3639 float translateToWindowY(float y) {
3640 float winY = y - mFrame.top;
3641 if (mEnforceSizeCompat) {
3642 winY *= mGlobalScale;
3643 }
3644 return winY;
3645 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003646
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003647 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003648 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003649 final DisplayContent dc = getDisplayContent();
3650 if (dimLayerUser != null && dc != null) {
3651 dc.mDimLayerController.applyDim(dimLayerUser,
3652 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003653 }
3654 }
3655
Robert Carrd1a010f2016-04-07 22:36:22 -07003656 // During activity relaunch due to resize, we sometimes use window replacement
3657 // for only child windows (as the main window is handled by window preservation)
3658 // and the big surface.
3659 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003660 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3661 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3662 // we also want to replace them at such phases, as they won't be covered by window
3663 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003664 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003665 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003666 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003667 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003668
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003669 void setWillReplaceChildWindows() {
3670 if (shouldBeReplacedWithChildren()) {
3671 setWillReplaceWindow(false /* animate */);
3672 }
3673 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003674 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003675 c.setWillReplaceChildWindows();
3676 }
3677 }
3678
3679 WindowState getReplacingWindow() {
3680 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3681 return this;
3682 }
3683 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003684 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003685 final WindowState replacing = c.getReplacingWindow();
3686 if (replacing != null) {
3687 return replacing;
3688 }
3689 }
3690 return null;
3691 }
3692
Jorim Jaggife762342016-10-13 14:33:27 +02003693 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003694 public int getRotationAnimationHint() {
3695 if (mAppToken != null) {
3696 return mAppToken.mRotationAnimationHint;
3697 } else {
3698 return -1;
3699 }
3700 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003701
Jorim Jaggife762342016-10-13 14:33:27 +02003702 @Override
3703 public boolean isInputMethodWindow() {
3704 return mIsImWindow;
3705 }
3706
Wale Ogunwale9d147902016-07-16 11:58:55 -07003707 // This must be called while inside a transaction.
3708 boolean performShowLocked() {
3709 if (isHiddenFromUserLocked()) {
3710 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3711 hideLw(false);
3712 return false;
3713 }
3714
3715 logPerformShow("performShow on ");
3716
Jorim Jaggib0d27342016-11-01 16:10:42 -07003717 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003718 return false;
3719 }
3720
3721 logPerformShow("Showing ");
3722
3723 mService.enableScreenIfNeededLocked();
3724 mWinAnimator.applyEnterAnimationLocked();
3725
3726 // Force the show in the next prepareSurfaceLocked() call.
3727 mWinAnimator.mLastAlpha = -1;
3728 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3729 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3730 mWinAnimator.mDrawState = HAS_DRAWN;
3731 mService.scheduleAnimationLocked();
3732
3733 if (mHidden) {
3734 mHidden = false;
3735 final DisplayContent displayContent = getDisplayContent();
3736
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003737 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003738 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003739 if (c.mWinAnimator.mSurfaceController != null) {
3740 c.performShowLocked();
3741 // It hadn't been shown, which means layout not performed on it, so now we
3742 // want to make sure to do a layout. If called from within the transaction
3743 // loop, this will cause it to restart with a new layout.
3744 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003745 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003746 }
3747 }
3748 }
3749 }
3750
3751 if (mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3752 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3753 }
3754
3755 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003756 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003757 }
3758
3759 return true;
3760 }
3761
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003762 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003763 if (DEBUG_VISIBILITY
3764 || (DEBUG_STARTING_WINDOW && mAttrs.type == TYPE_APPLICATION_STARTING)) {
3765 Slog.v(TAG, prefix + this
3766 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003767 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003768 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3769 + " during animation: policyVis=" + mPolicyVisibility
3770 + " parentHidden=" + isParentWindowHidden()
3771 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003772 + (mAppToken != null && mAppToken.hiddenRequested)
3773 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003774 + " animating=" + mWinAnimator.mAnimating
3775 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003776 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003777 + " Callers=" + Debug.getCallers(4));
3778 }
3779 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003780
3781 WindowInfo getWindowInfo() {
3782 WindowInfo windowInfo = WindowInfo.obtain();
3783 windowInfo.type = mAttrs.type;
3784 windowInfo.layer = mLayer;
3785 windowInfo.token = mClient.asBinder();
3786 windowInfo.title = mAttrs.accessibilityTitle;
3787 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3788 windowInfo.focused = isFocused();
3789
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003790 if (mIsChildWindow) {
3791 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003792 }
3793
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003794 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003795 if (childCount > 0) {
3796 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003797 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003798 }
3799 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003800 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003801 windowInfo.childTokens.add(child.mClient.asBinder());
3802 }
3803 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003804 return windowInfo;
3805 }
3806
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003807 int getHighestAnimLayer() {
3808 int highest = mWinAnimator.mAnimLayer;
3809 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003810 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003811 final int childLayer = c.getHighestAnimLayer();
3812 if (childLayer > highest) {
3813 highest = childLayer;
3814 }
3815 }
3816 return highest;
3817 }
3818
3819 int adjustAnimLayer(int adj) {
3820 int highestAnimLayer = mWinAnimator.mAnimLayer = mLayer + adj;
3821 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG_WM,
3822 "adjustAnimLayer win=" + this + " anim layer: " + mWinAnimator.mAnimLayer);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003823 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003824 final WindowState childWindow = mChildren.get(i);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003825 childWindow.adjustAnimLayer(adj);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003826 if (childWindow.mWinAnimator.mAnimLayer > highestAnimLayer) {
3827 highestAnimLayer = childWindow.mWinAnimator.mAnimLayer;
3828 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003829 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003830 return highestAnimLayer;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003831 }
3832
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003833 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003834 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003835 if (mChildren.isEmpty()) {
3836 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003837 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003838 }
3839
3840 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003841 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003842 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003843 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003844 }
3845 }
3846
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003847 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003848 // We want to consumer the negative sublayer children first because they need to appear
3849 // below the parent, then this window (the parent), and then the positive sublayer children
3850 // because they need to appear above the parent.
3851 int i = 0;
3852 final int count = mChildren.size();
3853 WindowState child = mChildren.get(i);
3854
3855 while (i < count && child.mSubLayer < 0) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003856 if (callback.apply(child)) {
3857 return true;
3858 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003859 i++;
3860 if (i >= count) {
3861 break;
3862 }
3863 child = mChildren.get(i);
3864 }
3865
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003866 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003867 return true;
3868 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003869
3870 while (i < count) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003871 if (callback.apply(child)) {
3872 return true;
3873 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003874 i++;
3875 if (i >= count) {
3876 break;
3877 }
3878 child = mChildren.get(i);
3879 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003880
3881 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003882 }
3883
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003884 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003885 // We want to consumer the positive sublayer children first because they need to appear
3886 // above the parent, then this window (the parent), and then the negative sublayer children
3887 // because they need to appear above the parent.
3888 int i = mChildren.size() - 1;
3889 WindowState child = mChildren.get(i);
3890
3891 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003892 if (callback.apply(child)) {
3893 return true;
3894 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003895 --i;
3896 if (i < 0) {
3897 break;
3898 }
3899 child = mChildren.get(i);
3900 }
3901
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003902 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003903 return true;
3904 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003905
3906 while (i >= 0) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003907 if (callback.apply(child)) {
3908 return true;
3909 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003910 --i;
3911 if (i < 0) {
3912 break;
3913 }
3914 child = mChildren.get(i);
3915 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003916
3917 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003918 }
3919
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003920 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3921 boolean traverseTopToBottom) {
3922 if (traverseTopToBottom) {
3923 if (mService.mInputMethodTarget == this) {
3924 // This window is the current IME target, so we need to process the IME windows
3925 // directly above it.
3926 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3927 return true;
3928 }
3929 }
3930 if (callback.apply(this)) {
3931 return true;
3932 }
3933 } else {
3934 if (callback.apply(this)) {
3935 return true;
3936 }
3937 if (mService.mInputMethodTarget == this) {
3938 // This window is the current IME target, so we need to process the IME windows
3939 // directly above it.
3940 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3941 return true;
3942 }
3943 }
3944 }
3945
3946 return false;
3947 }
3948
Wale Ogunwaled1880962016-11-08 10:31:59 -08003949 WindowState getWindow(Predicate<WindowState> callback) {
3950 if (callback.test(this)) {
3951 return this;
3952 }
3953 return super.getWindow(callback);
3954 }
3955
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003956 boolean isWindowAnimationSet() {
3957 if (mWinAnimator.isWindowAnimationSet()) {
3958 return true;
3959 }
3960 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003961 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003962 if (c.isWindowAnimationSet()) {
3963 return true;
3964 }
3965 }
3966 return false;
3967 }
3968
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003969 void onExitAnimationDone() {
3970 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3971 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
3972 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
3973
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003974 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003975 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003976 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003977 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003978 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003979 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003980 }
3981 }
3982
3983 if (mWinAnimator.mEnteringAnimation) {
3984 mWinAnimator.mEnteringAnimation = false;
3985 mService.requestTraversal();
3986 // System windows don't have an activity and an app token as a result, but need a way
3987 // to be informed about their entrance animation end.
3988 if (mAppToken == null) {
3989 try {
3990 mClient.dispatchWindowShown();
3991 } catch (RemoteException e) {
3992 }
3993 }
3994 }
3995
3996 if (!mWinAnimator.isWindowAnimationSet()) {
3997 //TODO (multidisplay): Accessibility is supported only for the default display.
3998 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3999 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4000 }
4001 }
4002
4003 if (!mAnimatingExit) {
4004 return;
4005 }
4006
4007 if (mWinAnimator.isWindowAnimationSet()) {
4008 return;
4009 }
4010
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004011 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004012 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4013
4014 mDestroying = true;
4015
4016 final boolean hasSurface = mWinAnimator.hasSurface();
4017 if (hasSurface) {
4018 mWinAnimator.hide("onExitAnimationDone");
4019 }
4020
4021 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4022 // care to ensure the activity has actually stopped and the surface is not still in use.
4023 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4024 // transaction.
4025 if (mAppToken != null) {
4026 mAppToken.destroySurfaces();
4027 } else {
4028 if (hasSurface) {
4029 mService.mDestroySurface.add(this);
4030 }
4031 if (mRemoveOnExit) {
4032 mService.mPendingRemove.add(this);
4033 mRemoveOnExit = false;
4034 }
4035 }
4036 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004037 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004038 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004039
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004040 boolean clearAnimatingFlags() {
4041 boolean didSomething = false;
4042 // We don't want to clear it out for windows that get replaced, because the
4043 // animation depends on the flag to remove the replaced window.
4044 //
4045 // We also don't clear the mAnimatingExit flag for windows which have the
4046 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4047 // by the client. We should let animation proceed and not clear this flag or
4048 // they won't eventually be removed by WindowStateAnimator#finishExit.
4049 if (!mWillReplaceWindow && !mRemoveOnExit) {
4050 // Clear mAnimating flag together with mAnimatingExit. When animation
4051 // changes from exiting to entering, we need to clear this flag until the
4052 // new animation gets applied, so that isAnimationStarting() becomes true
4053 // until then.
4054 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4055 // placement for this window during this period, one or more frame will
4056 // show up with wrong position or scale.
4057 if (mAnimatingExit) {
4058 mAnimatingExit = false;
4059 didSomething = true;
4060 }
4061 if (mWinAnimator.mAnimating) {
4062 mWinAnimator.mAnimating = false;
4063 didSomething = true;
4064 }
4065 if (mDestroying) {
4066 mDestroying = false;
4067 mService.mDestroySurface.remove(this);
4068 didSomething = true;
4069 }
4070 }
4071
4072 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004073 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004074 }
4075
4076 return didSomething;
4077 }
4078
Winson4b4ba902016-07-27 19:45:52 -07004079 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004080 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004081 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004082
4083 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004084 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004085 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004086 c.hideWallpaperWindow(wasDeferred, reason);
4087 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004088 if (!mWinAnimator.mLastHidden || wasDeferred) {
4089 mWinAnimator.hide(reason);
4090 dispatchWallpaperVisibility(false);
4091 final DisplayContent displayContent = getDisplayContent();
4092 if (displayContent != null) {
4093 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4094 }
4095 }
4096 }
4097
4098 /**
4099 * Check wallpaper window for visibility change and notify window if so.
4100 * @param visible Current visibility.
4101 */
4102 void dispatchWallpaperVisibility(final boolean visible) {
4103 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004104 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004105
4106 // Only send notification if the visibility actually changed and we are not trying to hide
4107 // the wallpaper when we are deferring hiding of the wallpaper.
4108 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4109 mWallpaperVisible = visible;
4110 try {
4111 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4112 "Updating vis of wallpaper " + this
4113 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4114 mClient.dispatchAppVisibility(visible);
4115 } catch (RemoteException e) {
4116 }
4117 }
4118 }
4119
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004120 boolean hasVisibleNotDrawnWallpaper() {
4121 if (mWallpaperVisible && !isDrawnLw()) {
4122 return true;
4123 }
4124 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004125 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004126 if (c.hasVisibleNotDrawnWallpaper()) {
4127 return true;
4128 }
4129 }
4130 return false;
4131 }
4132
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004133 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4134 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004135 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004136 c.updateReportedVisibility(results);
4137 }
4138
4139 if (mAppFreezing || mViewVisibility != View.VISIBLE
4140 || mAttrs.type == TYPE_APPLICATION_STARTING
4141 || mDestroying) {
4142 return;
4143 }
4144 if (DEBUG_VISIBILITY) {
4145 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4146 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4147 if (!isDrawnLw()) {
4148 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4149 + " pv=" + mPolicyVisibility
4150 + " mDrawState=" + mWinAnimator.mDrawState
4151 + " ph=" + isParentWindowHidden()
4152 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4153 + " a=" + mWinAnimator.mAnimating);
4154 }
4155 }
4156
4157 results.numInteresting++;
4158 if (isDrawnLw()) {
4159 results.numDrawn++;
4160 if (!mWinAnimator.isAnimationSet()) {
4161 results.numVisible++;
4162 }
4163 results.nowGone = false;
4164 } else if (mWinAnimator.isAnimationSet()) {
4165 results.nowGone = false;
4166 }
4167 }
4168
Robert Carrfbbde852016-10-18 11:02:28 -07004169 /**
4170 * Calculate the window crop according to system decor policy. In general this is
4171 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4172 * special cases. This rectangle is in screen space.
4173 */
4174 void calculatePolicyCrop(Rect policyCrop) {
4175 final DisplayContent displayContent = getDisplayContent();
4176 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4177
4178 if (!isDefaultDisplay()) {
4179 // On a different display there is no system decor. Crop the window
4180 // by the screen boundaries.
4181 // TODO(multi-display)
4182 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4183 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4184 displayInfo.logicalWidth - mCompatFrame.left,
4185 displayInfo.logicalHeight - mCompatFrame.top);
4186 } else if (mLayer >= mService.mSystemDecorLayer) {
4187 // Above the decor layer is easy, just use the entire window
4188 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4189 } else if (mDecorFrame.isEmpty()) {
4190 // Windows without policy decor aren't cropped.
4191 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4192 } else {
4193 // Crop to the system decor specified by policy.
4194 calculateSystemDecorRect(policyCrop);
4195 }
4196 }
4197
4198 /**
4199 * The system decor rect is the region of the window which is not covered
4200 * by system decorations.
4201 */
4202 private void calculateSystemDecorRect(Rect systemDecorRect) {
4203 final Rect decorRect = mDecorFrame;
4204 final int width = mFrame.width();
4205 final int height = mFrame.height();
4206
4207 // Compute the offset of the window in relation to the decor rect.
4208 final int left = mXOffset + mFrame.left;
4209 final int top = mYOffset + mFrame.top;
4210
4211 // Initialize the decor rect to the entire frame.
4212 if (isDockedResizing()) {
4213 // If we are resizing with the divider, the task bounds might be smaller than the
4214 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4215 // want in this case in order to avoid holes.
4216 //
4217 // We take care to not shrink the width, for surfaces which are larger than
4218 // the display region. Of course this area will not eventually be visible
4219 // but if we truncate the width now, we will calculate incorrectly
4220 // when adjusting to the stack bounds.
4221 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4222 systemDecorRect.set(0, 0,
4223 Math.max(width, displayInfo.logicalWidth),
4224 Math.max(height, displayInfo.logicalHeight));
4225 } else {
4226 systemDecorRect.set(0, 0, width, height);
4227 }
4228
4229 // If a freeform window is animating from a position where it would be cutoff, it would be
4230 // cutoff during the animation. We don't want that, so for the duration of the animation
4231 // we ignore the decor cropping and depend on layering to position windows correctly.
4232 final boolean cropToDecor = !(inFreeformWorkspace() && isAnimatingLw());
4233 if (cropToDecor) {
4234 // Intersect with the decor rect, offsetted by window position.
4235 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4236 decorRect.right - left, decorRect.bottom - top);
4237 }
4238
4239 // If size compatibility is being applied to the window, the
4240 // surface is scaled relative to the screen. Also apply this
4241 // scaling to the crop rect. We aren't using the standard rect
4242 // scale function because we want to round things to make the crop
4243 // always round to a larger rect to ensure we don't crop too
4244 // much and hide part of the window that should be seen.
4245 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4246 final float scale = mInvGlobalScale;
4247 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4248 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4249 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4250 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4251 }
4252
4253 }
4254
4255 /**
4256 * Expand the given rectangle by this windows surface insets. This
4257 * takes you from the 'window size' to the 'surface size'.
4258 * The surface insets are positive in each direction, so we inset by
4259 * the inverse.
4260 */
4261 void expandForSurfaceInsets(Rect r) {
4262 r.inset(-mAttrs.surfaceInsets.left,
4263 -mAttrs.surfaceInsets.top,
4264 -mAttrs.surfaceInsets.right,
4265 -mAttrs.surfaceInsets.bottom);
4266 }
4267
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004268 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4269 // access to its windows children. Need to investigate re-writing
4270 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4271 static final class UpdateReportedVisibilityResults {
4272 int numInteresting;
4273 int numVisible;
4274 int numDrawn;
4275 boolean nowGone = true;
4276
4277 void reset() {
4278 numInteresting = 0;
4279 numVisible = 0;
4280 numDrawn = 0;
4281 nowGone = true;
4282 }
4283 }
satokcef37fb2011-10-24 21:49:38 +09004284}