blob: 1fe6d5e163839dbffdb39957ee56040f1ee7351b [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;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080089import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070090import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
Robert Carra1eb4392015-12-10 12:43:51 -080091import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080092import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
93import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Robert Carrd1a010f2016-04-07 22:36:22 -070094import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080095import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080096import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Chong Zhangfea963e2016-08-15 17:14:16 -070097import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070098import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080099import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
100import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
101import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Chong Zhang4d7369a2016-04-25 16:09:14 -0700102import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700103import static android.view.WindowManagerPolicy.TRANSIT_ENTER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700104import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
105import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100106import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
107import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800108import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
109import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
110import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
111import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700112import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800113import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700114import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800115import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
116import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
117import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
118import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700119import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
120import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800121import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700122import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700123import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700124import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800125import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
126import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700127import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700128import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
129import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700130import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
131import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700132import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700133import static com.android.server.wm.WindowManagerService.localLOGV;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700134import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700135import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700136import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
137import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138
Craig Mautner59c00972012-07-30 12:10:24 -0700139class WindowList extends ArrayList<WindowState> {
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800140 WindowList() {}
141 WindowList(WindowList windowList) {
142 super(windowList);
143 }
Craig Mautner59c00972012-07-30 12:10:24 -0700144}
145
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700146/** A window in the window manager. */
147class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800148 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800149
Skuhne81c524a2015-08-12 13:34:14 -0700150 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700151 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
152 // use hard-coded min sizes for now.
153 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
154 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700155
156 // The thickness of a window resize handle outside the window bounds on the free form workspace
157 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700158 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700159
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700160 private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
Robert Carr7098dbd2016-02-01 12:31:01 -0800161
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700163 final WindowManagerPolicy mPolicy;
164 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 final Session mSession;
166 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800167 final int mAppOp;
168 // UserId and appId of the owner. Don't display windows of non-current user.
169 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800170 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800171 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700172 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700174
175 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
176 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800177 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
178 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700179 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 final int mBaseLayer;
181 final int mSubLayer;
182 final boolean mLayoutAttached;
183 final boolean mIsImWindow;
184 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700185 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700186 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700187 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800188 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700189 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700190 /**
191 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
192 * Normally set by calling {@link #showLw} and {@link #hideLw}.
193 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800194 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700195 /**
196 * What {@link #mPolicyVisibility} should be set to after a transition animation.
197 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
198 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
199 * animation is done.
200 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700202 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700203 boolean mPermanentlyHidden; // the window should never be shown again
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700205 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700207 private boolean mDragResizing;
208 private boolean mDragResizingChangeReported;
209 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700210
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700211 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800212
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700213 /**
214 * The window size that was requested by the application. These are in
215 * the application's coordinate space (without compatibility scale applied).
216 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800217 int mRequestedWidth;
218 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700219 private int mLastRequestedWidth;
220 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700221
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 boolean mHaveFrame;
224 boolean mObscured;
225 boolean mTurnOnScreen;
226
227 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700228
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700229 /**
230 * Used to store last reported to client configuration and check if we have newer available.
231 * We'll send configuration to client only if it is different from the last applied one and
232 * client won't perform unnecessary updates.
233 */
234 private final Configuration mLastReportedConfiguration = new Configuration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700235
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700236 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700237 * Actual position of the surface shown on-screen (may be modified by animation). These are
238 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700239 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700240 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241
242 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700243 * Insets that determine the actually visible area. These are in the application's
244 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 */
246 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700247 private final Rect mLastVisibleInsets = new Rect();
248 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249
250 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700251 * Insets that are covered by system windows (such as the status bar) and
252 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700253 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254 */
255 final Rect mContentInsets = new Rect();
256 final Rect mLastContentInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700257 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800258
259 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800260 * Insets that determine the area covered by the display overscan region. These are in the
261 * application's coordinate space (without compatibility scale applied).
262 */
263 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700264 private final Rect mLastOverscanInsets = new Rect();
265 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800266
267 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700268 * Insets that determine the area covered by the stable system windows. These are in the
269 * application's coordinate space (without compatibility scale applied).
270 */
271 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700272 private final Rect mLastStableInsets = new Rect();
273 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700274
275 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700276 * Outsets determine the area outside of the surface where we want to pretend that it's possible
277 * to draw anyway.
278 */
279 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700280 private final Rect mLastOutsets = new Rect();
281 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700282
283 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 * Set to true if we are waiting for this window to receive its
285 * given internal insets before laying out other windows based on it.
286 */
287 boolean mGivenInsetsPending;
288
289 /**
290 * These are the content insets that were given during layout for
291 * this window, to be applied to windows behind it.
292 */
293 final Rect mGivenContentInsets = new Rect();
294
295 /**
296 * These are the visible insets that were given during layout for
297 * this window, to be applied to windows behind it.
298 */
299 final Rect mGivenVisibleInsets = new Rect();
300
301 /**
302 * This is the given touchable area relative to the window frame, or null if none.
303 */
304 final Region mGivenTouchableRegion = new Region();
305
306 /**
307 * Flag indicating whether the touchable region should be adjusted by
308 * the visible insets; if false the area outside the visible insets is
309 * NOT touchable, so we must use those to adjust the frame during hit
310 * tests.
311 */
312 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
313
314 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400315 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700316 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800317 float mHScale=1, mVScale=1;
318 float mLastHScale=1, mLastVScale=1;
319 final Matrix mTmpMatrix = new Matrix();
320
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700321 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322 final Rect mFrame = new Rect();
323 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700324 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700325 // Frame that is scaled to the application's coordinate space when in
326 // screen size compatibility mode.
327 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800328
329 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700330
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700331 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700332
Wale Ogunwale94596652015-02-06 19:27:34 -0800333 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
334 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700335 final Rect mDisplayFrame = new Rect();
336
337 // The region of the display frame that the display type supports displaying content on. This
338 // is mostly a special case for TV where some displays don’t have the entire display usable.
339 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
340 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700341 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700342
343 // The display frame minus the stable insets. This value is always constant regardless of if
344 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700345 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800346
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700347 // The area not occupied by the status and navigation bars. So, if both status and navigation
348 // bars are visible, the decor frame is equal to the stable frame.
349 final Rect mDecorFrame = new Rect();
350
351 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
352 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700353 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700354
355 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
356 // displays hint text.
357 final Rect mVisibleFrame = new Rect();
358
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700359 // Frame that includes dead area outside of the surface but where we want to pretend that it's
360 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700361 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700362
Jorim Jaggidc249c42015-12-15 14:57:31 -0800363 /**
364 * Usually empty. Set to the task's tempInsetFrame. See
365 *{@link android.app.IActivityManager#resizeDockedStack}.
366 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700367 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800368
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800369 boolean mContentChanged;
370
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 // If a window showing a wallpaper: the requested offset for the
372 // wallpaper; if a wallpaper window: the currently applied offset.
373 float mWallpaperX = -1;
374 float mWallpaperY = -1;
375
376 // If a window showing a wallpaper: what fraction of the offset
377 // range corresponds to a full virtual screen.
378 float mWallpaperXStep = -1;
379 float mWallpaperYStep = -1;
380
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700381 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
382 // to its window; if a wallpaper window: not used.
383 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
384 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
385
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800386 // Wallpaper windows: pixels offset based on above variables.
387 int mXOffset;
388 int mYOffset;
389
Craig Mautner2268e7e2012-12-13 15:40:00 -0800390 /**
391 * This is set after IWindowSession.relayout() has been called at
392 * least once for the window. It allows us to detect the situation
393 * where we don't yet have a surface, but should have one soon, so
394 * we can give the window focus before waiting for the relayout.
395 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800396 boolean mRelayoutCalled;
397
Robert Carrfed10072016-05-26 11:48:49 -0700398 boolean mInRelayout;
399
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800400 /**
401 * If the application has called relayout() with changes that can
402 * impact its window's size, we need to perform a layout pass on it
403 * even if it is not currently visible for layout. This is set
404 * when in that case until the layout is done.
405 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800406 boolean mLayoutNeeded;
407
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800408 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800409 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800410
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800411 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800412 boolean mDestroying;
413
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800414 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800415 boolean mRemoveOnExit;
416
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800417 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800418 * Whether the app died while it was visible, if true we might need
419 * to continue to show it until it's restarted.
420 */
421 boolean mAppDied;
422
423 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800424 * Set when the orientation is changing and this window has not yet
425 * been updated for the new orientation.
426 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800427 boolean mOrientationChanging;
428
Dianne Hackborna57c6952013-03-29 14:46:40 -0700429 /**
Robert Carr237028a2016-07-26 10:39:45 -0700430 * The orientation during the last visible call to relayout. If our
431 * current orientation is different, the window can't be ready
432 * to be shown.
433 */
434 int mLastVisibleLayoutRotation = -1;
435
436 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700437 * How long we last kept the screen frozen.
438 */
439 int mLastFreezeDuration;
440
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800441 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800442 boolean mRemoved;
443
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800444 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800445 * It is save to remove the window and destroy the surface because the client requested removal
446 * or some other higher level component said so (e.g. activity manager).
447 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800448 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700449 private boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800450
451 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800452 * Temp for keeping track of windows that have been removed when
453 * rebuilding window list.
454 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800455 boolean mRebuilding;
456
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800457 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700458 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800459 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700460 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800461
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800462 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700463 private String mStringNameCache;
464 private CharSequence mLastTitle;
465 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800466
Craig Mautnera2c77052012-03-26 12:14:43 -0700467 final WindowStateAnimator mWinAnimator;
468
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700469 boolean mHasSurface = false;
470
Craig Mautner88400d32012-09-30 12:35:45 -0700471 /** When true this window can be displayed on screens owther than mOwnerUid's */
472 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700473
Robert Carr13f7be9e2015-12-02 18:39:45 -0800474 // Whether the window has a saved surface from last pause, which can be
475 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700476 private boolean mSurfaceSaved = false;
477
Chong Zhang8e4bda92016-05-04 15:08:18 -0700478 // Whether we're performing an entering animation with a saved surface. This flag is
479 // true during the time we're showing a window with a previously saved surface. It's
480 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700481 private boolean mAnimatingWithSavedSurface;
482
483 // Whether the window was visible when we set the app to invisible last time. WM uses
484 // this as a hint to restore the surface (if available) for early animation next time
485 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700486 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800487
Robert Carra1eb4392015-12-10 12:43:51 -0800488 // This window will be replaced due to relaunch. This allows window manager
489 // to differentiate between simple removal of a window and replacement. In the latter case it
490 // will preserve the old window until the new one is drawn.
491 boolean mWillReplaceWindow = false;
492 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700493 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800494 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700495 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800496 // If not null, the window that will be used to replace the old one. This is being set when
497 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700498 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700499 // For the new window in the replacement transition, if we have
500 // requested to replace without animation, then we should
501 // make sure we also don't apply an enter animation for
502 // the new window.
503 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800504 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700505 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800506
Jeff Brownc2932a12014-11-20 18:04:05 -0800507 /**
508 * Wake lock for drawing.
509 * Even though it's slightly more expensive to do so, we will use a separate wake lock
510 * for each app that is requesting to draw while dozing so that we can accurately track
511 * who is preventing the system from suspending.
512 * This lock is only acquired on first use.
513 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700514 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800515
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700516 final private Rect mTmpRect = new Rect();
517
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800518 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800519 * See {@link #notifyMovedInStack}.
520 */
521 private boolean mJustMovedInStack;
522
523 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800524 * Whether the window was resized by us while it was gone for layout.
525 */
526 boolean mResizedWhileGone = false;
527
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700528 /** @see #isResizedWhileNotDragResizing(). */
529 private boolean mResizedWhileNotDragResizing;
530
531 /** @see #isResizedWhileNotDragResizingReported(). */
532 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700533
Robert Carr6da3cc02016-06-16 15:17:07 -0700534 /**
535 * During seamless rotation we have two phases, first the old window contents
536 * are rotated to look as if they didn't move in the new coordinate system. Then we
537 * have to freeze updates to this layer (to preserve the transformation) until
538 * the resize actually occurs. This is true from when the transformation is set
539 * and false until the transaction to resize is sent.
540 */
541 boolean mSeamlesslyRotated = false;
542
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700543 private static final Region sEmptyRegion = new Region();
544
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700545 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700546 * 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 -0700547 * of z-order and 1 otherwise.
548 */
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700549 private static final Comparator<WindowState> sWindowSubLayerComparator = (w1, w2) -> {
550 final int layer1 = w1.mSubLayer;
551 final int layer2 = w2.mSubLayer;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700552 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
553 // We insert the child window into the list ordered by the sub-layer.
554 // For same sub-layers, the negative one should go below others; the positive one should
555 // go above others.
556 return -1;
557 }
558 return 1;
559 };
560
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800561 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700562 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700563 int viewVisibility, int ownerId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800564 mService = service;
565 mSession = s;
566 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800567 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800568 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700569 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700570 mOwnerUid = ownerId;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800571 mWindowId = new IWindowId.Stub() {
572 @Override
573 public void registerFocusObserver(IWindowFocusObserver observer) {
574 WindowState.this.registerFocusObserver(observer);
575 }
576 @Override
577 public void unregisterFocusObserver(IWindowFocusObserver observer) {
578 WindowState.this.unregisterFocusObserver(observer);
579 }
580 @Override
581 public boolean isFocused() {
582 return WindowState.this.isFocused();
583 }
584 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800585 mAttrs.copyFrom(a);
586 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700587 mPolicy = mService.mPolicy;
588 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800589 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700590 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700591 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700592 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700593 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700594 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800595 try {
596 c.asBinder().linkToDeath(deathRecipient, 0);
597 } catch (RemoteException e) {
598 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700599 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800600 mLayoutAttached = false;
601 mIsImWindow = false;
602 mIsWallpaper = false;
603 mIsFloatingLayer = false;
604 mBaseLayer = 0;
605 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700606 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700607 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800608 return;
609 }
610 mDeathRecipient = deathRecipient;
611
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700612 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800613 // The multiplier here is to reserve space for multiple
614 // windows in the same type layer.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700615 mBaseLayer = mPolicy.windowTypeToLayerLw(parentWindow.mAttrs.type)
616 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700617 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700618 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900619
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700620 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
621 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900622
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800623 mLayoutAttached = mAttrs.type !=
624 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700625 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
626 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
627 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800628 } else {
629 // The multiplier here is to reserve space for multiple
630 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700631 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700632 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800633 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700634 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800635 mLayoutAttached = false;
636 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
637 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
638 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800639 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700640 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800641
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700642 if (mAppToken != null && mAppToken.showForAllUsers) {
643 // Windows for apps that can show for all users should also show when the device is
644 // locked.
645 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700646 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800647
Craig Mautner322e4032012-07-13 13:35:20 -0700648 mWinAnimator = new WindowStateAnimator(this);
649 mWinAnimator.mAlpha = a.alpha;
650
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651 mRequestedWidth = 0;
652 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700653 mLastRequestedWidth = 0;
654 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800655 mXOffset = 0;
656 mYOffset = 0;
657 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800658 mInputWindowHandle = new InputWindowHandle(
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700659 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800660 }
661
662 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700663 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664 mSession.windowAddedLocked();
665 }
666
Craig Mautnera2c77052012-03-26 12:14:43 -0700667 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800668 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800669 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800670 }
671
672 @Override
673 public String getOwningPackage() {
674 return mAttrs.packageName;
675 }
676
Jorim Jaggif5834272016-04-04 20:25:41 -0700677 /**
678 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
679 * from {@param frame}. In other words, it applies the insets that would result if
680 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700681 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
682 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700683 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700684 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
685 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
686 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
687 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
688 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700689 frame.inset(left, top, right, bottom);
690 }
691
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800692 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700693 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
694 Rect osf) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800695 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700696 // This window is being replaced and either already got information that it's being
697 // removed or we are still waiting for some information. Because of this we don't
698 // want to apply any more changes to it, so it remains in this state until new window
699 // appears.
700 return;
701 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800702 mHaveFrame = true;
703
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700704 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700705 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800706 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700707 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800708
Chong Zhangae35fef2016-03-16 15:56:55 -0700709 // If the task has temp inset bounds set, we have to make sure all its windows uses
710 // the temp inset frame. Otherwise different display frames get applied to the main
711 // window and the child window, making them misaligned.
712 if (fullscreenTask) {
713 mInsetFrame.setEmpty();
714 } else {
715 task.getTempInsetBounds(mInsetFrame);
716 }
717
Jorim Jaggif5834272016-04-04 20:25:41 -0700718 // Denotes the actual frame used to calculate the insets and to perform the layout. When
719 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
720 // insets temporarily. By the notion of a task having a different layout frame, we can
721 // achieve that while still moving the task around.
722 final Rect layoutContainingFrame;
723 final Rect layoutDisplayFrame;
724
725 // The offset from the layout containing frame to the actual containing frame.
726 final int layoutXDiff;
727 final int layoutYDiff;
Wale Ogunwale7cd4b012016-05-07 12:41:22 -0700728 if (fullscreenTask || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800729 // We use the parent frame as the containing frame for fullscreen and child windows
730 mContainingFrame.set(pf);
731 mDisplayFrame.set(df);
Jorim Jaggif5834272016-04-04 20:25:41 -0700732 layoutDisplayFrame = df;
733 layoutContainingFrame = pf;
734 layoutXDiff = 0;
735 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800736 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700737 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100738 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
739
740 // If the bounds are frozen, we still want to translate the window freely and only
741 // freeze the size.
742 Rect frozen = mAppToken.mFrozenBounds.peek();
743 mContainingFrame.right = mContainingFrame.left + frozen.width();
744 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
745 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800746 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700747 // IME is up and obscuring this window. Adjust the window position so it is visible.
748 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
749 if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) {
750 // In freeform we want to move the top up directly.
751 // TODO: Investigate why this is cf not pf.
752 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
753 } else if (mContainingFrame.bottom > pf.bottom) {
754 // But in docked we want to behave like fullscreen
755 // and behave as if the task were given smaller bounds
756 // for the purposes of layout.
757 mContainingFrame.bottom = pf.bottom;
758 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700759 }
Skuhne81c524a2015-08-12 13:34:14 -0700760
Robert Carre6275582016-02-29 15:45:45 -0800761 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700762 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
763 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800764 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700765 if (mContainingFrame.isEmpty()) {
766 mContainingFrame.set(cf);
767 }
Doris Liu06d582d2015-06-01 13:18:43 -0700768 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800769 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700770 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
771 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
772 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700773 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Andrii Kuliandaea3572016-04-08 13:20:51 -0700774 subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700775 if (!layoutInParentFrame()) {
Andrii Kuliandaea3572016-04-08 13:20:51 -0700776 subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect);
777 subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700778 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700779 layoutDisplayFrame = df;
780 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700781 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800782
Craig Mautner967212c2013-04-13 21:10:58 -0700783 final int pw = mContainingFrame.width();
784 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800785
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800786 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800787 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800788 // + " to " + pf);
789 mParentFrame.set(pf);
790 mContentChanged = true;
791 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700792 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
793 mLastRequestedWidth = mRequestedWidth;
794 mLastRequestedHeight = mRequestedHeight;
795 mContentChanged = true;
796 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800797
Craig Mautnereda67292013-04-28 13:50:14 -0700798 mOverscanFrame.set(of);
799 mContentFrame.set(cf);
800 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400801 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700802 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700803 final boolean hasOutsets = osf != null;
804 if (hasOutsets) {
805 mOutsetFrame.set(osf);
806 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800807
Craig Mautnereda67292013-04-28 13:50:14 -0700808 final int fw = mFrame.width();
809 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800810
Jorim Jaggif5834272016-04-04 20:25:41 -0700811 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
812
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700813 // Calculate the outsets before the content frame gets shrinked to the window frame.
814 if (hasOutsets) {
815 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
816 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
817 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
818 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
819 } else {
820 mOutsets.set(0, 0, 0, 0);
821 }
822
Craig Mautnera248eee2013-05-07 11:41:27 -0700823 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800824 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800825 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700826 // Keep the frame out of the blocked system area, limit it in size to the content area
827 // and make sure that there is always a minimum visible so that the user can drag it
828 // into a usable area..
829 final int height = Math.min(mFrame.height(), mContentFrame.height());
830 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700831 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900832 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
833 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
834 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
835 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Skuhne81c524a2015-08-12 13:34:14 -0700836 final int top = Math.max(mContentFrame.top,
837 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
838 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
839 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
840 mFrame.set(left, top, left + width, top + height);
841 mContentFrame.set(mFrame);
842 mVisibleFrame.set(mContentFrame);
843 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700844 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700845 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100846 mContentFrame.set(mFrame);
847 if (!mFrame.equals(mLastFrame)) {
848 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800849 }
Skuhne81c524a2015-08-12 13:34:14 -0700850 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700851 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
852 Math.max(mContentFrame.top, mFrame.top),
853 Math.min(mContentFrame.right, mFrame.right),
854 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800855
Jorim Jaggi656f6502016-04-11 21:08:17 -0700856 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
857 Math.max(mVisibleFrame.top, mFrame.top),
858 Math.min(mVisibleFrame.right, mFrame.right),
859 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800860
Jorim Jaggi656f6502016-04-11 21:08:17 -0700861 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
862 Math.max(mStableFrame.top, mFrame.top),
863 Math.min(mStableFrame.right, mFrame.right),
864 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700865 }
Adrian Roosfa104232014-06-20 16:10:14 -0700866
Jorim Jaggi899327f2016-02-25 20:44:18 -0500867 if (fullscreenTask && !windowsAreFloating) {
868 // Windows that are not fullscreen can be positioned outside of the display frame,
869 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700870 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
871 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
872 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
873 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800874 }
Craig Mautnereda67292013-04-28 13:50:14 -0700875
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100876 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100877 // For the docked divider, we calculate the stable insets like a full-screen window
878 // so it can use it to calculate the snap positions.
879 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
880 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
881 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
882 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800883
884 // The divider doesn't care about insets in any case, so set it to empty so we don't
885 // trigger a relayout when moving it.
886 mContentInsets.setEmpty();
887 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100888 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700889 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700890 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
891 // non-fullscreen mode.
Winsonbf1ed3d2016-10-19 17:30:26 -0700892 boolean overrideRightInset = !windowsAreFloating && !fullscreenTask &&
893 mFrame.right > mTmpRect.right;
894 boolean overrideBottomInset = !windowsAreFloating && !fullscreenTask &&
895 mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700896 mContentInsets.set(mContentFrame.left - mFrame.left,
897 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700898 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700899 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700900 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700901 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800902
Jorim Jaggi656f6502016-04-11 21:08:17 -0700903 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
904 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700905 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700906 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700907 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700908 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800909
Jorim Jaggi656f6502016-04-11 21:08:17 -0700910 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
911 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700912 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700913 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700914 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700915 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100916 }
Adrian Roosfa104232014-06-20 16:10:14 -0700917
Jorim Jaggi656f6502016-04-11 21:08:17 -0700918 // Offset the actual frame by the amount layout frame is off.
919 mFrame.offset(-layoutXDiff, -layoutYDiff);
920 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700921 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
922 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
923 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
924
Craig Mautnereda67292013-04-28 13:50:14 -0700925 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400926 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700927 // If there is a size compatibility scale being applied to the
928 // window, we need to apply this to its insets so that they are
929 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700930 mOverscanInsets.scale(mInvGlobalScale);
931 mContentInsets.scale(mInvGlobalScale);
932 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700933 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700934 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700935
936 // Also the scaled frame that we report to the app needs to be
937 // adjusted to be in its coordinate space.
938 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400939 }
940
Craig Mautnereda67292013-04-28 13:50:14 -0700941 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800942 final DisplayContent displayContent = getDisplayContent();
943 if (displayContent != null) {
944 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700945 mService.mWallpaperControllerLocked.updateWallpaperOffset(
946 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800947 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800948 }
949
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700950 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700951 "Resolving (mRequestedWidth="
952 + mRequestedWidth + ", mRequestedheight="
953 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
954 + "): frame=" + mFrame.toShortString()
955 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700956 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700957 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700958 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800959 }
960
Craig Mautnera2c77052012-03-26 12:14:43 -0700961 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800962 public Rect getFrameLw() {
963 return mFrame;
964 }
965
Craig Mautnera2c77052012-03-26 12:14:43 -0700966 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700967 public Point getShownPositionLw() {
968 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800969 }
970
Craig Mautnera2c77052012-03-26 12:14:43 -0700971 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800972 public Rect getDisplayFrameLw() {
973 return mDisplayFrame;
974 }
975
Craig Mautnera2c77052012-03-26 12:14:43 -0700976 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800977 public Rect getOverscanFrameLw() {
978 return mOverscanFrame;
979 }
980
981 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800982 public Rect getContentFrameLw() {
983 return mContentFrame;
984 }
985
Craig Mautnera2c77052012-03-26 12:14:43 -0700986 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800987 public Rect getVisibleFrameLw() {
988 return mVisibleFrame;
989 }
990
Craig Mautnera2c77052012-03-26 12:14:43 -0700991 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800992 public boolean getGivenInsetsPendingLw() {
993 return mGivenInsetsPending;
994 }
995
Craig Mautnera2c77052012-03-26 12:14:43 -0700996 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997 public Rect getGivenContentInsetsLw() {
998 return mGivenContentInsets;
999 }
1000
Craig Mautnera2c77052012-03-26 12:14:43 -07001001 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001002 public Rect getGivenVisibleInsetsLw() {
1003 return mGivenVisibleInsets;
1004 }
1005
Craig Mautnera2c77052012-03-26 12:14:43 -07001006 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001007 public WindowManager.LayoutParams getAttrs() {
1008 return mAttrs;
1009 }
1010
Craig Mautner812d2ca2012-09-27 15:35:34 -07001011 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001012 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001013 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001014 }
1015
Craig Mautner19d59bc2012-09-04 11:15:56 -07001016 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001017 public int getSystemUiVisibility() {
1018 return mSystemUiVisibility;
1019 }
1020
Craig Mautner19d59bc2012-09-04 11:15:56 -07001021 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001022 public int getSurfaceLayer() {
1023 return mLayer;
1024 }
1025
Craig Mautner812d2ca2012-09-27 15:35:34 -07001026 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001027 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001028 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001029 }
1030
1031 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001032 public IApplicationToken getAppToken() {
1033 return mAppToken != null ? mAppToken.appToken : null;
1034 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001035
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001036 @Override
1037 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001038 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001039 }
1040
Robert Carr31aa98b2016-07-20 15:29:03 -07001041 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001042 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1043 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1044 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001045 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001046 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001047 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1048 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001049 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001050 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001051 }
1052
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001053 /**
1054 * Adds the window to the resizing list if any of the parameters we use to track the window
1055 * dimensions or insets have changed.
1056 */
1057 void updateResizingWindowIfNeeded() {
1058 final WindowStateAnimator winAnimator = mWinAnimator;
1059 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1060 return;
1061 }
1062
1063 final Task task = getTask();
1064 // In the case of stack bound animations, the window frames will update (unlike other
1065 // animations which just modify various transformation properties). We don't want to
1066 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1067 // the frame may not correspond to the surface size or the onscreen area at various
1068 // phases in the animation, and the client will become sad and confused.
1069 if (task != null && task.mStack.getBoundsAnimating()) {
1070 return;
1071 }
1072
1073 setReportResizeHints();
1074 boolean configChanged = isConfigChanged();
1075 if (DEBUG_CONFIGURATION && configChanged) {
1076 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1077 }
1078
1079 final boolean dragResizingChanged = isDragResizeChanged()
1080 && !isDragResizingChangeReported();
1081
1082 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1083 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1084 + " frame=" + mFrame);
1085
1086 // We update mLastFrame always rather than in the conditional with the last inset
1087 // variables, because mFrameSizeChanged only tracks the width and height changing.
1088 mLastFrame.set(mFrame);
1089
1090 if (mContentInsetsChanged
1091 || mVisibleInsetsChanged
1092 || winAnimator.mSurfaceResized
1093 || mOutsetsChanged
1094 || mFrameSizeChanged
1095 || configChanged
1096 || dragResizingChanged
1097 || !isResizedWhileNotDragResizingReported()) {
1098 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1099 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1100 + " contentInsetsChanged=" + mContentInsetsChanged
1101 + " " + mContentInsets.toShortString()
1102 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1103 + " " + mVisibleInsets.toShortString()
1104 + " stableInsetsChanged=" + mStableInsetsChanged
1105 + " " + mStableInsets.toShortString()
1106 + " outsetsChanged=" + mOutsetsChanged
1107 + " " + mOutsets.toShortString()
1108 + " surfaceResized=" + winAnimator.mSurfaceResized
1109 + " configChanged=" + configChanged
1110 + " dragResizingChanged=" + dragResizingChanged
1111 + " resizedWhileNotDragResizingReported="
1112 + isResizedWhileNotDragResizingReported());
1113 }
1114
1115 // If it's a dead window left on screen, and the configuration changed, there is nothing
1116 // we can do about it. Remove the window now.
1117 if (mAppToken != null && mAppDied) {
1118 mAppToken.removeDeadWindows();
1119 return;
1120 }
1121
1122 mLastOverscanInsets.set(mOverscanInsets);
1123 mLastContentInsets.set(mContentInsets);
1124 mLastVisibleInsets.set(mVisibleInsets);
1125 mLastStableInsets.set(mStableInsets);
1126 mLastOutsets.set(mOutsets);
1127 mService.makeWindowFreezingScreenIfNeededLocked(this);
1128
1129 // If the orientation is changing, or we're starting or ending a drag resizing action,
1130 // then we need to hold off on unfreezing the display until this window has been
1131 // redrawn; to do that, we need to go through the process of getting informed by the
1132 // application when it has finished drawing.
1133 if (mOrientationChanging || dragResizingChanged || isResizedWhileNotDragResizing()) {
1134 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1135 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1136 + ", mDrawState=DRAW_PENDING in " + this
1137 + ", surfaceController " + winAnimator.mSurfaceController);
1138 }
1139 winAnimator.mDrawState = DRAW_PENDING;
1140 if (mAppToken != null) {
1141 mAppToken.clearAllDrawn();
1142 }
1143 }
1144 if (!mService.mResizingWindows.contains(this)) {
1145 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1146 mService.mResizingWindows.add(this);
1147 }
1148 } else if (mOrientationChanging) {
1149 if (isDrawnLw()) {
1150 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1151 + this + ", surfaceController " + winAnimator.mSurfaceController);
1152 mOrientationChanging = false;
1153 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1154 - mService.mDisplayFreezeTime);
1155 }
1156 }
1157 }
1158
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001159 DisplayContent getDisplayContent() {
1160 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001161 }
1162
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001163 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001164 final DisplayContent displayContent = getDisplayContent();
1165 return displayContent != null ? displayContent.getDisplayInfo() : null;
1166 }
1167
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001168 int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001169 final DisplayContent displayContent = getDisplayContent();
1170 if (displayContent == null) {
1171 return -1;
1172 }
1173 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001174 }
1175
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001176 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001177 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001178 }
1179
1180 TaskStack getStack() {
1181 Task task = getTask();
1182 if (task != null) {
1183 if (task.mStack != null) {
1184 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001185 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001186 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001187 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1188 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001189 final DisplayContent dc = getDisplayContent();
1190 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001191 }
1192
Skuhnef932e562015-08-20 12:07:30 -07001193 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001194 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001195 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001196 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001197 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001198 final Task task = getTask();
1199 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001200 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001201 mTmpRect.setEmpty();
1202 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001203 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001204 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001205 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001206 } else {
1207 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001208 }
1209 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001210
Chong Zhang9184ec62015-09-24 12:32:21 -07001211 bounds.set(mVisibleFrame);
1212 if (intersectWithStackBounds) {
1213 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001214 }
1215
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001216 if (bounds.isEmpty()) {
1217 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001218 if (intersectWithStackBounds) {
1219 bounds.intersect(mTmpRect);
1220 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001221 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001222 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001223 }
1224
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001225 public long getInputDispatchingTimeoutNanos() {
1226 return mAppToken != null
1227 ? mAppToken.inputDispatchingTimeoutNanos
1228 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1229 }
1230
Craig Mautnere8552142012-11-07 13:55:47 -08001231 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001232 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001233 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001234 }
1235
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001236 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1237 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1238 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1239 if (dtdx < -.000001f || dtdx > .000001f) return false;
1240 if (dsdy < -.000001f || dsdy > .000001f) return false;
1241 return true;
1242 }
1243
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001244 void prelayout() {
1245 if (mEnforceSizeCompat) {
1246 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001247 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001248 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001249 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001250 }
1251 }
1252
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001253 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001254 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001255 // If we're animating with a saved surface, we're already visible.
1256 // Return true so that the alpha doesn't get cleared.
1257 if (!mAppFreezing && isDrawnLw()
1258 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1259 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1260 return true;
1261 }
1262
Wale Ogunwale44f21802016-09-02 12:49:48 -07001263 return super.hasContentToDisplay();
1264 }
1265
1266 @Override
1267 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -07001268 // TODO: The check for hiddenRequested is commented out below, because the window can still
1269 // be visible on screen when the flag is true. We would like the isVisible() method to
1270 // return an answer closer to if the window is truly visible (can't be an exact answer
1271 // without checking the surface state), so comment out the check for now so we can test to
1272 // see what problem it causes.
1273 // If it doesn't cause any issues, then we can remove just before we lock down the current
1274 // release (O) and also consolidate this method with #isVisibleUnchecked() and possibly
1275 // other methods like isVisibleNow().
1276 // If it does cause problems, then we can look if there are other ways to solve the problem.
1277 // If there isn't then uncomment and document here why it is needed.
1278 if (/*(mAppToken == null || !mAppToken.hiddenRequested) && */isVisibleUnchecked()
1279 // TODO: The window isn't considered visible when the token is hidden, however
1280 // uncommenting the check below breaks the visual transition from an app to the launcher
1281 // if the home buttons is pressed. Need to investigate an fix that issue before
1282 // uncommenting.
1283 /* && !mToken.hidden*/) {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001284 // Is this window visible? It is not visible if there is no surface, or we are in the
1285 // process of running an exit animation that will remove the surface, or its app token
1286 // has been hidden.
1287 return true;
1288 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001289 return false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001290 }
1291
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001292 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001293 * Does the minimal check for visibility. Callers generally want to use one of the public
1294 * methods as they perform additional checks on the app token.
1295 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001296 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001297 private boolean isVisibleUnchecked() {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001298 return mHasSurface && mPolicyVisibility && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001299 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001300 }
1301
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001302 @Override
1303 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001304 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001305 }
1306
1307 /**
1308 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1309 * keyguard as visible. This allows us to apply things like window flags that impact the
1310 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1311 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001312 */
Craig Mautner88400d32012-09-30 12:35:45 -07001313 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001314 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001315 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001316 return false;
1317 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001318 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001319 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001320 return mHasSurface && !mDestroying && !mAnimatingExit
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001321 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001322 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001323 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001324 }
1325
1326 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001327 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1328 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001329 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001330 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1331 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001332 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1333 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001334 }
1335
1336 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001337 * The same as isVisible(), but follows the current hidden state of the associated app token,
1338 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001339 */
1340 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001341 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001342 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001343 }
1344
1345 /**
1346 * Can this window possibly be a drag/drop target? The test here is
1347 * a combination of the above "visible now" with the check that the
1348 * Input Manager uses when discarding windows from input consideration.
1349 */
1350 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001351 return isVisibleNow() && !mRemoved
1352 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001353 }
1354
1355 /**
1356 * Same as isVisible(), but we also count it as visible between the
1357 * call to IWindowSession.add() and the first relayout().
1358 */
1359 boolean isVisibleOrAdding() {
1360 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001361 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001362 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001363 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001364 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001365 }
1366
1367 /**
1368 * Is this window currently on-screen? It is on-screen either if it
1369 * is visible or it is currently running an animation before no longer
1370 * being visible.
1371 */
1372 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001373 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1374 }
1375
1376 /**
1377 * Like isOnScreen(), but ignores any force hiding of the window due
1378 * to the keyguard.
1379 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001380 private boolean isOnScreenIgnoringKeyguard() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001381 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001382 return false;
1383 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001384 final AppWindowToken atoken = mAppToken;
1385 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001386 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001387 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001388 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001389 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001390 }
1391
1392 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001393 * Whether this window's drawn state might affect the drawn states of the app token.
1394 *
1395 * @param visibleOnly Whether we should consider only the windows that's currently
1396 * visible in layout. If true, windows that has not relayout to VISIBLE
1397 * would always return false.
1398 *
1399 * @return true if the window should be considered while evaluating allDrawn flags.
1400 */
1401 boolean mightAffectAllDrawn(boolean visibleOnly) {
Chong Zhange292eb32016-05-21 09:23:55 -07001402 final boolean isViewVisible = (mAppToken == null || !mAppToken.clientHidden)
1403 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001404 return (isOnScreenIgnoringKeyguard() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001405 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1406 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001407 && !mAnimatingExit && !mDestroying;
1408 }
1409
1410 /**
1411 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1412 * it must be drawn before allDrawn can become true.
1413 */
1414 boolean isInteresting() {
1415 return mAppToken != null && !mAppDied
1416 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1417 }
1418
1419 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001420 * Like isOnScreen(), but we don't return true if the window is part
1421 * of a transition that has not yet been started.
1422 */
1423 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001424 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001425 return false;
1426 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001427 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001428 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001429 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001430 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001431 }
1432
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001433 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001434 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1435 * to the keyguard.
1436 */
1437 boolean isReadyForDisplayIgnoringKeyguard() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001438 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001439 return false;
1440 }
1441 final AppWindowToken atoken = mAppToken;
1442 if (atoken == null && !mPolicyVisibility) {
1443 // If this is not an app window, and the policy has asked to force
1444 // hide, then we really do want to hide.
1445 return false;
1446 }
1447 return mHasSurface && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001448 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001449 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001450 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
Chong Zhang83caa362016-08-14 18:47:54 -07001451 && !mWinAnimator.isDummyAnimation())
1452 || isAnimatingWithSavedSurface());
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001453 }
1454
1455 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001456 * Like isOnScreen, but returns false if the surface hasn't yet
1457 * been drawn.
1458 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001459 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001460 public boolean isDisplayedLw() {
1461 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001462 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001463 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001464 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001465 || mWinAnimator.mAnimating
1466 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001467 }
1468
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001469 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001470 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001471 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001472 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001473 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001474 return mWinAnimator.mAnimation != null
1475 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001476 }
1477
Craig Mautner812d2ca2012-09-27 15:35:34 -07001478 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001479 public boolean isGoneForLayoutLw() {
1480 final AppWindowToken atoken = mAppToken;
1481 return mViewVisibility == View.GONE
1482 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001483 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001484 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001485 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001486 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001487 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001488 }
1489
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001490 /**
1491 * Returns true if the window has a surface that it has drawn a
1492 * complete UI in to.
1493 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001494 public boolean isDrawFinishedLw() {
1495 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001496 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1497 || mWinAnimator.mDrawState == READY_TO_SHOW
1498 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001499 }
1500
1501 /**
1502 * Returns true if the window has a surface that it has drawn a
1503 * complete UI in to.
1504 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001505 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001506 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001507 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001508 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001509 }
1510
1511 /**
1512 * Return true if the window is opaque and fully drawn. This indicates
1513 * it may obscure windows behind it.
1514 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001515 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001516 // When there is keyguard, wallpaper could be placed over the secure app
1517 // window but invisible. We need to check wallpaper visibility explicitly
1518 // to determine if it's occluding apps.
1519 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1520 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001521 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001522 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001523 }
1524
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001525 @Override
1526 void onMovedByResize() {
1527 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001528 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001529 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001530 }
1531
1532 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1533 boolean changed = false;
1534
1535 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001536 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001537 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1538 }
1539
1540 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1541 // Starting window that's exiting will be removed when the animation finishes.
1542 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1543 // to actually remove it.
1544 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1545 mAnimatingExit = true;
1546 mRemoveOnExit = true;
1547 mWindowRemovalAllowed = true;
1548 }
1549 return changed;
1550 }
1551
1552 if (visible != isVisibleNow()) {
1553 if (!runningAppAnimation) {
1554 final AccessibilityController accessibilityController =
1555 mService.mAccessibilityController;
1556 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1557 mWinAnimator.applyAnimationLocked(winTransit, visible);
1558 //TODO (multidisplay): Magnification is supported only for the default
1559 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1560 accessibilityController.onWindowTransitionLocked(this, winTransit);
1561 }
1562 }
1563 changed = true;
1564 setDisplayLayoutNeeded();
1565 }
1566
1567 return changed;
1568 }
1569
1570 boolean onSetAppExiting() {
1571 final DisplayContent displayContent = getDisplayContent();
1572 boolean changed = false;
1573
1574 if (isVisibleNow()) {
1575 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1576 //TODO (multidisplay): Magnification is supported only for the default
1577 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1578 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1579 }
1580 changed = true;
1581 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001582 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001583 }
1584 }
1585
1586 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001587 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001588 changed |= c.onSetAppExiting();
1589 }
1590
1591 return changed;
1592 }
1593
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001594 @Override
1595 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001596 // Some windows won't go through the resizing process, if they don't have a surface, so
1597 // destroy all saved surfaces here.
1598 destroySavedSurface();
1599
1600 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1601 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001602 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001603 resizingWindows.add(this);
1604
1605 // If we are not drag resizing, force recreating of a new surface so updating
1606 // the content and positioning that surface will be in sync.
1607 //
1608 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1609 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1610 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1611 // their frame to update crop, etc...
1612 //
1613 // Anyway we don't need to synchronize position and content updates for these
1614 // windows since they aren't at the base layer and could be moved around anyway.
1615 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
1616 !getTask().mStack.getBoundsAnimating() && !isGoneForLayoutLw() &&
1617 !getTask().inPinnedWorkspace()) {
1618 setResizedWhileNotDragResizing(true);
1619 }
1620 }
1621 if (isGoneForLayoutLw()) {
1622 mResizedWhileGone = true;
1623 }
1624
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001625 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001626 }
1627
1628 void onUnfreezeBounds() {
1629 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001630 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001631 c.onUnfreezeBounds();
1632 }
1633
1634 if (!mHasSurface) {
1635 return;
1636 }
1637
1638 mLayoutNeeded = true;
1639 setDisplayLayoutNeeded();
1640 if (!mService.mResizingWindows.contains(this)) {
1641 mService.mResizingWindows.add(this);
1642 }
1643 }
1644
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001645 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001646 * If the window has moved due to its containing content frame changing, then notify the
1647 * listeners and optionally animate it. Simply checking a change of position is not enough,
1648 * because being move due to dock divider is not a trigger for animation.
1649 */
1650 void handleWindowMovedIfNeeded() {
1651 if (!hasMoved()) {
1652 return;
1653 }
1654
1655 // Frame has moved, containing content frame has also moved, and we're not currently
1656 // animating... let's do something.
1657 final int left = mFrame.left;
1658 final int top = mFrame.top;
1659 final Task task = getTask();
1660 final boolean adjustedForMinimizedDockOrIme = task != null
1661 && (task.mStack.isAdjustedForMinimizedDockedStack()
1662 || task.mStack.isAdjustedForIme());
1663 if (mService.okToDisplay()
1664 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1665 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1666 && (task == null || getTask().mStack.hasMovementAnimations())
1667 && !mWinAnimator.mLastHidden) {
1668 mWinAnimator.setMoveAnimation(left, top);
1669 }
1670
1671 //TODO (multidisplay): Accessibility supported only for the default display.
1672 if (mService.mAccessibilityController != null
1673 && getDisplayContent().getDisplayId() == Display.DEFAULT_DISPLAY) {
1674 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1675 }
1676
1677 try {
1678 mClient.moved(left, top);
1679 } catch (RemoteException e) {
1680 }
1681 mMovedByResize = false;
1682 }
1683
1684 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001685 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001686 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1687 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001688 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001689 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001690 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001691 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001692 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001693 }
1694
Chong Zhang0abb20f2015-11-19 14:17:31 -08001695 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1696 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001697 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001698 return false;
1699 }
1700 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1701 return false;
1702 }
1703 return true;
1704 }
1705
1706 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1707 return mFrame.left <= 0 && mFrame.top <= 0
1708 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001709 }
1710
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001711 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001712 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001713 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001714 }
1715
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001716 boolean isAdjustedForMinimizedDock() {
1717 return mAppToken != null && mAppToken.mTask != null
1718 && mAppToken.mTask.mStack.isAdjustedForMinimizedDock();
1719 }
1720
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001721 void onWindowReplacementTimeout() {
1722 if (mWillReplaceWindow) {
1723 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001724 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001725 // delays removal on certain conditions, which will leave the stale window in the
1726 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1727 //
1728 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001729 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001730 } else {
1731 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001732 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001733 c.onWindowReplacementTimeout();
1734 }
1735 }
1736 }
1737
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001738 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001739 void forceWindowsScaleableInTransaction(boolean force) {
1740 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1741 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1742 }
1743
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001744 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001745 }
1746
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001747 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001748 void removeImmediately() {
1749 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001750
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001751 if (mRemoved) {
1752 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001753 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1754 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001755 return;
1756 }
1757
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001758 mRemoved = true;
1759
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001760 mWillReplaceWindow = false;
1761 if (mReplacementWindow != null) {
1762 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1763 }
1764
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001765 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001766 if (mService.mInputMethodTarget == this) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001767 dc.moveInputMethodWindowsIfNeeded(false);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001768 }
1769
1770 final int type = mAttrs.type;
1771 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001772 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001773 }
1774 mPolicy.removeWindowLw(this);
1775
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001776 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001777
Craig Mautner96868332012-12-04 14:29:11 -08001778 mWinAnimator.destroyDeferredSurfaceLocked();
1779 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001780 mSession.windowRemovedLocked();
1781 try {
1782 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1783 } catch (RuntimeException e) {
1784 // Ignore if it has already been removed (usually because
1785 // we are doing this as part of processing a death note.)
1786 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001787
1788 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001789 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001790
Wale Ogunwale571771c2016-08-26 13:18:50 -07001791 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001792 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001793 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001794 removeIfPossible(false /*keepVisibleDeadWindow*/);
1795 }
1796
Wale Ogunwale571771c2016-08-26 13:18:50 -07001797 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001798 mWindowRemovalAllowed = true;
1799 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1800 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1801
1802 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1803 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1804 "Starting window removed " + this);
1805
1806 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1807 Slog.v(TAG_WM, "Remove " + this + " client="
1808 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1809 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1810 + Debug.getCallers(5));
1811
1812 final long origId = Binder.clearCallingIdentity();
1813
1814 disposeInputChannel();
1815
1816 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1817 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1818 + " mAnimatingExit=" + mAnimatingExit
1819 + " mRemoveOnExit=" + mRemoveOnExit
1820 + " mHasSurface=" + mHasSurface
1821 + " surfaceShowing=" + mWinAnimator.getShown()
1822 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1823 + " app-animation="
1824 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1825 + " mWillReplaceWindow=" + mWillReplaceWindow
1826 + " inPendingTransaction="
1827 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1828 + " mDisplayFrozen=" + mService.mDisplayFrozen
1829 + " callers=" + Debug.getCallers(6));
1830
1831 // Visibility of the removed window. Will be used later to update orientation later on.
1832 boolean wasVisible = false;
1833
1834 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1835 // window until the animation is done. If the display is frozen, just remove immediately,
1836 // since the animation wouldn't be seen.
1837 if (mHasSurface && mService.okToDisplay()) {
1838 if (mWillReplaceWindow) {
1839 // This window is going to be replaced. We need to keep it around until the new one
1840 // gets added, then we will get rid of this one.
1841 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1842 "Preserving " + this + " until the new one is " + "added");
1843 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1844 // been removed. We probably need another flag to indicate that window removal
1845 // should be deffered vs. overloading the flag that says we are playing an exit
1846 // animation.
1847 mAnimatingExit = true;
1848 mReplacingRemoveRequested = true;
1849 Binder.restoreCallingIdentity(origId);
1850 return;
1851 }
1852
1853 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1854 // We started enter animation early with a saved surface, now the app asks to remove
1855 // this window. If we remove it now and the app is not yet drawn, we'll show a
1856 // flicker. Delay the removal now until it's really drawn.
1857 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1858 "removeWindowLocked: delay removal of " + this + " due to early animation");
1859 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1860 // immediately after the enter animation is done. If the app is not yet drawn then
1861 // it will show up as a flicker.
1862 setupWindowForRemoveOnExit();
1863 Binder.restoreCallingIdentity(origId);
1864 return;
1865 }
1866 // If we are not currently running the exit animation, we need to see about starting one
1867 wasVisible = isWinVisibleLw();
1868
1869 if (keepVisibleDeadWindow) {
1870 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1871 "Not removing " + this + " because app died while it's visible");
1872
1873 mAppDied = true;
1874 setDisplayLayoutNeeded();
1875 mService.mWindowPlacerLocked.performSurfacePlacement();
1876
1877 // Set up a replacement input channel since the app is now dead.
1878 // We need to catch tapping on the dead window to restart the app.
1879 openInputChannel(null);
1880 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1881
1882 Binder.restoreCallingIdentity(origId);
1883 return;
1884 }
1885
1886 if (wasVisible) {
1887 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1888
1889 // Try starting an animation.
1890 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1891 mAnimatingExit = true;
1892 }
1893 //TODO (multidisplay): Magnification is supported only for the default display.
1894 if (mService.mAccessibilityController != null
1895 && getDisplayId() == Display.DEFAULT_DISPLAY) {
1896 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1897 }
1898 }
1899 final boolean isAnimating =
1900 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1901 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001902 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001903 // We delay the removal of a window if it has a showing surface that can be used to run
1904 // exit animation and it is marked as exiting.
1905 // Also, If isn't the an animating starting window that is the last window in the app.
1906 // We allow the removal of the non-animating starting window now as there is no
1907 // additional window or animation that will trigger its removal.
1908 if (mWinAnimator.getShown() && mAnimatingExit
1909 && (!lastWindowIsStartingWindow || isAnimating)) {
1910 // The exit animation is running or should run... wait for it!
1911 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1912 "Not removing " + this + " due to exit animation ");
1913 setupWindowForRemoveOnExit();
1914 if (mAppToken != null) {
1915 mAppToken.updateReportedVisibilityLocked();
1916 }
1917 Binder.restoreCallingIdentity(origId);
1918 return;
1919 }
1920 }
1921
Wale Ogunwale571771c2016-08-26 13:18:50 -07001922 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001923 // Removing a visible window will effect the computed orientation
1924 // So just update orientation if needed.
1925 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false)) {
1926 mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION);
1927 }
1928 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1929 Binder.restoreCallingIdentity(origId);
1930 }
1931
1932 private void setupWindowForRemoveOnExit() {
1933 mRemoveOnExit = true;
1934 setDisplayLayoutNeeded();
1935 // Request a focus update as this window's input channel is already gone. Otherwise
1936 // we could have no focused window in input manager.
1937 final boolean focusChanged = mService.updateFocusedWindowLocked(
1938 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1939 mService.mWindowPlacerLocked.performSurfacePlacement();
1940 if (focusChanged) {
1941 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1942 }
1943 }
1944
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001945 void setHasSurface(boolean hasSurface) {
1946 mHasSurface = hasSurface;
1947 }
1948
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001949 int getAnimLayerAdjustment() {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001950 final boolean isImeType =
1951 mAttrs.type == TYPE_INPUT_METHOD || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
1952 if (isImeType && mService.mInputMethodTarget != null) {
1953 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1954 if (appToken != null) {
1955 return appToken.mAppAnimator.animLayerAdjustment;
1956 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001957 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07001958
1959 if (mAppToken != null) {
1960 return mAppToken.mAppAnimator.animLayerAdjustment;
1961 }
1962
1963 // Nothing is animating, so there is no animation adjustment.
1964 return 0;
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001965 }
1966
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001967 int getSpecialWindowAnimLayerAdjustment() {
1968 int specialAdjustment = 0;
1969 if (mIsImWindow) {
1970 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
1971 } else if (mIsWallpaper) {
1972 specialAdjustment = mService.mWallpaperControllerLocked.getAnimLayerAdjustment();
1973 }
1974
1975 return mLayer + specialAdjustment;
1976 }
1977
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001978 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001979 final DisplayContent dc = getDisplayContent();
1980 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001981 return;
1982 }
1983 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001984 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001985 // Force an animation pass just to update the mDimLayer layer.
1986 mService.scheduleAnimationLocked();
1987 }
1988 }
1989
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001990 /**
1991 * Notifies this window that the corresponding task has just moved in the stack.
1992 * <p>
1993 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
1994 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
1995 * the actual app transition that updates the visibility is delayed by a few transactions.
1996 * Instead of messing around with the ordering and timing how transitions and transactions are
1997 * executed, we introduce this little hack which prevents this window of getting visible again
1998 * with the wrong bounds until the app transitions has started.
1999 * <p>
2000 * This method notifies the window about that we just moved in the stack so we can apply this
2001 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
2002 */
2003 void notifyMovedInStack() {
2004 mJustMovedInStack = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002005
2006 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002007 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002008 c.notifyMovedInStack();
2009 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002010 }
2011
2012 /**
2013 * See {@link #notifyMovedInStack}.
2014 *
2015 * @return Whether we just got moved in the corresponding stack.
2016 */
2017 boolean hasJustMovedInStack() {
2018 return mJustMovedInStack;
2019 }
2020
2021 /**
2022 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
2023 */
2024 void resetJustMovedInStack() {
2025 mJustMovedInStack = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002026
2027 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002028 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002029 c.resetJustMovedInStack();
2030 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002031 }
2032
Chong Zhangacf11402015-11-04 16:23:10 -08002033 private final class DeadWindowEventReceiver extends InputEventReceiver {
2034 DeadWindowEventReceiver(InputChannel inputChannel) {
2035 super(inputChannel, mService.mH.getLooper());
2036 }
2037 @Override
2038 public void onInputEvent(InputEvent event) {
2039 finishInputEvent(event, true);
2040 }
2041 }
2042 /**
2043 * Dummy event receiver for windows that died visible.
2044 */
2045 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2046
Chong Zhang112eb8c2015-11-02 11:17:00 -08002047 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002048 if (mInputChannel != null) {
2049 throw new IllegalStateException("Window already has an input channel.");
2050 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002051 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002052 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2053 mInputChannel = inputChannels[0];
2054 mClientChannel = inputChannels[1];
2055 mInputWindowHandle.inputChannel = inputChannels[0];
2056 if (outInputChannel != null) {
2057 mClientChannel.transferTo(outInputChannel);
2058 mClientChannel.dispose();
2059 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002060 } else {
2061 // If the window died visible, we setup a dummy input channel, so that taps
2062 // can still detected by input monitor channel, and we can relaunch the app.
2063 // Create dummy event receiver that simply reports all events as handled.
2064 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002065 }
2066 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002067 }
2068
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002069 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002070 if (mDeadWindowEventReceiver != null) {
2071 mDeadWindowEventReceiver.dispose();
2072 mDeadWindowEventReceiver = null;
2073 }
2074
2075 // unregister server channel first otherwise it complains about broken channel
2076 if (mInputChannel != null) {
2077 mService.mInputManager.unregisterInputChannel(mInputChannel);
2078 mInputChannel.dispose();
2079 mInputChannel = null;
2080 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002081 if (mClientChannel != null) {
2082 mClientChannel.dispose();
2083 mClientChannel = null;
2084 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002085 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002086 }
2087
Chong Zhang112eb8c2015-11-02 11:17:00 -08002088 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002089 // When the app is terminated (eg. from Recents), the task might have already been
2090 // removed with the window pending removal. Don't apply dim in such cases, as there
2091 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2092 final AppWindowToken token = mAppToken;
2093 if (token != null && token.removed) {
2094 return;
2095 }
2096
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002097 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002098 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002099 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002100 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002101 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002102 && dc != null && !mAnimatingExit && isVisibleUnchecked()) {
2103 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002104 }
2105 }
2106
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002107 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002108 Task task = getTask();
2109 if (task != null) {
2110 return task;
2111 }
2112 return getStack();
2113 }
2114
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002115 /** Returns true if the replacement window was removed. */
2116 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2117 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2118 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2119 removeReplacedWindow();
2120 return true;
2121 }
2122
2123 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002124 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002125 if (c.removeReplacedWindowIfNeeded(replacement)) {
2126 return true;
2127 }
2128 }
2129 return false;
2130 }
2131
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002132 void removeReplacedWindow() {
2133 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2134 if (isDimming()) {
2135 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002136 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002137 mWillReplaceWindow = false;
2138 mAnimateReplacingWindow = false;
2139 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002140 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002141 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002142 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002143 }
2144 }
2145
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002146 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2147 boolean replacementSet = false;
2148
2149 if (mWillReplaceWindow && mReplacementWindow == null
2150 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2151
2152 mReplacementWindow = replacementCandidate;
2153 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2154 replacementSet = true;
2155 }
2156
2157 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002158 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002159 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2160 }
2161
2162 return replacementSet;
2163 }
2164
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002165 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002166 final DisplayContent dc = getDisplayContent();
2167 if (dc != null) {
2168 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002169 }
2170 }
2171
Robert Carrfed10072016-05-26 11:48:49 -07002172 // TODO: Strange usage of word workspace here and above.
2173 boolean inPinnedWorkspace() {
2174 final Task task = getTask();
2175 return task != null && task.inPinnedWorkspace();
2176 }
2177
Chong Zhang5117e272016-05-03 12:47:34 -07002178 void applyAdjustForImeIfNeeded() {
2179 final Task task = getTask();
2180 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2181 task.mStack.applyAdjustForImeIfNeeded(task);
2182 }
2183 }
2184
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002185 int getTouchableRegion(Region region, int flags) {
2186 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002187 if (modal && mAppToken != null) {
2188 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002189 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002190 // If this is a modal window we need to dismiss it if it's not full screen and the
2191 // touch happens outside of the frame that displays the content. This means we
2192 // need to intercept touches outside of that window. The dim layer user
2193 // associated with the window (task or stack) will give us the good bounds, as
2194 // they would be used to display the dim layer.
2195 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2196 if (dimLayerUser != null) {
2197 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002198 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002199 getVisibleBounds(mTmpRect);
2200 }
2201 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002202 // For freeform windows we the touch region to include the whole surface for the
2203 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002204 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2205 final int delta = WindowManagerService.dipToPixel(
2206 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2207 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002208 }
2209 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002210 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002211 } else {
2212 // Not modal or full screen modal
2213 getTouchableRegion(region);
2214 }
2215 return flags;
2216 }
2217
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002218 void checkPolicyVisibilityChange() {
2219 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2220 if (DEBUG_VISIBILITY) {
2221 Slog.v(TAG, "Policy visibility changing after anim in " +
2222 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2223 }
2224 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002225 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002226 if (!mPolicyVisibility) {
2227 if (mService.mCurrentFocus == this) {
2228 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2229 "setAnimationLocked: setting mFocusMayChange true");
2230 mService.mFocusMayChange = true;
2231 }
2232 // Window is no longer visible -- make sure if we were waiting
2233 // for it to be displayed before enabling the display, that
2234 // we allow the display to be enabled now.
2235 mService.enableScreenIfNeededLocked();
2236 }
2237 }
2238 }
2239
2240 void setRequestedSize(int requestedWidth, int requestedHeight) {
2241 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2242 mLayoutNeeded = true;
2243 mRequestedWidth = requestedWidth;
2244 mRequestedHeight = requestedHeight;
2245 }
2246 }
2247
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002248 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
2249 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2250 == SOFT_INPUT_ADJUST_RESIZE) {
2251 mLayoutNeeded = true;
2252 }
2253 if (isDrawnLw() && mService.okToDisplay()) {
2254 mWinAnimator.applyEnterAnimationLocked();
2255 }
2256 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2257 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2258 mTurnOnScreen = true;
2259 }
2260 if (isConfigChanged()) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002261 outConfig.setTo(getConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002262 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002263 + outConfig);
2264 mLastReportedConfiguration.setTo(outConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002265 }
2266 }
2267
2268 void adjustStartingWindowFlags() {
2269 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2270 && mAppToken.startingWindow != null) {
2271 // Special handling of starting window over the base
2272 // window of the app: propagate lock screen flags to it,
2273 // to provide the correct semantics while starting.
2274 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2275 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2276 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2277 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2278 }
2279 }
2280
2281 void setWindowScale(int requestedWidth, int requestedHeight) {
2282 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2283
2284 if (scaledWindow) {
2285 // requested{Width|Height} Surface's physical size
2286 // attrs.{width|height} Size on screen
2287 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2288 mHScale = (mAttrs.width != requestedWidth) ?
2289 (mAttrs.width / (float)requestedWidth) : 1.0f;
2290 mVScale = (mAttrs.height != requestedHeight) ?
2291 (mAttrs.height / (float)requestedHeight) : 1.0f;
2292 } else {
2293 mHScale = mVScale = 1;
2294 }
2295 }
2296
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002297 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002298 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002299 public void binderDied() {
2300 try {
2301 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002302 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002303 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002304 if (win != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002305 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002306 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2307 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002308 // just in case they have the divider at an unstable position. Better
2309 // also reset drag resizing state, because the owner can't do it
2310 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002311 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
2312 if (stack != null) {
2313 stack.resetDockedStackToMiddle();
2314 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002315 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002316 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002317 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002318 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002319 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002320 }
2321 }
2322 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002323 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002324 }
2325 }
2326 }
2327
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002328 /**
2329 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2330 * because we want to preserve its location on screen to be re-activated later when the user
2331 * interacts with it.
2332 */
2333 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002334 if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002335 // Not a visible app window or the app isn't dead.
2336 return false;
2337 }
2338
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002339 if (mAttrs.token != mClient.asBinder()) {
2340 // The window was add by a client using another client's app token. We don't want to
2341 // keep the dead window around for this case since this is meant for 'real' apps.
2342 return false;
2343 }
2344
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002345 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2346 // We don't keep starting windows since they were added by the window manager before
2347 // the app even launched.
2348 return false;
2349 }
2350
2351 final TaskStack stack = getStack();
2352 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2353 }
2354
Wale Ogunwaled045c822015-12-02 09:14:28 -08002355 /** @return true if this window desires key events. */
2356 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002357 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002358 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002359 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002360 && (mAppToken == null || mAppToken.windowsAreFocusable())
2361 && !isAdjustedForMinimizedDock();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002362 }
2363
Craig Mautner749a7bb2012-04-02 13:49:53 -07002364 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002365 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002366 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002367 }
2368
Craig Mautner749a7bb2012-04-02 13:49:53 -07002369 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002370 public boolean showLw(boolean doAnimation) {
2371 return showLw(doAnimation, true);
2372 }
2373
2374 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002375 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002376 return false;
2377 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002378 if (!mAppOpVisibility) {
2379 // Being hidden due to app op request.
2380 return false;
2381 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002382 if (mPermanentlyHidden) {
2383 // Permanently hidden until the app exists as apps aren't prepared
2384 // to handle their windows being removed from under them.
2385 return false;
2386 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002387 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002388 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002389 return false;
2390 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002391 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002392 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002393 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002394 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07002395 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002396 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002397 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002398 // Check for the case where we are currently visible and
2399 // not animating; we do not want to do animation at such a
2400 // point to become visible when we already are.
2401 doAnimation = false;
2402 }
2403 }
2404 mPolicyVisibility = true;
2405 mPolicyVisibilityAfterAnim = true;
2406 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002407 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002408 }
2409 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002410 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002411 }
2412 return true;
2413 }
2414
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002415 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002416 public boolean hideLw(boolean doAnimation) {
2417 return hideLw(doAnimation, true);
2418 }
2419
2420 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2421 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07002422 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002423 doAnimation = false;
2424 }
2425 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002426 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002427 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002428 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002429 return false;
2430 }
2431 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002432 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002433 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002434 doAnimation = false;
2435 }
2436 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002437 mPolicyVisibilityAfterAnim = false;
2438 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002439 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002440 mPolicyVisibility = false;
2441 // Window is no longer visible -- make sure if we were waiting
2442 // for it to be displayed before enabling the display, that
2443 // we allow the display to be enabled now.
2444 mService.enableScreenIfNeededLocked();
2445 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002446 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002447 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002448 mService.mFocusMayChange = true;
2449 }
2450 }
2451 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002452 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002453 }
2454 return true;
2455 }
2456
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002457 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002458 if (mAppOpVisibility != state) {
2459 mAppOpVisibility = state;
2460 if (state) {
2461 // If the policy visibility had last been to hide, then this
2462 // will incorrectly show at this point since we lost that
2463 // information. Not a big deal -- for the windows that have app
2464 // ops modifies they should only be hidden by policy due to the
2465 // lock screen, and the user won't be changing this if locked.
2466 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002467 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002468 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002469 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002470 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002471 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002472 }
2473
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002474 public void hidePermanentlyLw() {
2475 if (!mPermanentlyHidden) {
2476 mPermanentlyHidden = true;
2477 hideLw(true, true);
2478 }
2479 }
2480
Jeff Brownc2932a12014-11-20 18:04:05 -08002481 public void pokeDrawLockLw(long timeout) {
2482 if (isVisibleOrAdding()) {
2483 if (mDrawLock == null) {
2484 // We want the tag name to be somewhat stable so that it is easier to correlate
2485 // in wake lock statistics. So in particular, we don't want to include the
2486 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002487 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002488 mDrawLock = mService.mPowerManager.newWakeLock(
2489 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2490 mDrawLock.setReferenceCounted(false);
2491 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2492 }
2493 // Each call to acquire resets the timeout.
2494 if (DEBUG_POWER) {
2495 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2496 + mAttrs.packageName);
2497 }
2498 mDrawLock.acquire(timeout);
2499 } else if (DEBUG_POWER) {
2500 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2501 + "owned by " + mAttrs.packageName);
2502 }
2503 }
2504
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002505 @Override
2506 public boolean isAlive() {
2507 return mClient.asBinder().isBinderAlive();
2508 }
2509
Craig Mautnera987d432012-10-11 14:07:58 -07002510 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002511 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002512 }
2513
Chong Zhangbef461f2015-10-27 11:38:24 -07002514 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002515 return mAnimatingWithSavedSurface;
2516 }
2517
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002518 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002519 boolean isAnimating() {
2520 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2521 return true;
2522 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002523 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002524 }
2525
Chong Zhang8e4bda92016-05-04 15:08:18 -07002526 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002527 if (mAnimatingWithSavedSurface
2528 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2529 return true;
2530 }
2531 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002532 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002533 if (c.isAnimatingInvisibleWithSavedSurface()) {
2534 return true;
2535 }
2536 }
2537 return false;
2538 }
2539
2540 void stopUsingSavedSurface() {
2541 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002542 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002543 c.stopUsingSavedSurface();
2544 }
2545
2546 if (!isAnimatingInvisibleWithSavedSurface()) {
2547 return;
2548 }
2549
2550 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2551 clearAnimatingWithSavedSurface();
2552 mDestroying = true;
2553 mWinAnimator.hide("stopUsingSavedSurface");
2554 mService.mWallpaperControllerLocked.hideWallpapers(this);
2555 }
2556
2557 void markSavedSurfaceExiting() {
2558 if (isAnimatingInvisibleWithSavedSurface()) {
2559 mAnimatingExit = true;
2560 mWinAnimator.mAnimating = true;
2561 }
2562 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002563 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002564 c.markSavedSurfaceExiting();
2565 }
2566 }
2567
2568 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2569 animators.add(mWinAnimator);
2570
2571 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002572 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002573 c.addWinAnimatorToList(animators);
2574 }
2575 }
2576
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002577 void sendAppVisibilityToClients() {
2578 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002579
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002580 final boolean clientHidden = mAppToken.clientHidden;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002581 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2582 // Don't hide the starting window.
2583 return;
2584 }
2585
2586 try {
2587 if (DEBUG_VISIBILITY) Slog.v(TAG,
2588 "Setting visibility of " + this + ": " + (!clientHidden));
2589 mClient.dispatchAppVisibility(!clientHidden);
2590 } catch (RemoteException e) {
2591 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002592 }
2593
Chong Zhang92147042016-05-09 12:47:11 -07002594 public void setVisibleBeforeClientHidden() {
2595 mWasVisibleBeforeClientHidden |=
2596 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002597
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002598 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002599 }
2600
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002601 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002602 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002603 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002604 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002605 c.clearWasVisibleBeforeClientHidden();
2606 }
Chong Zhang92147042016-05-09 12:47:11 -07002607 }
2608
2609 public boolean wasVisibleBeforeClientHidden() {
2610 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002611 }
2612
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002613 void onStartFreezingScreen() {
2614 mAppFreezing = true;
2615 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002616 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002617 c.onStartFreezingScreen();
2618 }
2619 }
2620
2621 boolean onStopFreezingScreen() {
2622 boolean unfrozeWindows = false;
2623 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002624 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002625 unfrozeWindows |= c.onStopFreezingScreen();
2626 }
2627
2628 if (!mAppFreezing) {
2629 return unfrozeWindows;
2630 }
2631
Wale Ogunwale953171d2016-09-30 09:17:30 -07002632 mAppFreezing = false;
2633
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002634 if (mHasSurface && !mOrientationChanging
2635 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2636 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
2637 mOrientationChanging = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002638 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002639 }
2640 mLastFreezeDuration = 0;
2641 setDisplayLayoutNeeded();
2642 return true;
2643 }
2644
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002645 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002646 if (mWinAnimator.mSurfaceController == null) {
2647 // Don't bother if the surface controller is gone for any reason.
2648 return false;
2649 }
2650
Chong Zhang92147042016-05-09 12:47:11 -07002651 if (!mWasVisibleBeforeClientHidden) {
2652 return false;
2653 }
2654
Wale Ogunwale945d1972016-03-23 13:16:41 -07002655 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2656 // We don't save secure surfaces since their content shouldn't be shown while the app
2657 // isn't on screen and content might leak through during the transition animation with
2658 // saved surface.
2659 return false;
2660 }
2661
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002662 if (ActivityManager.isLowRamDeviceStatic()) {
2663 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002664 return false;
2665 }
2666
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002667 Task task = getTask();
2668 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002669 // Don't save surfaces for home stack apps. These usually resume and draw
2670 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002671 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002672 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002673
2674 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2675 if (taskTop != null && taskTop != mAppToken) {
2676 // Don't save if the window is not the topmost window.
2677 return false;
2678 }
2679
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002680 if (mResizedWhileGone) {
2681 // Somebody resized our window while we were gone for layout, which means that the
2682 // client got an old size, so we have an outdated surface here.
2683 return false;
2684 }
2685
Robert Carr7098dbd2016-02-01 12:31:01 -08002686 if (DEBUG_DISABLE_SAVING_SURFACES) {
2687 return false;
2688 }
2689
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002690 return mAppToken.shouldSaveSurface();
2691 }
2692
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002693 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2694 boolean destroyedSomething = false;
2695 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002696 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002697 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2698 }
2699
2700 if (appStopped || mWindowRemovalAllowed || cleanupOnResume) {
2701
2702 mWinAnimator.destroyPreservedSurfaceLocked();
2703
2704 if (mDestroying) {
2705 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2706 + " destroySurfaces: appStopped=" + appStopped
2707 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2708 + " win.mRemoveOnExit=" + mRemoveOnExit);
2709
2710 if (!cleanupOnResume || mRemoveOnExit) {
2711 destroyOrSaveSurface();
2712 }
2713 if (mRemoveOnExit) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002714 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002715 }
2716 if (cleanupOnResume) {
2717 requestUpdateWallpaperIfNeeded();
2718 }
2719 mDestroying = false;
2720 destroyedSomething = true;
2721 }
2722 }
2723 return destroyedSomething;
2724 }
Chris Craik3131bde2016-05-06 13:39:08 -07002725
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002726 void destroyOrSaveSurface() {
2727 mSurfaceSaved = shouldSaveSurface();
2728 if (mSurfaceSaved) {
2729 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2730 Slog.v(TAG, "Saving surface: " + this);
2731 }
Chris Craik3131bde2016-05-06 13:39:08 -07002732 // Previous user of the surface may have set a transparent region signaling a portion
2733 // doesn't need to be composited, so reset to default empty state.
2734 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002735
2736 mWinAnimator.hide("saved surface");
2737 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2738 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002739 // The client should have disconnected at this point, but if it doesn't,
2740 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2741 // the client can't reconnect to the buffer queue, and rendering will fail.
2742 if (mWinAnimator.mSurfaceController != null) {
2743 mWinAnimator.mSurfaceController.disconnectInTransaction();
2744 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002745 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002746 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002747 mWinAnimator.destroySurfaceLocked();
2748 }
Chong Zhang92147042016-05-09 12:47:11 -07002749 // Clear animating flags now, since the surface is now gone. (Note this is true even
2750 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2751 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002752 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002753
Chong Zhang92147042016-05-09 12:47:11 -07002754 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002755 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002756 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002757 c.destroySavedSurface();
2758 }
2759
Robert Carr13f7be9e2015-12-02 18:39:45 -08002760 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002761 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002762 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002763 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002764 }
Chong Zhang92147042016-05-09 12:47:11 -07002765 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002766 }
2767
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002768 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2769 int restoreSavedSurfaceForInterestingWindow() {
2770 int interestingNotDrawn = -1;
2771 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002772 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002773 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2774 if (childInterestingNotDrawn != -1) {
2775 if (interestingNotDrawn == -1) {
2776 interestingNotDrawn = childInterestingNotDrawn;
2777 } else {
2778 interestingNotDrawn += childInterestingNotDrawn;
2779 }
2780 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002781 }
Robert Carr237028a2016-07-26 10:39:45 -07002782
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002783 if (mAttrs.type == TYPE_APPLICATION_STARTING
2784 || mAppDied || !wasVisibleBeforeClientHidden()
2785 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2786 // Window isn't interesting...
2787 return interestingNotDrawn;
2788 }
2789
2790 restoreSavedSurface();
2791
2792 if (!isDrawnLw()) {
2793 if (interestingNotDrawn == -1) {
2794 interestingNotDrawn = 1;
2795 } else {
2796 interestingNotDrawn++;
2797 }
2798 }
2799 return interestingNotDrawn;
2800 }
2801
2802 /** Returns true if the saved surface was restored. */
2803 boolean restoreSavedSurface() {
2804 if (!mSurfaceSaved) {
2805 return false;
2806 }
2807
2808 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2809 // However this means the surface was never laid out in the new orientation.
2810 // We can only restore to the last rotation we were laid out as visible in.
Robert Carr237028a2016-07-26 10:39:45 -07002811 if (mLastVisibleLayoutRotation != mService.mRotation) {
2812 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002813 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002814 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002815 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002816
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002817 if (mWinAnimator.mSurfaceController != null) {
2818 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002819 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002820 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002821
Chong Zhang6e9872b2016-08-17 10:19:05 -07002822 requestUpdateWallpaperIfNeeded();
2823
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002824 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2825 Slog.v(TAG, "Restoring saved surface: " + this);
2826 }
2827 } else {
2828 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2829 // this point. Even if we destroyed the saved surface because of rotation
2830 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2831 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002832 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002833
2834 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002835 }
2836
Chong Zhang92147042016-05-09 12:47:11 -07002837 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002838 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2839 return true;
2840 }
2841
2842 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002843 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002844 if (c.canRestoreSurface()) {
2845 return true;
2846 }
2847 }
2848
2849 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002850 }
2851
2852 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002853 return mSurfaceSaved;
2854 }
2855
Chong Zhang92147042016-05-09 12:47:11 -07002856 void clearHasSavedSurface() {
2857 mSurfaceSaved = false;
2858 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002859 if (mWasVisibleBeforeClientHidden) {
2860 mAppToken.destroySavedSurfaces();
2861 }
Chong Zhang92147042016-05-09 12:47:11 -07002862 }
2863
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002864 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002865 if (mAnimatingWithSavedSurface) {
2866 // App has drawn something to its windows, we're no longer animating with
2867 // the saved surfaces.
2868 if (DEBUG_ANIM) Slog.d(TAG,
2869 "clearAnimatingWithSavedSurface(): win=" + this);
2870 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002871 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002872 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002873 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002874 }
2875
Craig Mautner69b08182012-09-05 13:07:13 -07002876 @Override
2877 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002878 final DisplayContent displayContent = getDisplayContent();
2879 if (displayContent == null) {
2880 // Only a window that was on a non-default display can be detached from it.
2881 return false;
2882 }
Winson Chung47a3e652014-05-21 16:03:42 -07002883 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002884 }
2885
Adrian Rooscd3884d2015-02-18 17:25:23 +01002886 @Override
2887 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002888 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002889 final DisplayContent dc = getDisplayContent();
2890 return dimLayerUser != null && dc != null
2891 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002892 }
2893
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002894 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002895 mShowToOwnerOnly = showToOwnerOnly;
2896 }
2897
Craig Mautner5962b122012-10-05 14:45:52 -07002898 boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002899 // Child windows are evaluated based on their parent window.
2900 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002901 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07002902 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002903
2904 // All window frames that are fullscreen extend above status bar, but some don't extend
2905 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2906 // bottom right.
2907 if (win.mFrame.left <= win.mDisplayFrame.left
2908 && win.mFrame.top <= win.mDisplayFrame.top
2909 && win.mFrame.right >= win.mStableFrame.right
2910 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002911 // Is a fullscreen window, like the clock alarm. Show to everyone.
2912 return false;
2913 }
2914 }
2915
Craig Mautner341220f2012-10-16 15:20:09 -07002916 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002917 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002918 }
2919
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002920 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2921 outRegion.set(
2922 frame.left + inset.left, frame.top + inset.top,
2923 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002924 }
2925
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002926 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002927 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002928 switch (mTouchableInsets) {
2929 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002930 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002931 outRegion.set(frame);
2932 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002933 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002934 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002935 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002936 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002937 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002938 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002939 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002940 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002941 outRegion.translate(frame.left, frame.top);
2942 break;
2943 }
2944 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002945 cropRegionToStackBoundsIfNeeded(outRegion);
2946 }
2947
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002948 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002949 final Task task = getTask();
2950 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002951 return;
2952 }
2953
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002954 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002955 if (stack == null) {
2956 return;
2957 }
2958
2959 stack.getDimBounds(mTmpRect);
2960 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002961 }
2962
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002963 /**
2964 * Report a focus change. Must be called with no locks held, and consistently
2965 * from the same serialized thread (such as dispatched from a handler).
2966 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002967 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002968 try {
2969 mClient.windowFocusChanged(focused, inTouchMode);
2970 } catch (RemoteException e) {
2971 }
2972 if (mFocusCallbacks != null) {
2973 final int N = mFocusCallbacks.beginBroadcast();
2974 for (int i=0; i<N; i++) {
2975 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2976 try {
2977 if (focused) {
2978 obs.focusGained(mWindowId.asBinder());
2979 } else {
2980 obs.focusLost(mWindowId.asBinder());
2981 }
2982 } catch (RemoteException e) {
2983 }
2984 }
2985 mFocusCallbacks.finishBroadcast();
2986 }
2987 }
2988
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002989 @Override
2990 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002991 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002992 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002993 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002994
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002995 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002996 }
2997
Craig Mautnerdf88d732014-01-27 09:21:32 -08002998 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002999 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003000 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003001 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3002 + ": " + mCompatFrame);
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003003 final Configuration newConfig;
3004 if (isConfigChanged()) {
3005 newConfig = new Configuration(getConfiguration());
3006 mLastReportedConfiguration.setTo(newConfig);
3007 } else {
3008 newConfig = null;
3009 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003010 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003011 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3012
Craig Mautnerdf88d732014-01-27 09:21:32 -08003013 final Rect frame = mFrame;
3014 final Rect overscanInsets = mLastOverscanInsets;
3015 final Rect contentInsets = mLastContentInsets;
3016 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003017 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003018 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003019 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07003020 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3021 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003022 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3023 mService.mH.post(new Runnable() {
3024 @Override
3025 public void run() {
3026 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003027 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
3028 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003029 } catch (RemoteException e) {
3030 // Not a remote call, RemoteException won't be raised.
3031 }
3032 }
3033 });
3034 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003035 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003036 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003037 }
Svetoslav4604abc2014-06-10 18:59:30 -07003038
3039 //TODO (multidisplay): Accessibility supported only for the default display.
3040 if (mService.mAccessibilityController != null
3041 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003042 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003043 }
3044
Craig Mautnerdf88d732014-01-27 09:21:32 -08003045 mOverscanInsetsChanged = false;
3046 mContentInsetsChanged = false;
3047 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003048 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003049 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003050 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003051 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003052 mWinAnimator.mSurfaceResized = false;
3053 } catch (RemoteException e) {
3054 mOrientationChanging = false;
3055 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3056 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003057 // We are assuming the hosting process is dead or in a zombie state.
3058 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3059 + ", removing this window.");
3060 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003061 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003062 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003063 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003064 }
3065
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003066 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003067 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3068 // start even if we haven't received the relayout window, so that the client requests
3069 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3070 // until the window to small size, otherwise the multithread renderer will shift last
3071 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3072 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003073 boolean resizing = isDragResizing() || isDragResizeChanged();
3074 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3075 return frame;
3076 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003077 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003078 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003079 return mTmpRect;
3080 }
3081
Jorim Jaggi86905582016-02-09 21:36:09 -08003082 @Override
3083 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003084 final TaskStack stack = getStack();
3085 if (stack == null) {
3086 return INVALID_STACK_ID;
3087 }
3088 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003089 }
3090
3091 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3092 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
3093 Configuration newConfig) throws RemoteException {
Chong Zhangedaf3052016-04-22 15:04:31 -07003094 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing;
3095
Jorim Jaggidc249c42015-12-15 14:57:31 -08003096 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08003097 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07003098 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003099 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003100 }
3101
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003102 public void registerFocusObserver(IWindowFocusObserver observer) {
3103 synchronized(mService.mWindowMap) {
3104 if (mFocusCallbacks == null) {
3105 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3106 }
3107 mFocusCallbacks.register(observer);
3108 }
3109 }
3110
3111 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3112 synchronized(mService.mWindowMap) {
3113 if (mFocusCallbacks != null) {
3114 mFocusCallbacks.unregister(observer);
3115 }
3116 }
3117 }
3118
3119 public boolean isFocused() {
3120 synchronized(mService.mWindowMap) {
3121 return mService.mCurrentFocus == this;
3122 }
3123 }
3124
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003125 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003126 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003127 return task != null && task.inFreeformWorkspace();
3128 }
3129
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003130 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003131 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003132 final Task task = getTask();
3133 return task != null && !task.isFullscreen();
3134 }
3135
Chong Zhang3005e752015-09-18 18:46:28 -07003136 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003137 return mDragResizing != computeDragResizing();
3138 }
3139
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003140 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003141 void setWaitingForDrawnIfResizingChanged() {
3142 if (isDragResizeChanged()) {
3143 mService.mWaitingForDrawn.add(this);
3144 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003145 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003146 }
3147
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003148 /**
3149 * @return Whether we reported a drag resize change to the application or not already.
3150 */
3151 boolean isDragResizingChangeReported() {
3152 return mDragResizingChangeReported;
3153 }
3154
3155 /**
3156 * Resets the state whether we reported a drag resize change to the app.
3157 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003158 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003159 void resetDragResizingChangeReported() {
3160 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003161 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003162 }
3163
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003164 /**
3165 * Set whether we got resized but drag resizing flag was false.
3166 * @see #isResizedWhileNotDragResizing().
3167 */
3168 void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
3169 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3170 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3171 }
3172
3173 /**
3174 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3175 * need to recreate the surface and defer surface bound updates in order to make sure the
3176 * buffer contents and the positioning/size stay in sync.
3177 */
3178 boolean isResizedWhileNotDragResizing() {
3179 return mResizedWhileNotDragResizing;
3180 }
3181
3182 /**
3183 * @return Whether we reported "resize while not drag resizing" to the application.
3184 * @see #isResizedWhileNotDragResizing()
3185 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003186 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003187 return mResizedWhileNotDragResizingReported;
3188 }
3189
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003190 int getResizeMode() {
3191 return mResizeMode;
3192 }
3193
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003194 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003195 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003196 if (task == null) {
3197 return false;
3198 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003199 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
3200
3201 // Floating windows never enter drag resize mode.
3202 return false;
3203 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003204 if (task.isDragResizing()) {
3205 return true;
3206 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003207
3208 // If the bounds are currently frozen, it means that the layout size that the app sees
3209 // and the bounds we clip this window to might be different. In order to avoid holes, we
3210 // simulate that we are still resizing so the app fills the hole with the resizing
3211 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003212 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003213 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003214 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003215
Chong Zhang3005e752015-09-18 18:46:28 -07003216 }
3217
3218 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003219 final boolean resizing = computeDragResizing();
3220 if (resizing == mDragResizing) {
3221 return;
3222 }
3223 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003224 final Task task = getTask();
3225 if (task != null && task.isDragResizing()) {
3226 mResizeMode = task.getDragResizeMode();
3227 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003228 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003229 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3230 : DRAG_RESIZE_MODE_FREEFORM;
3231 }
Chong Zhang3005e752015-09-18 18:46:28 -07003232 }
3233
3234 boolean isDragResizing() {
3235 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003236 }
3237
Robert Carr2487ce72016-04-07 15:18:45 -07003238 boolean isDockedResizing() {
3239 return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
3240 }
3241
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003242 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003243 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003244 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003245 if (stack != null) {
3246 pw.print(" stackId="); pw.print(stack.mStackId);
3247 }
Craig Mautner59c00972012-07-30 12:10:24 -07003248 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003249 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003250 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003251 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3252 pw.print(" package="); pw.print(mAttrs.packageName);
3253 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003254 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003255 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3256 pw.print(" h="); pw.print(mRequestedHeight);
3257 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003258 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3259 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3260 pw.print(" h="); pw.println(mLastRequestedHeight);
3261 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003262 if (mIsChildWindow || mLayoutAttached) {
3263 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003264 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3265 }
3266 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3267 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3268 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3269 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3270 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3271 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003272 if (dumpAll) {
3273 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3274 pw.print(" mSubLayer="); pw.print(mSubLayer);
3275 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003276 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003277 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3278 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003279 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003280 if (dumpAll) {
3281 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003282 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003283 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3284 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003285 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08003286 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003287 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003288 pw.print(prefix); pw.print("mViewVisibility=0x");
3289 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003290 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3291 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003292 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3293 pw.print(" mSystemUiVisibility=0x");
3294 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003295 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003296 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Svetoslav Ganov71c51022016-09-02 17:54:37 -07003297 || isParentWindowHidden()|| mPermanentlyHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003298 pw.print(prefix); pw.print("mPolicyVisibility=");
3299 pw.print(mPolicyVisibility);
3300 pw.print(" mPolicyVisibilityAfterAnim=");
3301 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003302 pw.print(" mAppOpVisibility=");
3303 pw.print(mAppOpVisibility);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003304 pw.print(" parentHidden="); pw.println(isParentWindowHidden());
Svetoslav Ganovaa076532016-08-01 19:16:43 -07003305 pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003306 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003307 if (!mRelayoutCalled || mLayoutNeeded) {
3308 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3309 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003310 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003311 if (mXOffset != 0 || mYOffset != 0) {
3312 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3313 pw.print(" y="); pw.println(mYOffset);
3314 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003315 if (dumpAll) {
3316 pw.print(prefix); pw.print("mGivenContentInsets=");
3317 mGivenContentInsets.printShortString(pw);
3318 pw.print(" mGivenVisibleInsets=");
3319 mGivenVisibleInsets.printShortString(pw);
3320 pw.println();
3321 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3322 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3323 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003324 Region region = new Region();
3325 getTouchableRegion(region);
3326 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003327 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003328 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3329 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3330 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003331 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003332 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003333 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003334 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003335 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3336 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003337 if (dumpAll) {
3338 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3339 pw.print(" last="); mLastFrame.printShortString(pw);
3340 pw.println();
3341 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003342 if (mEnforceSizeCompat) {
3343 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003344 pw.println();
3345 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003346 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003347 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003348 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003349 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003350 pw.println();
3351 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3352 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003353 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003354 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003355 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003356 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003357 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3358 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003359 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3360 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003361 pw.print(prefix); pw.print("Cur insets: overscan=");
3362 mOverscanInsets.printShortString(pw);
3363 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003364 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003365 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003366 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003367 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003368 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003369 pw.print(prefix); pw.print("Lst insets: overscan=");
3370 mLastOverscanInsets.printShortString(pw);
3371 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003372 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003373 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003374 pw.print(" physical="); mLastOutsets.printShortString(pw);
3375 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003376 pw.println();
3377 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003378 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3379 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003380 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3381 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003382 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3383 pw.print(" mDestroying="); pw.print(mDestroying);
3384 pw.print(" mRemoved="); pw.println(mRemoved);
3385 }
3386 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
3387 pw.print(prefix); pw.print("mOrientationChanging=");
3388 pw.print(mOrientationChanging);
3389 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
3390 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
3391 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003392 if (mLastFreezeDuration != 0) {
3393 pw.print(prefix); pw.print("mLastFreezeDuration=");
3394 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3395 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003396 if (mHScale != 1 || mVScale != 1) {
3397 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3398 pw.print(" mVScale="); pw.println(mVScale);
3399 }
3400 if (mWallpaperX != -1 || mWallpaperY != -1) {
3401 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3402 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3403 }
3404 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3405 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3406 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3407 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003408 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3409 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3410 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3411 pw.print(mWallpaperDisplayOffsetX);
3412 pw.print(" mWallpaperDisplayOffsetY=");
3413 pw.println(mWallpaperDisplayOffsetY);
3414 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003415 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003416 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003417 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003418 if (isDragResizing()) {
3419 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3420 }
3421 if (computeDragResizing()) {
3422 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3423 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003424 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003425
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003426 @Override
3427 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003428 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003429 + " " + getWindowTag();
3430 }
3431
Robert Carra1eb4392015-12-10 12:43:51 -08003432 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003433 CharSequence tag = mAttrs.getTitle();
3434 if (tag == null || tag.length() <= 0) {
3435 tag = mAttrs.packageName;
3436 }
3437 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003438 }
3439
3440 @Override
3441 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003442 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003443 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003444 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003445 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003446 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003447 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003448 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003449 }
3450 return mStringNameCache;
3451 }
Robert Carr58f29132015-10-29 14:19:05 -07003452
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003453 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003454 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003455 clipRect.left = (int) (clipRect.left / mHScale);
3456 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003457 }
3458 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003459 clipRect.top = (int) (clipRect.top / mVScale);
3460 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003461 }
3462 }
Robert Carr31e28482015-12-02 16:53:18 -08003463
Jorim Jaggif5834272016-04-04 20:25:41 -07003464 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3465 final int pw = containingFrame.width();
3466 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003467 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07003468 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003469 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3470
3471 // We need to fit it to the display if either
3472 // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless
3473 // windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003474 // b) If it's a secondary app window, we also need to fit it to the display unless
3475 // 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 -07003476 // but SurfaceViews want to be always at a specific location so we don't fit it to the
3477 // display.
3478 final boolean fitToDisplay = (task == null || !nonFullscreenTask)
Robert Carr6f44db12016-07-21 14:54:43 -07003479 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003480 float x, y;
3481 int w,h;
3482
3483 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3484 if (mAttrs.width < 0) {
3485 w = pw;
3486 } else if (mEnforceSizeCompat) {
3487 w = (int)(mAttrs.width * mGlobalScale + .5f);
3488 } else {
3489 w = mAttrs.width;
3490 }
3491 if (mAttrs.height < 0) {
3492 h = ph;
3493 } else if (mEnforceSizeCompat) {
3494 h = (int)(mAttrs.height * mGlobalScale + .5f);
3495 } else {
3496 h = mAttrs.height;
3497 }
3498 } else {
3499 if (mAttrs.width == MATCH_PARENT) {
3500 w = pw;
3501 } else if (mEnforceSizeCompat) {
3502 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3503 } else {
3504 w = mRequestedWidth;
3505 }
3506 if (mAttrs.height == MATCH_PARENT) {
3507 h = ph;
3508 } else if (mEnforceSizeCompat) {
3509 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3510 } else {
3511 h = mRequestedHeight;
3512 }
3513 }
3514
3515 if (mEnforceSizeCompat) {
3516 x = mAttrs.x * mGlobalScale;
3517 y = mAttrs.y * mGlobalScale;
3518 } else {
3519 x = mAttrs.x;
3520 y = mAttrs.y;
3521 }
3522
Robert Carr1d2bacb2016-03-30 14:29:35 -07003523 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003524 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003525 // required by {@link Gravity#apply} call.
3526 w = Math.min(w, pw);
3527 h = Math.min(h, ph);
3528 }
3529
3530 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003531 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003532 (int) (x + mAttrs.horizontalMargin * pw),
3533 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3534
3535 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003536 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003537 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003538 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003539
3540 // We need to make sure we update the CompatFrame as it is used for
3541 // cropping decisions, etc, on systems where we lack a decor layer.
3542 mCompatFrame.set(mFrame);
3543 if (mEnforceSizeCompat) {
3544 // See comparable block in computeFrameLw.
3545 mCompatFrame.scale(mInvGlobalScale);
3546 }
Robert Carr31e28482015-12-02 16:53:18 -08003547 }
Robert Carr51a1b872015-12-08 14:03:13 -08003548
3549 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003550 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003551 }
3552
3553 /**
3554 * Returns the bottom child window in regards to z-order of this window or null if no children.
3555 */
3556 WindowState getBottomChild() {
3557 // Child windows are z-ordered based on sub-layer using {@link #sWindowSubLayerComparator}
3558 // and the child with the lowest z-order will be at the head of the list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003559 WindowState c = mChildren.peekFirst();
3560 return c == null ? null : c;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003561 }
3562
Robert Carrf3b72c72016-03-21 18:16:39 -07003563 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003564 return mIsChildWindow
3565 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003566 }
3567
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003568 /** Returns the parent window if this is a child of another window, else null. */
3569 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003570 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3571 // WindowContainer that isn't a WindowState.
3572 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003573 }
3574
3575 /** Returns the topmost parent window if this is a child of another window, else this. */
3576 WindowState getTopParentWindow() {
3577 WindowState w = this;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07003578 while (w != null && w.mIsChildWindow) {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003579 w = w.getParentWindow();
3580 }
3581 return w;
3582 }
3583
Wale Ogunwale9d147902016-07-16 11:58:55 -07003584 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003585 final WindowState parent = getParentWindow();
3586 return (parent == null) ? false : parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003587 }
3588
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003589 void setWillReplaceWindow(boolean animate) {
3590 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003591 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003592 c.setWillReplaceWindow(animate);
3593 }
3594
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003595 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3596 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3597 // We don't set replacing on starting windows since they are added by window manager and
3598 // not the client so won't be replaced by the client.
3599 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003600 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003601
3602 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003603 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003604 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003605 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003606
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003607 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003608 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003609 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003610 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003611
3612 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003613 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003614 c.clearWillReplaceWindow();
3615 }
3616 }
3617
3618 boolean waitingForReplacement() {
3619 if (mWillReplaceWindow) {
3620 return true;
3621 }
3622
3623 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003624 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003625 if (c.waitingForReplacement()) {
3626 return true;
3627 }
3628 }
3629 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003630 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003631
Chong Zhang4d7369a2016-04-25 16:09:14 -07003632 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003633 final DisplayContent dc = getDisplayContent();
3634 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3635 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3636 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003637 mService.mWindowPlacerLocked.requestTraversal();
3638 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003639
3640 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003641 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003642 c.requestUpdateWallpaperIfNeeded();
3643 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003644 }
3645
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003646 float translateToWindowX(float x) {
3647 float winX = x - mFrame.left;
3648 if (mEnforceSizeCompat) {
3649 winX *= mGlobalScale;
3650 }
3651 return winX;
3652 }
3653
3654 float translateToWindowY(float y) {
3655 float winY = y - mFrame.top;
3656 if (mEnforceSizeCompat) {
3657 winY *= mGlobalScale;
3658 }
3659 return winY;
3660 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003661
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003662 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003663 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003664 final DisplayContent dc = getDisplayContent();
3665 if (dimLayerUser != null && dc != null) {
3666 dc.mDimLayerController.applyDim(dimLayerUser,
3667 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003668 }
3669 }
3670
Robert Carrd1a010f2016-04-07 22:36:22 -07003671 // During activity relaunch due to resize, we sometimes use window replacement
3672 // for only child windows (as the main window is handled by window preservation)
3673 // and the big surface.
3674 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003675 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3676 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3677 // we also want to replace them at such phases, as they won't be covered by window
3678 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003679 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003680 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003681 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003682 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003683
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003684 void setWillReplaceChildWindows() {
3685 if (shouldBeReplacedWithChildren()) {
3686 setWillReplaceWindow(false /* animate */);
3687 }
3688 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003689 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003690 c.setWillReplaceChildWindows();
3691 }
3692 }
3693
3694 WindowState getReplacingWindow() {
3695 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3696 return this;
3697 }
3698 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003699 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003700 final WindowState replacing = c.getReplacingWindow();
3701 if (replacing != null) {
3702 return replacing;
3703 }
3704 }
3705 return null;
3706 }
3707
Robert Carrfd10cd12016-06-29 16:41:50 -07003708 public int getRotationAnimationHint() {
3709 if (mAppToken != null) {
3710 return mAppToken.mRotationAnimationHint;
3711 } else {
3712 return -1;
3713 }
3714 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003715
3716 // This must be called while inside a transaction.
3717 boolean performShowLocked() {
3718 if (isHiddenFromUserLocked()) {
3719 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3720 hideLw(false);
3721 return false;
3722 }
3723
3724 logPerformShow("performShow on ");
3725
3726 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplayIgnoringKeyguard()) {
3727 return false;
3728 }
3729
3730 logPerformShow("Showing ");
3731
3732 mService.enableScreenIfNeededLocked();
3733 mWinAnimator.applyEnterAnimationLocked();
3734
3735 // Force the show in the next prepareSurfaceLocked() call.
3736 mWinAnimator.mLastAlpha = -1;
3737 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3738 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3739 mWinAnimator.mDrawState = HAS_DRAWN;
3740 mService.scheduleAnimationLocked();
3741
3742 if (mHidden) {
3743 mHidden = false;
3744 final DisplayContent displayContent = getDisplayContent();
3745
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003746 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003747 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003748 if (c.mWinAnimator.mSurfaceController != null) {
3749 c.performShowLocked();
3750 // It hadn't been shown, which means layout not performed on it, so now we
3751 // want to make sure to do a layout. If called from within the transaction
3752 // loop, this will cause it to restart with a new layout.
3753 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003754 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003755 }
3756 }
3757 }
3758 }
3759
3760 if (mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3761 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3762 }
3763
3764 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003765 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003766 }
3767
3768 return true;
3769 }
3770
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003771 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003772 if (DEBUG_VISIBILITY
3773 || (DEBUG_STARTING_WINDOW && mAttrs.type == TYPE_APPLICATION_STARTING)) {
3774 Slog.v(TAG, prefix + this
3775 + ": mDrawState=" + mWinAnimator.drawStateToString()
3776 + " readyForDisplay=" + isReadyForDisplayIgnoringKeyguard()
3777 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3778 + " during animation: policyVis=" + mPolicyVisibility
3779 + " parentHidden=" + isParentWindowHidden()
3780 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003781 + (mAppToken != null && mAppToken.hiddenRequested)
3782 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003783 + " animating=" + mWinAnimator.mAnimating
3784 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003785 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003786 + " Callers=" + Debug.getCallers(4));
3787 }
3788 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003789
3790 WindowInfo getWindowInfo() {
3791 WindowInfo windowInfo = WindowInfo.obtain();
3792 windowInfo.type = mAttrs.type;
3793 windowInfo.layer = mLayer;
3794 windowInfo.token = mClient.asBinder();
3795 windowInfo.title = mAttrs.accessibilityTitle;
3796 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3797 windowInfo.focused = isFocused();
3798
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003799 if (mIsChildWindow) {
3800 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003801 }
3802
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003803 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003804 if (childCount > 0) {
3805 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003806 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003807 }
3808 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003809 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003810 windowInfo.childTokens.add(child.mClient.asBinder());
3811 }
3812 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003813 return windowInfo;
3814 }
3815
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003816 int getHighestAnimLayer() {
3817 int highest = mWinAnimator.mAnimLayer;
3818 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003819 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003820 final int childLayer = c.getHighestAnimLayer();
3821 if (childLayer > highest) {
3822 highest = childLayer;
3823 }
3824 }
3825 return highest;
3826 }
3827
3828 int adjustAnimLayer(int adj) {
3829 int highestAnimLayer = mWinAnimator.mAnimLayer = mLayer + adj;
3830 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG_WM,
3831 "adjustAnimLayer win=" + this + " anim layer: " + mWinAnimator.mAnimLayer);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003832 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003833 final WindowState childWindow = mChildren.get(i);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003834 childWindow.adjustAnimLayer(adj);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003835 if (childWindow.mWinAnimator.mAnimLayer > highestAnimLayer) {
3836 highestAnimLayer = childWindow.mWinAnimator.mAnimLayer;
3837 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003838 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003839 return highestAnimLayer;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003840 }
3841
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003842 @Override
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003843 int rebuildWindowList(int addIndex) {
3844 return reAddWindow(addIndex);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003845 }
3846
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003847 // TODO: come-up with a better name for this method that represents what it does.
3848 // Or, it is probably not going to matter anyways if we are successful in getting rid of
3849 // the WindowList concept.
Wale Ogunwale92fc3722016-08-05 12:19:08 -07003850 int reAddWindow(int index) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003851 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003852 // Adding child windows relies on child windows being ordered by mSubLayer using
3853 // {@link #sWindowSubLayerComparator}.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003854 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003855 boolean winAdded = false;
3856 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003857 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003858 if (!winAdded && child.mSubLayer >= 0) {
3859 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3860 "Re-adding child window at " + index + ": " + child);
3861 mRebuilding = false;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003862 dc.addToWindowList(this, index);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003863 index++;
3864 winAdded = true;
3865 }
3866 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + child);
3867 child.mRebuilding = false;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003868 dc.addToWindowList(child, index);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003869 index++;
3870 }
3871 if (!winAdded) {
3872 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + this);
3873 mRebuilding = false;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003874 dc.addToWindowList(this, index);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003875 index++;
3876 }
3877 mService.mWindowsChanged = true;
3878 return index;
3879 }
3880
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003881 boolean isWindowAnimationSet() {
3882 if (mWinAnimator.isWindowAnimationSet()) {
3883 return true;
3884 }
3885 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003886 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003887 if (c.isWindowAnimationSet()) {
3888 return true;
3889 }
3890 }
3891 return false;
3892 }
3893
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003894 void onExitAnimationDone() {
3895 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3896 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
3897 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
3898
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003899 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003900 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003901 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003902 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003903 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003904 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003905 }
3906 }
3907
3908 if (mWinAnimator.mEnteringAnimation) {
3909 mWinAnimator.mEnteringAnimation = false;
3910 mService.requestTraversal();
3911 // System windows don't have an activity and an app token as a result, but need a way
3912 // to be informed about their entrance animation end.
3913 if (mAppToken == null) {
3914 try {
3915 mClient.dispatchWindowShown();
3916 } catch (RemoteException e) {
3917 }
3918 }
3919 }
3920
3921 if (!mWinAnimator.isWindowAnimationSet()) {
3922 //TODO (multidisplay): Accessibility is supported only for the default display.
3923 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3924 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3925 }
3926 }
3927
3928 if (!mAnimatingExit) {
3929 return;
3930 }
3931
3932 if (mWinAnimator.isWindowAnimationSet()) {
3933 return;
3934 }
3935
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003936 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003937 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3938
3939 mDestroying = true;
3940
3941 final boolean hasSurface = mWinAnimator.hasSurface();
3942 if (hasSurface) {
3943 mWinAnimator.hide("onExitAnimationDone");
3944 }
3945
3946 // If we have an app token, we ask it to destroy the surface for us, so that it can take
3947 // care to ensure the activity has actually stopped and the surface is not still in use.
3948 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
3949 // transaction.
3950 if (mAppToken != null) {
3951 mAppToken.destroySurfaces();
3952 } else {
3953 if (hasSurface) {
3954 mService.mDestroySurface.add(this);
3955 }
3956 if (mRemoveOnExit) {
3957 mService.mPendingRemove.add(this);
3958 mRemoveOnExit = false;
3959 }
3960 }
3961 mAnimatingExit = false;
3962 mService.mWallpaperControllerLocked.hideWallpapers(this);
3963 }
Dan Willemsen117197f2016-07-30 13:02:59 -07003964
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003965 boolean clearAnimatingFlags() {
3966 boolean didSomething = false;
3967 // We don't want to clear it out for windows that get replaced, because the
3968 // animation depends on the flag to remove the replaced window.
3969 //
3970 // We also don't clear the mAnimatingExit flag for windows which have the
3971 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
3972 // by the client. We should let animation proceed and not clear this flag or
3973 // they won't eventually be removed by WindowStateAnimator#finishExit.
3974 if (!mWillReplaceWindow && !mRemoveOnExit) {
3975 // Clear mAnimating flag together with mAnimatingExit. When animation
3976 // changes from exiting to entering, we need to clear this flag until the
3977 // new animation gets applied, so that isAnimationStarting() becomes true
3978 // until then.
3979 // Otherwise applySurfaceChangesTransaction will fail to skip surface
3980 // placement for this window during this period, one or more frame will
3981 // show up with wrong position or scale.
3982 if (mAnimatingExit) {
3983 mAnimatingExit = false;
3984 didSomething = true;
3985 }
3986 if (mWinAnimator.mAnimating) {
3987 mWinAnimator.mAnimating = false;
3988 didSomething = true;
3989 }
3990 if (mDestroying) {
3991 mDestroying = false;
3992 mService.mDestroySurface.remove(this);
3993 didSomething = true;
3994 }
3995 }
3996
3997 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003998 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003999 }
4000
4001 return didSomething;
4002 }
4003
Winson4b4ba902016-07-27 19:45:52 -07004004 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004005 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004006 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004007
4008 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004009 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004010 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004011 c.hideWallpaperWindow(wasDeferred, reason);
4012 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004013 if (!mWinAnimator.mLastHidden || wasDeferred) {
4014 mWinAnimator.hide(reason);
4015 dispatchWallpaperVisibility(false);
4016 final DisplayContent displayContent = getDisplayContent();
4017 if (displayContent != null) {
4018 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4019 }
4020 }
4021 }
4022
4023 /**
4024 * Check wallpaper window for visibility change and notify window if so.
4025 * @param visible Current visibility.
4026 */
4027 void dispatchWallpaperVisibility(final boolean visible) {
4028 final boolean hideAllowed =
4029 mService.mWallpaperControllerLocked.mDeferredHideWallpaper == null;
4030
4031 // Only send notification if the visibility actually changed and we are not trying to hide
4032 // the wallpaper when we are deferring hiding of the wallpaper.
4033 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4034 mWallpaperVisible = visible;
4035 try {
4036 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4037 "Updating vis of wallpaper " + this
4038 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4039 mClient.dispatchAppVisibility(visible);
4040 } catch (RemoteException e) {
4041 }
4042 }
4043 }
4044
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004045 boolean hasVisibleNotDrawnWallpaper() {
4046 if (mWallpaperVisible && !isDrawnLw()) {
4047 return true;
4048 }
4049 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004050 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004051 if (c.hasVisibleNotDrawnWallpaper()) {
4052 return true;
4053 }
4054 }
4055 return false;
4056 }
4057
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004058 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4059 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004060 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004061 c.updateReportedVisibility(results);
4062 }
4063
4064 if (mAppFreezing || mViewVisibility != View.VISIBLE
4065 || mAttrs.type == TYPE_APPLICATION_STARTING
4066 || mDestroying) {
4067 return;
4068 }
4069 if (DEBUG_VISIBILITY) {
4070 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4071 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4072 if (!isDrawnLw()) {
4073 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4074 + " pv=" + mPolicyVisibility
4075 + " mDrawState=" + mWinAnimator.mDrawState
4076 + " ph=" + isParentWindowHidden()
4077 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4078 + " a=" + mWinAnimator.mAnimating);
4079 }
4080 }
4081
4082 results.numInteresting++;
4083 if (isDrawnLw()) {
4084 results.numDrawn++;
4085 if (!mWinAnimator.isAnimationSet()) {
4086 results.numVisible++;
4087 }
4088 results.nowGone = false;
4089 } else if (mWinAnimator.isAnimationSet()) {
4090 results.nowGone = false;
4091 }
4092 }
4093
4094 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4095 // access to its windows children. Need to investigate re-writing
4096 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4097 static final class UpdateReportedVisibilityResults {
4098 int numInteresting;
4099 int numVisible;
4100 int numDrawn;
4101 boolean nowGone = true;
4102
4103 void reset() {
4104 numInteresting = 0;
4105 numVisible = 0;
4106 numDrawn = 0;
4107 nowGone = true;
4108 }
4109 }
satokcef37fb2011-10-24 21:49:38 +09004110}