blob: fa4dbc4f4f10d9da3151607afafabe0d9f220da9 [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 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700547 * Compares two window sub-layers and returns -1 if the first is lesser than the second in terms
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700548 * 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(
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700660 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800661 }
662
663 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700664 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800665 mSession.windowAddedLocked();
666 }
667
Craig Mautnera2c77052012-03-26 12:14:43 -0700668 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800669 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800670 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800671 }
672
673 @Override
674 public String getOwningPackage() {
675 return mAttrs.packageName;
676 }
677
Jorim Jaggif5834272016-04-04 20:25:41 -0700678 /**
679 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
680 * from {@param frame}. In other words, it applies the insets that would result if
681 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700682 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
683 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700684 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700685 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
686 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
687 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
688 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
689 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700690 frame.inset(left, top, right, bottom);
691 }
692
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800693 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700694 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
695 Rect osf) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800696 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700697 // This window is being replaced and either already got information that it's being
698 // removed or we are still waiting for some information. Because of this we don't
699 // want to apply any more changes to it, so it remains in this state until new window
700 // appears.
701 return;
702 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800703 mHaveFrame = true;
704
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700705 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700706 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800707 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700708 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800709
Chong Zhangae35fef2016-03-16 15:56:55 -0700710 // If the task has temp inset bounds set, we have to make sure all its windows uses
711 // the temp inset frame. Otherwise different display frames get applied to the main
712 // window and the child window, making them misaligned.
713 if (fullscreenTask) {
714 mInsetFrame.setEmpty();
715 } else {
716 task.getTempInsetBounds(mInsetFrame);
717 }
718
Jorim Jaggif5834272016-04-04 20:25:41 -0700719 // Denotes the actual frame used to calculate the insets and to perform the layout. When
720 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
721 // insets temporarily. By the notion of a task having a different layout frame, we can
722 // achieve that while still moving the task around.
723 final Rect layoutContainingFrame;
724 final Rect layoutDisplayFrame;
725
726 // The offset from the layout containing frame to the actual containing frame.
727 final int layoutXDiff;
728 final int layoutYDiff;
Wale Ogunwale7cd4b012016-05-07 12:41:22 -0700729 if (fullscreenTask || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800730 // We use the parent frame as the containing frame for fullscreen and child windows
731 mContainingFrame.set(pf);
732 mDisplayFrame.set(df);
Jorim Jaggif5834272016-04-04 20:25:41 -0700733 layoutDisplayFrame = df;
734 layoutContainingFrame = pf;
735 layoutXDiff = 0;
736 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800737 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700738 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100739 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
740
741 // If the bounds are frozen, we still want to translate the window freely and only
742 // freeze the size.
743 Rect frozen = mAppToken.mFrozenBounds.peek();
744 mContainingFrame.right = mContainingFrame.left + frozen.width();
745 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
746 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800747 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700748 // IME is up and obscuring this window. Adjust the window position so it is visible.
749 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
750 if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) {
751 // In freeform we want to move the top up directly.
752 // TODO: Investigate why this is cf not pf.
753 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
754 } else if (mContainingFrame.bottom > pf.bottom) {
755 // But in docked we want to behave like fullscreen
756 // and behave as if the task were given smaller bounds
757 // for the purposes of layout.
758 mContainingFrame.bottom = pf.bottom;
759 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700760 }
Skuhne81c524a2015-08-12 13:34:14 -0700761
Robert Carre6275582016-02-29 15:45:45 -0800762 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700763 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
764 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800765 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700766 if (mContainingFrame.isEmpty()) {
767 mContainingFrame.set(cf);
768 }
Doris Liu06d582d2015-06-01 13:18:43 -0700769 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800770 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700771 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
772 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
773 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700774 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Andrii Kuliandaea3572016-04-08 13:20:51 -0700775 subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700776 if (!layoutInParentFrame()) {
Andrii Kuliandaea3572016-04-08 13:20:51 -0700777 subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect);
778 subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700779 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700780 layoutDisplayFrame = df;
781 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700782 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800783
Craig Mautner967212c2013-04-13 21:10:58 -0700784 final int pw = mContainingFrame.width();
785 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800786
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800787 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800788 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800789 // + " to " + pf);
790 mParentFrame.set(pf);
791 mContentChanged = true;
792 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700793 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
794 mLastRequestedWidth = mRequestedWidth;
795 mLastRequestedHeight = mRequestedHeight;
796 mContentChanged = true;
797 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800798
Craig Mautnereda67292013-04-28 13:50:14 -0700799 mOverscanFrame.set(of);
800 mContentFrame.set(cf);
801 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400802 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700803 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700804 final boolean hasOutsets = osf != null;
805 if (hasOutsets) {
806 mOutsetFrame.set(osf);
807 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800808
Craig Mautnereda67292013-04-28 13:50:14 -0700809 final int fw = mFrame.width();
810 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800811
Jorim Jaggif5834272016-04-04 20:25:41 -0700812 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
813
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700814 // Calculate the outsets before the content frame gets shrinked to the window frame.
815 if (hasOutsets) {
816 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
817 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
818 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
819 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
820 } else {
821 mOutsets.set(0, 0, 0, 0);
822 }
823
Craig Mautnera248eee2013-05-07 11:41:27 -0700824 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800825 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800826 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700827 // Keep the frame out of the blocked system area, limit it in size to the content area
828 // and make sure that there is always a minimum visible so that the user can drag it
829 // into a usable area..
830 final int height = Math.min(mFrame.height(), mContentFrame.height());
831 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700832 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900833 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
834 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
835 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
836 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Skuhne81c524a2015-08-12 13:34:14 -0700837 final int top = Math.max(mContentFrame.top,
838 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
839 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
840 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
841 mFrame.set(left, top, left + width, top + height);
842 mContentFrame.set(mFrame);
843 mVisibleFrame.set(mContentFrame);
844 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700845 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700846 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100847 mContentFrame.set(mFrame);
848 if (!mFrame.equals(mLastFrame)) {
849 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800850 }
Skuhne81c524a2015-08-12 13:34:14 -0700851 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700852 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
853 Math.max(mContentFrame.top, mFrame.top),
854 Math.min(mContentFrame.right, mFrame.right),
855 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800856
Jorim Jaggi656f6502016-04-11 21:08:17 -0700857 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
858 Math.max(mVisibleFrame.top, mFrame.top),
859 Math.min(mVisibleFrame.right, mFrame.right),
860 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800861
Jorim Jaggi656f6502016-04-11 21:08:17 -0700862 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
863 Math.max(mStableFrame.top, mFrame.top),
864 Math.min(mStableFrame.right, mFrame.right),
865 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700866 }
Adrian Roosfa104232014-06-20 16:10:14 -0700867
Jorim Jaggi899327f2016-02-25 20:44:18 -0500868 if (fullscreenTask && !windowsAreFloating) {
869 // Windows that are not fullscreen can be positioned outside of the display frame,
870 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700871 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
872 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
873 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
874 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800875 }
Craig Mautnereda67292013-04-28 13:50:14 -0700876
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100877 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100878 // For the docked divider, we calculate the stable insets like a full-screen window
879 // so it can use it to calculate the snap positions.
880 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
881 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
882 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
883 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800884
885 // The divider doesn't care about insets in any case, so set it to empty so we don't
886 // trigger a relayout when moving it.
887 mContentInsets.setEmpty();
888 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100889 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700890 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700891 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
892 // non-fullscreen mode.
Jorim Jaggi656f6502016-04-11 21:08:17 -0700893 boolean overrideRightInset = !fullscreenTask && mFrame.right > mTmpRect.right;
894 boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mTmpRect.bottom;
895 mContentInsets.set(mContentFrame.left - mFrame.left,
896 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700897 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700898 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700899 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700900 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800901
Jorim Jaggi656f6502016-04-11 21:08:17 -0700902 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
903 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700904 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700905 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700906 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700907 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800908
Jorim Jaggi656f6502016-04-11 21:08:17 -0700909 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
910 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700911 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700912 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700913 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700914 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100915 }
Adrian Roosfa104232014-06-20 16:10:14 -0700916
Jorim Jaggi656f6502016-04-11 21:08:17 -0700917 // Offset the actual frame by the amount layout frame is off.
918 mFrame.offset(-layoutXDiff, -layoutYDiff);
919 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700920 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
921 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
922 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
923
Craig Mautnereda67292013-04-28 13:50:14 -0700924 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400925 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700926 // If there is a size compatibility scale being applied to the
927 // window, we need to apply this to its insets so that they are
928 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700929 mOverscanInsets.scale(mInvGlobalScale);
930 mContentInsets.scale(mInvGlobalScale);
931 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700932 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700933 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700934
935 // Also the scaled frame that we report to the app needs to be
936 // adjusted to be in its coordinate space.
937 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400938 }
939
Craig Mautnereda67292013-04-28 13:50:14 -0700940 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800941 final DisplayContent displayContent = getDisplayContent();
942 if (displayContent != null) {
943 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700944 mService.mWallpaperControllerLocked.updateWallpaperOffset(
945 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800946 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800947 }
948
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700949 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700950 "Resolving (mRequestedWidth="
951 + mRequestedWidth + ", mRequestedheight="
952 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
953 + "): frame=" + mFrame.toShortString()
954 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700955 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700956 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700957 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800958 }
959
Craig Mautnera2c77052012-03-26 12:14:43 -0700960 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800961 public Rect getFrameLw() {
962 return mFrame;
963 }
964
Craig Mautnera2c77052012-03-26 12:14:43 -0700965 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700966 public Point getShownPositionLw() {
967 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800968 }
969
Craig Mautnera2c77052012-03-26 12:14:43 -0700970 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800971 public Rect getDisplayFrameLw() {
972 return mDisplayFrame;
973 }
974
Craig Mautnera2c77052012-03-26 12:14:43 -0700975 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800976 public Rect getOverscanFrameLw() {
977 return mOverscanFrame;
978 }
979
980 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800981 public Rect getContentFrameLw() {
982 return mContentFrame;
983 }
984
Craig Mautnera2c77052012-03-26 12:14:43 -0700985 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800986 public Rect getVisibleFrameLw() {
987 return mVisibleFrame;
988 }
989
Craig Mautnera2c77052012-03-26 12:14:43 -0700990 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800991 public boolean getGivenInsetsPendingLw() {
992 return mGivenInsetsPending;
993 }
994
Craig Mautnera2c77052012-03-26 12:14:43 -0700995 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800996 public Rect getGivenContentInsetsLw() {
997 return mGivenContentInsets;
998 }
999
Craig Mautnera2c77052012-03-26 12:14:43 -07001000 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001001 public Rect getGivenVisibleInsetsLw() {
1002 return mGivenVisibleInsets;
1003 }
1004
Craig Mautnera2c77052012-03-26 12:14:43 -07001005 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001006 public WindowManager.LayoutParams getAttrs() {
1007 return mAttrs;
1008 }
1009
Craig Mautner812d2ca2012-09-27 15:35:34 -07001010 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001011 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
1012 int index = -1;
1013 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -07001014 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001015 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07001016 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
1017 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001018 }
1019 // If we reached the bottom of the range of windows we are considering,
1020 // assume no menu is needed.
1021 if (ws == bottom) {
1022 return false;
1023 }
1024 // The current window hasn't specified whether menu key is needed;
1025 // look behind it.
1026 // First, we may need to determine the starting position.
1027 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -07001028 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001029 }
1030 index--;
1031 if (index < 0) {
1032 return false;
1033 }
Craig Mautner59c00972012-07-30 12:10:24 -07001034 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001035 }
1036 }
1037
Craig Mautner19d59bc2012-09-04 11:15:56 -07001038 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001039 public int getSystemUiVisibility() {
1040 return mSystemUiVisibility;
1041 }
1042
Craig Mautner19d59bc2012-09-04 11:15:56 -07001043 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001044 public int getSurfaceLayer() {
1045 return mLayer;
1046 }
1047
Craig Mautner812d2ca2012-09-27 15:35:34 -07001048 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001049 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001050 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001051 }
1052
1053 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001054 public IApplicationToken getAppToken() {
1055 return mAppToken != null ? mAppToken.appToken : null;
1056 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001057
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001058 @Override
1059 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001060 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001061 }
1062
Robert Carr31aa98b2016-07-20 15:29:03 -07001063 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001064 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1065 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1066 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001067 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001068 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001069 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1070 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001071 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001072 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001073 }
1074
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001075 /**
1076 * Adds the window to the resizing list if any of the parameters we use to track the window
1077 * dimensions or insets have changed.
1078 */
1079 void updateResizingWindowIfNeeded() {
1080 final WindowStateAnimator winAnimator = mWinAnimator;
1081 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1082 return;
1083 }
1084
1085 final Task task = getTask();
1086 // In the case of stack bound animations, the window frames will update (unlike other
1087 // animations which just modify various transformation properties). We don't want to
1088 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1089 // the frame may not correspond to the surface size or the onscreen area at various
1090 // phases in the animation, and the client will become sad and confused.
1091 if (task != null && task.mStack.getBoundsAnimating()) {
1092 return;
1093 }
1094
1095 setReportResizeHints();
1096 boolean configChanged = isConfigChanged();
1097 if (DEBUG_CONFIGURATION && configChanged) {
1098 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1099 }
1100
1101 final boolean dragResizingChanged = isDragResizeChanged()
1102 && !isDragResizingChangeReported();
1103
1104 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1105 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1106 + " frame=" + mFrame);
1107
1108 // We update mLastFrame always rather than in the conditional with the last inset
1109 // variables, because mFrameSizeChanged only tracks the width and height changing.
1110 mLastFrame.set(mFrame);
1111
1112 if (mContentInsetsChanged
1113 || mVisibleInsetsChanged
1114 || winAnimator.mSurfaceResized
1115 || mOutsetsChanged
1116 || mFrameSizeChanged
1117 || configChanged
1118 || dragResizingChanged
1119 || !isResizedWhileNotDragResizingReported()) {
1120 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1121 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1122 + " contentInsetsChanged=" + mContentInsetsChanged
1123 + " " + mContentInsets.toShortString()
1124 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1125 + " " + mVisibleInsets.toShortString()
1126 + " stableInsetsChanged=" + mStableInsetsChanged
1127 + " " + mStableInsets.toShortString()
1128 + " outsetsChanged=" + mOutsetsChanged
1129 + " " + mOutsets.toShortString()
1130 + " surfaceResized=" + winAnimator.mSurfaceResized
1131 + " configChanged=" + configChanged
1132 + " dragResizingChanged=" + dragResizingChanged
1133 + " resizedWhileNotDragResizingReported="
1134 + isResizedWhileNotDragResizingReported());
1135 }
1136
1137 // If it's a dead window left on screen, and the configuration changed, there is nothing
1138 // we can do about it. Remove the window now.
1139 if (mAppToken != null && mAppDied) {
1140 mAppToken.removeDeadWindows();
1141 return;
1142 }
1143
1144 mLastOverscanInsets.set(mOverscanInsets);
1145 mLastContentInsets.set(mContentInsets);
1146 mLastVisibleInsets.set(mVisibleInsets);
1147 mLastStableInsets.set(mStableInsets);
1148 mLastOutsets.set(mOutsets);
1149 mService.makeWindowFreezingScreenIfNeededLocked(this);
1150
1151 // If the orientation is changing, or we're starting or ending a drag resizing action,
1152 // then we need to hold off on unfreezing the display until this window has been
1153 // redrawn; to do that, we need to go through the process of getting informed by the
1154 // application when it has finished drawing.
1155 if (mOrientationChanging || dragResizingChanged || isResizedWhileNotDragResizing()) {
1156 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1157 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1158 + ", mDrawState=DRAW_PENDING in " + this
1159 + ", surfaceController " + winAnimator.mSurfaceController);
1160 }
1161 winAnimator.mDrawState = DRAW_PENDING;
1162 if (mAppToken != null) {
1163 mAppToken.clearAllDrawn();
1164 }
1165 }
1166 if (!mService.mResizingWindows.contains(this)) {
1167 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1168 mService.mResizingWindows.add(this);
1169 }
1170 } else if (mOrientationChanging) {
1171 if (isDrawnLw()) {
1172 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1173 + this + ", surfaceController " + winAnimator.mSurfaceController);
1174 mOrientationChanging = false;
1175 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1176 - mService.mDisplayFreezeTime);
1177 }
1178 }
1179 }
1180
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001181 DisplayContent getDisplayContent() {
1182 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001183 }
1184
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001185 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001186 final DisplayContent displayContent = getDisplayContent();
1187 return displayContent != null ? displayContent.getDisplayInfo() : null;
1188 }
1189
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001190 int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001191 final DisplayContent displayContent = getDisplayContent();
1192 if (displayContent == null) {
1193 return -1;
1194 }
1195 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001196 }
1197
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001198 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001199 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001200 }
1201
1202 TaskStack getStack() {
1203 Task task = getTask();
1204 if (task != null) {
1205 if (task.mStack != null) {
1206 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001207 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001208 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001209 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1210 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001211 final DisplayContent dc = getDisplayContent();
1212 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001213 }
1214
Skuhnef932e562015-08-20 12:07:30 -07001215 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001216 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001217 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001218 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001219 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001220 final Task task = getTask();
1221 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001222 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001223 mTmpRect.setEmpty();
1224 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001225 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001226 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001227 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001228 } else {
1229 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001230 }
1231 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001232
Chong Zhang9184ec62015-09-24 12:32:21 -07001233 bounds.set(mVisibleFrame);
1234 if (intersectWithStackBounds) {
1235 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001236 }
1237
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001238 if (bounds.isEmpty()) {
1239 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001240 if (intersectWithStackBounds) {
1241 bounds.intersect(mTmpRect);
1242 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001243 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001244 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001245 }
1246
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001247 public long getInputDispatchingTimeoutNanos() {
1248 return mAppToken != null
1249 ? mAppToken.inputDispatchingTimeoutNanos
1250 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1251 }
1252
Craig Mautnere8552142012-11-07 13:55:47 -08001253 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001254 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001255 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001256 }
1257
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001258 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1259 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1260 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1261 if (dtdx < -.000001f || dtdx > .000001f) return false;
1262 if (dsdy < -.000001f || dsdy > .000001f) return false;
1263 return true;
1264 }
1265
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001266 void prelayout() {
1267 if (mEnforceSizeCompat) {
1268 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001269 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001270 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001271 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001272 }
1273 }
1274
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001275 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001276 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001277 // If we're animating with a saved surface, we're already visible.
1278 // Return true so that the alpha doesn't get cleared.
1279 if (!mAppFreezing && isDrawnLw()
1280 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1281 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1282 return true;
1283 }
1284
Wale Ogunwale44f21802016-09-02 12:49:48 -07001285 return super.hasContentToDisplay();
1286 }
1287
1288 @Override
1289 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -07001290 // TODO: The check for hiddenRequested is commented out below, because the window can still
1291 // be visible on screen when the flag is true. We would like the isVisible() method to
1292 // return an answer closer to if the window is truly visible (can't be an exact answer
1293 // without checking the surface state), so comment out the check for now so we can test to
1294 // see what problem it causes.
1295 // If it doesn't cause any issues, then we can remove just before we lock down the current
1296 // release (O) and also consolidate this method with #isVisibleUnchecked() and possibly
1297 // other methods like isVisibleNow().
1298 // If it does cause problems, then we can look if there are other ways to solve the problem.
1299 // If there isn't then uncomment and document here why it is needed.
1300 if (/*(mAppToken == null || !mAppToken.hiddenRequested) && */isVisibleUnchecked()
1301 // TODO: The window isn't considered visible when the token is hidden, however
1302 // uncommenting the check below breaks the visual transition from an app to the launcher
1303 // if the home buttons is pressed. Need to investigate an fix that issue before
1304 // uncommenting.
1305 /* && !mToken.hidden*/) {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001306 // Is this window visible? It is not visible if there is no surface, or we are in the
1307 // process of running an exit animation that will remove the surface, or its app token
1308 // has been hidden.
1309 return true;
1310 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001311 return false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001312 }
1313
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001314 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001315 * Does the minimal check for visibility. Callers generally want to use one of the public
1316 * methods as they perform additional checks on the app token.
1317 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001318 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001319 private boolean isVisibleUnchecked() {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001320 return mHasSurface && mPolicyVisibility && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001321 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001322 }
1323
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001324 @Override
1325 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001326 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001327 }
1328
1329 /**
1330 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1331 * keyguard as visible. This allows us to apply things like window flags that impact the
1332 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1333 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001334 */
Craig Mautner88400d32012-09-30 12:35:45 -07001335 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001336 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001337 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001338 return false;
1339 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001340 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001341 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001342 return mHasSurface && !mDestroying && !mAnimatingExit
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001343 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001344 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001345 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001346 }
1347
1348 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001349 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1350 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001351 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001352 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1353 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001354 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1355 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001356 }
1357
1358 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001359 * The same as isVisible(), but follows the current hidden state of the associated app token,
1360 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001361 */
1362 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001363 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001364 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001365 }
1366
1367 /**
1368 * Can this window possibly be a drag/drop target? The test here is
1369 * a combination of the above "visible now" with the check that the
1370 * Input Manager uses when discarding windows from input consideration.
1371 */
1372 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001373 return isVisibleNow() && !mRemoved
1374 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001375 }
1376
1377 /**
1378 * Same as isVisible(), but we also count it as visible between the
1379 * call to IWindowSession.add() and the first relayout().
1380 */
1381 boolean isVisibleOrAdding() {
1382 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001383 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001384 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001385 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001386 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001387 }
1388
1389 /**
1390 * Is this window currently on-screen? It is on-screen either if it
1391 * is visible or it is currently running an animation before no longer
1392 * being visible.
1393 */
1394 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001395 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1396 }
1397
1398 /**
1399 * Like isOnScreen(), but ignores any force hiding of the window due
1400 * to the keyguard.
1401 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001402 private boolean isOnScreenIgnoringKeyguard() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001403 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001404 return false;
1405 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001406 final AppWindowToken atoken = mAppToken;
1407 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001408 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001409 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001410 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001411 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 }
1413
1414 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001415 * Whether this window's drawn state might affect the drawn states of the app token.
1416 *
1417 * @param visibleOnly Whether we should consider only the windows that's currently
1418 * visible in layout. If true, windows that has not relayout to VISIBLE
1419 * would always return false.
1420 *
1421 * @return true if the window should be considered while evaluating allDrawn flags.
1422 */
1423 boolean mightAffectAllDrawn(boolean visibleOnly) {
Chong Zhange292eb32016-05-21 09:23:55 -07001424 final boolean isViewVisible = (mAppToken == null || !mAppToken.clientHidden)
1425 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001426 return (isOnScreenIgnoringKeyguard() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001427 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1428 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001429 && !mAnimatingExit && !mDestroying;
1430 }
1431
1432 /**
1433 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1434 * it must be drawn before allDrawn can become true.
1435 */
1436 boolean isInteresting() {
1437 return mAppToken != null && !mAppDied
1438 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1439 }
1440
1441 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001442 * Like isOnScreen(), but we don't return true if the window is part
1443 * of a transition that has not yet been started.
1444 */
1445 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001446 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001447 return false;
1448 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001449 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001450 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001451 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001452 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001453 }
1454
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001455 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001456 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1457 * to the keyguard.
1458 */
1459 boolean isReadyForDisplayIgnoringKeyguard() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001460 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001461 return false;
1462 }
1463 final AppWindowToken atoken = mAppToken;
1464 if (atoken == null && !mPolicyVisibility) {
1465 // If this is not an app window, and the policy has asked to force
1466 // hide, then we really do want to hide.
1467 return false;
1468 }
1469 return mHasSurface && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001470 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001471 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001472 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
Chong Zhang83caa362016-08-14 18:47:54 -07001473 && !mWinAnimator.isDummyAnimation())
1474 || isAnimatingWithSavedSurface());
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001475 }
1476
1477 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001478 * Like isOnScreen, but returns false if the surface hasn't yet
1479 * been drawn.
1480 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001481 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001482 public boolean isDisplayedLw() {
1483 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001484 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001485 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001486 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001487 || mWinAnimator.mAnimating
1488 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 }
1490
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001491 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001492 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001493 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001494 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001495 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001496 return mWinAnimator.mAnimation != null
1497 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001498 }
1499
Craig Mautner812d2ca2012-09-27 15:35:34 -07001500 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001501 public boolean isGoneForLayoutLw() {
1502 final AppWindowToken atoken = mAppToken;
1503 return mViewVisibility == View.GONE
1504 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001505 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001506 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001507 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001508 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001509 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001510 }
1511
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001512 /**
1513 * Returns true if the window has a surface that it has drawn a
1514 * complete UI in to.
1515 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001516 public boolean isDrawFinishedLw() {
1517 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001518 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1519 || mWinAnimator.mDrawState == READY_TO_SHOW
1520 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001521 }
1522
1523 /**
1524 * Returns true if the window has a surface that it has drawn a
1525 * complete UI in to.
1526 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001527 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001528 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001529 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001530 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001531 }
1532
1533 /**
1534 * Return true if the window is opaque and fully drawn. This indicates
1535 * it may obscure windows behind it.
1536 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001537 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001538 // When there is keyguard, wallpaper could be placed over the secure app
1539 // window but invisible. We need to check wallpaper visibility explicitly
1540 // to determine if it's occluding apps.
1541 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1542 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001543 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001544 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001545 }
1546
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001547 @Override
1548 void onMovedByResize() {
1549 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001550 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001551 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001552 }
1553
1554 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1555 boolean changed = false;
1556
1557 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001558 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001559 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1560 }
1561
1562 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1563 // Starting window that's exiting will be removed when the animation finishes.
1564 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1565 // to actually remove it.
1566 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1567 mAnimatingExit = true;
1568 mRemoveOnExit = true;
1569 mWindowRemovalAllowed = true;
1570 }
1571 return changed;
1572 }
1573
1574 if (visible != isVisibleNow()) {
1575 if (!runningAppAnimation) {
1576 final AccessibilityController accessibilityController =
1577 mService.mAccessibilityController;
1578 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1579 mWinAnimator.applyAnimationLocked(winTransit, visible);
1580 //TODO (multidisplay): Magnification is supported only for the default
1581 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1582 accessibilityController.onWindowTransitionLocked(this, winTransit);
1583 }
1584 }
1585 changed = true;
1586 setDisplayLayoutNeeded();
1587 }
1588
1589 return changed;
1590 }
1591
1592 boolean onSetAppExiting() {
1593 final DisplayContent displayContent = getDisplayContent();
1594 boolean changed = false;
1595
1596 if (isVisibleNow()) {
1597 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1598 //TODO (multidisplay): Magnification is supported only for the default
1599 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1600 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1601 }
1602 changed = true;
1603 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001604 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001605 }
1606 }
1607
1608 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001609 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001610 changed |= c.onSetAppExiting();
1611 }
1612
1613 return changed;
1614 }
1615
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001616 @Override
1617 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001618 // Some windows won't go through the resizing process, if they don't have a surface, so
1619 // destroy all saved surfaces here.
1620 destroySavedSurface();
1621
1622 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1623 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001624 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001625 resizingWindows.add(this);
1626
1627 // If we are not drag resizing, force recreating of a new surface so updating
1628 // the content and positioning that surface will be in sync.
1629 //
1630 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1631 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1632 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1633 // their frame to update crop, etc...
1634 //
1635 // Anyway we don't need to synchronize position and content updates for these
1636 // windows since they aren't at the base layer and could be moved around anyway.
1637 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
1638 !getTask().mStack.getBoundsAnimating() && !isGoneForLayoutLw() &&
1639 !getTask().inPinnedWorkspace()) {
1640 setResizedWhileNotDragResizing(true);
1641 }
1642 }
1643 if (isGoneForLayoutLw()) {
1644 mResizedWhileGone = true;
1645 }
1646
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001647 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001648 }
1649
1650 void onUnfreezeBounds() {
1651 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001652 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001653 c.onUnfreezeBounds();
1654 }
1655
1656 if (!mHasSurface) {
1657 return;
1658 }
1659
1660 mLayoutNeeded = true;
1661 setDisplayLayoutNeeded();
1662 if (!mService.mResizingWindows.contains(this)) {
1663 mService.mResizingWindows.add(this);
1664 }
1665 }
1666
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001667 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001668 * If the window has moved due to its containing content frame changing, then notify the
1669 * listeners and optionally animate it. Simply checking a change of position is not enough,
1670 * because being move due to dock divider is not a trigger for animation.
1671 */
1672 void handleWindowMovedIfNeeded() {
1673 if (!hasMoved()) {
1674 return;
1675 }
1676
1677 // Frame has moved, containing content frame has also moved, and we're not currently
1678 // animating... let's do something.
1679 final int left = mFrame.left;
1680 final int top = mFrame.top;
1681 final Task task = getTask();
1682 final boolean adjustedForMinimizedDockOrIme = task != null
1683 && (task.mStack.isAdjustedForMinimizedDockedStack()
1684 || task.mStack.isAdjustedForIme());
1685 if (mService.okToDisplay()
1686 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1687 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1688 && (task == null || getTask().mStack.hasMovementAnimations())
1689 && !mWinAnimator.mLastHidden) {
1690 mWinAnimator.setMoveAnimation(left, top);
1691 }
1692
1693 //TODO (multidisplay): Accessibility supported only for the default display.
1694 if (mService.mAccessibilityController != null
1695 && getDisplayContent().getDisplayId() == Display.DEFAULT_DISPLAY) {
1696 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1697 }
1698
1699 try {
1700 mClient.moved(left, top);
1701 } catch (RemoteException e) {
1702 }
1703 mMovedByResize = false;
1704 }
1705
1706 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001707 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001708 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1709 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001710 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001711 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001712 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001713 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001714 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001715 }
1716
Chong Zhang0abb20f2015-11-19 14:17:31 -08001717 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1718 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001719 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001720 return false;
1721 }
1722 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1723 return false;
1724 }
1725 return true;
1726 }
1727
1728 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1729 return mFrame.left <= 0 && mFrame.top <= 0
1730 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001731 }
1732
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001733 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001734 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001735 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001736 }
1737
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001738 boolean isAdjustedForMinimizedDock() {
1739 return mAppToken != null && mAppToken.mTask != null
1740 && mAppToken.mTask.mStack.isAdjustedForMinimizedDock();
1741 }
1742
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001743 void onWindowReplacementTimeout() {
1744 if (mWillReplaceWindow) {
1745 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001746 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001747 // delays removal on certain conditions, which will leave the stale window in the
1748 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1749 //
1750 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001751 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001752 } else {
1753 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001754 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001755 c.onWindowReplacementTimeout();
1756 }
1757 }
1758 }
1759
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001760 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001761 void forceWindowsScaleableInTransaction(boolean force) {
1762 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1763 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1764 }
1765
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001766 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001767 }
1768
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001769 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001770 void removeImmediately() {
1771 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001772
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001773 if (mRemoved) {
1774 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001775 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1776 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001777 return;
1778 }
1779
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001780 mRemoved = true;
1781
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001782 mWillReplaceWindow = false;
1783 if (mReplacementWindow != null) {
1784 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1785 }
1786
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001787 if (mService.mInputMethodTarget == this) {
1788 mService.moveInputMethodWindowsIfNeededLocked(false);
1789 }
1790
1791 final int type = mAttrs.type;
1792 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
1793 final DisplayContent displaycontent = getDisplayContent();
1794 displaycontent.mTapExcludedWindows.remove(this);
1795 }
1796 mPolicy.removeWindowLw(this);
1797
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001798 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001799
Craig Mautner96868332012-12-04 14:29:11 -08001800 mWinAnimator.destroyDeferredSurfaceLocked();
1801 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001802 mSession.windowRemovedLocked();
1803 try {
1804 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1805 } catch (RuntimeException e) {
1806 // Ignore if it has already been removed (usually because
1807 // we are doing this as part of processing a death note.)
1808 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001809
1810 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001811 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001812
Wale Ogunwale571771c2016-08-26 13:18:50 -07001813 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001814 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001815 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001816 removeIfPossible(false /*keepVisibleDeadWindow*/);
1817 }
1818
Wale Ogunwale571771c2016-08-26 13:18:50 -07001819 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001820 mWindowRemovalAllowed = true;
1821 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1822 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1823
1824 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1825 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1826 "Starting window removed " + this);
1827
1828 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1829 Slog.v(TAG_WM, "Remove " + this + " client="
1830 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1831 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1832 + Debug.getCallers(5));
1833
1834 final long origId = Binder.clearCallingIdentity();
1835
1836 disposeInputChannel();
1837
1838 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1839 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1840 + " mAnimatingExit=" + mAnimatingExit
1841 + " mRemoveOnExit=" + mRemoveOnExit
1842 + " mHasSurface=" + mHasSurface
1843 + " surfaceShowing=" + mWinAnimator.getShown()
1844 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1845 + " app-animation="
1846 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1847 + " mWillReplaceWindow=" + mWillReplaceWindow
1848 + " inPendingTransaction="
1849 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1850 + " mDisplayFrozen=" + mService.mDisplayFrozen
1851 + " callers=" + Debug.getCallers(6));
1852
1853 // Visibility of the removed window. Will be used later to update orientation later on.
1854 boolean wasVisible = false;
1855
1856 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1857 // window until the animation is done. If the display is frozen, just remove immediately,
1858 // since the animation wouldn't be seen.
1859 if (mHasSurface && mService.okToDisplay()) {
1860 if (mWillReplaceWindow) {
1861 // This window is going to be replaced. We need to keep it around until the new one
1862 // gets added, then we will get rid of this one.
1863 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1864 "Preserving " + this + " until the new one is " + "added");
1865 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1866 // been removed. We probably need another flag to indicate that window removal
1867 // should be deffered vs. overloading the flag that says we are playing an exit
1868 // animation.
1869 mAnimatingExit = true;
1870 mReplacingRemoveRequested = true;
1871 Binder.restoreCallingIdentity(origId);
1872 return;
1873 }
1874
1875 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1876 // We started enter animation early with a saved surface, now the app asks to remove
1877 // this window. If we remove it now and the app is not yet drawn, we'll show a
1878 // flicker. Delay the removal now until it's really drawn.
1879 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1880 "removeWindowLocked: delay removal of " + this + " due to early animation");
1881 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1882 // immediately after the enter animation is done. If the app is not yet drawn then
1883 // it will show up as a flicker.
1884 setupWindowForRemoveOnExit();
1885 Binder.restoreCallingIdentity(origId);
1886 return;
1887 }
1888 // If we are not currently running the exit animation, we need to see about starting one
1889 wasVisible = isWinVisibleLw();
1890
1891 if (keepVisibleDeadWindow) {
1892 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1893 "Not removing " + this + " because app died while it's visible");
1894
1895 mAppDied = true;
1896 setDisplayLayoutNeeded();
1897 mService.mWindowPlacerLocked.performSurfacePlacement();
1898
1899 // Set up a replacement input channel since the app is now dead.
1900 // We need to catch tapping on the dead window to restart the app.
1901 openInputChannel(null);
1902 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1903
1904 Binder.restoreCallingIdentity(origId);
1905 return;
1906 }
1907
1908 if (wasVisible) {
1909 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1910
1911 // Try starting an animation.
1912 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1913 mAnimatingExit = true;
1914 }
1915 //TODO (multidisplay): Magnification is supported only for the default display.
1916 if (mService.mAccessibilityController != null
1917 && getDisplayId() == Display.DEFAULT_DISPLAY) {
1918 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1919 }
1920 }
1921 final boolean isAnimating =
1922 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1923 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001924 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001925 // We delay the removal of a window if it has a showing surface that can be used to run
1926 // exit animation and it is marked as exiting.
1927 // Also, If isn't the an animating starting window that is the last window in the app.
1928 // We allow the removal of the non-animating starting window now as there is no
1929 // additional window or animation that will trigger its removal.
1930 if (mWinAnimator.getShown() && mAnimatingExit
1931 && (!lastWindowIsStartingWindow || isAnimating)) {
1932 // The exit animation is running or should run... wait for it!
1933 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1934 "Not removing " + this + " due to exit animation ");
1935 setupWindowForRemoveOnExit();
1936 if (mAppToken != null) {
1937 mAppToken.updateReportedVisibilityLocked();
1938 }
1939 Binder.restoreCallingIdentity(origId);
1940 return;
1941 }
1942 }
1943
Wale Ogunwale571771c2016-08-26 13:18:50 -07001944 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001945 // Removing a visible window will effect the computed orientation
1946 // So just update orientation if needed.
1947 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false)) {
1948 mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION);
1949 }
1950 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1951 Binder.restoreCallingIdentity(origId);
1952 }
1953
1954 private void setupWindowForRemoveOnExit() {
1955 mRemoveOnExit = true;
1956 setDisplayLayoutNeeded();
1957 // Request a focus update as this window's input channel is already gone. Otherwise
1958 // we could have no focused window in input manager.
1959 final boolean focusChanged = mService.updateFocusedWindowLocked(
1960 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1961 mService.mWindowPlacerLocked.performSurfacePlacement();
1962 if (focusChanged) {
1963 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1964 }
1965 }
1966
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001967 void setHasSurface(boolean hasSurface) {
1968 mHasSurface = hasSurface;
1969 }
1970
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001971 int getAnimLayerAdjustment() {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001972 final boolean isImeType =
1973 mAttrs.type == TYPE_INPUT_METHOD || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
1974 if (isImeType && mService.mInputMethodTarget != null) {
1975 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1976 if (appToken != null) {
1977 return appToken.mAppAnimator.animLayerAdjustment;
1978 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001979 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07001980
1981 if (mAppToken != null) {
1982 return mAppToken.mAppAnimator.animLayerAdjustment;
1983 }
1984
1985 // Nothing is animating, so there is no animation adjustment.
1986 return 0;
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001987 }
1988
1989 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001990 final DisplayContent dc = getDisplayContent();
1991 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001992 return;
1993 }
1994 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001995 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001996 // Force an animation pass just to update the mDimLayer layer.
1997 mService.scheduleAnimationLocked();
1998 }
1999 }
2000
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002001 /**
2002 * Notifies this window that the corresponding task has just moved in the stack.
2003 * <p>
2004 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
2005 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
2006 * the actual app transition that updates the visibility is delayed by a few transactions.
2007 * Instead of messing around with the ordering and timing how transitions and transactions are
2008 * executed, we introduce this little hack which prevents this window of getting visible again
2009 * with the wrong bounds until the app transitions has started.
2010 * <p>
2011 * This method notifies the window about that we just moved in the stack so we can apply this
2012 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
2013 */
2014 void notifyMovedInStack() {
2015 mJustMovedInStack = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002016
2017 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002018 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002019 c.notifyMovedInStack();
2020 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002021 }
2022
2023 /**
2024 * See {@link #notifyMovedInStack}.
2025 *
2026 * @return Whether we just got moved in the corresponding stack.
2027 */
2028 boolean hasJustMovedInStack() {
2029 return mJustMovedInStack;
2030 }
2031
2032 /**
2033 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
2034 */
2035 void resetJustMovedInStack() {
2036 mJustMovedInStack = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002037
2038 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002039 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002040 c.resetJustMovedInStack();
2041 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002042 }
2043
Chong Zhangacf11402015-11-04 16:23:10 -08002044 private final class DeadWindowEventReceiver extends InputEventReceiver {
2045 DeadWindowEventReceiver(InputChannel inputChannel) {
2046 super(inputChannel, mService.mH.getLooper());
2047 }
2048 @Override
2049 public void onInputEvent(InputEvent event) {
2050 finishInputEvent(event, true);
2051 }
2052 }
2053 /**
2054 * Dummy event receiver for windows that died visible.
2055 */
2056 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2057
Chong Zhang112eb8c2015-11-02 11:17:00 -08002058 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002059 if (mInputChannel != null) {
2060 throw new IllegalStateException("Window already has an input channel.");
2061 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002062 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002063 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2064 mInputChannel = inputChannels[0];
2065 mClientChannel = inputChannels[1];
2066 mInputWindowHandle.inputChannel = inputChannels[0];
2067 if (outInputChannel != null) {
2068 mClientChannel.transferTo(outInputChannel);
2069 mClientChannel.dispose();
2070 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002071 } else {
2072 // If the window died visible, we setup a dummy input channel, so that taps
2073 // can still detected by input monitor channel, and we can relaunch the app.
2074 // Create dummy event receiver that simply reports all events as handled.
2075 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002076 }
2077 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002078 }
2079
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002080 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002081 if (mDeadWindowEventReceiver != null) {
2082 mDeadWindowEventReceiver.dispose();
2083 mDeadWindowEventReceiver = null;
2084 }
2085
2086 // unregister server channel first otherwise it complains about broken channel
2087 if (mInputChannel != null) {
2088 mService.mInputManager.unregisterInputChannel(mInputChannel);
2089 mInputChannel.dispose();
2090 mInputChannel = null;
2091 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002092 if (mClientChannel != null) {
2093 mClientChannel.dispose();
2094 mClientChannel = null;
2095 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002096 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002097 }
2098
Chong Zhang112eb8c2015-11-02 11:17:00 -08002099 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002100 // When the app is terminated (eg. from Recents), the task might have already been
2101 // removed with the window pending removal. Don't apply dim in such cases, as there
2102 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2103 final AppWindowToken token = mAppToken;
2104 if (token != null && token.removed) {
2105 return;
2106 }
2107
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002108 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002109 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002110 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002111 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002112 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002113 && dc != null && !mAnimatingExit && isVisibleUnchecked()) {
2114 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002115 }
2116 }
2117
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002118 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002119 Task task = getTask();
2120 if (task != null) {
2121 return task;
2122 }
2123 return getStack();
2124 }
2125
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002126 /** Returns true if the replacement window was removed. */
2127 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2128 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2129 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2130 removeReplacedWindow();
2131 return true;
2132 }
2133
2134 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002135 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002136 if (c.removeReplacedWindowIfNeeded(replacement)) {
2137 return true;
2138 }
2139 }
2140 return false;
2141 }
2142
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002143 void removeReplacedWindow() {
2144 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2145 if (isDimming()) {
2146 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002147 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002148 mWillReplaceWindow = false;
2149 mAnimateReplacingWindow = false;
2150 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002151 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002152 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002153 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002154 }
2155 }
2156
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002157 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2158 boolean replacementSet = false;
2159
2160 if (mWillReplaceWindow && mReplacementWindow == null
2161 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2162
2163 mReplacementWindow = replacementCandidate;
2164 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2165 replacementSet = true;
2166 }
2167
2168 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002169 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002170 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2171 }
2172
2173 return replacementSet;
2174 }
2175
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002176 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002177 final DisplayContent dc = getDisplayContent();
2178 if (dc != null) {
2179 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002180 }
2181 }
2182
Robert Carrfed10072016-05-26 11:48:49 -07002183 // TODO: Strange usage of word workspace here and above.
2184 boolean inPinnedWorkspace() {
2185 final Task task = getTask();
2186 return task != null && task.inPinnedWorkspace();
2187 }
2188
Chong Zhang5117e272016-05-03 12:47:34 -07002189 void applyAdjustForImeIfNeeded() {
2190 final Task task = getTask();
2191 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2192 task.mStack.applyAdjustForImeIfNeeded(task);
2193 }
2194 }
2195
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002196 int getTouchableRegion(Region region, int flags) {
2197 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002198 if (modal && mAppToken != null) {
2199 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002200 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002201 // If this is a modal window we need to dismiss it if it's not full screen and the
2202 // touch happens outside of the frame that displays the content. This means we
2203 // need to intercept touches outside of that window. The dim layer user
2204 // associated with the window (task or stack) will give us the good bounds, as
2205 // they would be used to display the dim layer.
2206 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2207 if (dimLayerUser != null) {
2208 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002209 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002210 getVisibleBounds(mTmpRect);
2211 }
2212 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002213 // For freeform windows we the touch region to include the whole surface for the
2214 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002215 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2216 final int delta = WindowManagerService.dipToPixel(
2217 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2218 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002219 }
2220 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002221 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002222 } else {
2223 // Not modal or full screen modal
2224 getTouchableRegion(region);
2225 }
2226 return flags;
2227 }
2228
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002229 void checkPolicyVisibilityChange() {
2230 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2231 if (DEBUG_VISIBILITY) {
2232 Slog.v(TAG, "Policy visibility changing after anim in " +
2233 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2234 }
2235 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002236 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002237 if (!mPolicyVisibility) {
2238 if (mService.mCurrentFocus == this) {
2239 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2240 "setAnimationLocked: setting mFocusMayChange true");
2241 mService.mFocusMayChange = true;
2242 }
2243 // Window is no longer visible -- make sure if we were waiting
2244 // for it to be displayed before enabling the display, that
2245 // we allow the display to be enabled now.
2246 mService.enableScreenIfNeededLocked();
2247 }
2248 }
2249 }
2250
2251 void setRequestedSize(int requestedWidth, int requestedHeight) {
2252 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2253 mLayoutNeeded = true;
2254 mRequestedWidth = requestedWidth;
2255 mRequestedHeight = requestedHeight;
2256 }
2257 }
2258
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002259 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
2260 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2261 == SOFT_INPUT_ADJUST_RESIZE) {
2262 mLayoutNeeded = true;
2263 }
2264 if (isDrawnLw() && mService.okToDisplay()) {
2265 mWinAnimator.applyEnterAnimationLocked();
2266 }
2267 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2268 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2269 mTurnOnScreen = true;
2270 }
2271 if (isConfigChanged()) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002272 outConfig.setTo(getConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002273 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002274 + outConfig);
2275 mLastReportedConfiguration.setTo(outConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002276 }
2277 }
2278
2279 void adjustStartingWindowFlags() {
2280 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2281 && mAppToken.startingWindow != null) {
2282 // Special handling of starting window over the base
2283 // window of the app: propagate lock screen flags to it,
2284 // to provide the correct semantics while starting.
2285 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2286 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2287 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2288 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2289 }
2290 }
2291
2292 void setWindowScale(int requestedWidth, int requestedHeight) {
2293 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2294
2295 if (scaledWindow) {
2296 // requested{Width|Height} Surface's physical size
2297 // attrs.{width|height} Size on screen
2298 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2299 mHScale = (mAttrs.width != requestedWidth) ?
2300 (mAttrs.width / (float)requestedWidth) : 1.0f;
2301 mVScale = (mAttrs.height != requestedHeight) ?
2302 (mAttrs.height / (float)requestedHeight) : 1.0f;
2303 } else {
2304 mHScale = mVScale = 1;
2305 }
2306 }
2307
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002308 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002309 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002310 public void binderDied() {
2311 try {
2312 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002313 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002314 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002315 if (win != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002316 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002317 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2318 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002319 // just in case they have the divider at an unstable position. Better
2320 // also reset drag resizing state, because the owner can't do it
2321 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002322 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
2323 if (stack != null) {
2324 stack.resetDockedStackToMiddle();
2325 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002326 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002327 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002328 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002329 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002330 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002331 }
2332 }
2333 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002334 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002335 }
2336 }
2337 }
2338
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002339 /**
2340 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2341 * because we want to preserve its location on screen to be re-activated later when the user
2342 * interacts with it.
2343 */
2344 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002345 if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002346 // Not a visible app window or the app isn't dead.
2347 return false;
2348 }
2349
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002350 if (mAttrs.token != mClient.asBinder()) {
2351 // The window was add by a client using another client's app token. We don't want to
2352 // keep the dead window around for this case since this is meant for 'real' apps.
2353 return false;
2354 }
2355
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002356 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2357 // We don't keep starting windows since they were added by the window manager before
2358 // the app even launched.
2359 return false;
2360 }
2361
2362 final TaskStack stack = getStack();
2363 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2364 }
2365
Wale Ogunwaled045c822015-12-02 09:14:28 -08002366 /** @return true if this window desires key events. */
2367 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002368 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002369 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002370 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002371 && (mAppToken == null || mAppToken.windowsAreFocusable())
2372 && !isAdjustedForMinimizedDock();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002373 }
2374
Craig Mautner749a7bb2012-04-02 13:49:53 -07002375 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002376 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002377 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002378 }
2379
Craig Mautner749a7bb2012-04-02 13:49:53 -07002380 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002381 public boolean showLw(boolean doAnimation) {
2382 return showLw(doAnimation, true);
2383 }
2384
2385 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002386 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002387 return false;
2388 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002389 if (!mAppOpVisibility) {
2390 // Being hidden due to app op request.
2391 return false;
2392 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002393 if (mPermanentlyHidden) {
2394 // Permanently hidden until the app exists as apps aren't prepared
2395 // to handle their windows being removed from under them.
2396 return false;
2397 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002398 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002399 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002400 return false;
2401 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002402 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002403 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002404 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002405 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07002406 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002407 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002408 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002409 // Check for the case where we are currently visible and
2410 // not animating; we do not want to do animation at such a
2411 // point to become visible when we already are.
2412 doAnimation = false;
2413 }
2414 }
2415 mPolicyVisibility = true;
2416 mPolicyVisibilityAfterAnim = true;
2417 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002418 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002419 }
2420 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002421 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002422 }
2423 return true;
2424 }
2425
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002426 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002427 public boolean hideLw(boolean doAnimation) {
2428 return hideLw(doAnimation, true);
2429 }
2430
2431 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2432 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07002433 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002434 doAnimation = false;
2435 }
2436 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002437 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002438 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002439 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002440 return false;
2441 }
2442 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002443 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002444 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002445 doAnimation = false;
2446 }
2447 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002448 mPolicyVisibilityAfterAnim = false;
2449 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002450 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002451 mPolicyVisibility = false;
2452 // Window is no longer visible -- make sure if we were waiting
2453 // for it to be displayed before enabling the display, that
2454 // we allow the display to be enabled now.
2455 mService.enableScreenIfNeededLocked();
2456 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002457 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002458 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002459 mService.mFocusMayChange = true;
2460 }
2461 }
2462 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002463 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002464 }
2465 return true;
2466 }
2467
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002468 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002469 if (mAppOpVisibility != state) {
2470 mAppOpVisibility = state;
2471 if (state) {
2472 // If the policy visibility had last been to hide, then this
2473 // will incorrectly show at this point since we lost that
2474 // information. Not a big deal -- for the windows that have app
2475 // ops modifies they should only be hidden by policy due to the
2476 // lock screen, and the user won't be changing this if locked.
2477 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002478 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002479 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002480 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002481 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002482 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002483 }
2484
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002485 public void hidePermanentlyLw() {
2486 if (!mPermanentlyHidden) {
2487 mPermanentlyHidden = true;
2488 hideLw(true, true);
2489 }
2490 }
2491
Jeff Brownc2932a12014-11-20 18:04:05 -08002492 public void pokeDrawLockLw(long timeout) {
2493 if (isVisibleOrAdding()) {
2494 if (mDrawLock == null) {
2495 // We want the tag name to be somewhat stable so that it is easier to correlate
2496 // in wake lock statistics. So in particular, we don't want to include the
2497 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002498 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002499 mDrawLock = mService.mPowerManager.newWakeLock(
2500 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2501 mDrawLock.setReferenceCounted(false);
2502 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2503 }
2504 // Each call to acquire resets the timeout.
2505 if (DEBUG_POWER) {
2506 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2507 + mAttrs.packageName);
2508 }
2509 mDrawLock.acquire(timeout);
2510 } else if (DEBUG_POWER) {
2511 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2512 + "owned by " + mAttrs.packageName);
2513 }
2514 }
2515
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002516 @Override
2517 public boolean isAlive() {
2518 return mClient.asBinder().isBinderAlive();
2519 }
2520
Craig Mautnera987d432012-10-11 14:07:58 -07002521 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002522 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002523 }
2524
Chong Zhangbef461f2015-10-27 11:38:24 -07002525 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002526 return mAnimatingWithSavedSurface;
2527 }
2528
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002529 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002530 boolean isAnimating() {
2531 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2532 return true;
2533 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002534 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002535 }
2536
Chong Zhang8e4bda92016-05-04 15:08:18 -07002537 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002538 if (mAnimatingWithSavedSurface
2539 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2540 return true;
2541 }
2542 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002543 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002544 if (c.isAnimatingInvisibleWithSavedSurface()) {
2545 return true;
2546 }
2547 }
2548 return false;
2549 }
2550
2551 void stopUsingSavedSurface() {
2552 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002553 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002554 c.stopUsingSavedSurface();
2555 }
2556
2557 if (!isAnimatingInvisibleWithSavedSurface()) {
2558 return;
2559 }
2560
2561 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2562 clearAnimatingWithSavedSurface();
2563 mDestroying = true;
2564 mWinAnimator.hide("stopUsingSavedSurface");
2565 mService.mWallpaperControllerLocked.hideWallpapers(this);
2566 }
2567
2568 void markSavedSurfaceExiting() {
2569 if (isAnimatingInvisibleWithSavedSurface()) {
2570 mAnimatingExit = true;
2571 mWinAnimator.mAnimating = true;
2572 }
2573 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002574 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002575 c.markSavedSurfaceExiting();
2576 }
2577 }
2578
2579 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2580 animators.add(mWinAnimator);
2581
2582 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002583 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002584 c.addWinAnimatorToList(animators);
2585 }
2586 }
2587
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002588 void sendAppVisibilityToClients() {
2589 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002590
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002591 final boolean clientHidden = mAppToken.clientHidden;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002592 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2593 // Don't hide the starting window.
2594 return;
2595 }
2596
2597 try {
2598 if (DEBUG_VISIBILITY) Slog.v(TAG,
2599 "Setting visibility of " + this + ": " + (!clientHidden));
2600 mClient.dispatchAppVisibility(!clientHidden);
2601 } catch (RemoteException e) {
2602 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002603 }
2604
Chong Zhang92147042016-05-09 12:47:11 -07002605 public void setVisibleBeforeClientHidden() {
2606 mWasVisibleBeforeClientHidden |=
2607 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002608
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002609 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002610 }
2611
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002612 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002613 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002614 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002615 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002616 c.clearWasVisibleBeforeClientHidden();
2617 }
Chong Zhang92147042016-05-09 12:47:11 -07002618 }
2619
2620 public boolean wasVisibleBeforeClientHidden() {
2621 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002622 }
2623
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002624 void onStartFreezingScreen() {
2625 mAppFreezing = true;
2626 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002627 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002628 c.onStartFreezingScreen();
2629 }
2630 }
2631
2632 boolean onStopFreezingScreen() {
2633 boolean unfrozeWindows = false;
2634 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002635 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002636 unfrozeWindows |= c.onStopFreezingScreen();
2637 }
2638
2639 if (!mAppFreezing) {
2640 return unfrozeWindows;
2641 }
2642
Wale Ogunwale953171d2016-09-30 09:17:30 -07002643 mAppFreezing = false;
2644
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002645 if (mHasSurface && !mOrientationChanging
2646 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2647 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
2648 mOrientationChanging = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002649 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002650 }
2651 mLastFreezeDuration = 0;
2652 setDisplayLayoutNeeded();
2653 return true;
2654 }
2655
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002656 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002657 if (mWinAnimator.mSurfaceController == null) {
2658 // Don't bother if the surface controller is gone for any reason.
2659 return false;
2660 }
2661
Chong Zhang92147042016-05-09 12:47:11 -07002662 if (!mWasVisibleBeforeClientHidden) {
2663 return false;
2664 }
2665
Wale Ogunwale945d1972016-03-23 13:16:41 -07002666 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2667 // We don't save secure surfaces since their content shouldn't be shown while the app
2668 // isn't on screen and content might leak through during the transition animation with
2669 // saved surface.
2670 return false;
2671 }
2672
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002673 if (ActivityManager.isLowRamDeviceStatic()) {
2674 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002675 return false;
2676 }
2677
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002678 Task task = getTask();
2679 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002680 // Don't save surfaces for home stack apps. These usually resume and draw
2681 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002682 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002683 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002684
2685 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2686 if (taskTop != null && taskTop != mAppToken) {
2687 // Don't save if the window is not the topmost window.
2688 return false;
2689 }
2690
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002691 if (mResizedWhileGone) {
2692 // Somebody resized our window while we were gone for layout, which means that the
2693 // client got an old size, so we have an outdated surface here.
2694 return false;
2695 }
2696
Robert Carr7098dbd2016-02-01 12:31:01 -08002697 if (DEBUG_DISABLE_SAVING_SURFACES) {
2698 return false;
2699 }
2700
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002701 return mAppToken.shouldSaveSurface();
2702 }
2703
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002704 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2705 boolean destroyedSomething = false;
2706 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002707 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002708 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2709 }
2710
2711 if (appStopped || mWindowRemovalAllowed || cleanupOnResume) {
2712
2713 mWinAnimator.destroyPreservedSurfaceLocked();
2714
2715 if (mDestroying) {
2716 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2717 + " destroySurfaces: appStopped=" + appStopped
2718 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2719 + " win.mRemoveOnExit=" + mRemoveOnExit);
2720
2721 if (!cleanupOnResume || mRemoveOnExit) {
2722 destroyOrSaveSurface();
2723 }
2724 if (mRemoveOnExit) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002725 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002726 }
2727 if (cleanupOnResume) {
2728 requestUpdateWallpaperIfNeeded();
2729 }
2730 mDestroying = false;
2731 destroyedSomething = true;
2732 }
2733 }
2734 return destroyedSomething;
2735 }
Chris Craik3131bde2016-05-06 13:39:08 -07002736
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002737 void destroyOrSaveSurface() {
2738 mSurfaceSaved = shouldSaveSurface();
2739 if (mSurfaceSaved) {
2740 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2741 Slog.v(TAG, "Saving surface: " + this);
2742 }
Chris Craik3131bde2016-05-06 13:39:08 -07002743 // Previous user of the surface may have set a transparent region signaling a portion
2744 // doesn't need to be composited, so reset to default empty state.
2745 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002746
2747 mWinAnimator.hide("saved surface");
2748 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2749 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002750 // The client should have disconnected at this point, but if it doesn't,
2751 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2752 // the client can't reconnect to the buffer queue, and rendering will fail.
2753 if (mWinAnimator.mSurfaceController != null) {
2754 mWinAnimator.mSurfaceController.disconnectInTransaction();
2755 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002756 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002757 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002758 mWinAnimator.destroySurfaceLocked();
2759 }
Chong Zhang92147042016-05-09 12:47:11 -07002760 // Clear animating flags now, since the surface is now gone. (Note this is true even
2761 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2762 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002763 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002764
Chong Zhang92147042016-05-09 12:47:11 -07002765 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002766 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002767 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002768 c.destroySavedSurface();
2769 }
2770
Robert Carr13f7be9e2015-12-02 18:39:45 -08002771 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002772 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002773 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002774 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002775 }
Chong Zhang92147042016-05-09 12:47:11 -07002776 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002777 }
2778
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002779 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2780 int restoreSavedSurfaceForInterestingWindow() {
2781 int interestingNotDrawn = -1;
2782 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002783 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002784 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2785 if (childInterestingNotDrawn != -1) {
2786 if (interestingNotDrawn == -1) {
2787 interestingNotDrawn = childInterestingNotDrawn;
2788 } else {
2789 interestingNotDrawn += childInterestingNotDrawn;
2790 }
2791 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002792 }
Robert Carr237028a2016-07-26 10:39:45 -07002793
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002794 if (mAttrs.type == TYPE_APPLICATION_STARTING
2795 || mAppDied || !wasVisibleBeforeClientHidden()
2796 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2797 // Window isn't interesting...
2798 return interestingNotDrawn;
2799 }
2800
2801 restoreSavedSurface();
2802
2803 if (!isDrawnLw()) {
2804 if (interestingNotDrawn == -1) {
2805 interestingNotDrawn = 1;
2806 } else {
2807 interestingNotDrawn++;
2808 }
2809 }
2810 return interestingNotDrawn;
2811 }
2812
2813 /** Returns true if the saved surface was restored. */
2814 boolean restoreSavedSurface() {
2815 if (!mSurfaceSaved) {
2816 return false;
2817 }
2818
2819 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2820 // However this means the surface was never laid out in the new orientation.
2821 // We can only restore to the last rotation we were laid out as visible in.
Robert Carr237028a2016-07-26 10:39:45 -07002822 if (mLastVisibleLayoutRotation != mService.mRotation) {
2823 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002824 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002825 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002826 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002827
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002828 if (mWinAnimator.mSurfaceController != null) {
2829 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002830 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002831 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002832
Chong Zhang6e9872b2016-08-17 10:19:05 -07002833 requestUpdateWallpaperIfNeeded();
2834
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002835 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2836 Slog.v(TAG, "Restoring saved surface: " + this);
2837 }
2838 } else {
2839 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2840 // this point. Even if we destroyed the saved surface because of rotation
2841 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2842 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002843 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002844
2845 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002846 }
2847
Chong Zhang92147042016-05-09 12:47:11 -07002848 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002849 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2850 return true;
2851 }
2852
2853 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002854 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002855 if (c.canRestoreSurface()) {
2856 return true;
2857 }
2858 }
2859
2860 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002861 }
2862
2863 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002864 return mSurfaceSaved;
2865 }
2866
Chong Zhang92147042016-05-09 12:47:11 -07002867 void clearHasSavedSurface() {
2868 mSurfaceSaved = false;
2869 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002870 if (mWasVisibleBeforeClientHidden) {
2871 mAppToken.destroySavedSurfaces();
2872 }
Chong Zhang92147042016-05-09 12:47:11 -07002873 }
2874
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002875 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002876 if (mAnimatingWithSavedSurface) {
2877 // App has drawn something to its windows, we're no longer animating with
2878 // the saved surfaces.
2879 if (DEBUG_ANIM) Slog.d(TAG,
2880 "clearAnimatingWithSavedSurface(): win=" + this);
2881 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002882 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002883 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002884 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002885 }
2886
Craig Mautner69b08182012-09-05 13:07:13 -07002887 @Override
2888 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002889 final DisplayContent displayContent = getDisplayContent();
2890 if (displayContent == null) {
2891 // Only a window that was on a non-default display can be detached from it.
2892 return false;
2893 }
Winson Chung47a3e652014-05-21 16:03:42 -07002894 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002895 }
2896
Adrian Rooscd3884d2015-02-18 17:25:23 +01002897 @Override
2898 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002899 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002900 final DisplayContent dc = getDisplayContent();
2901 return dimLayerUser != null && dc != null
2902 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002903 }
2904
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002905 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002906 mShowToOwnerOnly = showToOwnerOnly;
2907 }
2908
Craig Mautner5962b122012-10-05 14:45:52 -07002909 boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002910 // Child windows are evaluated based on their parent window.
2911 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002912 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07002913 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002914
2915 // All window frames that are fullscreen extend above status bar, but some don't extend
2916 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2917 // bottom right.
2918 if (win.mFrame.left <= win.mDisplayFrame.left
2919 && win.mFrame.top <= win.mDisplayFrame.top
2920 && win.mFrame.right >= win.mStableFrame.right
2921 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002922 // Is a fullscreen window, like the clock alarm. Show to everyone.
2923 return false;
2924 }
2925 }
2926
Craig Mautner341220f2012-10-16 15:20:09 -07002927 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002928 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002929 }
2930
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002931 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2932 outRegion.set(
2933 frame.left + inset.left, frame.top + inset.top,
2934 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002935 }
2936
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002937 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002938 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002939 switch (mTouchableInsets) {
2940 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002941 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002942 outRegion.set(frame);
2943 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002944 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002945 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002946 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002947 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002948 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002949 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002950 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002951 final Region givenTouchableRegion = mGivenTouchableRegion;
2952 outRegion.set(givenTouchableRegion);
2953 outRegion.translate(frame.left, frame.top);
2954 break;
2955 }
2956 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002957 cropRegionToStackBoundsIfNeeded(outRegion);
2958 }
2959
2960 void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002961 final Task task = getTask();
2962 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002963 return;
2964 }
2965
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002966 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002967 if (stack == null) {
2968 return;
2969 }
2970
2971 stack.getDimBounds(mTmpRect);
2972 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002973 }
2974
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002975 // TODO: This is one reason why WindowList are bad...prime candidate for removal once we
2976 // figure-out a good way to replace WindowList with WindowContainer hierarchy.
Craig Mautner59c00972012-07-30 12:10:24 -07002977 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002978 final DisplayContent displayContent = getDisplayContent();
2979 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07002980 }
2981
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002982 /**
2983 * Report a focus change. Must be called with no locks held, and consistently
2984 * from the same serialized thread (such as dispatched from a handler).
2985 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002986 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002987 try {
2988 mClient.windowFocusChanged(focused, inTouchMode);
2989 } catch (RemoteException e) {
2990 }
2991 if (mFocusCallbacks != null) {
2992 final int N = mFocusCallbacks.beginBroadcast();
2993 for (int i=0; i<N; i++) {
2994 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2995 try {
2996 if (focused) {
2997 obs.focusGained(mWindowId.asBinder());
2998 } else {
2999 obs.focusLost(mWindowId.asBinder());
3000 }
3001 } catch (RemoteException e) {
3002 }
3003 }
3004 mFocusCallbacks.finishBroadcast();
3005 }
3006 }
3007
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003008 @Override
3009 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003010 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003011 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003012 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003013
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003014 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003015 }
3016
Craig Mautnerdf88d732014-01-27 09:21:32 -08003017 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003018 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003019 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003020 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3021 + ": " + mCompatFrame);
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003022 final Configuration newConfig;
3023 if (isConfigChanged()) {
3024 newConfig = new Configuration(getConfiguration());
3025 mLastReportedConfiguration.setTo(newConfig);
3026 } else {
3027 newConfig = null;
3028 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003029 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003030 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3031
Craig Mautnerdf88d732014-01-27 09:21:32 -08003032 final Rect frame = mFrame;
3033 final Rect overscanInsets = mLastOverscanInsets;
3034 final Rect contentInsets = mLastContentInsets;
3035 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003036 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003037 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003038 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07003039 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3040 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003041 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3042 mService.mH.post(new Runnable() {
3043 @Override
3044 public void run() {
3045 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003046 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
3047 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003048 } catch (RemoteException e) {
3049 // Not a remote call, RemoteException won't be raised.
3050 }
3051 }
3052 });
3053 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003054 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003055 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003056 }
Svetoslav4604abc2014-06-10 18:59:30 -07003057
3058 //TODO (multidisplay): Accessibility supported only for the default display.
3059 if (mService.mAccessibilityController != null
3060 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003061 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003062 }
3063
Craig Mautnerdf88d732014-01-27 09:21:32 -08003064 mOverscanInsetsChanged = false;
3065 mContentInsetsChanged = false;
3066 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003067 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003068 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003069 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003070 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003071 mWinAnimator.mSurfaceResized = false;
3072 } catch (RemoteException e) {
3073 mOrientationChanging = false;
3074 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3075 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003076 // We are assuming the hosting process is dead or in a zombie state.
3077 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3078 + ", removing this window.");
3079 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003080 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003081 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003082 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003083 }
3084
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003085 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003086 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3087 // start even if we haven't received the relayout window, so that the client requests
3088 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3089 // until the window to small size, otherwise the multithread renderer will shift last
3090 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3091 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003092 boolean resizing = isDragResizing() || isDragResizeChanged();
3093 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3094 return frame;
3095 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003096 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003097 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003098 return mTmpRect;
3099 }
3100
Jorim Jaggi86905582016-02-09 21:36:09 -08003101 @Override
3102 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003103 final TaskStack stack = getStack();
3104 if (stack == null) {
3105 return INVALID_STACK_ID;
3106 }
3107 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003108 }
3109
3110 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3111 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
3112 Configuration newConfig) throws RemoteException {
Chong Zhangedaf3052016-04-22 15:04:31 -07003113 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing;
3114
Jorim Jaggidc249c42015-12-15 14:57:31 -08003115 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08003116 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07003117 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003118 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003119 }
3120
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003121 public void registerFocusObserver(IWindowFocusObserver observer) {
3122 synchronized(mService.mWindowMap) {
3123 if (mFocusCallbacks == null) {
3124 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3125 }
3126 mFocusCallbacks.register(observer);
3127 }
3128 }
3129
3130 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3131 synchronized(mService.mWindowMap) {
3132 if (mFocusCallbacks != null) {
3133 mFocusCallbacks.unregister(observer);
3134 }
3135 }
3136 }
3137
3138 public boolean isFocused() {
3139 synchronized(mService.mWindowMap) {
3140 return mService.mCurrentFocus == this;
3141 }
3142 }
3143
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003144 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003145 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003146 return task != null && task.inFreeformWorkspace();
3147 }
3148
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003149 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003150 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003151 final Task task = getTask();
3152 return task != null && !task.isFullscreen();
3153 }
3154
Chong Zhang3005e752015-09-18 18:46:28 -07003155 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003156 return mDragResizing != computeDragResizing();
3157 }
3158
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003159 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003160 void setWaitingForDrawnIfResizingChanged() {
3161 if (isDragResizeChanged()) {
3162 mService.mWaitingForDrawn.add(this);
3163 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003164 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003165 }
3166
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003167 /**
3168 * @return Whether we reported a drag resize change to the application or not already.
3169 */
3170 boolean isDragResizingChangeReported() {
3171 return mDragResizingChangeReported;
3172 }
3173
3174 /**
3175 * Resets the state whether we reported a drag resize change to the app.
3176 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003177 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003178 void resetDragResizingChangeReported() {
3179 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003180 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003181 }
3182
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003183 /**
3184 * Set whether we got resized but drag resizing flag was false.
3185 * @see #isResizedWhileNotDragResizing().
3186 */
3187 void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
3188 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3189 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3190 }
3191
3192 /**
3193 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3194 * need to recreate the surface and defer surface bound updates in order to make sure the
3195 * buffer contents and the positioning/size stay in sync.
3196 */
3197 boolean isResizedWhileNotDragResizing() {
3198 return mResizedWhileNotDragResizing;
3199 }
3200
3201 /**
3202 * @return Whether we reported "resize while not drag resizing" to the application.
3203 * @see #isResizedWhileNotDragResizing()
3204 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003205 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003206 return mResizedWhileNotDragResizingReported;
3207 }
3208
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003209 int getResizeMode() {
3210 return mResizeMode;
3211 }
3212
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003213 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003214 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003215 if (task == null) {
3216 return false;
3217 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003218 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
3219
3220 // Floating windows never enter drag resize mode.
3221 return false;
3222 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003223 if (task.isDragResizing()) {
3224 return true;
3225 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003226
3227 // If the bounds are currently frozen, it means that the layout size that the app sees
3228 // and the bounds we clip this window to might be different. In order to avoid holes, we
3229 // simulate that we are still resizing so the app fills the hole with the resizing
3230 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003231 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003232 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003233 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003234
Chong Zhang3005e752015-09-18 18:46:28 -07003235 }
3236
3237 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003238 final boolean resizing = computeDragResizing();
3239 if (resizing == mDragResizing) {
3240 return;
3241 }
3242 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003243 final Task task = getTask();
3244 if (task != null && task.isDragResizing()) {
3245 mResizeMode = task.getDragResizeMode();
3246 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003247 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003248 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3249 : DRAG_RESIZE_MODE_FREEFORM;
3250 }
Chong Zhang3005e752015-09-18 18:46:28 -07003251 }
3252
3253 boolean isDragResizing() {
3254 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003255 }
3256
Robert Carr2487ce72016-04-07 15:18:45 -07003257 boolean isDockedResizing() {
3258 return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
3259 }
3260
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003261 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003262 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003263 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003264 if (stack != null) {
3265 pw.print(" stackId="); pw.print(stack.mStackId);
3266 }
Craig Mautner59c00972012-07-30 12:10:24 -07003267 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003268 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003269 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003270 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3271 pw.print(" package="); pw.print(mAttrs.packageName);
3272 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003273 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003274 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3275 pw.print(" h="); pw.print(mRequestedHeight);
3276 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003277 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3278 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3279 pw.print(" h="); pw.println(mLastRequestedHeight);
3280 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003281 if (mIsChildWindow || mLayoutAttached) {
3282 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003283 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3284 }
3285 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3286 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3287 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3288 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3289 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3290 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003291 if (dumpAll) {
3292 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3293 pw.print(" mSubLayer="); pw.print(mSubLayer);
3294 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003295 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003296 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3297 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003298 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003299 if (dumpAll) {
3300 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003301 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003302 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3303 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003304 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08003305 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003306 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003307 pw.print(prefix); pw.print("mViewVisibility=0x");
3308 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003309 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3310 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003311 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3312 pw.print(" mSystemUiVisibility=0x");
3313 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003314 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003315 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Svetoslav Ganov71c51022016-09-02 17:54:37 -07003316 || isParentWindowHidden()|| mPermanentlyHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003317 pw.print(prefix); pw.print("mPolicyVisibility=");
3318 pw.print(mPolicyVisibility);
3319 pw.print(" mPolicyVisibilityAfterAnim=");
3320 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003321 pw.print(" mAppOpVisibility=");
3322 pw.print(mAppOpVisibility);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003323 pw.print(" parentHidden="); pw.println(isParentWindowHidden());
Svetoslav Ganovaa076532016-08-01 19:16:43 -07003324 pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003325 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003326 if (!mRelayoutCalled || mLayoutNeeded) {
3327 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3328 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003329 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003330 if (mXOffset != 0 || mYOffset != 0) {
3331 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3332 pw.print(" y="); pw.println(mYOffset);
3333 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003334 if (dumpAll) {
3335 pw.print(prefix); pw.print("mGivenContentInsets=");
3336 mGivenContentInsets.printShortString(pw);
3337 pw.print(" mGivenVisibleInsets=");
3338 mGivenVisibleInsets.printShortString(pw);
3339 pw.println();
3340 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3341 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3342 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003343 Region region = new Region();
3344 getTouchableRegion(region);
3345 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003346 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003347 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3348 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3349 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003350 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003351 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003352 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003353 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003354 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3355 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003356 if (dumpAll) {
3357 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3358 pw.print(" last="); mLastFrame.printShortString(pw);
3359 pw.println();
3360 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003361 if (mEnforceSizeCompat) {
3362 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003363 pw.println();
3364 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003365 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003366 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003367 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003368 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003369 pw.println();
3370 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3371 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003372 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003373 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003374 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003375 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003376 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3377 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003378 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3379 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003380 pw.print(prefix); pw.print("Cur insets: overscan=");
3381 mOverscanInsets.printShortString(pw);
3382 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003383 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003384 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003385 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003386 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003387 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003388 pw.print(prefix); pw.print("Lst insets: overscan=");
3389 mLastOverscanInsets.printShortString(pw);
3390 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003391 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003392 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003393 pw.print(" physical="); mLastOutsets.printShortString(pw);
3394 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003395 pw.println();
3396 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003397 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3398 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003399 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3400 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003401 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3402 pw.print(" mDestroying="); pw.print(mDestroying);
3403 pw.print(" mRemoved="); pw.println(mRemoved);
3404 }
3405 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
3406 pw.print(prefix); pw.print("mOrientationChanging=");
3407 pw.print(mOrientationChanging);
3408 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
3409 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
3410 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003411 if (mLastFreezeDuration != 0) {
3412 pw.print(prefix); pw.print("mLastFreezeDuration=");
3413 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3414 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003415 if (mHScale != 1 || mVScale != 1) {
3416 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3417 pw.print(" mVScale="); pw.println(mVScale);
3418 }
3419 if (mWallpaperX != -1 || mWallpaperY != -1) {
3420 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3421 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3422 }
3423 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3424 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3425 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3426 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003427 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3428 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3429 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3430 pw.print(mWallpaperDisplayOffsetX);
3431 pw.print(" mWallpaperDisplayOffsetY=");
3432 pw.println(mWallpaperDisplayOffsetY);
3433 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003434 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003435 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003436 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003437 if (isDragResizing()) {
3438 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3439 }
3440 if (computeDragResizing()) {
3441 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3442 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003443 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003444
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003445 @Override
3446 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003447 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003448 + " " + getWindowTag();
3449 }
3450
Robert Carra1eb4392015-12-10 12:43:51 -08003451 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003452 CharSequence tag = mAttrs.getTitle();
3453 if (tag == null || tag.length() <= 0) {
3454 tag = mAttrs.packageName;
3455 }
3456 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003457 }
3458
3459 @Override
3460 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003461 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003462 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003463 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003464 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003465 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003466 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003467 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003468 }
3469 return mStringNameCache;
3470 }
Robert Carr58f29132015-10-29 14:19:05 -07003471
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003472 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003473 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003474 clipRect.left = (int) (clipRect.left / mHScale);
3475 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003476 }
3477 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003478 clipRect.top = (int) (clipRect.top / mVScale);
3479 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003480 }
3481 }
Robert Carr31e28482015-12-02 16:53:18 -08003482
Jorim Jaggif5834272016-04-04 20:25:41 -07003483 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3484 final int pw = containingFrame.width();
3485 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003486 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07003487 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003488 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3489
3490 // We need to fit it to the display if either
3491 // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless
3492 // windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003493 // b) If it's a secondary app window, we also need to fit it to the display unless
3494 // 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 -07003495 // but SurfaceViews want to be always at a specific location so we don't fit it to the
3496 // display.
3497 final boolean fitToDisplay = (task == null || !nonFullscreenTask)
Robert Carr6f44db12016-07-21 14:54:43 -07003498 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003499 float x, y;
3500 int w,h;
3501
3502 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3503 if (mAttrs.width < 0) {
3504 w = pw;
3505 } else if (mEnforceSizeCompat) {
3506 w = (int)(mAttrs.width * mGlobalScale + .5f);
3507 } else {
3508 w = mAttrs.width;
3509 }
3510 if (mAttrs.height < 0) {
3511 h = ph;
3512 } else if (mEnforceSizeCompat) {
3513 h = (int)(mAttrs.height * mGlobalScale + .5f);
3514 } else {
3515 h = mAttrs.height;
3516 }
3517 } else {
3518 if (mAttrs.width == MATCH_PARENT) {
3519 w = pw;
3520 } else if (mEnforceSizeCompat) {
3521 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3522 } else {
3523 w = mRequestedWidth;
3524 }
3525 if (mAttrs.height == MATCH_PARENT) {
3526 h = ph;
3527 } else if (mEnforceSizeCompat) {
3528 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3529 } else {
3530 h = mRequestedHeight;
3531 }
3532 }
3533
3534 if (mEnforceSizeCompat) {
3535 x = mAttrs.x * mGlobalScale;
3536 y = mAttrs.y * mGlobalScale;
3537 } else {
3538 x = mAttrs.x;
3539 y = mAttrs.y;
3540 }
3541
Robert Carr1d2bacb2016-03-30 14:29:35 -07003542 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003543 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003544 // required by {@link Gravity#apply} call.
3545 w = Math.min(w, pw);
3546 h = Math.min(h, ph);
3547 }
3548
3549 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003550 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003551 (int) (x + mAttrs.horizontalMargin * pw),
3552 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3553
3554 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003555 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003556 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003557 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003558
3559 // We need to make sure we update the CompatFrame as it is used for
3560 // cropping decisions, etc, on systems where we lack a decor layer.
3561 mCompatFrame.set(mFrame);
3562 if (mEnforceSizeCompat) {
3563 // See comparable block in computeFrameLw.
3564 mCompatFrame.scale(mInvGlobalScale);
3565 }
Robert Carr31e28482015-12-02 16:53:18 -08003566 }
Robert Carr51a1b872015-12-08 14:03:13 -08003567
3568 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003569 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003570 }
3571
3572 /**
3573 * Returns the bottom child window in regards to z-order of this window or null if no children.
3574 */
3575 WindowState getBottomChild() {
3576 // Child windows are z-ordered based on sub-layer using {@link #sWindowSubLayerComparator}
3577 // and the child with the lowest z-order will be at the head of the list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003578 WindowState c = mChildren.peekFirst();
3579 return c == null ? null : c;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003580 }
3581
Robert Carrf3b72c72016-03-21 18:16:39 -07003582 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003583 return mIsChildWindow
3584 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003585 }
3586
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003587 /** Returns the parent window if this is a child of another window, else null. */
3588 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003589 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3590 // WindowContainer that isn't a WindowState.
3591 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003592 }
3593
3594 /** Returns the topmost parent window if this is a child of another window, else this. */
3595 WindowState getTopParentWindow() {
3596 WindowState w = this;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07003597 while (w != null && w.mIsChildWindow) {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003598 w = w.getParentWindow();
3599 }
3600 return w;
3601 }
3602
Wale Ogunwale9d147902016-07-16 11:58:55 -07003603 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003604 final WindowState parent = getParentWindow();
3605 return (parent == null) ? false : parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003606 }
3607
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003608 void setWillReplaceWindow(boolean animate) {
3609 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003610 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003611 c.setWillReplaceWindow(animate);
3612 }
3613
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003614 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3615 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3616 // We don't set replacing on starting windows since they are added by window manager and
3617 // not the client so won't be replaced by the client.
3618 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003619 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003620
3621 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003622 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003623 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003624 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003625
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003626 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003627 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003628 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003629 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003630
3631 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003632 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003633 c.clearWillReplaceWindow();
3634 }
3635 }
3636
3637 boolean waitingForReplacement() {
3638 if (mWillReplaceWindow) {
3639 return true;
3640 }
3641
3642 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003643 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003644 if (c.waitingForReplacement()) {
3645 return true;
3646 }
3647 }
3648 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003649 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003650
Chong Zhang4d7369a2016-04-25 16:09:14 -07003651 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003652 final DisplayContent dc = getDisplayContent();
3653 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3654 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3655 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003656 mService.mWindowPlacerLocked.requestTraversal();
3657 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003658
3659 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003660 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003661 c.requestUpdateWallpaperIfNeeded();
3662 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003663 }
3664
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003665 float translateToWindowX(float x) {
3666 float winX = x - mFrame.left;
3667 if (mEnforceSizeCompat) {
3668 winX *= mGlobalScale;
3669 }
3670 return winX;
3671 }
3672
3673 float translateToWindowY(float y) {
3674 float winY = y - mFrame.top;
3675 if (mEnforceSizeCompat) {
3676 winY *= mGlobalScale;
3677 }
3678 return winY;
3679 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003680
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003681 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003682 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003683 final DisplayContent dc = getDisplayContent();
3684 if (dimLayerUser != null && dc != null) {
3685 dc.mDimLayerController.applyDim(dimLayerUser,
3686 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003687 }
3688 }
3689
Robert Carrd1a010f2016-04-07 22:36:22 -07003690 // During activity relaunch due to resize, we sometimes use window replacement
3691 // for only child windows (as the main window is handled by window preservation)
3692 // and the big surface.
3693 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003694 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3695 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3696 // we also want to replace them at such phases, as they won't be covered by window
3697 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003698 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003699 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003700 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003701 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003702
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003703 void setWillReplaceChildWindows() {
3704 if (shouldBeReplacedWithChildren()) {
3705 setWillReplaceWindow(false /* animate */);
3706 }
3707 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003708 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003709 c.setWillReplaceChildWindows();
3710 }
3711 }
3712
3713 WindowState getReplacingWindow() {
3714 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3715 return this;
3716 }
3717 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003718 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003719 final WindowState replacing = c.getReplacingWindow();
3720 if (replacing != null) {
3721 return replacing;
3722 }
3723 }
3724 return null;
3725 }
3726
Robert Carrfd10cd12016-06-29 16:41:50 -07003727 public int getRotationAnimationHint() {
3728 if (mAppToken != null) {
3729 return mAppToken.mRotationAnimationHint;
3730 } else {
3731 return -1;
3732 }
3733 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003734
3735 // This must be called while inside a transaction.
3736 boolean performShowLocked() {
3737 if (isHiddenFromUserLocked()) {
3738 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3739 hideLw(false);
3740 return false;
3741 }
3742
3743 logPerformShow("performShow on ");
3744
3745 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplayIgnoringKeyguard()) {
3746 return false;
3747 }
3748
3749 logPerformShow("Showing ");
3750
3751 mService.enableScreenIfNeededLocked();
3752 mWinAnimator.applyEnterAnimationLocked();
3753
3754 // Force the show in the next prepareSurfaceLocked() call.
3755 mWinAnimator.mLastAlpha = -1;
3756 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3757 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3758 mWinAnimator.mDrawState = HAS_DRAWN;
3759 mService.scheduleAnimationLocked();
3760
3761 if (mHidden) {
3762 mHidden = false;
3763 final DisplayContent displayContent = getDisplayContent();
3764
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003765 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003766 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003767 if (c.mWinAnimator.mSurfaceController != null) {
3768 c.performShowLocked();
3769 // It hadn't been shown, which means layout not performed on it, so now we
3770 // want to make sure to do a layout. If called from within the transaction
3771 // loop, this will cause it to restart with a new layout.
3772 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003773 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003774 }
3775 }
3776 }
3777 }
3778
3779 if (mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3780 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3781 }
3782
3783 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003784 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003785 }
3786
3787 return true;
3788 }
3789
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003790 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003791 if (DEBUG_VISIBILITY
3792 || (DEBUG_STARTING_WINDOW && mAttrs.type == TYPE_APPLICATION_STARTING)) {
3793 Slog.v(TAG, prefix + this
3794 + ": mDrawState=" + mWinAnimator.drawStateToString()
3795 + " readyForDisplay=" + isReadyForDisplayIgnoringKeyguard()
3796 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3797 + " during animation: policyVis=" + mPolicyVisibility
3798 + " parentHidden=" + isParentWindowHidden()
3799 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003800 + (mAppToken != null && mAppToken.hiddenRequested)
3801 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003802 + " animating=" + mWinAnimator.mAnimating
3803 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003804 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003805 + " Callers=" + Debug.getCallers(4));
3806 }
3807 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003808
3809 WindowInfo getWindowInfo() {
3810 WindowInfo windowInfo = WindowInfo.obtain();
3811 windowInfo.type = mAttrs.type;
3812 windowInfo.layer = mLayer;
3813 windowInfo.token = mClient.asBinder();
3814 windowInfo.title = mAttrs.accessibilityTitle;
3815 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3816 windowInfo.focused = isFocused();
3817
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003818 if (mIsChildWindow) {
3819 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003820 }
3821
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003822 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003823 if (childCount > 0) {
3824 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003825 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003826 }
3827 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003828 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003829 windowInfo.childTokens.add(child.mClient.asBinder());
3830 }
3831 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003832 return windowInfo;
3833 }
3834
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003835 int getHighestAnimLayer() {
3836 int highest = mWinAnimator.mAnimLayer;
3837 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003838 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003839 final int childLayer = c.getHighestAnimLayer();
3840 if (childLayer > highest) {
3841 highest = childLayer;
3842 }
3843 }
3844 return highest;
3845 }
3846
3847 int adjustAnimLayer(int adj) {
3848 int highestAnimLayer = mWinAnimator.mAnimLayer = mLayer + adj;
3849 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG_WM,
3850 "adjustAnimLayer win=" + this + " anim layer: " + mWinAnimator.mAnimLayer);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003851 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003852 final WindowState childWindow = mChildren.get(i);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003853 childWindow.adjustAnimLayer(adj);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003854 if (childWindow.mWinAnimator.mAnimLayer > highestAnimLayer) {
3855 highestAnimLayer = childWindow.mWinAnimator.mAnimLayer;
3856 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003857 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003858 return highestAnimLayer;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003859 }
3860
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003861 @Override
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003862 int rebuildWindowList(int addIndex) {
3863 return reAddWindow(addIndex);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003864 }
3865
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003866 // TODO: come-up with a better name for this method that represents what it does.
3867 // Or, it is probably not going to matter anyways if we are successful in getting rid of
3868 // the WindowList concept.
Wale Ogunwale92fc3722016-08-05 12:19:08 -07003869 int reAddWindow(int index) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003870 final WindowList windows = getWindowList();
3871 // Adding child windows relies on child windows being ordered by mSubLayer using
3872 // {@link #sWindowSubLayerComparator}.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003873 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003874 boolean winAdded = false;
3875 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003876 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003877 if (!winAdded && child.mSubLayer >= 0) {
3878 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3879 "Re-adding child window at " + index + ": " + child);
3880 mRebuilding = false;
3881 windows.add(index, this);
3882 index++;
3883 winAdded = true;
3884 }
3885 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + child);
3886 child.mRebuilding = false;
3887 windows.add(index, child);
3888 index++;
3889 }
3890 if (!winAdded) {
3891 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + this);
3892 mRebuilding = false;
3893 windows.add(index, this);
3894 index++;
3895 }
3896 mService.mWindowsChanged = true;
3897 return index;
3898 }
3899
3900 int removeFromWindowList(int interestingPos) {
3901 final WindowList windows = getWindowList();
3902 int wpos = windows.indexOf(this);
3903 if (wpos < 0) {
3904 return interestingPos;
3905 }
3906
3907 if (wpos < interestingPos) interestingPos--;
3908 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this);
3909 windows.remove(wpos);
3910 mService.mWindowsChanged = true;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003911 int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003912 while (childCount > 0) {
3913 childCount--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003914 final WindowState cw = mChildren.get(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003915 int cpos = windows.indexOf(cw);
3916 if (cpos >= 0) {
3917 if (cpos < interestingPos) interestingPos--;
3918 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3919 "Temp removing child at " + cpos + ": " + cw);
3920 windows.remove(cpos);
3921 }
3922 }
3923 return interestingPos;
3924 }
3925
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003926 boolean isWindowAnimationSet() {
3927 if (mWinAnimator.isWindowAnimationSet()) {
3928 return true;
3929 }
3930 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003931 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003932 if (c.isWindowAnimationSet()) {
3933 return true;
3934 }
3935 }
3936 return false;
3937 }
3938
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003939 void onExitAnimationDone() {
3940 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3941 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
3942 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
3943
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003944 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003945 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003946 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003947 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003948 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003949 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003950 }
3951 }
3952
3953 if (mWinAnimator.mEnteringAnimation) {
3954 mWinAnimator.mEnteringAnimation = false;
3955 mService.requestTraversal();
3956 // System windows don't have an activity and an app token as a result, but need a way
3957 // to be informed about their entrance animation end.
3958 if (mAppToken == null) {
3959 try {
3960 mClient.dispatchWindowShown();
3961 } catch (RemoteException e) {
3962 }
3963 }
3964 }
3965
3966 if (!mWinAnimator.isWindowAnimationSet()) {
3967 //TODO (multidisplay): Accessibility is supported only for the default display.
3968 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3969 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3970 }
3971 }
3972
3973 if (!mAnimatingExit) {
3974 return;
3975 }
3976
3977 if (mWinAnimator.isWindowAnimationSet()) {
3978 return;
3979 }
3980
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003981 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003982 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3983
3984 mDestroying = true;
3985
3986 final boolean hasSurface = mWinAnimator.hasSurface();
3987 if (hasSurface) {
3988 mWinAnimator.hide("onExitAnimationDone");
3989 }
3990
3991 // If we have an app token, we ask it to destroy the surface for us, so that it can take
3992 // care to ensure the activity has actually stopped and the surface is not still in use.
3993 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
3994 // transaction.
3995 if (mAppToken != null) {
3996 mAppToken.destroySurfaces();
3997 } else {
3998 if (hasSurface) {
3999 mService.mDestroySurface.add(this);
4000 }
4001 if (mRemoveOnExit) {
4002 mService.mPendingRemove.add(this);
4003 mRemoveOnExit = false;
4004 }
4005 }
4006 mAnimatingExit = false;
4007 mService.mWallpaperControllerLocked.hideWallpapers(this);
4008 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004009
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004010 boolean clearAnimatingFlags() {
4011 boolean didSomething = false;
4012 // We don't want to clear it out for windows that get replaced, because the
4013 // animation depends on the flag to remove the replaced window.
4014 //
4015 // We also don't clear the mAnimatingExit flag for windows which have the
4016 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4017 // by the client. We should let animation proceed and not clear this flag or
4018 // they won't eventually be removed by WindowStateAnimator#finishExit.
4019 if (!mWillReplaceWindow && !mRemoveOnExit) {
4020 // Clear mAnimating flag together with mAnimatingExit. When animation
4021 // changes from exiting to entering, we need to clear this flag until the
4022 // new animation gets applied, so that isAnimationStarting() becomes true
4023 // until then.
4024 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4025 // placement for this window during this period, one or more frame will
4026 // show up with wrong position or scale.
4027 if (mAnimatingExit) {
4028 mAnimatingExit = false;
4029 didSomething = true;
4030 }
4031 if (mWinAnimator.mAnimating) {
4032 mWinAnimator.mAnimating = false;
4033 didSomething = true;
4034 }
4035 if (mDestroying) {
4036 mDestroying = false;
4037 mService.mDestroySurface.remove(this);
4038 didSomething = true;
4039 }
4040 }
4041
4042 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004043 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004044 }
4045
4046 return didSomething;
4047 }
4048
Winson4b4ba902016-07-27 19:45:52 -07004049 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004050 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004051 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004052
4053 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004054 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004055 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004056 c.hideWallpaperWindow(wasDeferred, reason);
4057 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004058 if (!mWinAnimator.mLastHidden || wasDeferred) {
4059 mWinAnimator.hide(reason);
4060 dispatchWallpaperVisibility(false);
4061 final DisplayContent displayContent = getDisplayContent();
4062 if (displayContent != null) {
4063 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4064 }
4065 }
4066 }
4067
4068 /**
4069 * Check wallpaper window for visibility change and notify window if so.
4070 * @param visible Current visibility.
4071 */
4072 void dispatchWallpaperVisibility(final boolean visible) {
4073 final boolean hideAllowed =
4074 mService.mWallpaperControllerLocked.mDeferredHideWallpaper == null;
4075
4076 // Only send notification if the visibility actually changed and we are not trying to hide
4077 // the wallpaper when we are deferring hiding of the wallpaper.
4078 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4079 mWallpaperVisible = visible;
4080 try {
4081 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4082 "Updating vis of wallpaper " + this
4083 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4084 mClient.dispatchAppVisibility(visible);
4085 } catch (RemoteException e) {
4086 }
4087 }
4088 }
4089
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004090 boolean hasVisibleNotDrawnWallpaper() {
4091 if (mWallpaperVisible && !isDrawnLw()) {
4092 return true;
4093 }
4094 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004095 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004096 if (c.hasVisibleNotDrawnWallpaper()) {
4097 return true;
4098 }
4099 }
4100 return false;
4101 }
4102
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004103 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4104 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004105 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004106 c.updateReportedVisibility(results);
4107 }
4108
4109 if (mAppFreezing || mViewVisibility != View.VISIBLE
4110 || mAttrs.type == TYPE_APPLICATION_STARTING
4111 || mDestroying) {
4112 return;
4113 }
4114 if (DEBUG_VISIBILITY) {
4115 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4116 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4117 if (!isDrawnLw()) {
4118 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4119 + " pv=" + mPolicyVisibility
4120 + " mDrawState=" + mWinAnimator.mDrawState
4121 + " ph=" + isParentWindowHidden()
4122 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4123 + " a=" + mWinAnimator.mAnimating);
4124 }
4125 }
4126
4127 results.numInteresting++;
4128 if (isDrawnLw()) {
4129 results.numDrawn++;
4130 if (!mWinAnimator.isAnimationSet()) {
4131 results.numVisible++;
4132 }
4133 results.nowGone = false;
4134 } else if (mWinAnimator.isAnimationSet()) {
4135 results.nowGone = false;
4136 }
4137 }
4138
4139 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4140 // access to its windows children. Need to investigate re-writing
4141 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4142 static final class UpdateReportedVisibilityResults {
4143 int numInteresting;
4144 int numVisible;
4145 int numDrawn;
4146 boolean nowGone = true;
4147
4148 void reset() {
4149 numInteresting = 0;
4150 numVisible = 0;
4151 numDrawn = 0;
4152 nowGone = true;
4153 }
4154 }
satokcef37fb2011-10-24 21:49:38 +09004155}