blob: a13c4d0d110fec1bee8c51768b5cf58272d70795 [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;
41import android.view.Display;
42import android.view.DisplayInfo;
43import android.view.Gravity;
44import android.view.IApplicationToken;
45import android.view.IWindow;
46import android.view.IWindowFocusObserver;
47import android.view.IWindowId;
48import android.view.InputChannel;
49import android.view.InputEvent;
50import android.view.InputEventReceiver;
51import android.view.View;
52import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070053import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080054import android.view.WindowManager;
55import android.view.WindowManagerPolicy;
56
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 Ogunwale053c8e42015-11-16 14:27:21 -080063
Wale Ogunwaled045c822015-12-02 09:14:28 -080064import static android.app.ActivityManager.StackId;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -080065import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -080066import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070067import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070068import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080069import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
70import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
71import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
72import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080073import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -070074import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080075import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070076import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080077import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggi5f23a572016-04-22 15:05:50 -070078import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080079import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
80import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080081import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale945d1972016-03-23 13:16:41 -070082import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Chong Zhang4d7369a2016-04-25 16:09:14 -070083import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070084import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080085import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080086import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080087import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080088import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080089import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080090import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070091import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
Robert Carra1eb4392015-12-10 12:43:51 -080092import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080093import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
94import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Robert Carrd1a010f2016-04-07 22:36:22 -070095import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080096import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080097import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Chong Zhangfea963e2016-08-15 17:14:16 -070098import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070099import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800100import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
101import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
102import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Chong Zhang4d7369a2016-04-25 16:09:14 -0700103import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700104import static android.view.WindowManagerPolicy.TRANSIT_ENTER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700105import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
106import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100107import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
108import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800109import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
110import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
111import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
112import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700113import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800114import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700115import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800116import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
117import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
118import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
119import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700120import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
121import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800122import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700123import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700124import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700125import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800126import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
127import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700128import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700129import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
130import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700131import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
132import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700133import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700134import static com.android.server.wm.WindowManagerService.localLOGV;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700135import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700136import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700137import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
138import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139
Craig Mautner59c00972012-07-30 12:10:24 -0700140class WindowList extends ArrayList<WindowState> {
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800141 WindowList() {}
142 WindowList(WindowList windowList) {
143 super(windowList);
144 }
Craig Mautner59c00972012-07-30 12:10:24 -0700145}
146
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700147/** A window in the window manager. */
148class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800149 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800150
Skuhne81c524a2015-08-12 13:34:14 -0700151 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700152 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
153 // use hard-coded min sizes for now.
154 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
155 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700156
157 // The thickness of a window resize handle outside the window bounds on the free form workspace
158 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700159 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700160
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700161 private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
Robert Carr7098dbd2016-02-01 12:31:01 -0800162
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800163 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700164 final WindowManagerPolicy mPolicy;
165 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166 final Session mSession;
167 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800168 final int mAppOp;
169 // UserId and appId of the owner. Don't display windows of non-current user.
170 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800171 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800172 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700173 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700175
176 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
177 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
179 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700180 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800181 final int mBaseLayer;
182 final int mSubLayer;
183 final boolean mLayoutAttached;
184 final boolean mIsImWindow;
185 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700186 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700187 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700188 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800189 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700190 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700191 /**
192 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
193 * Normally set by calling {@link #showLw} and {@link #hideLw}.
194 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700196 /**
197 * What {@link #mPolicyVisibility} should be set to after a transition animation.
198 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
199 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
200 * animation is done.
201 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700203 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700204 boolean mPermanentlyHidden; // the window should never be shown again
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800205 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700206 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800207 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700208 private boolean mDragResizing;
209 private boolean mDragResizingChangeReported;
210 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700211
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700212 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800213
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700214 /**
215 * The window size that was requested by the application. These are in
216 * the application's coordinate space (without compatibility scale applied).
217 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800218 int mRequestedWidth;
219 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700220 private int mLastRequestedWidth;
221 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700222
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 boolean mHaveFrame;
225 boolean mObscured;
226 boolean mTurnOnScreen;
227
228 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700229
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700230 /**
231 * Used to store last reported to client configuration and check if we have newer available.
232 * We'll send configuration to client only if it is different from the last applied one and
233 * client won't perform unnecessary updates.
234 */
235 private final Configuration mLastReportedConfiguration = new Configuration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700236
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700237 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700238 * Actual position of the surface shown on-screen (may be modified by animation). These are
239 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700240 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700241 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242
243 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700244 * Insets that determine the actually visible area. These are in the application's
245 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246 */
247 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700248 private final Rect mLastVisibleInsets = new Rect();
249 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800250
251 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700252 * Insets that are covered by system windows (such as the status bar) and
253 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700254 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 */
256 final Rect mContentInsets = new Rect();
257 final Rect mLastContentInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700258 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259
260 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800261 * Insets that determine the area covered by the display overscan region. These are in the
262 * application's coordinate space (without compatibility scale applied).
263 */
264 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700265 private final Rect mLastOverscanInsets = new Rect();
266 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800267
268 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700269 * Insets that determine the area covered by the stable system windows. These are in the
270 * application's coordinate space (without compatibility scale applied).
271 */
272 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700273 private final Rect mLastStableInsets = new Rect();
274 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700275
276 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700277 * Outsets determine the area outside of the surface where we want to pretend that it's possible
278 * to draw anyway.
279 */
280 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700281 private final Rect mLastOutsets = new Rect();
282 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700283
284 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 * Set to true if we are waiting for this window to receive its
286 * given internal insets before laying out other windows based on it.
287 */
288 boolean mGivenInsetsPending;
289
290 /**
291 * These are the content insets that were given during layout for
292 * this window, to be applied to windows behind it.
293 */
294 final Rect mGivenContentInsets = new Rect();
295
296 /**
297 * These are the visible insets that were given during layout for
298 * this window, to be applied to windows behind it.
299 */
300 final Rect mGivenVisibleInsets = new Rect();
301
302 /**
303 * This is the given touchable area relative to the window frame, or null if none.
304 */
305 final Region mGivenTouchableRegion = new Region();
306
307 /**
308 * Flag indicating whether the touchable region should be adjusted by
309 * the visible insets; if false the area outside the visible insets is
310 * NOT touchable, so we must use those to adjust the frame during hit
311 * tests.
312 */
313 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
314
315 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400316 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700317 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 float mHScale=1, mVScale=1;
319 float mLastHScale=1, mLastVScale=1;
320 final Matrix mTmpMatrix = new Matrix();
321
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700322 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 final Rect mFrame = new Rect();
324 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700325 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700326 // Frame that is scaled to the application's coordinate space when in
327 // screen size compatibility mode.
328 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800329
330 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700331
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700332 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700333
Wale Ogunwale94596652015-02-06 19:27:34 -0800334 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
335 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700336 final Rect mDisplayFrame = new Rect();
337
338 // The region of the display frame that the display type supports displaying content on. This
339 // is mostly a special case for TV where some displays don’t have the entire display usable.
340 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
341 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700342 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700343
344 // The display frame minus the stable insets. This value is always constant regardless of if
345 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700346 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800347
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700348 // The area not occupied by the status and navigation bars. So, if both status and navigation
349 // bars are visible, the decor frame is equal to the stable frame.
350 final Rect mDecorFrame = new Rect();
351
352 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
353 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700354 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700355
356 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
357 // displays hint text.
358 final Rect mVisibleFrame = new Rect();
359
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700360 // Frame that includes dead area outside of the surface but where we want to pretend that it's
361 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700362 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700363
Jorim Jaggidc249c42015-12-15 14:57:31 -0800364 /**
365 * Usually empty. Set to the task's tempInsetFrame. See
366 *{@link android.app.IActivityManager#resizeDockedStack}.
367 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700368 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800369
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800370 boolean mContentChanged;
371
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800372 // If a window showing a wallpaper: the requested offset for the
373 // wallpaper; if a wallpaper window: the currently applied offset.
374 float mWallpaperX = -1;
375 float mWallpaperY = -1;
376
377 // If a window showing a wallpaper: what fraction of the offset
378 // range corresponds to a full virtual screen.
379 float mWallpaperXStep = -1;
380 float mWallpaperYStep = -1;
381
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700382 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
383 // to its window; if a wallpaper window: not used.
384 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
385 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
386
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 // Wallpaper windows: pixels offset based on above variables.
388 int mXOffset;
389 int mYOffset;
390
Craig Mautner2268e7e2012-12-13 15:40:00 -0800391 /**
392 * This is set after IWindowSession.relayout() has been called at
393 * least once for the window. It allows us to detect the situation
394 * where we don't yet have a surface, but should have one soon, so
395 * we can give the window focus before waiting for the relayout.
396 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800397 boolean mRelayoutCalled;
398
Robert Carrfed10072016-05-26 11:48:49 -0700399 boolean mInRelayout;
400
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800401 /**
402 * If the application has called relayout() with changes that can
403 * impact its window's size, we need to perform a layout pass on it
404 * even if it is not currently visible for layout. This is set
405 * when in that case until the layout is done.
406 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800407 boolean mLayoutNeeded;
408
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800409 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800410 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800411
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800412 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800413 boolean mDestroying;
414
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800415 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800416 boolean mRemoveOnExit;
417
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800418 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800419 * Whether the app died while it was visible, if true we might need
420 * to continue to show it until it's restarted.
421 */
422 boolean mAppDied;
423
424 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800425 * Set when the orientation is changing and this window has not yet
426 * been updated for the new orientation.
427 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800428 boolean mOrientationChanging;
429
Dianne Hackborna57c6952013-03-29 14:46:40 -0700430 /**
Robert Carr237028a2016-07-26 10:39:45 -0700431 * The orientation during the last visible call to relayout. If our
432 * current orientation is different, the window can't be ready
433 * to be shown.
434 */
435 int mLastVisibleLayoutRotation = -1;
436
437 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700438 * How long we last kept the screen frozen.
439 */
440 int mLastFreezeDuration;
441
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800442 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800443 boolean mRemoved;
444
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800445 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800446 * It is save to remove the window and destroy the surface because the client requested removal
447 * or some other higher level component said so (e.g. activity manager).
448 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800449 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700450 private boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800451
452 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800453 * Temp for keeping track of windows that have been removed when
454 * rebuilding window list.
455 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456 boolean mRebuilding;
457
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800458 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700459 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800460 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700461 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800462
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700464 private String mStringNameCache;
465 private CharSequence mLastTitle;
466 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800467
Craig Mautnera2c77052012-03-26 12:14:43 -0700468 final WindowStateAnimator mWinAnimator;
469
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700470 boolean mHasSurface = false;
471
Craig Mautner88400d32012-09-30 12:35:45 -0700472 /** When true this window can be displayed on screens owther than mOwnerUid's */
473 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700474
Robert Carr13f7be9e2015-12-02 18:39:45 -0800475 // Whether the window has a saved surface from last pause, which can be
476 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700477 private boolean mSurfaceSaved = false;
478
Chong Zhang8e4bda92016-05-04 15:08:18 -0700479 // Whether we're performing an entering animation with a saved surface. This flag is
480 // true during the time we're showing a window with a previously saved surface. It's
481 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700482 private boolean mAnimatingWithSavedSurface;
483
484 // Whether the window was visible when we set the app to invisible last time. WM uses
485 // this as a hint to restore the surface (if available) for early animation next time
486 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700487 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800488
Robert Carra1eb4392015-12-10 12:43:51 -0800489 // This window will be replaced due to relaunch. This allows window manager
490 // to differentiate between simple removal of a window and replacement. In the latter case it
491 // will preserve the old window until the new one is drawn.
492 boolean mWillReplaceWindow = false;
493 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700494 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800495 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700496 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800497 // If not null, the window that will be used to replace the old one. This is being set when
498 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700499 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700500 // For the new window in the replacement transition, if we have
501 // requested to replace without animation, then we should
502 // make sure we also don't apply an enter animation for
503 // the new window.
504 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800505 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700506 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800507
Jeff Brownc2932a12014-11-20 18:04:05 -0800508 /**
509 * Wake lock for drawing.
510 * Even though it's slightly more expensive to do so, we will use a separate wake lock
511 * for each app that is requesting to draw while dozing so that we can accurately track
512 * who is preventing the system from suspending.
513 * This lock is only acquired on first use.
514 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700515 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800516
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700517 final private Rect mTmpRect = new Rect();
518
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800519 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800520 * See {@link #notifyMovedInStack}.
521 */
522 private boolean mJustMovedInStack;
523
524 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800525 * Whether the window was resized by us while it was gone for layout.
526 */
527 boolean mResizedWhileGone = false;
528
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700529 /** @see #isResizedWhileNotDragResizing(). */
530 private boolean mResizedWhileNotDragResizing;
531
532 /** @see #isResizedWhileNotDragResizingReported(). */
533 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700534
Robert Carr6da3cc02016-06-16 15:17:07 -0700535 /**
536 * During seamless rotation we have two phases, first the old window contents
537 * are rotated to look as if they didn't move in the new coordinate system. Then we
538 * have to freeze updates to this layer (to preserve the transformation) until
539 * the resize actually occurs. This is true from when the transformation is set
540 * and false until the transaction to resize is sent.
541 */
542 boolean mSeamlesslyRotated = false;
543
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700544 private static final Region sEmptyRegion = new Region();
545
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700546 /**
547 * Compares to window sub-layers and returns -1 if the first is lesser than the second in terms
548 * of z-order and 1 otherwise.
549 */
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700550 private static final Comparator<WindowState> sWindowSubLayerComparator = (w1, w2) -> {
551 final int layer1 = w1.mSubLayer;
552 final int layer2 = w2.mSubLayer;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700553 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
554 // We insert the child window into the list ordered by the sub-layer.
555 // For same sub-layers, the negative one should go below others; the positive one should
556 // go above others.
557 return -1;
558 }
559 return 1;
560 };
561
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800562 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700563 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700564 int viewVisibility, int ownerId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800565 mService = service;
566 mSession = s;
567 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800568 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800569 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700570 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700571 mOwnerUid = ownerId;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800572 mWindowId = new IWindowId.Stub() {
573 @Override
574 public void registerFocusObserver(IWindowFocusObserver observer) {
575 WindowState.this.registerFocusObserver(observer);
576 }
577 @Override
578 public void unregisterFocusObserver(IWindowFocusObserver observer) {
579 WindowState.this.unregisterFocusObserver(observer);
580 }
581 @Override
582 public boolean isFocused() {
583 return WindowState.this.isFocused();
584 }
585 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800586 mAttrs.copyFrom(a);
587 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700588 mPolicy = mService.mPolicy;
589 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800590 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700591 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700592 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700593 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700594 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700595 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800596 try {
597 c.asBinder().linkToDeath(deathRecipient, 0);
598 } catch (RemoteException e) {
599 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700600 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800601 mLayoutAttached = false;
602 mIsImWindow = false;
603 mIsWallpaper = false;
604 mIsFloatingLayer = false;
605 mBaseLayer = 0;
606 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700607 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700608 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800609 return;
610 }
611 mDeathRecipient = deathRecipient;
612
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700613 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800614 // The multiplier here is to reserve space for multiple
615 // windows in the same type layer.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700616 mBaseLayer = mPolicy.windowTypeToLayerLw(parentWindow.mAttrs.type)
617 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700618 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700619 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900620
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700621 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
622 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900623
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800624 mLayoutAttached = mAttrs.type !=
625 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700626 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
627 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
628 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800629 } else {
630 // The multiplier here is to reserve space for multiple
631 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700632 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700633 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800634 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700635 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636 mLayoutAttached = false;
637 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
638 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
639 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800640 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700641 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700643 if (mAppToken != null && mAppToken.showForAllUsers) {
644 // Windows for apps that can show for all users should also show when the device is
645 // locked.
646 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700647 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800648
Craig Mautner322e4032012-07-13 13:35:20 -0700649 mWinAnimator = new WindowStateAnimator(this);
650 mWinAnimator.mAlpha = a.alpha;
651
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800652 mRequestedWidth = 0;
653 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700654 mLastRequestedWidth = 0;
655 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800656 mXOffset = 0;
657 mYOffset = 0;
658 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800659 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700660 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700661 getDisplayContent().getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800662 }
663
664 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700665 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800666 mSession.windowAddedLocked();
667 }
668
Craig Mautnera2c77052012-03-26 12:14:43 -0700669 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800670 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800671 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800672 }
673
674 @Override
675 public String getOwningPackage() {
676 return mAttrs.packageName;
677 }
678
Jorim Jaggif5834272016-04-04 20:25:41 -0700679 /**
680 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
681 * from {@param frame}. In other words, it applies the insets that would result if
682 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700683 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
684 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700685 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700686 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
687 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
688 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
689 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
690 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700691 frame.inset(left, top, right, bottom);
692 }
693
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800694 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700695 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
696 Rect osf) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800697 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700698 // This window is being replaced and either already got information that it's being
699 // removed or we are still waiting for some information. Because of this we don't
700 // want to apply any more changes to it, so it remains in this state until new window
701 // appears.
702 return;
703 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800704 mHaveFrame = true;
705
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700706 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700707 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800708 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700709 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800710
Chong Zhangae35fef2016-03-16 15:56:55 -0700711 // If the task has temp inset bounds set, we have to make sure all its windows uses
712 // the temp inset frame. Otherwise different display frames get applied to the main
713 // window and the child window, making them misaligned.
714 if (fullscreenTask) {
715 mInsetFrame.setEmpty();
716 } else {
717 task.getTempInsetBounds(mInsetFrame);
718 }
719
Jorim Jaggif5834272016-04-04 20:25:41 -0700720 // Denotes the actual frame used to calculate the insets and to perform the layout. When
721 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
722 // insets temporarily. By the notion of a task having a different layout frame, we can
723 // achieve that while still moving the task around.
724 final Rect layoutContainingFrame;
725 final Rect layoutDisplayFrame;
726
727 // The offset from the layout containing frame to the actual containing frame.
728 final int layoutXDiff;
729 final int layoutYDiff;
Wale Ogunwale7cd4b012016-05-07 12:41:22 -0700730 if (fullscreenTask || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800731 // We use the parent frame as the containing frame for fullscreen and child windows
732 mContainingFrame.set(pf);
733 mDisplayFrame.set(df);
Jorim Jaggif5834272016-04-04 20:25:41 -0700734 layoutDisplayFrame = df;
735 layoutContainingFrame = pf;
736 layoutXDiff = 0;
737 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800738 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700739 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100740 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
741
742 // If the bounds are frozen, we still want to translate the window freely and only
743 // freeze the size.
744 Rect frozen = mAppToken.mFrozenBounds.peek();
745 mContainingFrame.right = mContainingFrame.left + frozen.width();
746 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
747 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800748 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700749 // IME is up and obscuring this window. Adjust the window position so it is visible.
750 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
751 if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) {
752 // In freeform we want to move the top up directly.
753 // TODO: Investigate why this is cf not pf.
754 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
755 } else if (mContainingFrame.bottom > pf.bottom) {
756 // But in docked we want to behave like fullscreen
757 // and behave as if the task were given smaller bounds
758 // for the purposes of layout.
759 mContainingFrame.bottom = pf.bottom;
760 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700761 }
Skuhne81c524a2015-08-12 13:34:14 -0700762
Robert Carre6275582016-02-29 15:45:45 -0800763 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700764 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
765 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800766 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700767 if (mContainingFrame.isEmpty()) {
768 mContainingFrame.set(cf);
769 }
Doris Liu06d582d2015-06-01 13:18:43 -0700770 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800771 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700772 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
773 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
774 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700775 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Andrii Kuliandaea3572016-04-08 13:20:51 -0700776 subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700777 if (!layoutInParentFrame()) {
Andrii Kuliandaea3572016-04-08 13:20:51 -0700778 subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect);
779 subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700780 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700781 layoutDisplayFrame = df;
782 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700783 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800784
Craig Mautner967212c2013-04-13 21:10:58 -0700785 final int pw = mContainingFrame.width();
786 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800787
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800788 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800789 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800790 // + " to " + pf);
791 mParentFrame.set(pf);
792 mContentChanged = true;
793 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700794 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
795 mLastRequestedWidth = mRequestedWidth;
796 mLastRequestedHeight = mRequestedHeight;
797 mContentChanged = true;
798 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800799
Craig Mautnereda67292013-04-28 13:50:14 -0700800 mOverscanFrame.set(of);
801 mContentFrame.set(cf);
802 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400803 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700804 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700805 final boolean hasOutsets = osf != null;
806 if (hasOutsets) {
807 mOutsetFrame.set(osf);
808 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800809
Craig Mautnereda67292013-04-28 13:50:14 -0700810 final int fw = mFrame.width();
811 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800812
Jorim Jaggif5834272016-04-04 20:25:41 -0700813 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
814
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700815 // Calculate the outsets before the content frame gets shrinked to the window frame.
816 if (hasOutsets) {
817 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
818 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
819 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
820 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
821 } else {
822 mOutsets.set(0, 0, 0, 0);
823 }
824
Craig Mautnera248eee2013-05-07 11:41:27 -0700825 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800826 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800827 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700828 // Keep the frame out of the blocked system area, limit it in size to the content area
829 // and make sure that there is always a minimum visible so that the user can drag it
830 // into a usable area..
831 final int height = Math.min(mFrame.height(), mContentFrame.height());
832 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700833 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900834 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
835 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
836 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
837 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Skuhne81c524a2015-08-12 13:34:14 -0700838 final int top = Math.max(mContentFrame.top,
839 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
840 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
841 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
842 mFrame.set(left, top, left + width, top + height);
843 mContentFrame.set(mFrame);
844 mVisibleFrame.set(mContentFrame);
845 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700846 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700847 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100848 mContentFrame.set(mFrame);
849 if (!mFrame.equals(mLastFrame)) {
850 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800851 }
Skuhne81c524a2015-08-12 13:34:14 -0700852 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700853 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
854 Math.max(mContentFrame.top, mFrame.top),
855 Math.min(mContentFrame.right, mFrame.right),
856 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800857
Jorim Jaggi656f6502016-04-11 21:08:17 -0700858 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
859 Math.max(mVisibleFrame.top, mFrame.top),
860 Math.min(mVisibleFrame.right, mFrame.right),
861 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800862
Jorim Jaggi656f6502016-04-11 21:08:17 -0700863 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
864 Math.max(mStableFrame.top, mFrame.top),
865 Math.min(mStableFrame.right, mFrame.right),
866 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700867 }
Adrian Roosfa104232014-06-20 16:10:14 -0700868
Jorim Jaggi899327f2016-02-25 20:44:18 -0500869 if (fullscreenTask && !windowsAreFloating) {
870 // Windows that are not fullscreen can be positioned outside of the display frame,
871 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700872 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
873 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
874 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
875 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800876 }
Craig Mautnereda67292013-04-28 13:50:14 -0700877
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100878 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100879 // For the docked divider, we calculate the stable insets like a full-screen window
880 // so it can use it to calculate the snap positions.
881 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
882 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
883 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
884 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800885
886 // The divider doesn't care about insets in any case, so set it to empty so we don't
887 // trigger a relayout when moving it.
888 mContentInsets.setEmpty();
889 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100890 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700891 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700892 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
893 // non-fullscreen mode.
Jorim Jaggi656f6502016-04-11 21:08:17 -0700894 boolean overrideRightInset = !fullscreenTask && mFrame.right > mTmpRect.right;
895 boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mTmpRect.bottom;
896 mContentInsets.set(mContentFrame.left - mFrame.left,
897 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700898 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700899 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700900 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700901 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800902
Jorim Jaggi656f6502016-04-11 21:08:17 -0700903 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
904 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700905 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700906 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700907 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700908 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800909
Jorim Jaggi656f6502016-04-11 21:08:17 -0700910 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
911 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700912 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700913 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700914 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700915 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100916 }
Adrian Roosfa104232014-06-20 16:10:14 -0700917
Jorim Jaggi656f6502016-04-11 21:08:17 -0700918 // Offset the actual frame by the amount layout frame is off.
919 mFrame.offset(-layoutXDiff, -layoutYDiff);
920 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700921 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
922 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
923 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
924
Craig Mautnereda67292013-04-28 13:50:14 -0700925 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400926 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700927 // If there is a size compatibility scale being applied to the
928 // window, we need to apply this to its insets so that they are
929 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700930 mOverscanInsets.scale(mInvGlobalScale);
931 mContentInsets.scale(mInvGlobalScale);
932 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700933 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700934 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700935
936 // Also the scaled frame that we report to the app needs to be
937 // adjusted to be in its coordinate space.
938 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400939 }
940
Craig Mautnereda67292013-04-28 13:50:14 -0700941 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800942 final DisplayContent displayContent = getDisplayContent();
943 if (displayContent != null) {
944 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700945 mService.mWallpaperControllerLocked.updateWallpaperOffset(
946 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800947 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800948 }
949
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700950 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700951 "Resolving (mRequestedWidth="
952 + mRequestedWidth + ", mRequestedheight="
953 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
954 + "): frame=" + mFrame.toShortString()
955 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700956 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700957 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700958 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800959 }
960
Craig Mautnera2c77052012-03-26 12:14:43 -0700961 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800962 public Rect getFrameLw() {
963 return mFrame;
964 }
965
Craig Mautnera2c77052012-03-26 12:14:43 -0700966 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700967 public Point getShownPositionLw() {
968 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800969 }
970
Craig Mautnera2c77052012-03-26 12:14:43 -0700971 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800972 public Rect getDisplayFrameLw() {
973 return mDisplayFrame;
974 }
975
Craig Mautnera2c77052012-03-26 12:14:43 -0700976 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800977 public Rect getOverscanFrameLw() {
978 return mOverscanFrame;
979 }
980
981 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800982 public Rect getContentFrameLw() {
983 return mContentFrame;
984 }
985
Craig Mautnera2c77052012-03-26 12:14:43 -0700986 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800987 public Rect getVisibleFrameLw() {
988 return mVisibleFrame;
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) {
1013 int index = -1;
1014 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -07001015 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001016 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07001017 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
1018 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001019 }
1020 // If we reached the bottom of the range of windows we are considering,
1021 // assume no menu is needed.
1022 if (ws == bottom) {
1023 return false;
1024 }
1025 // The current window hasn't specified whether menu key is needed;
1026 // look behind it.
1027 // First, we may need to determine the starting position.
1028 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -07001029 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001030 }
1031 index--;
1032 if (index < 0) {
1033 return false;
1034 }
Craig Mautner59c00972012-07-30 12:10:24 -07001035 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001036 }
1037 }
1038
Craig Mautner19d59bc2012-09-04 11:15:56 -07001039 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001040 public int getSystemUiVisibility() {
1041 return mSystemUiVisibility;
1042 }
1043
Craig Mautner19d59bc2012-09-04 11:15:56 -07001044 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001045 public int getSurfaceLayer() {
1046 return mLayer;
1047 }
1048
Craig Mautner812d2ca2012-09-27 15:35:34 -07001049 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001050 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001051 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001052 }
1053
1054 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001055 public IApplicationToken getAppToken() {
1056 return mAppToken != null ? mAppToken.appToken : null;
1057 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001058
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001059 @Override
1060 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001061 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001062 }
1063
Robert Carr31aa98b2016-07-20 15:29:03 -07001064 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001065 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1066 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1067 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001068 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001069 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001070 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1071 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001072 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001073 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001074 }
1075
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001076 /**
1077 * Adds the window to the resizing list if any of the parameters we use to track the window
1078 * dimensions or insets have changed.
1079 */
1080 void updateResizingWindowIfNeeded() {
1081 final WindowStateAnimator winAnimator = mWinAnimator;
1082 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1083 return;
1084 }
1085
1086 final Task task = getTask();
1087 // In the case of stack bound animations, the window frames will update (unlike other
1088 // animations which just modify various transformation properties). We don't want to
1089 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1090 // the frame may not correspond to the surface size or the onscreen area at various
1091 // phases in the animation, and the client will become sad and confused.
1092 if (task != null && task.mStack.getBoundsAnimating()) {
1093 return;
1094 }
1095
1096 setReportResizeHints();
1097 boolean configChanged = isConfigChanged();
1098 if (DEBUG_CONFIGURATION && configChanged) {
1099 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1100 }
1101
1102 final boolean dragResizingChanged = isDragResizeChanged()
1103 && !isDragResizingChangeReported();
1104
1105 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1106 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1107 + " frame=" + mFrame);
1108
1109 // We update mLastFrame always rather than in the conditional with the last inset
1110 // variables, because mFrameSizeChanged only tracks the width and height changing.
1111 mLastFrame.set(mFrame);
1112
1113 if (mContentInsetsChanged
1114 || mVisibleInsetsChanged
1115 || winAnimator.mSurfaceResized
1116 || mOutsetsChanged
1117 || mFrameSizeChanged
1118 || configChanged
1119 || dragResizingChanged
1120 || !isResizedWhileNotDragResizingReported()) {
1121 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1122 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1123 + " contentInsetsChanged=" + mContentInsetsChanged
1124 + " " + mContentInsets.toShortString()
1125 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1126 + " " + mVisibleInsets.toShortString()
1127 + " stableInsetsChanged=" + mStableInsetsChanged
1128 + " " + mStableInsets.toShortString()
1129 + " outsetsChanged=" + mOutsetsChanged
1130 + " " + mOutsets.toShortString()
1131 + " surfaceResized=" + winAnimator.mSurfaceResized
1132 + " configChanged=" + configChanged
1133 + " dragResizingChanged=" + dragResizingChanged
1134 + " resizedWhileNotDragResizingReported="
1135 + isResizedWhileNotDragResizingReported());
1136 }
1137
1138 // If it's a dead window left on screen, and the configuration changed, there is nothing
1139 // we can do about it. Remove the window now.
1140 if (mAppToken != null && mAppDied) {
1141 mAppToken.removeDeadWindows();
1142 return;
1143 }
1144
1145 mLastOverscanInsets.set(mOverscanInsets);
1146 mLastContentInsets.set(mContentInsets);
1147 mLastVisibleInsets.set(mVisibleInsets);
1148 mLastStableInsets.set(mStableInsets);
1149 mLastOutsets.set(mOutsets);
1150 mService.makeWindowFreezingScreenIfNeededLocked(this);
1151
1152 // If the orientation is changing, or we're starting or ending a drag resizing action,
1153 // then we need to hold off on unfreezing the display until this window has been
1154 // redrawn; to do that, we need to go through the process of getting informed by the
1155 // application when it has finished drawing.
1156 if (mOrientationChanging || dragResizingChanged || isResizedWhileNotDragResizing()) {
1157 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1158 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1159 + ", mDrawState=DRAW_PENDING in " + this
1160 + ", surfaceController " + winAnimator.mSurfaceController);
1161 }
1162 winAnimator.mDrawState = DRAW_PENDING;
1163 if (mAppToken != null) {
1164 mAppToken.clearAllDrawn();
1165 }
1166 }
1167 if (!mService.mResizingWindows.contains(this)) {
1168 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1169 mService.mResizingWindows.add(this);
1170 }
1171 } else if (mOrientationChanging) {
1172 if (isDrawnLw()) {
1173 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1174 + this + ", surfaceController " + winAnimator.mSurfaceController);
1175 mOrientationChanging = false;
1176 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1177 - mService.mDisplayFreezeTime);
1178 }
1179 }
1180 }
1181
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001182 DisplayContent getDisplayContent() {
1183 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001184 }
1185
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001186 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001187 final DisplayContent displayContent = getDisplayContent();
1188 return displayContent != null ? displayContent.getDisplayInfo() : null;
1189 }
1190
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001191 int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001192 final DisplayContent displayContent = getDisplayContent();
1193 if (displayContent == null) {
1194 return -1;
1195 }
1196 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001197 }
1198
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001199 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001200 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001201 }
1202
1203 TaskStack getStack() {
1204 Task task = getTask();
1205 if (task != null) {
1206 if (task.mStack != null) {
1207 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001208 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001209 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001210 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1211 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001212 final DisplayContent dc = getDisplayContent();
1213 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001214 }
1215
Skuhnef932e562015-08-20 12:07:30 -07001216 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001217 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001218 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001219 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001220 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001221 final Task task = getTask();
1222 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001223 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001224 mTmpRect.setEmpty();
1225 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001226 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001227 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001228 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001229 } else {
1230 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001231 }
1232 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001233
Chong Zhang9184ec62015-09-24 12:32:21 -07001234 bounds.set(mVisibleFrame);
1235 if (intersectWithStackBounds) {
1236 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001237 }
1238
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001239 if (bounds.isEmpty()) {
1240 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001241 if (intersectWithStackBounds) {
1242 bounds.intersect(mTmpRect);
1243 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001244 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001245 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001246 }
1247
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001248 public long getInputDispatchingTimeoutNanos() {
1249 return mAppToken != null
1250 ? mAppToken.inputDispatchingTimeoutNanos
1251 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1252 }
1253
Craig Mautnere8552142012-11-07 13:55:47 -08001254 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001255 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001256 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001257 }
1258
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001259 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1260 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1261 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1262 if (dtdx < -.000001f || dtdx > .000001f) return false;
1263 if (dsdy < -.000001f || dsdy > .000001f) return false;
1264 return true;
1265 }
1266
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001267 void prelayout() {
1268 if (mEnforceSizeCompat) {
1269 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001270 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001271 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001272 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001273 }
1274 }
1275
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001276 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001277 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001278 // If we're animating with a saved surface, we're already visible.
1279 // Return true so that the alpha doesn't get cleared.
1280 if (!mAppFreezing && isDrawnLw()
1281 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1282 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1283 return true;
1284 }
1285
Wale Ogunwale44f21802016-09-02 12:49:48 -07001286 return super.hasContentToDisplay();
1287 }
1288
1289 @Override
1290 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -07001291 // TODO: The check for hiddenRequested is commented out below, because the window can still
1292 // be visible on screen when the flag is true. We would like the isVisible() method to
1293 // return an answer closer to if the window is truly visible (can't be an exact answer
1294 // without checking the surface state), so comment out the check for now so we can test to
1295 // see what problem it causes.
1296 // If it doesn't cause any issues, then we can remove just before we lock down the current
1297 // release (O) and also consolidate this method with #isVisibleUnchecked() and possibly
1298 // other methods like isVisibleNow().
1299 // If it does cause problems, then we can look if there are other ways to solve the problem.
1300 // If there isn't then uncomment and document here why it is needed.
1301 if (/*(mAppToken == null || !mAppToken.hiddenRequested) && */isVisibleUnchecked()
1302 // TODO: The window isn't considered visible when the token is hidden, however
1303 // uncommenting the check below breaks the visual transition from an app to the launcher
1304 // if the home buttons is pressed. Need to investigate an fix that issue before
1305 // uncommenting.
1306 /* && !mToken.hidden*/) {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001307 // Is this window visible? It is not visible if there is no surface, or we are in the
1308 // process of running an exit animation that will remove the surface, or its app token
1309 // has been hidden.
1310 return true;
1311 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001312 return false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001313 }
1314
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001315 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001316 * Does the minimal check for visibility. Callers generally want to use one of the public
1317 * methods as they perform additional checks on the app token.
1318 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001319 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001320 private boolean isVisibleUnchecked() {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001321 return mHasSurface && mPolicyVisibility && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001322 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001323 }
1324
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001325 @Override
1326 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001327 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001328 }
1329
1330 /**
1331 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1332 * keyguard as visible. This allows us to apply things like window flags that impact the
1333 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1334 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001335 */
Craig Mautner88400d32012-09-30 12:35:45 -07001336 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001337 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001338 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001339 return false;
1340 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001342 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001343 return mHasSurface && !mDestroying && !mAnimatingExit
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001344 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001345 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001346 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001347 }
1348
1349 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001350 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1351 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001352 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001353 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1354 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001355 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1356 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001357 }
1358
1359 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001360 * The same as isVisible(), but follows the current hidden state of the associated app token,
1361 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001362 */
1363 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001364 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001365 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001366 }
1367
1368 /**
1369 * Can this window possibly be a drag/drop target? The test here is
1370 * a combination of the above "visible now" with the check that the
1371 * Input Manager uses when discarding windows from input consideration.
1372 */
1373 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001374 return isVisibleNow() && !mRemoved
1375 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001376 }
1377
1378 /**
1379 * Same as isVisible(), but we also count it as visible between the
1380 * call to IWindowSession.add() and the first relayout().
1381 */
1382 boolean isVisibleOrAdding() {
1383 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001384 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001385 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001386 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001387 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001388 }
1389
1390 /**
1391 * Is this window currently on-screen? It is on-screen either if it
1392 * is visible or it is currently running an animation before no longer
1393 * being visible.
1394 */
1395 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001396 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1397 }
1398
1399 /**
1400 * Like isOnScreen(), but ignores any force hiding of the window due
1401 * to the keyguard.
1402 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001403 private boolean isOnScreenIgnoringKeyguard() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001404 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001405 return false;
1406 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001407 final AppWindowToken atoken = mAppToken;
1408 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001409 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001410 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001411 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001412 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001413 }
1414
1415 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001416 * Whether this window's drawn state might affect the drawn states of the app token.
1417 *
1418 * @param visibleOnly Whether we should consider only the windows that's currently
1419 * visible in layout. If true, windows that has not relayout to VISIBLE
1420 * would always return false.
1421 *
1422 * @return true if the window should be considered while evaluating allDrawn flags.
1423 */
1424 boolean mightAffectAllDrawn(boolean visibleOnly) {
Chong Zhange292eb32016-05-21 09:23:55 -07001425 final boolean isViewVisible = (mAppToken == null || !mAppToken.clientHidden)
1426 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001427 return (isOnScreenIgnoringKeyguard() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001428 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1429 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001430 && !mAnimatingExit && !mDestroying;
1431 }
1432
1433 /**
1434 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1435 * it must be drawn before allDrawn can become true.
1436 */
1437 boolean isInteresting() {
1438 return mAppToken != null && !mAppDied
1439 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1440 }
1441
1442 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001443 * Like isOnScreen(), but we don't return true if the window is part
1444 * of a transition that has not yet been started.
1445 */
1446 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001447 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001448 return false;
1449 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001450 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001451 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001452 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001453 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001454 }
1455
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001456 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001457 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1458 * to the keyguard.
1459 */
1460 boolean isReadyForDisplayIgnoringKeyguard() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001461 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001462 return false;
1463 }
1464 final AppWindowToken atoken = mAppToken;
1465 if (atoken == null && !mPolicyVisibility) {
1466 // If this is not an app window, and the policy has asked to force
1467 // hide, then we really do want to hide.
1468 return false;
1469 }
1470 return mHasSurface && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001471 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001472 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001473 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
Chong Zhang83caa362016-08-14 18:47:54 -07001474 && !mWinAnimator.isDummyAnimation())
1475 || isAnimatingWithSavedSurface());
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001476 }
1477
1478 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001479 * Like isOnScreen, but returns false if the surface hasn't yet
1480 * been drawn.
1481 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001482 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001483 public boolean isDisplayedLw() {
1484 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001485 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001486 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001487 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001488 || mWinAnimator.mAnimating
1489 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001490 }
1491
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001492 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001493 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001494 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001495 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001496 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001497 return mWinAnimator.mAnimation != null
1498 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001499 }
1500
Craig Mautner812d2ca2012-09-27 15:35:34 -07001501 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001502 public boolean isGoneForLayoutLw() {
1503 final AppWindowToken atoken = mAppToken;
1504 return mViewVisibility == View.GONE
1505 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001506 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001507 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001508 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001509 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001510 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001511 }
1512
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001513 /**
1514 * Returns true if the window has a surface that it has drawn a
1515 * complete UI in to.
1516 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001517 public boolean isDrawFinishedLw() {
1518 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001519 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1520 || mWinAnimator.mDrawState == READY_TO_SHOW
1521 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001522 }
1523
1524 /**
1525 * Returns true if the window has a surface that it has drawn a
1526 * complete UI in to.
1527 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001528 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001529 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001530 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001531 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001532 }
1533
1534 /**
1535 * Return true if the window is opaque and fully drawn. This indicates
1536 * it may obscure windows behind it.
1537 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001538 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001539 // When there is keyguard, wallpaper could be placed over the secure app
1540 // window but invisible. We need to check wallpaper visibility explicitly
1541 // to determine if it's occluding apps.
1542 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1543 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001544 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001545 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001546 }
1547
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001548 @Override
1549 void onMovedByResize() {
1550 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001551 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001552 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001553 }
1554
1555 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1556 boolean changed = false;
1557
1558 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001559 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001560 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1561 }
1562
1563 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1564 // Starting window that's exiting will be removed when the animation finishes.
1565 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1566 // to actually remove it.
1567 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1568 mAnimatingExit = true;
1569 mRemoveOnExit = true;
1570 mWindowRemovalAllowed = true;
1571 }
1572 return changed;
1573 }
1574
1575 if (visible != isVisibleNow()) {
1576 if (!runningAppAnimation) {
1577 final AccessibilityController accessibilityController =
1578 mService.mAccessibilityController;
1579 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1580 mWinAnimator.applyAnimationLocked(winTransit, visible);
1581 //TODO (multidisplay): Magnification is supported only for the default
1582 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1583 accessibilityController.onWindowTransitionLocked(this, winTransit);
1584 }
1585 }
1586 changed = true;
1587 setDisplayLayoutNeeded();
1588 }
1589
1590 return changed;
1591 }
1592
1593 boolean onSetAppExiting() {
1594 final DisplayContent displayContent = getDisplayContent();
1595 boolean changed = false;
1596
1597 if (isVisibleNow()) {
1598 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1599 //TODO (multidisplay): Magnification is supported only for the default
1600 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1601 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1602 }
1603 changed = true;
1604 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001605 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001606 }
1607 }
1608
1609 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001610 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001611 changed |= c.onSetAppExiting();
1612 }
1613
1614 return changed;
1615 }
1616
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001617 @Override
1618 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001619 // Some windows won't go through the resizing process, if they don't have a surface, so
1620 // destroy all saved surfaces here.
1621 destroySavedSurface();
1622
1623 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1624 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001625 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001626 resizingWindows.add(this);
1627
1628 // If we are not drag resizing, force recreating of a new surface so updating
1629 // the content and positioning that surface will be in sync.
1630 //
1631 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1632 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1633 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1634 // their frame to update crop, etc...
1635 //
1636 // Anyway we don't need to synchronize position and content updates for these
1637 // windows since they aren't at the base layer and could be moved around anyway.
1638 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
1639 !getTask().mStack.getBoundsAnimating() && !isGoneForLayoutLw() &&
1640 !getTask().inPinnedWorkspace()) {
1641 setResizedWhileNotDragResizing(true);
1642 }
1643 }
1644 if (isGoneForLayoutLw()) {
1645 mResizedWhileGone = true;
1646 }
1647
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001648 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001649 }
1650
1651 void onUnfreezeBounds() {
1652 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001653 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001654 c.onUnfreezeBounds();
1655 }
1656
1657 if (!mHasSurface) {
1658 return;
1659 }
1660
1661 mLayoutNeeded = true;
1662 setDisplayLayoutNeeded();
1663 if (!mService.mResizingWindows.contains(this)) {
1664 mService.mResizingWindows.add(this);
1665 }
1666 }
1667
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001668 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001669 * If the window has moved due to its containing content frame changing, then notify the
1670 * listeners and optionally animate it. Simply checking a change of position is not enough,
1671 * because being move due to dock divider is not a trigger for animation.
1672 */
1673 void handleWindowMovedIfNeeded() {
1674 if (!hasMoved()) {
1675 return;
1676 }
1677
1678 // Frame has moved, containing content frame has also moved, and we're not currently
1679 // animating... let's do something.
1680 final int left = mFrame.left;
1681 final int top = mFrame.top;
1682 final Task task = getTask();
1683 final boolean adjustedForMinimizedDockOrIme = task != null
1684 && (task.mStack.isAdjustedForMinimizedDockedStack()
1685 || task.mStack.isAdjustedForIme());
1686 if (mService.okToDisplay()
1687 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1688 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1689 && (task == null || getTask().mStack.hasMovementAnimations())
1690 && !mWinAnimator.mLastHidden) {
1691 mWinAnimator.setMoveAnimation(left, top);
1692 }
1693
1694 //TODO (multidisplay): Accessibility supported only for the default display.
1695 if (mService.mAccessibilityController != null
1696 && getDisplayContent().getDisplayId() == Display.DEFAULT_DISPLAY) {
1697 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1698 }
1699
1700 try {
1701 mClient.moved(left, top);
1702 } catch (RemoteException e) {
1703 }
1704 mMovedByResize = false;
1705 }
1706
1707 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001708 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001709 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1710 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001711 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001712 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001713 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001714 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001715 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001716 }
1717
Chong Zhang0abb20f2015-11-19 14:17:31 -08001718 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1719 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001720 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001721 return false;
1722 }
1723 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1724 return false;
1725 }
1726 return true;
1727 }
1728
1729 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1730 return mFrame.left <= 0 && mFrame.top <= 0
1731 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001732 }
1733
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001734 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001735 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001736 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001737 }
1738
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001739 boolean isAdjustedForMinimizedDock() {
1740 return mAppToken != null && mAppToken.mTask != null
1741 && mAppToken.mTask.mStack.isAdjustedForMinimizedDock();
1742 }
1743
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001744 void onWindowReplacementTimeout() {
1745 if (mWillReplaceWindow) {
1746 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001747 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001748 // delays removal on certain conditions, which will leave the stale window in the
1749 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1750 //
1751 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001752 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001753 } else {
1754 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001755 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001756 c.onWindowReplacementTimeout();
1757 }
1758 }
1759 }
1760
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001761 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001762 void forceWindowsScaleableInTransaction(boolean force) {
1763 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1764 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1765 }
1766
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001767 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001768 }
1769
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001770 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001771 void removeImmediately() {
1772 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001773
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001774 if (mRemoved) {
1775 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001776 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1777 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001778 return;
1779 }
1780
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001781 mRemoved = true;
1782
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001783 mWillReplaceWindow = false;
1784 if (mReplacementWindow != null) {
1785 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1786 }
1787
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001788 if (mService.mInputMethodTarget == this) {
1789 mService.moveInputMethodWindowsIfNeededLocked(false);
1790 }
1791
1792 final int type = mAttrs.type;
1793 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
1794 final DisplayContent displaycontent = getDisplayContent();
1795 displaycontent.mTapExcludedWindows.remove(this);
1796 }
1797 mPolicy.removeWindowLw(this);
1798
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001799 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001800
Craig Mautner96868332012-12-04 14:29:11 -08001801 mWinAnimator.destroyDeferredSurfaceLocked();
1802 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001803 mSession.windowRemovedLocked();
1804 try {
1805 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1806 } catch (RuntimeException e) {
1807 // Ignore if it has already been removed (usually because
1808 // we are doing this as part of processing a death note.)
1809 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001810
1811 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001812 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001813
Wale Ogunwale571771c2016-08-26 13:18:50 -07001814 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001815 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001816 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001817 removeIfPossible(false /*keepVisibleDeadWindow*/);
1818 }
1819
Wale Ogunwale571771c2016-08-26 13:18:50 -07001820 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001821 mWindowRemovalAllowed = true;
1822 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1823 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1824
1825 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1826 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1827 "Starting window removed " + this);
1828
1829 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1830 Slog.v(TAG_WM, "Remove " + this + " client="
1831 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1832 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1833 + Debug.getCallers(5));
1834
1835 final long origId = Binder.clearCallingIdentity();
1836
1837 disposeInputChannel();
1838
1839 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1840 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1841 + " mAnimatingExit=" + mAnimatingExit
1842 + " mRemoveOnExit=" + mRemoveOnExit
1843 + " mHasSurface=" + mHasSurface
1844 + " surfaceShowing=" + mWinAnimator.getShown()
1845 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1846 + " app-animation="
1847 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1848 + " mWillReplaceWindow=" + mWillReplaceWindow
1849 + " inPendingTransaction="
1850 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1851 + " mDisplayFrozen=" + mService.mDisplayFrozen
1852 + " callers=" + Debug.getCallers(6));
1853
1854 // Visibility of the removed window. Will be used later to update orientation later on.
1855 boolean wasVisible = false;
1856
1857 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1858 // window until the animation is done. If the display is frozen, just remove immediately,
1859 // since the animation wouldn't be seen.
1860 if (mHasSurface && mService.okToDisplay()) {
1861 if (mWillReplaceWindow) {
1862 // This window is going to be replaced. We need to keep it around until the new one
1863 // gets added, then we will get rid of this one.
1864 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1865 "Preserving " + this + " until the new one is " + "added");
1866 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1867 // been removed. We probably need another flag to indicate that window removal
1868 // should be deffered vs. overloading the flag that says we are playing an exit
1869 // animation.
1870 mAnimatingExit = true;
1871 mReplacingRemoveRequested = true;
1872 Binder.restoreCallingIdentity(origId);
1873 return;
1874 }
1875
1876 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1877 // We started enter animation early with a saved surface, now the app asks to remove
1878 // this window. If we remove it now and the app is not yet drawn, we'll show a
1879 // flicker. Delay the removal now until it's really drawn.
1880 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1881 "removeWindowLocked: delay removal of " + this + " due to early animation");
1882 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1883 // immediately after the enter animation is done. If the app is not yet drawn then
1884 // it will show up as a flicker.
1885 setupWindowForRemoveOnExit();
1886 Binder.restoreCallingIdentity(origId);
1887 return;
1888 }
1889 // If we are not currently running the exit animation, we need to see about starting one
1890 wasVisible = isWinVisibleLw();
1891
1892 if (keepVisibleDeadWindow) {
1893 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1894 "Not removing " + this + " because app died while it's visible");
1895
1896 mAppDied = true;
1897 setDisplayLayoutNeeded();
1898 mService.mWindowPlacerLocked.performSurfacePlacement();
1899
1900 // Set up a replacement input channel since the app is now dead.
1901 // We need to catch tapping on the dead window to restart the app.
1902 openInputChannel(null);
1903 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1904
1905 Binder.restoreCallingIdentity(origId);
1906 return;
1907 }
1908
1909 if (wasVisible) {
1910 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1911
1912 // Try starting an animation.
1913 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1914 mAnimatingExit = true;
1915 }
1916 //TODO (multidisplay): Magnification is supported only for the default display.
1917 if (mService.mAccessibilityController != null
1918 && getDisplayId() == Display.DEFAULT_DISPLAY) {
1919 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1920 }
1921 }
1922 final boolean isAnimating =
1923 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1924 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001925 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001926 // We delay the removal of a window if it has a showing surface that can be used to run
1927 // exit animation and it is marked as exiting.
1928 // Also, If isn't the an animating starting window that is the last window in the app.
1929 // We allow the removal of the non-animating starting window now as there is no
1930 // additional window or animation that will trigger its removal.
1931 if (mWinAnimator.getShown() && mAnimatingExit
1932 && (!lastWindowIsStartingWindow || isAnimating)) {
1933 // The exit animation is running or should run... wait for it!
1934 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1935 "Not removing " + this + " due to exit animation ");
1936 setupWindowForRemoveOnExit();
1937 if (mAppToken != null) {
1938 mAppToken.updateReportedVisibilityLocked();
1939 }
1940 Binder.restoreCallingIdentity(origId);
1941 return;
1942 }
1943 }
1944
Wale Ogunwale571771c2016-08-26 13:18:50 -07001945 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001946 // Removing a visible window will effect the computed orientation
1947 // So just update orientation if needed.
1948 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false)) {
1949 mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION);
1950 }
1951 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1952 Binder.restoreCallingIdentity(origId);
1953 }
1954
1955 private void setupWindowForRemoveOnExit() {
1956 mRemoveOnExit = true;
1957 setDisplayLayoutNeeded();
1958 // Request a focus update as this window's input channel is already gone. Otherwise
1959 // we could have no focused window in input manager.
1960 final boolean focusChanged = mService.updateFocusedWindowLocked(
1961 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1962 mService.mWindowPlacerLocked.performSurfacePlacement();
1963 if (focusChanged) {
1964 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1965 }
1966 }
1967
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001968 void setHasSurface(boolean hasSurface) {
1969 mHasSurface = hasSurface;
1970 }
1971
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001972 int getAnimLayerAdjustment() {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001973 final boolean isImeType =
1974 mAttrs.type == TYPE_INPUT_METHOD || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
1975 if (isImeType && mService.mInputMethodTarget != null) {
1976 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1977 if (appToken != null) {
1978 return appToken.mAppAnimator.animLayerAdjustment;
1979 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001980 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07001981
1982 if (mAppToken != null) {
1983 return mAppToken.mAppAnimator.animLayerAdjustment;
1984 }
1985
1986 // Nothing is animating, so there is no animation adjustment.
1987 return 0;
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001988 }
1989
1990 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001991 final DisplayContent dc = getDisplayContent();
1992 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001993 return;
1994 }
1995 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001996 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001997 // Force an animation pass just to update the mDimLayer layer.
1998 mService.scheduleAnimationLocked();
1999 }
2000 }
2001
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002002 /**
2003 * Notifies this window that the corresponding task has just moved in the stack.
2004 * <p>
2005 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
2006 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
2007 * the actual app transition that updates the visibility is delayed by a few transactions.
2008 * Instead of messing around with the ordering and timing how transitions and transactions are
2009 * executed, we introduce this little hack which prevents this window of getting visible again
2010 * with the wrong bounds until the app transitions has started.
2011 * <p>
2012 * This method notifies the window about that we just moved in the stack so we can apply this
2013 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
2014 */
2015 void notifyMovedInStack() {
2016 mJustMovedInStack = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002017
2018 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002019 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002020 c.notifyMovedInStack();
2021 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002022 }
2023
2024 /**
2025 * See {@link #notifyMovedInStack}.
2026 *
2027 * @return Whether we just got moved in the corresponding stack.
2028 */
2029 boolean hasJustMovedInStack() {
2030 return mJustMovedInStack;
2031 }
2032
2033 /**
2034 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
2035 */
2036 void resetJustMovedInStack() {
2037 mJustMovedInStack = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002038
2039 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002040 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002041 c.resetJustMovedInStack();
2042 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002043 }
2044
Chong Zhangacf11402015-11-04 16:23:10 -08002045 private final class DeadWindowEventReceiver extends InputEventReceiver {
2046 DeadWindowEventReceiver(InputChannel inputChannel) {
2047 super(inputChannel, mService.mH.getLooper());
2048 }
2049 @Override
2050 public void onInputEvent(InputEvent event) {
2051 finishInputEvent(event, true);
2052 }
2053 }
2054 /**
2055 * Dummy event receiver for windows that died visible.
2056 */
2057 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2058
Chong Zhang112eb8c2015-11-02 11:17:00 -08002059 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002060 if (mInputChannel != null) {
2061 throw new IllegalStateException("Window already has an input channel.");
2062 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002063 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002064 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2065 mInputChannel = inputChannels[0];
2066 mClientChannel = inputChannels[1];
2067 mInputWindowHandle.inputChannel = inputChannels[0];
2068 if (outInputChannel != null) {
2069 mClientChannel.transferTo(outInputChannel);
2070 mClientChannel.dispose();
2071 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002072 } else {
2073 // If the window died visible, we setup a dummy input channel, so that taps
2074 // can still detected by input monitor channel, and we can relaunch the app.
2075 // Create dummy event receiver that simply reports all events as handled.
2076 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002077 }
2078 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002079 }
2080
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002081 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002082 if (mDeadWindowEventReceiver != null) {
2083 mDeadWindowEventReceiver.dispose();
2084 mDeadWindowEventReceiver = null;
2085 }
2086
2087 // unregister server channel first otherwise it complains about broken channel
2088 if (mInputChannel != null) {
2089 mService.mInputManager.unregisterInputChannel(mInputChannel);
2090 mInputChannel.dispose();
2091 mInputChannel = null;
2092 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002093 if (mClientChannel != null) {
2094 mClientChannel.dispose();
2095 mClientChannel = null;
2096 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002097 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002098 }
2099
Chong Zhang112eb8c2015-11-02 11:17:00 -08002100 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002101 // When the app is terminated (eg. from Recents), the task might have already been
2102 // removed with the window pending removal. Don't apply dim in such cases, as there
2103 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2104 final AppWindowToken token = mAppToken;
2105 if (token != null && token.removed) {
2106 return;
2107 }
2108
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002109 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002110 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002111 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002112 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002113 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002114 && dc != null && !mAnimatingExit && isVisibleUnchecked()) {
2115 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002116 }
2117 }
2118
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002119 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002120 Task task = getTask();
2121 if (task != null) {
2122 return task;
2123 }
2124 return getStack();
2125 }
2126
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002127 /** Returns true if the replacement window was removed. */
2128 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2129 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2130 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2131 removeReplacedWindow();
2132 return true;
2133 }
2134
2135 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002136 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002137 if (c.removeReplacedWindowIfNeeded(replacement)) {
2138 return true;
2139 }
2140 }
2141 return false;
2142 }
2143
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002144 void removeReplacedWindow() {
2145 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2146 if (isDimming()) {
2147 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002148 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002149 mWillReplaceWindow = false;
2150 mAnimateReplacingWindow = false;
2151 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002152 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002153 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002154 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002155 }
2156 }
2157
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002158 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2159 boolean replacementSet = false;
2160
2161 if (mWillReplaceWindow && mReplacementWindow == null
2162 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2163
2164 mReplacementWindow = replacementCandidate;
2165 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2166 replacementSet = true;
2167 }
2168
2169 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002170 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002171 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2172 }
2173
2174 return replacementSet;
2175 }
2176
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002177 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002178 final DisplayContent dc = getDisplayContent();
2179 if (dc != null) {
2180 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002181 }
2182 }
2183
Robert Carrfed10072016-05-26 11:48:49 -07002184 // TODO: Strange usage of word workspace here and above.
2185 boolean inPinnedWorkspace() {
2186 final Task task = getTask();
2187 return task != null && task.inPinnedWorkspace();
2188 }
2189
Chong Zhang5117e272016-05-03 12:47:34 -07002190 void applyAdjustForImeIfNeeded() {
2191 final Task task = getTask();
2192 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2193 task.mStack.applyAdjustForImeIfNeeded(task);
2194 }
2195 }
2196
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002197 int getTouchableRegion(Region region, int flags) {
2198 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002199 if (modal && mAppToken != null) {
2200 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002201 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002202 // If this is a modal window we need to dismiss it if it's not full screen and the
2203 // touch happens outside of the frame that displays the content. This means we
2204 // need to intercept touches outside of that window. The dim layer user
2205 // associated with the window (task or stack) will give us the good bounds, as
2206 // they would be used to display the dim layer.
2207 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2208 if (dimLayerUser != null) {
2209 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002210 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002211 getVisibleBounds(mTmpRect);
2212 }
2213 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002214 // For freeform windows we the touch region to include the whole surface for the
2215 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002216 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2217 final int delta = WindowManagerService.dipToPixel(
2218 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2219 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002220 }
2221 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002222 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002223 } else {
2224 // Not modal or full screen modal
2225 getTouchableRegion(region);
2226 }
2227 return flags;
2228 }
2229
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002230 void checkPolicyVisibilityChange() {
2231 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2232 if (DEBUG_VISIBILITY) {
2233 Slog.v(TAG, "Policy visibility changing after anim in " +
2234 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2235 }
2236 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002237 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002238 if (!mPolicyVisibility) {
2239 if (mService.mCurrentFocus == this) {
2240 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2241 "setAnimationLocked: setting mFocusMayChange true");
2242 mService.mFocusMayChange = true;
2243 }
2244 // Window is no longer visible -- make sure if we were waiting
2245 // for it to be displayed before enabling the display, that
2246 // we allow the display to be enabled now.
2247 mService.enableScreenIfNeededLocked();
2248 }
2249 }
2250 }
2251
2252 void setRequestedSize(int requestedWidth, int requestedHeight) {
2253 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2254 mLayoutNeeded = true;
2255 mRequestedWidth = requestedWidth;
2256 mRequestedHeight = requestedHeight;
2257 }
2258 }
2259
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002260 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
2261 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2262 == SOFT_INPUT_ADJUST_RESIZE) {
2263 mLayoutNeeded = true;
2264 }
2265 if (isDrawnLw() && mService.okToDisplay()) {
2266 mWinAnimator.applyEnterAnimationLocked();
2267 }
2268 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2269 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2270 mTurnOnScreen = true;
2271 }
2272 if (isConfigChanged()) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002273 outConfig.setTo(getConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002274 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002275 + outConfig);
2276 mLastReportedConfiguration.setTo(outConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002277 }
2278 }
2279
2280 void adjustStartingWindowFlags() {
2281 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2282 && mAppToken.startingWindow != null) {
2283 // Special handling of starting window over the base
2284 // window of the app: propagate lock screen flags to it,
2285 // to provide the correct semantics while starting.
2286 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2287 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2288 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2289 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2290 }
2291 }
2292
2293 void setWindowScale(int requestedWidth, int requestedHeight) {
2294 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2295
2296 if (scaledWindow) {
2297 // requested{Width|Height} Surface's physical size
2298 // attrs.{width|height} Size on screen
2299 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2300 mHScale = (mAttrs.width != requestedWidth) ?
2301 (mAttrs.width / (float)requestedWidth) : 1.0f;
2302 mVScale = (mAttrs.height != requestedHeight) ?
2303 (mAttrs.height / (float)requestedHeight) : 1.0f;
2304 } else {
2305 mHScale = mVScale = 1;
2306 }
2307 }
2308
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002309 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002310 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002311 public void binderDied() {
2312 try {
2313 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002314 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002315 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002316 if (win != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002317 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002318 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2319 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002320 // just in case they have the divider at an unstable position. Better
2321 // also reset drag resizing state, because the owner can't do it
2322 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002323 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
2324 if (stack != null) {
2325 stack.resetDockedStackToMiddle();
2326 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002327 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002328 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002329 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002330 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002331 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002332 }
2333 }
2334 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002335 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002336 }
2337 }
2338 }
2339
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002340 /**
2341 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2342 * because we want to preserve its location on screen to be re-activated later when the user
2343 * interacts with it.
2344 */
2345 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002346 if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002347 // Not a visible app window or the app isn't dead.
2348 return false;
2349 }
2350
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002351 if (mAttrs.token != mClient.asBinder()) {
2352 // The window was add by a client using another client's app token. We don't want to
2353 // keep the dead window around for this case since this is meant for 'real' apps.
2354 return false;
2355 }
2356
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002357 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2358 // We don't keep starting windows since they were added by the window manager before
2359 // the app even launched.
2360 return false;
2361 }
2362
2363 final TaskStack stack = getStack();
2364 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2365 }
2366
Wale Ogunwaled045c822015-12-02 09:14:28 -08002367 /** @return true if this window desires key events. */
2368 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002369 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002370 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002371 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002372 && (mAppToken == null || mAppToken.windowsAreFocusable())
2373 && !isAdjustedForMinimizedDock();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002374 }
2375
Craig Mautner749a7bb2012-04-02 13:49:53 -07002376 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002377 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002378 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002379 }
2380
Craig Mautner749a7bb2012-04-02 13:49:53 -07002381 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002382 public boolean showLw(boolean doAnimation) {
2383 return showLw(doAnimation, true);
2384 }
2385
2386 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002387 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002388 return false;
2389 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002390 if (!mAppOpVisibility) {
2391 // Being hidden due to app op request.
2392 return false;
2393 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002394 if (mPermanentlyHidden) {
2395 // Permanently hidden until the app exists as apps aren't prepared
2396 // to handle their windows being removed from under them.
2397 return false;
2398 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002399 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002400 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002401 return false;
2402 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002403 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002404 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002405 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002406 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07002407 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002408 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002409 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002410 // Check for the case where we are currently visible and
2411 // not animating; we do not want to do animation at such a
2412 // point to become visible when we already are.
2413 doAnimation = false;
2414 }
2415 }
2416 mPolicyVisibility = true;
2417 mPolicyVisibilityAfterAnim = true;
2418 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002419 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002420 }
2421 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002422 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002423 }
2424 return true;
2425 }
2426
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002427 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002428 public boolean hideLw(boolean doAnimation) {
2429 return hideLw(doAnimation, true);
2430 }
2431
2432 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2433 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07002434 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002435 doAnimation = false;
2436 }
2437 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002438 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002439 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002440 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002441 return false;
2442 }
2443 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002444 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002445 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002446 doAnimation = false;
2447 }
2448 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002449 mPolicyVisibilityAfterAnim = false;
2450 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002451 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002452 mPolicyVisibility = false;
2453 // Window is no longer visible -- make sure if we were waiting
2454 // for it to be displayed before enabling the display, that
2455 // we allow the display to be enabled now.
2456 mService.enableScreenIfNeededLocked();
2457 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002458 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002459 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002460 mService.mFocusMayChange = true;
2461 }
2462 }
2463 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002464 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002465 }
2466 return true;
2467 }
2468
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002469 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002470 if (mAppOpVisibility != state) {
2471 mAppOpVisibility = state;
2472 if (state) {
2473 // If the policy visibility had last been to hide, then this
2474 // will incorrectly show at this point since we lost that
2475 // information. Not a big deal -- for the windows that have app
2476 // ops modifies they should only be hidden by policy due to the
2477 // lock screen, and the user won't be changing this if locked.
2478 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002479 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002480 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002481 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002482 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002483 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002484 }
2485
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002486 public void hidePermanentlyLw() {
2487 if (!mPermanentlyHidden) {
2488 mPermanentlyHidden = true;
2489 hideLw(true, true);
2490 }
2491 }
2492
Jeff Brownc2932a12014-11-20 18:04:05 -08002493 public void pokeDrawLockLw(long timeout) {
2494 if (isVisibleOrAdding()) {
2495 if (mDrawLock == null) {
2496 // We want the tag name to be somewhat stable so that it is easier to correlate
2497 // in wake lock statistics. So in particular, we don't want to include the
2498 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002499 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002500 mDrawLock = mService.mPowerManager.newWakeLock(
2501 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2502 mDrawLock.setReferenceCounted(false);
2503 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2504 }
2505 // Each call to acquire resets the timeout.
2506 if (DEBUG_POWER) {
2507 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2508 + mAttrs.packageName);
2509 }
2510 mDrawLock.acquire(timeout);
2511 } else if (DEBUG_POWER) {
2512 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2513 + "owned by " + mAttrs.packageName);
2514 }
2515 }
2516
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002517 @Override
2518 public boolean isAlive() {
2519 return mClient.asBinder().isBinderAlive();
2520 }
2521
Craig Mautnera987d432012-10-11 14:07:58 -07002522 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002523 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002524 }
2525
Chong Zhangbef461f2015-10-27 11:38:24 -07002526 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002527 return mAnimatingWithSavedSurface;
2528 }
2529
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002530 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002531 boolean isAnimating() {
2532 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2533 return true;
2534 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002535 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002536 }
2537
Chong Zhang8e4bda92016-05-04 15:08:18 -07002538 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002539 if (mAnimatingWithSavedSurface
2540 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2541 return true;
2542 }
2543 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002544 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002545 if (c.isAnimatingInvisibleWithSavedSurface()) {
2546 return true;
2547 }
2548 }
2549 return false;
2550 }
2551
2552 void stopUsingSavedSurface() {
2553 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002554 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002555 c.stopUsingSavedSurface();
2556 }
2557
2558 if (!isAnimatingInvisibleWithSavedSurface()) {
2559 return;
2560 }
2561
2562 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2563 clearAnimatingWithSavedSurface();
2564 mDestroying = true;
2565 mWinAnimator.hide("stopUsingSavedSurface");
2566 mService.mWallpaperControllerLocked.hideWallpapers(this);
2567 }
2568
2569 void markSavedSurfaceExiting() {
2570 if (isAnimatingInvisibleWithSavedSurface()) {
2571 mAnimatingExit = true;
2572 mWinAnimator.mAnimating = true;
2573 }
2574 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002575 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002576 c.markSavedSurfaceExiting();
2577 }
2578 }
2579
2580 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2581 animators.add(mWinAnimator);
2582
2583 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002584 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002585 c.addWinAnimatorToList(animators);
2586 }
2587 }
2588
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002589 void sendAppVisibilityToClients() {
2590 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002591
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002592 final boolean clientHidden = mAppToken.clientHidden;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002593 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2594 // Don't hide the starting window.
2595 return;
2596 }
2597
2598 try {
2599 if (DEBUG_VISIBILITY) Slog.v(TAG,
2600 "Setting visibility of " + this + ": " + (!clientHidden));
2601 mClient.dispatchAppVisibility(!clientHidden);
2602 } catch (RemoteException e) {
2603 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002604 }
2605
Chong Zhang92147042016-05-09 12:47:11 -07002606 public void setVisibleBeforeClientHidden() {
2607 mWasVisibleBeforeClientHidden |=
2608 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002609
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002610 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002611 }
2612
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002613 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002614 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002615 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002616 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002617 c.clearWasVisibleBeforeClientHidden();
2618 }
Chong Zhang92147042016-05-09 12:47:11 -07002619 }
2620
2621 public boolean wasVisibleBeforeClientHidden() {
2622 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002623 }
2624
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002625 void onStartFreezingScreen() {
2626 mAppFreezing = true;
2627 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002628 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002629 c.onStartFreezingScreen();
2630 }
2631 }
2632
2633 boolean onStopFreezingScreen() {
2634 boolean unfrozeWindows = false;
2635 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002636 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002637 unfrozeWindows |= c.onStopFreezingScreen();
2638 }
2639
2640 if (!mAppFreezing) {
2641 return unfrozeWindows;
2642 }
2643
Wale Ogunwale953171d2016-09-30 09:17:30 -07002644 mAppFreezing = false;
2645
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002646 if (mHasSurface && !mOrientationChanging
2647 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2648 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
2649 mOrientationChanging = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002650 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002651 }
2652 mLastFreezeDuration = 0;
2653 setDisplayLayoutNeeded();
2654 return true;
2655 }
2656
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002657 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002658 if (mWinAnimator.mSurfaceController == null) {
2659 // Don't bother if the surface controller is gone for any reason.
2660 return false;
2661 }
2662
Chong Zhang92147042016-05-09 12:47:11 -07002663 if (!mWasVisibleBeforeClientHidden) {
2664 return false;
2665 }
2666
Wale Ogunwale945d1972016-03-23 13:16:41 -07002667 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2668 // We don't save secure surfaces since their content shouldn't be shown while the app
2669 // isn't on screen and content might leak through during the transition animation with
2670 // saved surface.
2671 return false;
2672 }
2673
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002674 if (ActivityManager.isLowRamDeviceStatic()) {
2675 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002676 return false;
2677 }
2678
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002679 Task task = getTask();
2680 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002681 // Don't save surfaces for home stack apps. These usually resume and draw
2682 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002683 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002684 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002685
2686 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2687 if (taskTop != null && taskTop != mAppToken) {
2688 // Don't save if the window is not the topmost window.
2689 return false;
2690 }
2691
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002692 if (mResizedWhileGone) {
2693 // Somebody resized our window while we were gone for layout, which means that the
2694 // client got an old size, so we have an outdated surface here.
2695 return false;
2696 }
2697
Robert Carr7098dbd2016-02-01 12:31:01 -08002698 if (DEBUG_DISABLE_SAVING_SURFACES) {
2699 return false;
2700 }
2701
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002702 return mAppToken.shouldSaveSurface();
2703 }
2704
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002705 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2706 boolean destroyedSomething = false;
2707 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002708 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002709 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2710 }
2711
2712 if (appStopped || mWindowRemovalAllowed || cleanupOnResume) {
2713
2714 mWinAnimator.destroyPreservedSurfaceLocked();
2715
2716 if (mDestroying) {
2717 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2718 + " destroySurfaces: appStopped=" + appStopped
2719 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2720 + " win.mRemoveOnExit=" + mRemoveOnExit);
2721
2722 if (!cleanupOnResume || mRemoveOnExit) {
2723 destroyOrSaveSurface();
2724 }
2725 if (mRemoveOnExit) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002726 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002727 }
2728 if (cleanupOnResume) {
2729 requestUpdateWallpaperIfNeeded();
2730 }
2731 mDestroying = false;
2732 destroyedSomething = true;
2733 }
2734 }
2735 return destroyedSomething;
2736 }
Chris Craik3131bde2016-05-06 13:39:08 -07002737
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002738 void destroyOrSaveSurface() {
2739 mSurfaceSaved = shouldSaveSurface();
2740 if (mSurfaceSaved) {
2741 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2742 Slog.v(TAG, "Saving surface: " + this);
2743 }
Chris Craik3131bde2016-05-06 13:39:08 -07002744 // Previous user of the surface may have set a transparent region signaling a portion
2745 // doesn't need to be composited, so reset to default empty state.
2746 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002747
2748 mWinAnimator.hide("saved surface");
2749 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2750 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002751 // The client should have disconnected at this point, but if it doesn't,
2752 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2753 // the client can't reconnect to the buffer queue, and rendering will fail.
2754 if (mWinAnimator.mSurfaceController != null) {
2755 mWinAnimator.mSurfaceController.disconnectInTransaction();
2756 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002757 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002758 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002759 mWinAnimator.destroySurfaceLocked();
2760 }
Chong Zhang92147042016-05-09 12:47:11 -07002761 // Clear animating flags now, since the surface is now gone. (Note this is true even
2762 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2763 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002764 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002765
Chong Zhang92147042016-05-09 12:47:11 -07002766 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002767 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002768 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002769 c.destroySavedSurface();
2770 }
2771
Robert Carr13f7be9e2015-12-02 18:39:45 -08002772 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002773 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002774 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002775 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002776 }
Chong Zhang92147042016-05-09 12:47:11 -07002777 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002778 }
2779
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002780 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2781 int restoreSavedSurfaceForInterestingWindow() {
2782 int interestingNotDrawn = -1;
2783 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002784 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002785 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2786 if (childInterestingNotDrawn != -1) {
2787 if (interestingNotDrawn == -1) {
2788 interestingNotDrawn = childInterestingNotDrawn;
2789 } else {
2790 interestingNotDrawn += childInterestingNotDrawn;
2791 }
2792 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002793 }
Robert Carr237028a2016-07-26 10:39:45 -07002794
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002795 if (mAttrs.type == TYPE_APPLICATION_STARTING
2796 || mAppDied || !wasVisibleBeforeClientHidden()
2797 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2798 // Window isn't interesting...
2799 return interestingNotDrawn;
2800 }
2801
2802 restoreSavedSurface();
2803
2804 if (!isDrawnLw()) {
2805 if (interestingNotDrawn == -1) {
2806 interestingNotDrawn = 1;
2807 } else {
2808 interestingNotDrawn++;
2809 }
2810 }
2811 return interestingNotDrawn;
2812 }
2813
2814 /** Returns true if the saved surface was restored. */
2815 boolean restoreSavedSurface() {
2816 if (!mSurfaceSaved) {
2817 return false;
2818 }
2819
2820 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2821 // However this means the surface was never laid out in the new orientation.
2822 // We can only restore to the last rotation we were laid out as visible in.
Robert Carr237028a2016-07-26 10:39:45 -07002823 if (mLastVisibleLayoutRotation != mService.mRotation) {
2824 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002825 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002826 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002827 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002828
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002829 if (mWinAnimator.mSurfaceController != null) {
2830 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002831 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002832 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002833
Chong Zhang6e9872b2016-08-17 10:19:05 -07002834 requestUpdateWallpaperIfNeeded();
2835
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002836 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2837 Slog.v(TAG, "Restoring saved surface: " + this);
2838 }
2839 } else {
2840 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2841 // this point. Even if we destroyed the saved surface because of rotation
2842 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2843 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002844 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002845
2846 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002847 }
2848
Chong Zhang92147042016-05-09 12:47:11 -07002849 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002850 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2851 return true;
2852 }
2853
2854 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002855 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002856 if (c.canRestoreSurface()) {
2857 return true;
2858 }
2859 }
2860
2861 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002862 }
2863
2864 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002865 return mSurfaceSaved;
2866 }
2867
Chong Zhang92147042016-05-09 12:47:11 -07002868 void clearHasSavedSurface() {
2869 mSurfaceSaved = false;
2870 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002871 if (mWasVisibleBeforeClientHidden) {
2872 mAppToken.destroySavedSurfaces();
2873 }
Chong Zhang92147042016-05-09 12:47:11 -07002874 }
2875
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002876 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002877 if (mAnimatingWithSavedSurface) {
2878 // App has drawn something to its windows, we're no longer animating with
2879 // the saved surfaces.
2880 if (DEBUG_ANIM) Slog.d(TAG,
2881 "clearAnimatingWithSavedSurface(): win=" + this);
2882 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002883 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002884 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002885 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002886 }
2887
Craig Mautner69b08182012-09-05 13:07:13 -07002888 @Override
2889 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002890 final DisplayContent displayContent = getDisplayContent();
2891 if (displayContent == null) {
2892 // Only a window that was on a non-default display can be detached from it.
2893 return false;
2894 }
Winson Chung47a3e652014-05-21 16:03:42 -07002895 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002896 }
2897
Adrian Rooscd3884d2015-02-18 17:25:23 +01002898 @Override
2899 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002900 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002901 final DisplayContent dc = getDisplayContent();
2902 return dimLayerUser != null && dc != null
2903 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002904 }
2905
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002906 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002907 mShowToOwnerOnly = showToOwnerOnly;
2908 }
2909
Craig Mautner5962b122012-10-05 14:45:52 -07002910 boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002911 // Child windows are evaluated based on their parent window.
2912 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002913 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07002914 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002915
2916 // All window frames that are fullscreen extend above status bar, but some don't extend
2917 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2918 // bottom right.
2919 if (win.mFrame.left <= win.mDisplayFrame.left
2920 && win.mFrame.top <= win.mDisplayFrame.top
2921 && win.mFrame.right >= win.mStableFrame.right
2922 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002923 // Is a fullscreen window, like the clock alarm. Show to everyone.
2924 return false;
2925 }
2926 }
2927
Craig Mautner341220f2012-10-16 15:20:09 -07002928 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002929 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002930 }
2931
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002932 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2933 outRegion.set(
2934 frame.left + inset.left, frame.top + inset.top,
2935 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002936 }
2937
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002938 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002939 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002940 switch (mTouchableInsets) {
2941 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002942 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002943 outRegion.set(frame);
2944 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002945 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002946 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002947 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002948 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002949 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002950 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002951 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002952 final Region givenTouchableRegion = mGivenTouchableRegion;
2953 outRegion.set(givenTouchableRegion);
2954 outRegion.translate(frame.left, frame.top);
2955 break;
2956 }
2957 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002958 cropRegionToStackBoundsIfNeeded(outRegion);
2959 }
2960
2961 void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002962 final Task task = getTask();
2963 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002964 return;
2965 }
2966
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002967 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002968 if (stack == null) {
2969 return;
2970 }
2971
2972 stack.getDimBounds(mTmpRect);
2973 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002974 }
2975
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002976 // TODO: This is one reason why WindowList are bad...prime candidate for removal once we
2977 // figure-out a good way to replace WindowList with WindowContainer hierarchy.
Craig Mautner59c00972012-07-30 12:10:24 -07002978 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002979 final DisplayContent displayContent = getDisplayContent();
2980 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07002981 }
2982
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002983 /**
2984 * Report a focus change. Must be called with no locks held, and consistently
2985 * from the same serialized thread (such as dispatched from a handler).
2986 */
2987 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
2988 try {
2989 mClient.windowFocusChanged(focused, inTouchMode);
2990 } catch (RemoteException e) {
2991 }
2992 if (mFocusCallbacks != null) {
2993 final int N = mFocusCallbacks.beginBroadcast();
2994 for (int i=0; i<N; i++) {
2995 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2996 try {
2997 if (focused) {
2998 obs.focusGained(mWindowId.asBinder());
2999 } else {
3000 obs.focusLost(mWindowId.asBinder());
3001 }
3002 } catch (RemoteException e) {
3003 }
3004 }
3005 mFocusCallbacks.finishBroadcast();
3006 }
3007 }
3008
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003009 @Override
3010 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003011 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003012 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003013 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003014
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003015 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003016 }
3017
Craig Mautnerdf88d732014-01-27 09:21:32 -08003018 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003019 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003020 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003021 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3022 + ": " + mCompatFrame);
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003023 final Configuration newConfig;
3024 if (isConfigChanged()) {
3025 newConfig = new Configuration(getConfiguration());
3026 mLastReportedConfiguration.setTo(newConfig);
3027 } else {
3028 newConfig = null;
3029 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003030 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003031 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3032
Craig Mautnerdf88d732014-01-27 09:21:32 -08003033 final Rect frame = mFrame;
3034 final Rect overscanInsets = mLastOverscanInsets;
3035 final Rect contentInsets = mLastContentInsets;
3036 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003037 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003038 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003039 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07003040 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3041 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003042 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3043 mService.mH.post(new Runnable() {
3044 @Override
3045 public void run() {
3046 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003047 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
3048 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003049 } catch (RemoteException e) {
3050 // Not a remote call, RemoteException won't be raised.
3051 }
3052 }
3053 });
3054 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003055 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003056 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003057 }
Svetoslav4604abc2014-06-10 18:59:30 -07003058
3059 //TODO (multidisplay): Accessibility supported only for the default display.
3060 if (mService.mAccessibilityController != null
3061 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003062 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003063 }
3064
Craig Mautnerdf88d732014-01-27 09:21:32 -08003065 mOverscanInsetsChanged = false;
3066 mContentInsetsChanged = false;
3067 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003068 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003069 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003070 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003071 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003072 mWinAnimator.mSurfaceResized = false;
3073 } catch (RemoteException e) {
3074 mOrientationChanging = false;
3075 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3076 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003077 // We are assuming the hosting process is dead or in a zombie state.
3078 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3079 + ", removing this window.");
3080 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003081 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003082 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003083 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003084 }
3085
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003086 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003087 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3088 // start even if we haven't received the relayout window, so that the client requests
3089 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3090 // until the window to small size, otherwise the multithread renderer will shift last
3091 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3092 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003093 boolean resizing = isDragResizing() || isDragResizeChanged();
3094 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3095 return frame;
3096 }
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003097 DisplayInfo displayInfo = getDisplayInfo();
3098 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003099 return mTmpRect;
3100 }
3101
Jorim Jaggi86905582016-02-09 21:36:09 -08003102 @Override
3103 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003104 final TaskStack stack = getStack();
3105 if (stack == null) {
3106 return INVALID_STACK_ID;
3107 }
3108 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003109 }
3110
3111 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3112 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
3113 Configuration newConfig) throws RemoteException {
Chong Zhangedaf3052016-04-22 15:04:31 -07003114 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing;
3115
Jorim Jaggidc249c42015-12-15 14:57:31 -08003116 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08003117 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07003118 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003119 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003120 }
3121
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003122 public void registerFocusObserver(IWindowFocusObserver observer) {
3123 synchronized(mService.mWindowMap) {
3124 if (mFocusCallbacks == null) {
3125 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3126 }
3127 mFocusCallbacks.register(observer);
3128 }
3129 }
3130
3131 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3132 synchronized(mService.mWindowMap) {
3133 if (mFocusCallbacks != null) {
3134 mFocusCallbacks.unregister(observer);
3135 }
3136 }
3137 }
3138
3139 public boolean isFocused() {
3140 synchronized(mService.mWindowMap) {
3141 return mService.mCurrentFocus == this;
3142 }
3143 }
3144
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003145 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003146 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003147 return task != null && task.inFreeformWorkspace();
3148 }
3149
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003150 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003151 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003152 final Task task = getTask();
3153 return task != null && !task.isFullscreen();
3154 }
3155
Chong Zhang3005e752015-09-18 18:46:28 -07003156 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003157 return mDragResizing != computeDragResizing();
3158 }
3159
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003160 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003161 void setWaitingForDrawnIfResizingChanged() {
3162 if (isDragResizeChanged()) {
3163 mService.mWaitingForDrawn.add(this);
3164 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003165 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003166 }
3167
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003168 /**
3169 * @return Whether we reported a drag resize change to the application or not already.
3170 */
3171 boolean isDragResizingChangeReported() {
3172 return mDragResizingChangeReported;
3173 }
3174
3175 /**
3176 * Resets the state whether we reported a drag resize change to the app.
3177 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003178 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003179 void resetDragResizingChangeReported() {
3180 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003181 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003182 }
3183
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003184 /**
3185 * Set whether we got resized but drag resizing flag was false.
3186 * @see #isResizedWhileNotDragResizing().
3187 */
3188 void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
3189 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3190 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3191 }
3192
3193 /**
3194 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3195 * need to recreate the surface and defer surface bound updates in order to make sure the
3196 * buffer contents and the positioning/size stay in sync.
3197 */
3198 boolean isResizedWhileNotDragResizing() {
3199 return mResizedWhileNotDragResizing;
3200 }
3201
3202 /**
3203 * @return Whether we reported "resize while not drag resizing" to the application.
3204 * @see #isResizedWhileNotDragResizing()
3205 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003206 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003207 return mResizedWhileNotDragResizingReported;
3208 }
3209
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003210 int getResizeMode() {
3211 return mResizeMode;
3212 }
3213
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003214 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003215 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003216 if (task == null) {
3217 return false;
3218 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003219 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
3220
3221 // Floating windows never enter drag resize mode.
3222 return false;
3223 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003224 if (task.isDragResizing()) {
3225 return true;
3226 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003227
3228 // If the bounds are currently frozen, it means that the layout size that the app sees
3229 // and the bounds we clip this window to might be different. In order to avoid holes, we
3230 // simulate that we are still resizing so the app fills the hole with the resizing
3231 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003232 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003233 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003234 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003235
Chong Zhang3005e752015-09-18 18:46:28 -07003236 }
3237
3238 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003239 final boolean resizing = computeDragResizing();
3240 if (resizing == mDragResizing) {
3241 return;
3242 }
3243 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003244 final Task task = getTask();
3245 if (task != null && task.isDragResizing()) {
3246 mResizeMode = task.getDragResizeMode();
3247 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003248 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003249 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3250 : DRAG_RESIZE_MODE_FREEFORM;
3251 }
Chong Zhang3005e752015-09-18 18:46:28 -07003252 }
3253
3254 boolean isDragResizing() {
3255 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003256 }
3257
Robert Carr2487ce72016-04-07 15:18:45 -07003258 boolean isDockedResizing() {
3259 return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
3260 }
3261
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003262 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003263 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003264 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003265 if (stack != null) {
3266 pw.print(" stackId="); pw.print(stack.mStackId);
3267 }
Craig Mautner59c00972012-07-30 12:10:24 -07003268 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003269 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003270 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003271 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3272 pw.print(" package="); pw.print(mAttrs.packageName);
3273 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003274 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003275 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3276 pw.print(" h="); pw.print(mRequestedHeight);
3277 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003278 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3279 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3280 pw.print(" h="); pw.println(mLastRequestedHeight);
3281 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003282 if (mIsChildWindow || mLayoutAttached) {
3283 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003284 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3285 }
3286 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3287 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3288 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3289 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3290 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3291 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003292 if (dumpAll) {
3293 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3294 pw.print(" mSubLayer="); pw.print(mSubLayer);
3295 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003296 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003297 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3298 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003299 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003300 if (dumpAll) {
3301 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003302 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003303 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3304 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003305 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08003306 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003307 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003308 pw.print(prefix); pw.print("mViewVisibility=0x");
3309 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003310 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3311 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003312 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3313 pw.print(" mSystemUiVisibility=0x");
3314 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003315 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003316 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Svetoslav Ganov71c51022016-09-02 17:54:37 -07003317 || isParentWindowHidden()|| mPermanentlyHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003318 pw.print(prefix); pw.print("mPolicyVisibility=");
3319 pw.print(mPolicyVisibility);
3320 pw.print(" mPolicyVisibilityAfterAnim=");
3321 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003322 pw.print(" mAppOpVisibility=");
3323 pw.print(mAppOpVisibility);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003324 pw.print(" parentHidden="); pw.println(isParentWindowHidden());
Svetoslav Ganovaa076532016-08-01 19:16:43 -07003325 pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003326 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003327 if (!mRelayoutCalled || mLayoutNeeded) {
3328 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3329 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003330 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003331 if (mXOffset != 0 || mYOffset != 0) {
3332 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3333 pw.print(" y="); pw.println(mYOffset);
3334 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003335 if (dumpAll) {
3336 pw.print(prefix); pw.print("mGivenContentInsets=");
3337 mGivenContentInsets.printShortString(pw);
3338 pw.print(" mGivenVisibleInsets=");
3339 mGivenVisibleInsets.printShortString(pw);
3340 pw.println();
3341 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3342 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3343 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003344 Region region = new Region();
3345 getTouchableRegion(region);
3346 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003347 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003348 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3349 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3350 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003351 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003352 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003353 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003354 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003355 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3356 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003357 if (dumpAll) {
3358 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3359 pw.print(" last="); mLastFrame.printShortString(pw);
3360 pw.println();
3361 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003362 if (mEnforceSizeCompat) {
3363 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003364 pw.println();
3365 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003366 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003367 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003368 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003369 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003370 pw.println();
3371 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3372 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003373 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003374 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003375 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003376 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003377 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3378 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003379 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3380 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003381 pw.print(prefix); pw.print("Cur insets: overscan=");
3382 mOverscanInsets.printShortString(pw);
3383 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003384 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003385 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003386 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003387 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003388 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003389 pw.print(prefix); pw.print("Lst insets: overscan=");
3390 mLastOverscanInsets.printShortString(pw);
3391 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003392 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003393 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003394 pw.print(" physical="); mLastOutsets.printShortString(pw);
3395 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003396 pw.println();
3397 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003398 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3399 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003400 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3401 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003402 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3403 pw.print(" mDestroying="); pw.print(mDestroying);
3404 pw.print(" mRemoved="); pw.println(mRemoved);
3405 }
3406 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
3407 pw.print(prefix); pw.print("mOrientationChanging=");
3408 pw.print(mOrientationChanging);
3409 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
3410 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
3411 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003412 if (mLastFreezeDuration != 0) {
3413 pw.print(prefix); pw.print("mLastFreezeDuration=");
3414 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3415 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003416 if (mHScale != 1 || mVScale != 1) {
3417 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3418 pw.print(" mVScale="); pw.println(mVScale);
3419 }
3420 if (mWallpaperX != -1 || mWallpaperY != -1) {
3421 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3422 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3423 }
3424 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3425 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3426 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3427 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003428 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3429 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3430 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3431 pw.print(mWallpaperDisplayOffsetX);
3432 pw.print(" mWallpaperDisplayOffsetY=");
3433 pw.println(mWallpaperDisplayOffsetY);
3434 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003435 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003436 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003437 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003438 if (isDragResizing()) {
3439 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3440 }
3441 if (computeDragResizing()) {
3442 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3443 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003444 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003445
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003446 @Override
3447 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003448 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003449 + " " + getWindowTag();
3450 }
3451
Robert Carra1eb4392015-12-10 12:43:51 -08003452 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003453 CharSequence tag = mAttrs.getTitle();
3454 if (tag == null || tag.length() <= 0) {
3455 tag = mAttrs.packageName;
3456 }
3457 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003458 }
3459
3460 @Override
3461 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003462 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003463 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003464 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003465 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003466 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003467 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003468 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003469 }
3470 return mStringNameCache;
3471 }
Robert Carr58f29132015-10-29 14:19:05 -07003472
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003473 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003474 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003475 clipRect.left = (int) (clipRect.left / mHScale);
3476 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003477 }
3478 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003479 clipRect.top = (int) (clipRect.top / mVScale);
3480 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003481 }
3482 }
Robert Carr31e28482015-12-02 16:53:18 -08003483
Jorim Jaggif5834272016-04-04 20:25:41 -07003484 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3485 final int pw = containingFrame.width();
3486 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003487 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07003488 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003489 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3490
3491 // We need to fit it to the display if either
3492 // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless
3493 // windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003494 // b) If it's a secondary app window, we also need to fit it to the display unless
3495 // 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 -07003496 // but SurfaceViews want to be always at a specific location so we don't fit it to the
3497 // display.
3498 final boolean fitToDisplay = (task == null || !nonFullscreenTask)
Robert Carr6f44db12016-07-21 14:54:43 -07003499 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003500 float x, y;
3501 int w,h;
3502
3503 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3504 if (mAttrs.width < 0) {
3505 w = pw;
3506 } else if (mEnforceSizeCompat) {
3507 w = (int)(mAttrs.width * mGlobalScale + .5f);
3508 } else {
3509 w = mAttrs.width;
3510 }
3511 if (mAttrs.height < 0) {
3512 h = ph;
3513 } else if (mEnforceSizeCompat) {
3514 h = (int)(mAttrs.height * mGlobalScale + .5f);
3515 } else {
3516 h = mAttrs.height;
3517 }
3518 } else {
3519 if (mAttrs.width == MATCH_PARENT) {
3520 w = pw;
3521 } else if (mEnforceSizeCompat) {
3522 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3523 } else {
3524 w = mRequestedWidth;
3525 }
3526 if (mAttrs.height == MATCH_PARENT) {
3527 h = ph;
3528 } else if (mEnforceSizeCompat) {
3529 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3530 } else {
3531 h = mRequestedHeight;
3532 }
3533 }
3534
3535 if (mEnforceSizeCompat) {
3536 x = mAttrs.x * mGlobalScale;
3537 y = mAttrs.y * mGlobalScale;
3538 } else {
3539 x = mAttrs.x;
3540 y = mAttrs.y;
3541 }
3542
Robert Carr1d2bacb2016-03-30 14:29:35 -07003543 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003544 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003545 // required by {@link Gravity#apply} call.
3546 w = Math.min(w, pw);
3547 h = Math.min(h, ph);
3548 }
3549
3550 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003551 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003552 (int) (x + mAttrs.horizontalMargin * pw),
3553 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3554
3555 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003556 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003557 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003558 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003559
3560 // We need to make sure we update the CompatFrame as it is used for
3561 // cropping decisions, etc, on systems where we lack a decor layer.
3562 mCompatFrame.set(mFrame);
3563 if (mEnforceSizeCompat) {
3564 // See comparable block in computeFrameLw.
3565 mCompatFrame.scale(mInvGlobalScale);
3566 }
Robert Carr31e28482015-12-02 16:53:18 -08003567 }
Robert Carr51a1b872015-12-08 14:03:13 -08003568
3569 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003570 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003571 }
3572
3573 /**
3574 * Returns the bottom child window in regards to z-order of this window or null if no children.
3575 */
3576 WindowState getBottomChild() {
3577 // Child windows are z-ordered based on sub-layer using {@link #sWindowSubLayerComparator}
3578 // and the child with the lowest z-order will be at the head of the list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003579 WindowState c = mChildren.peekFirst();
3580 return c == null ? null : c;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003581 }
3582
Robert Carrf3b72c72016-03-21 18:16:39 -07003583 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003584 return mIsChildWindow
3585 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003586 }
3587
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003588 /** Returns the parent window if this is a child of another window, else null. */
3589 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003590 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3591 // WindowContainer that isn't a WindowState.
3592 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003593 }
3594
3595 /** Returns the topmost parent window if this is a child of another window, else this. */
3596 WindowState getTopParentWindow() {
3597 WindowState w = this;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07003598 while (w != null && w.mIsChildWindow) {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003599 w = w.getParentWindow();
3600 }
3601 return w;
3602 }
3603
Wale Ogunwale9d147902016-07-16 11:58:55 -07003604 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003605 final WindowState parent = getParentWindow();
3606 return (parent == null) ? false : parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003607 }
3608
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003609 void setWillReplaceWindow(boolean animate) {
3610 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003611 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003612 c.setWillReplaceWindow(animate);
3613 }
3614
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003615 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3616 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3617 // We don't set replacing on starting windows since they are added by window manager and
3618 // not the client so won't be replaced by the client.
3619 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003620 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003621
3622 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003623 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003624 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003625 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003626
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003627 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003628 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003629 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003630 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003631
3632 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003633 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003634 c.clearWillReplaceWindow();
3635 }
3636 }
3637
3638 boolean waitingForReplacement() {
3639 if (mWillReplaceWindow) {
3640 return true;
3641 }
3642
3643 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003644 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003645 if (c.waitingForReplacement()) {
3646 return true;
3647 }
3648 }
3649 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003650 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003651
Chong Zhang4d7369a2016-04-25 16:09:14 -07003652 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003653 final DisplayContent dc = getDisplayContent();
3654 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3655 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3656 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003657 mService.mWindowPlacerLocked.requestTraversal();
3658 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003659
3660 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003661 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003662 c.requestUpdateWallpaperIfNeeded();
3663 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003664 }
3665
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003666 float translateToWindowX(float x) {
3667 float winX = x - mFrame.left;
3668 if (mEnforceSizeCompat) {
3669 winX *= mGlobalScale;
3670 }
3671 return winX;
3672 }
3673
3674 float translateToWindowY(float y) {
3675 float winY = y - mFrame.top;
3676 if (mEnforceSizeCompat) {
3677 winY *= mGlobalScale;
3678 }
3679 return winY;
3680 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003681
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003682 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003683 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003684 final DisplayContent dc = getDisplayContent();
3685 if (dimLayerUser != null && dc != null) {
3686 dc.mDimLayerController.applyDim(dimLayerUser,
3687 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003688 }
3689 }
3690
Robert Carrd1a010f2016-04-07 22:36:22 -07003691 // During activity relaunch due to resize, we sometimes use window replacement
3692 // for only child windows (as the main window is handled by window preservation)
3693 // and the big surface.
3694 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003695 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3696 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3697 // we also want to replace them at such phases, as they won't be covered by window
3698 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003699 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003700 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003701 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003702 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003703
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003704 void setWillReplaceChildWindows() {
3705 if (shouldBeReplacedWithChildren()) {
3706 setWillReplaceWindow(false /* animate */);
3707 }
3708 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003709 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003710 c.setWillReplaceChildWindows();
3711 }
3712 }
3713
3714 WindowState getReplacingWindow() {
3715 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3716 return this;
3717 }
3718 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003719 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003720 final WindowState replacing = c.getReplacingWindow();
3721 if (replacing != null) {
3722 return replacing;
3723 }
3724 }
3725 return null;
3726 }
3727
Robert Carrfd10cd12016-06-29 16:41:50 -07003728 public int getRotationAnimationHint() {
3729 if (mAppToken != null) {
3730 return mAppToken.mRotationAnimationHint;
3731 } else {
3732 return -1;
3733 }
3734 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003735
3736 // This must be called while inside a transaction.
3737 boolean performShowLocked() {
3738 if (isHiddenFromUserLocked()) {
3739 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3740 hideLw(false);
3741 return false;
3742 }
3743
3744 logPerformShow("performShow on ");
3745
3746 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplayIgnoringKeyguard()) {
3747 return false;
3748 }
3749
3750 logPerformShow("Showing ");
3751
3752 mService.enableScreenIfNeededLocked();
3753 mWinAnimator.applyEnterAnimationLocked();
3754
3755 // Force the show in the next prepareSurfaceLocked() call.
3756 mWinAnimator.mLastAlpha = -1;
3757 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3758 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3759 mWinAnimator.mDrawState = HAS_DRAWN;
3760 mService.scheduleAnimationLocked();
3761
3762 if (mHidden) {
3763 mHidden = false;
3764 final DisplayContent displayContent = getDisplayContent();
3765
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003766 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003767 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003768 if (c.mWinAnimator.mSurfaceController != null) {
3769 c.performShowLocked();
3770 // It hadn't been shown, which means layout not performed on it, so now we
3771 // want to make sure to do a layout. If called from within the transaction
3772 // loop, this will cause it to restart with a new layout.
3773 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003774 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003775 }
3776 }
3777 }
3778 }
3779
3780 if (mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3781 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3782 }
3783
3784 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003785 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003786 }
3787
3788 return true;
3789 }
3790
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003791 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003792 if (DEBUG_VISIBILITY
3793 || (DEBUG_STARTING_WINDOW && mAttrs.type == TYPE_APPLICATION_STARTING)) {
3794 Slog.v(TAG, prefix + this
3795 + ": mDrawState=" + mWinAnimator.drawStateToString()
3796 + " readyForDisplay=" + isReadyForDisplayIgnoringKeyguard()
3797 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3798 + " during animation: policyVis=" + mPolicyVisibility
3799 + " parentHidden=" + isParentWindowHidden()
3800 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003801 + (mAppToken != null && mAppToken.hiddenRequested)
3802 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003803 + " animating=" + mWinAnimator.mAnimating
3804 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003805 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003806 + " Callers=" + Debug.getCallers(4));
3807 }
3808 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003809
3810 WindowInfo getWindowInfo() {
3811 WindowInfo windowInfo = WindowInfo.obtain();
3812 windowInfo.type = mAttrs.type;
3813 windowInfo.layer = mLayer;
3814 windowInfo.token = mClient.asBinder();
3815 windowInfo.title = mAttrs.accessibilityTitle;
3816 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3817 windowInfo.focused = isFocused();
3818
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003819 if (mIsChildWindow) {
3820 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003821 }
3822
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003823 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003824 if (childCount > 0) {
3825 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003826 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003827 }
3828 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003829 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003830 windowInfo.childTokens.add(child.mClient.asBinder());
3831 }
3832 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003833 return windowInfo;
3834 }
3835
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003836 int getHighestAnimLayer() {
3837 int highest = mWinAnimator.mAnimLayer;
3838 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003839 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003840 final int childLayer = c.getHighestAnimLayer();
3841 if (childLayer > highest) {
3842 highest = childLayer;
3843 }
3844 }
3845 return highest;
3846 }
3847
3848 int adjustAnimLayer(int adj) {
3849 int highestAnimLayer = mWinAnimator.mAnimLayer = mLayer + adj;
3850 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG_WM,
3851 "adjustAnimLayer win=" + this + " anim layer: " + mWinAnimator.mAnimLayer);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003852 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003853 final WindowState childWindow = mChildren.get(i);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003854 childWindow.adjustAnimLayer(adj);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003855 if (childWindow.mWinAnimator.mAnimLayer > highestAnimLayer) {
3856 highestAnimLayer = childWindow.mWinAnimator.mAnimLayer;
3857 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003858 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003859 return highestAnimLayer;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003860 }
3861
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003862 @Override
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003863 int rebuildWindowList(int addIndex) {
3864 return reAddWindow(addIndex);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003865 }
3866
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003867 // TODO: come-up with a better name for this method that represents what it does.
3868 // Or, it is probably not going to matter anyways if we are successful in getting rid of
3869 // the WindowList concept.
Wale Ogunwale92fc3722016-08-05 12:19:08 -07003870 int reAddWindow(int index) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003871 final WindowList windows = getWindowList();
3872 // Adding child windows relies on child windows being ordered by mSubLayer using
3873 // {@link #sWindowSubLayerComparator}.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003874 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003875 boolean winAdded = false;
3876 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003877 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003878 if (!winAdded && child.mSubLayer >= 0) {
3879 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3880 "Re-adding child window at " + index + ": " + child);
3881 mRebuilding = false;
3882 windows.add(index, this);
3883 index++;
3884 winAdded = true;
3885 }
3886 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + child);
3887 child.mRebuilding = false;
3888 windows.add(index, child);
3889 index++;
3890 }
3891 if (!winAdded) {
3892 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + this);
3893 mRebuilding = false;
3894 windows.add(index, this);
3895 index++;
3896 }
3897 mService.mWindowsChanged = true;
3898 return index;
3899 }
3900
3901 int removeFromWindowList(int interestingPos) {
3902 final WindowList windows = getWindowList();
3903 int wpos = windows.indexOf(this);
3904 if (wpos < 0) {
3905 return interestingPos;
3906 }
3907
3908 if (wpos < interestingPos) interestingPos--;
3909 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this);
3910 windows.remove(wpos);
3911 mService.mWindowsChanged = true;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003912 int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003913 while (childCount > 0) {
3914 childCount--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003915 final WindowState cw = mChildren.get(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003916 int cpos = windows.indexOf(cw);
3917 if (cpos >= 0) {
3918 if (cpos < interestingPos) interestingPos--;
3919 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3920 "Temp removing child at " + cpos + ": " + cw);
3921 windows.remove(cpos);
3922 }
3923 }
3924 return interestingPos;
3925 }
3926
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003927 boolean isWindowAnimationSet() {
3928 if (mWinAnimator.isWindowAnimationSet()) {
3929 return true;
3930 }
3931 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003932 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003933 if (c.isWindowAnimationSet()) {
3934 return true;
3935 }
3936 }
3937 return false;
3938 }
3939
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003940 void onExitAnimationDone() {
3941 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3942 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
3943 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
3944
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003945 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003946 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003947 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003948 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003949 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003950 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003951 }
3952 }
3953
3954 if (mWinAnimator.mEnteringAnimation) {
3955 mWinAnimator.mEnteringAnimation = false;
3956 mService.requestTraversal();
3957 // System windows don't have an activity and an app token as a result, but need a way
3958 // to be informed about their entrance animation end.
3959 if (mAppToken == null) {
3960 try {
3961 mClient.dispatchWindowShown();
3962 } catch (RemoteException e) {
3963 }
3964 }
3965 }
3966
3967 if (!mWinAnimator.isWindowAnimationSet()) {
3968 //TODO (multidisplay): Accessibility is supported only for the default display.
3969 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3970 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3971 }
3972 }
3973
3974 if (!mAnimatingExit) {
3975 return;
3976 }
3977
3978 if (mWinAnimator.isWindowAnimationSet()) {
3979 return;
3980 }
3981
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003982 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003983 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3984
3985 mDestroying = true;
3986
3987 final boolean hasSurface = mWinAnimator.hasSurface();
3988 if (hasSurface) {
3989 mWinAnimator.hide("onExitAnimationDone");
3990 }
3991
3992 // If we have an app token, we ask it to destroy the surface for us, so that it can take
3993 // care to ensure the activity has actually stopped and the surface is not still in use.
3994 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
3995 // transaction.
3996 if (mAppToken != null) {
3997 mAppToken.destroySurfaces();
3998 } else {
3999 if (hasSurface) {
4000 mService.mDestroySurface.add(this);
4001 }
4002 if (mRemoveOnExit) {
4003 mService.mPendingRemove.add(this);
4004 mRemoveOnExit = false;
4005 }
4006 }
4007 mAnimatingExit = false;
4008 mService.mWallpaperControllerLocked.hideWallpapers(this);
4009 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004010
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004011 boolean clearAnimatingFlags() {
4012 boolean didSomething = false;
4013 // We don't want to clear it out for windows that get replaced, because the
4014 // animation depends on the flag to remove the replaced window.
4015 //
4016 // We also don't clear the mAnimatingExit flag for windows which have the
4017 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4018 // by the client. We should let animation proceed and not clear this flag or
4019 // they won't eventually be removed by WindowStateAnimator#finishExit.
4020 if (!mWillReplaceWindow && !mRemoveOnExit) {
4021 // Clear mAnimating flag together with mAnimatingExit. When animation
4022 // changes from exiting to entering, we need to clear this flag until the
4023 // new animation gets applied, so that isAnimationStarting() becomes true
4024 // until then.
4025 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4026 // placement for this window during this period, one or more frame will
4027 // show up with wrong position or scale.
4028 if (mAnimatingExit) {
4029 mAnimatingExit = false;
4030 didSomething = true;
4031 }
4032 if (mWinAnimator.mAnimating) {
4033 mWinAnimator.mAnimating = false;
4034 didSomething = true;
4035 }
4036 if (mDestroying) {
4037 mDestroying = false;
4038 mService.mDestroySurface.remove(this);
4039 didSomething = true;
4040 }
4041 }
4042
4043 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004044 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004045 }
4046
4047 return didSomething;
4048 }
4049
Winson4b4ba902016-07-27 19:45:52 -07004050 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004051 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004052 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004053
4054 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004055 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004056 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004057 c.hideWallpaperWindow(wasDeferred, reason);
4058 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004059 if (!mWinAnimator.mLastHidden || wasDeferred) {
4060 mWinAnimator.hide(reason);
4061 dispatchWallpaperVisibility(false);
4062 final DisplayContent displayContent = getDisplayContent();
4063 if (displayContent != null) {
4064 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4065 }
4066 }
4067 }
4068
4069 /**
4070 * Check wallpaper window for visibility change and notify window if so.
4071 * @param visible Current visibility.
4072 */
4073 void dispatchWallpaperVisibility(final boolean visible) {
4074 final boolean hideAllowed =
4075 mService.mWallpaperControllerLocked.mDeferredHideWallpaper == null;
4076
4077 // Only send notification if the visibility actually changed and we are not trying to hide
4078 // the wallpaper when we are deferring hiding of the wallpaper.
4079 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4080 mWallpaperVisible = visible;
4081 try {
4082 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4083 "Updating vis of wallpaper " + this
4084 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4085 mClient.dispatchAppVisibility(visible);
4086 } catch (RemoteException e) {
4087 }
4088 }
4089 }
4090
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004091 boolean hasVisibleNotDrawnWallpaper() {
4092 if (mWallpaperVisible && !isDrawnLw()) {
4093 return true;
4094 }
4095 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004096 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004097 if (c.hasVisibleNotDrawnWallpaper()) {
4098 return true;
4099 }
4100 }
4101 return false;
4102 }
4103
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004104 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4105 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004106 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004107 c.updateReportedVisibility(results);
4108 }
4109
4110 if (mAppFreezing || mViewVisibility != View.VISIBLE
4111 || mAttrs.type == TYPE_APPLICATION_STARTING
4112 || mDestroying) {
4113 return;
4114 }
4115 if (DEBUG_VISIBILITY) {
4116 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4117 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4118 if (!isDrawnLw()) {
4119 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4120 + " pv=" + mPolicyVisibility
4121 + " mDrawState=" + mWinAnimator.mDrawState
4122 + " ph=" + isParentWindowHidden()
4123 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4124 + " a=" + mWinAnimator.mAnimating);
4125 }
4126 }
4127
4128 results.numInteresting++;
4129 if (isDrawnLw()) {
4130 results.numDrawn++;
4131 if (!mWinAnimator.isAnimationSet()) {
4132 results.numVisible++;
4133 }
4134 results.nowGone = false;
4135 } else if (mWinAnimator.isAnimationSet()) {
4136 results.nowGone = false;
4137 }
4138 }
4139
4140 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4141 // access to its windows children. Need to investigate re-writing
4142 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4143 static final class UpdateReportedVisibilityResults {
4144 int numInteresting;
4145 int numVisible;
4146 int numDrawn;
4147 boolean nowGone = true;
4148
4149 void reset() {
4150 numInteresting = 0;
4151 numVisible = 0;
4152 numDrawn = 0;
4153 nowGone = true;
4154 }
4155 }
satokcef37fb2011-10-24 21:49:38 +09004156}