blob: 4dbac7eb26b69596bb25fe26680df09adf6f1937 [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 Ogunwale9d147902016-07-16 11:58:55 -070028import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080029import android.os.IBinder;
30import android.os.PowerManager;
31import android.os.RemoteCallbackList;
32import android.os.RemoteException;
33import android.os.SystemClock;
34import android.os.Trace;
35import android.os.UserHandle;
36import android.os.WorkSource;
37import android.util.DisplayMetrics;
38import android.util.Slog;
39import android.util.TimeUtils;
40import android.view.Display;
41import android.view.DisplayInfo;
42import android.view.Gravity;
43import android.view.IApplicationToken;
44import android.view.IWindow;
45import android.view.IWindowFocusObserver;
46import android.view.IWindowId;
47import android.view.InputChannel;
48import android.view.InputEvent;
49import android.view.InputEventReceiver;
50import android.view.View;
51import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070052import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080053import android.view.WindowManager;
54import android.view.WindowManagerPolicy;
55
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080056import com.android.server.input.InputWindowHandle;
57
Wale Ogunwale053c8e42015-11-16 14:27:21 -080058import java.io.PrintWriter;
59import java.util.ArrayList;
60
Wale Ogunwaled045c822015-12-02 09:14:28 -080061import static android.app.ActivityManager.StackId;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -080062import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -080063import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070064import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070065import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080066import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
67import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
68import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
69import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080070import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080071import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070072import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080073import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggi5f23a572016-04-22 15:05:50 -070074import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080075import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
76import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080077import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale945d1972016-03-23 13:16:41 -070078import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Chong Zhang4d7369a2016-04-25 16:09:14 -070079import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070080import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080081import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080082import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080083import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080084import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080085import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080086import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Robert Carra1eb4392015-12-10 12:43:51 -080087import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080088import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
89import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Robert Carrd1a010f2016-04-07 22:36:22 -070090import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080091import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080092import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070093import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080094import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
95import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
96import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Chong Zhang4d7369a2016-04-25 16:09:14 -070097import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010098import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
99import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800100import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
101import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
102import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
103import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
104import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700105import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800106import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
107import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
108import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
109import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700110import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
111import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800112import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700113import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800114import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
115import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700116import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
117import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
118import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800119
Craig Mautner59c00972012-07-30 12:10:24 -0700120class WindowList extends ArrayList<WindowState> {
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800121 WindowList() {}
122 WindowList(WindowList windowList) {
123 super(windowList);
124 }
Craig Mautner59c00972012-07-30 12:10:24 -0700125}
126
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127/**
128 * A window in the window manager.
129 */
Craig Mautnere32c3072012-03-12 15:25:35 -0700130final class WindowState implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800131 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800132
Skuhne81c524a2015-08-12 13:34:14 -0700133 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700134 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
135 // use hard-coded min sizes for now.
136 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
137 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700138
139 // The thickness of a window resize handle outside the window bounds on the free form workspace
140 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700141 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700142
Robert Carr7098dbd2016-02-01 12:31:01 -0800143 static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
144
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800145 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700146 final WindowManagerPolicy mPolicy;
147 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148 final Session mSession;
149 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800150 final int mAppOp;
151 // UserId and appId of the owner. Don't display windows of non-current user.
152 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800153 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800154 WindowToken mToken;
155 WindowToken mRootToken;
156 AppWindowToken mAppToken;
157 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700158
159 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
160 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
162 final DeathRecipient mDeathRecipient;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700163 final WindowState mParentWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700164 private final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 final int mBaseLayer;
166 final int mSubLayer;
167 final boolean mLayoutAttached;
168 final boolean mIsImWindow;
169 final boolean mIsWallpaper;
170 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700171 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700172 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700174 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175 boolean mPolicyVisibility = true;
176 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800177 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700179 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700181 boolean mDragResizing;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800182 boolean mDragResizingChangeReported;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100183 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700184
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800185 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
186
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700187 /**
188 * The window size that was requested by the application. These are in
189 * the application's coordinate space (without compatibility scale applied).
190 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 int mRequestedWidth;
192 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700193 int mLastRequestedWidth;
194 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700195
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800196 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197 boolean mHaveFrame;
198 boolean mObscured;
199 boolean mTurnOnScreen;
200
201 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700202
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700203 private final Configuration mTmpConfig = new Configuration();
Robert Carrc24d8f92016-02-29 16:24:33 -0800204 // Represents the changes from our override configuration applied
205 // to the global configuration. This is the only form of configuration
206 // which is suitable for delivery to the client.
207 private Configuration mMergedConfiguration = new Configuration();
Craig Mautnere8552142012-11-07 13:55:47 -0800208 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
209 // Used only on {@link #TYPE_KEYGUARD}.
210 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700211
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700212 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700213 * Actual position of the surface shown on-screen (may be modified by animation). These are
214 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700215 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700216 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800217
218 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700219 * Insets that determine the actually visible area. These are in the application's
220 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 */
222 final Rect mVisibleInsets = new Rect();
223 final Rect mLastVisibleInsets = new Rect();
224 boolean mVisibleInsetsChanged;
225
226 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700227 * Insets that are covered by system windows (such as the status bar) and
228 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700229 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 */
231 final Rect mContentInsets = new Rect();
232 final Rect mLastContentInsets = new Rect();
233 boolean mContentInsetsChanged;
234
235 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800236 * Insets that determine the area covered by the display overscan region. These are in the
237 * application's coordinate space (without compatibility scale applied).
238 */
239 final Rect mOverscanInsets = new Rect();
240 final Rect mLastOverscanInsets = new Rect();
241 boolean mOverscanInsetsChanged;
242
243 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700244 * Insets that determine the area covered by the stable system windows. These are in the
245 * application's coordinate space (without compatibility scale applied).
246 */
247 final Rect mStableInsets = new Rect();
248 final Rect mLastStableInsets = new Rect();
249 boolean mStableInsetsChanged;
250
251 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700252 * Outsets determine the area outside of the surface where we want to pretend that it's possible
253 * to draw anyway.
254 */
255 final Rect mOutsets = new Rect();
256 final Rect mLastOutsets = new Rect();
257 boolean mOutsetsChanged = false;
258
259 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260 * Set to true if we are waiting for this window to receive its
261 * given internal insets before laying out other windows based on it.
262 */
263 boolean mGivenInsetsPending;
264
265 /**
266 * These are the content insets that were given during layout for
267 * this window, to be applied to windows behind it.
268 */
269 final Rect mGivenContentInsets = new Rect();
270
271 /**
272 * These are the visible insets that were given during layout for
273 * this window, to be applied to windows behind it.
274 */
275 final Rect mGivenVisibleInsets = new Rect();
276
277 /**
278 * This is the given touchable area relative to the window frame, or null if none.
279 */
280 final Region mGivenTouchableRegion = new Region();
281
282 /**
283 * Flag indicating whether the touchable region should be adjusted by
284 * the visible insets; if false the area outside the visible insets is
285 * NOT touchable, so we must use those to adjust the frame during hit
286 * tests.
287 */
288 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
289
290 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400291 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700292 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293 float mHScale=1, mVScale=1;
294 float mLastHScale=1, mLastVScale=1;
295 final Matrix mTmpMatrix = new Matrix();
296
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700297 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298 final Rect mFrame = new Rect();
299 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700300 // Frame that is scaled to the application's coordinate space when in
301 // screen size compatibility mode.
302 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303
304 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700305
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700307
Wale Ogunwale94596652015-02-06 19:27:34 -0800308 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
309 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700310 final Rect mDisplayFrame = new Rect();
311
312 // The region of the display frame that the display type supports displaying content on. This
313 // is mostly a special case for TV where some displays don’t have the entire display usable.
314 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
315 // window display contents to extend into the overscan region.
316 final Rect mOverscanFrame = new Rect();
317
318 // The display frame minus the stable insets. This value is always constant regardless of if
319 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700320 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800321
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700322 // The area not occupied by the status and navigation bars. So, if both status and navigation
323 // bars are visible, the decor frame is equal to the stable frame.
324 final Rect mDecorFrame = new Rect();
325
326 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
327 // minus the area occupied by the IME if the IME is present.
328 final Rect mContentFrame = new Rect();
329
330 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
331 // displays hint text.
332 final Rect mVisibleFrame = new Rect();
333
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700334 // Frame that includes dead area outside of the surface but where we want to pretend that it's
335 // possible to draw.
336 final Rect mOutsetFrame = new Rect();
337
Jorim Jaggidc249c42015-12-15 14:57:31 -0800338 /**
339 * Usually empty. Set to the task's tempInsetFrame. See
340 *{@link android.app.IActivityManager#resizeDockedStack}.
341 */
342 final Rect mInsetFrame = new Rect();
343
Jorim Jaggif5834272016-04-04 20:25:41 -0700344 private static final Rect sTmpRect = new Rect();
345
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800346 boolean mContentChanged;
347
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800348 // If a window showing a wallpaper: the requested offset for the
349 // wallpaper; if a wallpaper window: the currently applied offset.
350 float mWallpaperX = -1;
351 float mWallpaperY = -1;
352
353 // If a window showing a wallpaper: what fraction of the offset
354 // range corresponds to a full virtual screen.
355 float mWallpaperXStep = -1;
356 float mWallpaperYStep = -1;
357
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700358 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
359 // to its window; if a wallpaper window: not used.
360 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
361 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
362
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363 // Wallpaper windows: pixels offset based on above variables.
364 int mXOffset;
365 int mYOffset;
366
Craig Mautner2268e7e2012-12-13 15:40:00 -0800367 /**
368 * This is set after IWindowSession.relayout() has been called at
369 * least once for the window. It allows us to detect the situation
370 * where we don't yet have a surface, but should have one soon, so
371 * we can give the window focus before waiting for the relayout.
372 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800373 boolean mRelayoutCalled;
374
Robert Carrfed10072016-05-26 11:48:49 -0700375 boolean mInRelayout;
376
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800377 /**
378 * If the application has called relayout() with changes that can
379 * impact its window's size, we need to perform a layout pass on it
380 * even if it is not currently visible for layout. This is set
381 * when in that case until the layout is done.
382 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800383 boolean mLayoutNeeded;
384
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800385 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800386 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800388 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800389 boolean mDestroying;
390
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800391 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392 boolean mRemoveOnExit;
393
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800394 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800395 * Whether the app died while it was visible, if true we might need
396 * to continue to show it until it's restarted.
397 */
398 boolean mAppDied;
399
400 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800401 * Set when the orientation is changing and this window has not yet
402 * been updated for the new orientation.
403 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800404 boolean mOrientationChanging;
405
Dianne Hackborna57c6952013-03-29 14:46:40 -0700406 /**
407 * How long we last kept the screen frozen.
408 */
409 int mLastFreezeDuration;
410
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800411 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800412 boolean mRemoved;
413
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800414 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800415 * It is save to remove the window and destroy the surface because the client requested removal
416 * or some other higher level component said so (e.g. activity manager).
417 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800418 */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800419 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800420
421 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800422 * Temp for keeping track of windows that have been removed when
423 * rebuilding window list.
424 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800425 boolean mRebuilding;
426
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800427 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700428 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800429 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800430 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800431
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800432 // Used to improve performance of toString()
433 String mStringNameCache;
434 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700435 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800436
Craig Mautnera2c77052012-03-26 12:14:43 -0700437 final WindowStateAnimator mWinAnimator;
438
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700439 boolean mHasSurface = false;
440
Craig Mautner19ab8282014-05-07 10:35:34 -0700441 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700442 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700443
Craig Mautner88400d32012-09-30 12:35:45 -0700444 /** When true this window can be displayed on screens owther than mOwnerUid's */
445 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700446
Robert Carr13f7be9e2015-12-02 18:39:45 -0800447 // Whether the window has a saved surface from last pause, which can be
448 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700449 private boolean mSurfaceSaved = false;
450
Chong Zhang8e4bda92016-05-04 15:08:18 -0700451 // Whether we're performing an entering animation with a saved surface. This flag is
452 // true during the time we're showing a window with a previously saved surface. It's
453 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700454 private boolean mAnimatingWithSavedSurface;
455
456 // Whether the window was visible when we set the app to invisible last time. WM uses
457 // this as a hint to restore the surface (if available) for early animation next time
458 // the app is brought visible.
459 boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800460
Robert Carra1eb4392015-12-10 12:43:51 -0800461 // This window will be replaced due to relaunch. This allows window manager
462 // to differentiate between simple removal of a window and replacement. In the latter case it
463 // will preserve the old window until the new one is drawn.
464 boolean mWillReplaceWindow = false;
465 // If true, the replaced window was already requested to be removed.
466 boolean mReplacingRemoveRequested = false;
467 // Whether the replacement of the window should trigger app transition animation.
468 boolean mAnimateReplacingWindow = false;
469 // If not null, the window that will be used to replace the old one. This is being set when
470 // the window is added and unset when this window reports its first draw.
471 WindowState mReplacingWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700472 // For the new window in the replacement transition, if we have
473 // requested to replace without animation, then we should
474 // make sure we also don't apply an enter animation for
475 // the new window.
476 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800477 // Whether this window is being moved via the resize API
478 boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800479
Jeff Brownc2932a12014-11-20 18:04:05 -0800480 /**
481 * Wake lock for drawing.
482 * Even though it's slightly more expensive to do so, we will use a separate wake lock
483 * for each app that is requesting to draw while dozing so that we can accurately track
484 * who is preventing the system from suspending.
485 * This lock is only acquired on first use.
486 */
487 PowerManager.WakeLock mDrawLock;
488
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700489 final private Rect mTmpRect = new Rect();
490
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800491 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800492 * See {@link #notifyMovedInStack}.
493 */
494 private boolean mJustMovedInStack;
495
496 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800497 * Whether the window was resized by us while it was gone for layout.
498 */
499 boolean mResizedWhileGone = false;
500
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700501 /** @see #isResizedWhileNotDragResizing(). */
502 private boolean mResizedWhileNotDragResizing;
503
504 /** @see #isResizedWhileNotDragResizingReported(). */
505 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700506
Robert Carr6da3cc02016-06-16 15:17:07 -0700507 /**
508 * During seamless rotation we have two phases, first the old window contents
509 * are rotated to look as if they didn't move in the new coordinate system. Then we
510 * have to freeze updates to this layer (to preserve the transformation) until
511 * the resize actually occurs. This is true from when the transformation is set
512 * and false until the transaction to resize is sent.
513 */
514 boolean mSeamlesslyRotated = false;
515
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800516 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700517 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700518 int viewVisibility, final DisplayContent displayContent, int ownerId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519 mService = service;
520 mSession = s;
521 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800522 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800523 mToken = token;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700524 mOwnerUid = ownerId;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800525 mWindowId = new IWindowId.Stub() {
526 @Override
527 public void registerFocusObserver(IWindowFocusObserver observer) {
528 WindowState.this.registerFocusObserver(observer);
529 }
530 @Override
531 public void unregisterFocusObserver(IWindowFocusObserver observer) {
532 WindowState.this.unregisterFocusObserver(observer);
533 }
534 @Override
535 public boolean isFocused() {
536 return WindowState.this.isFocused();
537 }
538 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800539 mAttrs.copyFrom(a);
540 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700541 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700542 mPolicy = mService.mPolicy;
543 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800544 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700545 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700546 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800547 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700548 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700549 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800550 try {
551 c.asBinder().linkToDeath(deathRecipient, 0);
552 } catch (RemoteException e) {
553 mDeathRecipient = null;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700554 mParentWindow = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800555 mLayoutAttached = false;
556 mIsImWindow = false;
557 mIsWallpaper = false;
558 mIsFloatingLayer = false;
559 mBaseLayer = 0;
560 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700561 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700562 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800563 return;
564 }
565 mDeathRecipient = deathRecipient;
566
567 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
568 mAttrs.type <= LAST_SUB_WINDOW)) {
569 // The multiplier here is to reserve space for multiple
570 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700571 mBaseLayer = mPolicy.windowTypeToLayerLw(
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700572 parentWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800573 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700574 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700575 mParentWindow = parentWindow;
576 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mParentWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900577
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700578 final WindowList childWindows = mParentWindow.mChildWindows;
tiger_huange2a98a72014-11-13 19:46:28 +0800579 final int numChildWindows = childWindows.size();
580 if (numChildWindows == 0) {
581 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900582 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800583 boolean added = false;
584 for (int i = 0; i < numChildWindows; i++) {
585 final int childSubLayer = childWindows.get(i).mSubLayer;
586 if (mSubLayer < childSubLayer
587 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
588 // We insert the child window into the list ordered by the sub-layer. For
589 // same sub-layers, the negative one should go below others; the positive
590 // one should go above others.
591 childWindows.add(i, this);
592 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900593 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900594 }
595 }
tiger_huange2a98a72014-11-13 19:46:28 +0800596 if (!added) {
597 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900598 }
599 }
600
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800601 mLayoutAttached = mAttrs.type !=
602 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700603 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
604 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
605 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800606 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
607 } else {
608 // The multiplier here is to reserve space for multiple
609 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700610 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800611 * WindowManagerService.TYPE_LAYER_MULTIPLIER
612 + WindowManagerService.TYPE_LAYER_OFFSET;
613 mSubLayer = 0;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700614 mParentWindow = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800615 mLayoutAttached = false;
616 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
617 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
618 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
619 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
620 }
621
622 WindowState appWin = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800623 while (appWin.isChildWindow()) {
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700624 appWin = appWin.mParentWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800625 }
626 WindowToken appToken = appWin.mToken;
627 while (appToken.appWindowToken == null) {
628 WindowToken parent = mService.mTokenMap.get(appToken.token);
629 if (parent == null || appToken == parent) {
630 break;
631 }
632 appToken = parent;
633 }
634 mRootToken = appToken;
635 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700636 if (mAppToken != null) {
637 final DisplayContent appDisplay = getDisplayContent();
638 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700639
640 if (mAppToken.showForAllUsers) {
641 // Windows for apps that can show for all users should also show when the
642 // device is locked.
643 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
644 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700645 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800646
Craig Mautner322e4032012-07-13 13:35:20 -0700647 mWinAnimator = new WindowStateAnimator(this);
648 mWinAnimator.mAlpha = a.alpha;
649
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800650 mRequestedWidth = 0;
651 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700652 mLastRequestedWidth = 0;
653 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800654 mXOffset = 0;
655 mYOffset = 0;
656 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800657 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700658 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
659 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800660 }
661
662 void attach() {
663 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700664 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800665 + ", list=" + mToken.windows);
666 mSession.windowAddedLocked();
667 }
668
Craig Mautnera2c77052012-03-26 12:14:43 -0700669 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800670 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800671 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800672 }
673
674 @Override
675 public String getOwningPackage() {
676 return mAttrs.packageName;
677 }
678
Jorim Jaggif5834272016-04-04 20:25:41 -0700679 /**
680 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
681 * from {@param frame}. In other words, it applies the insets that would result if
682 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700683 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
684 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700685 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700686 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
687 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
688 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
689 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
690 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700691 frame.inset(left, top, right, bottom);
692 }
693
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800694 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700695 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
696 Rect osf) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800697 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700698 // This window is being replaced and either already got information that it's being
699 // removed or we are still waiting for some information. Because of this we don't
700 // want to apply any more changes to it, so it remains in this state until new window
701 // appears.
702 return;
703 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800704 mHaveFrame = true;
705
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700706 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700707 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800708 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800709
Chong Zhangae35fef2016-03-16 15:56:55 -0700710 // If the task has temp inset bounds set, we have to make sure all its windows uses
711 // the temp inset frame. Otherwise different display frames get applied to the main
712 // window and the child window, making them misaligned.
713 if (fullscreenTask) {
714 mInsetFrame.setEmpty();
715 } else {
716 task.getTempInsetBounds(mInsetFrame);
717 }
718
Jorim Jaggif5834272016-04-04 20:25:41 -0700719 // Denotes the actual frame used to calculate the insets and to perform the layout. When
720 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
721 // insets temporarily. By the notion of a task having a different layout frame, we can
722 // achieve that while still moving the task around.
723 final Rect layoutContainingFrame;
724 final Rect layoutDisplayFrame;
725
726 // The offset from the layout containing frame to the actual containing frame.
727 final int layoutXDiff;
728 final int layoutYDiff;
Wale Ogunwale7cd4b012016-05-07 12:41:22 -0700729 if (fullscreenTask || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800730 // We use the parent frame as the containing frame for fullscreen and child windows
731 mContainingFrame.set(pf);
732 mDisplayFrame.set(df);
Jorim Jaggif5834272016-04-04 20:25:41 -0700733 layoutDisplayFrame = df;
734 layoutContainingFrame = pf;
735 layoutXDiff = 0;
736 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800737 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700738 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100739 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
740
741 // If the bounds are frozen, we still want to translate the window freely and only
742 // freeze the size.
743 Rect frozen = mAppToken.mFrozenBounds.peek();
744 mContainingFrame.right = mContainingFrame.left + frozen.width();
745 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
746 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800747 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700748 // IME is up and obscuring this window. Adjust the window position so it is visible.
749 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
750 if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) {
751 // In freeform we want to move the top up directly.
752 // TODO: Investigate why this is cf not pf.
753 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
754 } else if (mContainingFrame.bottom > pf.bottom) {
755 // But in docked we want to behave like fullscreen
756 // and behave as if the task were given smaller bounds
757 // for the purposes of layout.
758 mContainingFrame.bottom = pf.bottom;
759 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700760 }
Skuhne81c524a2015-08-12 13:34:14 -0700761
Robert Carre6275582016-02-29 15:45:45 -0800762 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700763 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
764 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800765 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700766 if (mContainingFrame.isEmpty()) {
767 mContainingFrame.set(cf);
768 }
Doris Liu06d582d2015-06-01 13:18:43 -0700769 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800770 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700771 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
772 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
773 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Andrii Kuliandaea3572016-04-08 13:20:51 -0700774 mTmpRect.set(0, 0, mDisplayContent.getDisplayInfo().logicalWidth,
775 mDisplayContent.getDisplayInfo().logicalHeight);
776 subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700777 if (!layoutInParentFrame()) {
Andrii Kuliandaea3572016-04-08 13:20:51 -0700778 subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect);
779 subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700780 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700781 layoutDisplayFrame = df;
782 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700783 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800784
Craig Mautner967212c2013-04-13 21:10:58 -0700785 final int pw = mContainingFrame.width();
786 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800787
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800788 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800789 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800790 // + " to " + pf);
791 mParentFrame.set(pf);
792 mContentChanged = true;
793 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700794 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
795 mLastRequestedWidth = mRequestedWidth;
796 mLastRequestedHeight = mRequestedHeight;
797 mContentChanged = true;
798 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800799
Craig Mautnereda67292013-04-28 13:50:14 -0700800 mOverscanFrame.set(of);
801 mContentFrame.set(cf);
802 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400803 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700804 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700805 final boolean hasOutsets = osf != null;
806 if (hasOutsets) {
807 mOutsetFrame.set(osf);
808 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800809
Craig Mautnereda67292013-04-28 13:50:14 -0700810 final int fw = mFrame.width();
811 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800812
Jorim Jaggif5834272016-04-04 20:25:41 -0700813 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
814
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700815 // Calculate the outsets before the content frame gets shrinked to the window frame.
816 if (hasOutsets) {
817 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
818 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
819 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
820 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
821 } else {
822 mOutsets.set(0, 0, 0, 0);
823 }
824
Craig Mautnera248eee2013-05-07 11:41:27 -0700825 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800826 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800827 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700828 // Keep the frame out of the blocked system area, limit it in size to the content area
829 // and make sure that there is always a minimum visible so that the user can drag it
830 // into a usable area..
831 final int height = Math.min(mFrame.height(), mContentFrame.height());
832 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700833 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700834 final int minVisibleHeight = WindowManagerService.dipToPixel(
835 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
836 final int minVisibleWidth = WindowManagerService.dipToPixel(
837 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700838 final int top = Math.max(mContentFrame.top,
839 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
840 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
841 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
842 mFrame.set(left, top, left + width, top + height);
843 mContentFrame.set(mFrame);
844 mVisibleFrame.set(mContentFrame);
845 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700846 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100847 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
848 mContentFrame.set(mFrame);
849 if (!mFrame.equals(mLastFrame)) {
850 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800851 }
Skuhne81c524a2015-08-12 13:34:14 -0700852 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700853 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
854 Math.max(mContentFrame.top, mFrame.top),
855 Math.min(mContentFrame.right, mFrame.right),
856 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800857
Jorim Jaggi656f6502016-04-11 21:08:17 -0700858 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
859 Math.max(mVisibleFrame.top, mFrame.top),
860 Math.min(mVisibleFrame.right, mFrame.right),
861 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800862
Jorim Jaggi656f6502016-04-11 21:08:17 -0700863 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
864 Math.max(mStableFrame.top, mFrame.top),
865 Math.min(mStableFrame.right, mFrame.right),
866 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700867 }
Adrian Roosfa104232014-06-20 16:10:14 -0700868
Jorim Jaggi899327f2016-02-25 20:44:18 -0500869 if (fullscreenTask && !windowsAreFloating) {
870 // Windows that are not fullscreen can be positioned outside of the display frame,
871 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700872 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
873 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
874 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
875 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800876 }
Craig Mautnereda67292013-04-28 13:50:14 -0700877
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100878 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100879 // For the docked divider, we calculate the stable insets like a full-screen window
880 // so it can use it to calculate the snap positions.
881 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
882 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
883 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
884 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800885
886 // The divider doesn't care about insets in any case, so set it to empty so we don't
887 // trigger a relayout when moving it.
888 mContentInsets.setEmpty();
889 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100890 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700891 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700892 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
893 // non-fullscreen mode.
Jorim Jaggi656f6502016-04-11 21:08:17 -0700894 boolean overrideRightInset = !fullscreenTask && mFrame.right > mTmpRect.right;
895 boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mTmpRect.bottom;
896 mContentInsets.set(mContentFrame.left - mFrame.left,
897 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700898 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700899 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700900 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700901 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800902
Jorim Jaggi656f6502016-04-11 21:08:17 -0700903 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
904 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700905 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700906 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700907 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700908 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800909
Jorim Jaggi656f6502016-04-11 21:08:17 -0700910 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
911 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700912 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700913 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700914 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700915 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100916 }
Adrian Roosfa104232014-06-20 16:10:14 -0700917
Jorim Jaggi656f6502016-04-11 21:08:17 -0700918 // Offset the actual frame by the amount layout frame is off.
919 mFrame.offset(-layoutXDiff, -layoutYDiff);
920 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700921 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
922 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
923 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
924
Craig Mautnereda67292013-04-28 13:50:14 -0700925 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400926 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700927 // If there is a size compatibility scale being applied to the
928 // window, we need to apply this to its insets so that they are
929 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700930 mOverscanInsets.scale(mInvGlobalScale);
931 mContentInsets.scale(mInvGlobalScale);
932 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700933 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700934 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700935
936 // Also the scaled frame that we report to the app needs to be
937 // adjusted to be in its coordinate space.
938 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400939 }
940
Craig Mautnereda67292013-04-28 13:50:14 -0700941 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800942 final DisplayContent displayContent = getDisplayContent();
943 if (displayContent != null) {
944 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700945 mService.mWallpaperControllerLocked.updateWallpaperOffset(
946 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800947 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800948 }
949
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700950 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
951 "Resolving (mRequestedWidth="
952 + mRequestedWidth + ", mRequestedheight="
953 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
954 + "): frame=" + mFrame.toShortString()
955 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700956 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700957 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700958 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800959 }
960
Craig Mautnera2c77052012-03-26 12:14:43 -0700961 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800962 public Rect getFrameLw() {
963 return mFrame;
964 }
965
Craig Mautnera2c77052012-03-26 12:14:43 -0700966 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700967 public Point getShownPositionLw() {
968 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800969 }
970
Craig Mautnera2c77052012-03-26 12:14:43 -0700971 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800972 public Rect getDisplayFrameLw() {
973 return mDisplayFrame;
974 }
975
Craig Mautnera2c77052012-03-26 12:14:43 -0700976 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800977 public Rect getOverscanFrameLw() {
978 return mOverscanFrame;
979 }
980
981 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800982 public Rect getContentFrameLw() {
983 return mContentFrame;
984 }
985
Craig Mautnera2c77052012-03-26 12:14:43 -0700986 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800987 public Rect getVisibleFrameLw() {
988 return mVisibleFrame;
989 }
990
Craig Mautnera2c77052012-03-26 12:14:43 -0700991 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800992 public boolean getGivenInsetsPendingLw() {
993 return mGivenInsetsPending;
994 }
995
Craig Mautnera2c77052012-03-26 12:14:43 -0700996 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997 public Rect getGivenContentInsetsLw() {
998 return mGivenContentInsets;
999 }
1000
Craig Mautnera2c77052012-03-26 12:14:43 -07001001 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001002 public Rect getGivenVisibleInsetsLw() {
1003 return mGivenVisibleInsets;
1004 }
1005
Craig Mautnera2c77052012-03-26 12:14:43 -07001006 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001007 public WindowManager.LayoutParams getAttrs() {
1008 return mAttrs;
1009 }
1010
Craig Mautner812d2ca2012-09-27 15:35:34 -07001011 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001012 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
1013 int index = -1;
1014 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -07001015 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001016 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07001017 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
1018 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001019 }
1020 // If we reached the bottom of the range of windows we are considering,
1021 // assume no menu is needed.
1022 if (ws == bottom) {
1023 return false;
1024 }
1025 // The current window hasn't specified whether menu key is needed;
1026 // look behind it.
1027 // First, we may need to determine the starting position.
1028 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -07001029 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001030 }
1031 index--;
1032 if (index < 0) {
1033 return false;
1034 }
Craig Mautner59c00972012-07-30 12:10:24 -07001035 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001036 }
1037 }
1038
Craig Mautner19d59bc2012-09-04 11:15:56 -07001039 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001040 public int getSystemUiVisibility() {
1041 return mSystemUiVisibility;
1042 }
1043
Craig Mautner19d59bc2012-09-04 11:15:56 -07001044 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001045 public int getSurfaceLayer() {
1046 return mLayer;
1047 }
1048
Craig Mautner812d2ca2012-09-27 15:35:34 -07001049 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001050 public int getBaseType() {
1051 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001052 while (win.isChildWindow()) {
Wale Ogunwale7ed4d372016-07-09 15:28:55 -07001053 win = win.mParentWindow;
Selim Cinekd6623612015-05-22 18:56:22 -07001054 }
1055 return win.mAttrs.type;
1056 }
1057
1058 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001059 public IApplicationToken getAppToken() {
1060 return mAppToken != null ? mAppToken.appToken : null;
1061 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001062
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001063 @Override
1064 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001065 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001066 }
1067
Craig Mautner4c5eb222013-11-18 12:59:05 -08001068 boolean setInsetsChanged() {
1069 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1070 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1071 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001072 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001073 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
1074 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
1075 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001076 }
1077
Craig Mautnerdf88d732014-01-27 09:21:32 -08001078 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -07001079 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -07001080 return mDisplayContent;
1081 }
1082 final TaskStack stack = getStack();
1083 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001084 }
1085
Chong Zhang09b21ef2015-09-14 10:20:21 -07001086 public DisplayInfo getDisplayInfo() {
1087 final DisplayContent displayContent = getDisplayContent();
1088 return displayContent != null ? displayContent.getDisplayInfo() : null;
1089 }
1090
Craig Mautner19d59bc2012-09-04 11:15:56 -07001091 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001092 final DisplayContent displayContent = getDisplayContent();
1093 if (displayContent == null) {
1094 return -1;
1095 }
1096 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001097 }
1098
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001099 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001100 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001101 }
1102
1103 TaskStack getStack() {
1104 Task task = getTask();
1105 if (task != null) {
1106 if (task.mStack != null) {
1107 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001108 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001109 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001110 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1111 // associate them with some stack to enable dimming.
1112 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1113 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001114 }
1115
Skuhnef932e562015-08-20 12:07:30 -07001116 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001117 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001118 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001119 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001120 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001121 final Task task = getTask();
1122 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001123 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001124 mTmpRect.setEmpty();
1125 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001126 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001127 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001128 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001129 } else {
1130 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001131 }
1132 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001133
Chong Zhang9184ec62015-09-24 12:32:21 -07001134 bounds.set(mVisibleFrame);
1135 if (intersectWithStackBounds) {
1136 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001137 }
1138
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001139 if (bounds.isEmpty()) {
1140 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001141 if (intersectWithStackBounds) {
1142 bounds.intersect(mTmpRect);
1143 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001144 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001145 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001146 }
1147
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001148 public long getInputDispatchingTimeoutNanos() {
1149 return mAppToken != null
1150 ? mAppToken.inputDispatchingTimeoutNanos
1151 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1152 }
1153
Craig Mautnere8552142012-11-07 13:55:47 -08001154 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001155 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001156 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001157 }
1158
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001159 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1160 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1161 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1162 if (dtdx < -.000001f || dtdx > .000001f) return false;
1163 if (dsdy < -.000001f || dsdy > .000001f) return false;
1164 return true;
1165 }
1166
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001167 void prelayout() {
1168 if (mEnforceSizeCompat) {
1169 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001170 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001171 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001172 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001173 }
1174 }
1175
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001176 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001177 * Does the minimal check for visibility. Callers generally want to use one of the public
1178 * methods as they perform additional checks on the app token.
1179 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001180 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001181 private boolean isVisibleUnchecked() {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001182 return mHasSurface && mPolicyVisibility && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001183 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001184 }
1185
1186 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001187 * Is this window visible? It is not visible if there is no surface, or we are in the process
1188 * of running an exit animation that will remove the surface, or its app token has been hidden.
1189 */
1190 @Override
1191 public boolean isVisibleLw() {
1192 return (mAppToken == null || !mAppToken.hiddenRequested) && isVisibleUnchecked();
1193 }
1194
1195 /**
1196 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1197 * keyguard as visible. This allows us to apply things like window flags that impact the
1198 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1199 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001200 */
Craig Mautner88400d32012-09-30 12:35:45 -07001201 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001202 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001203 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001204 return false;
1205 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001206 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001207 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001208 return mHasSurface && !mDestroying && !mAnimatingExit
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001209 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001210 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001211 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001212 }
1213
1214 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001215 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1216 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001217 */
1218 public boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001219 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1220 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001221 }
1222
1223 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001224 * The same as isVisible(), but follows the current hidden state of the associated app token,
1225 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001226 */
1227 boolean isVisibleNow() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001228 return (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1229 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001230 }
1231
1232 /**
1233 * Can this window possibly be a drag/drop target? The test here is
1234 * a combination of the above "visible now" with the check that the
1235 * Input Manager uses when discarding windows from input consideration.
1236 */
1237 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001238 return isVisibleNow() && !mRemoved
1239 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001240 }
1241
1242 /**
1243 * Same as isVisible(), but we also count it as visible between the
1244 * call to IWindowSession.add() and the first relayout().
1245 */
1246 boolean isVisibleOrAdding() {
1247 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001248 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001249 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001250 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001251 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001252 }
1253
1254 /**
1255 * Is this window currently on-screen? It is on-screen either if it
1256 * is visible or it is currently running an animation before no longer
1257 * being visible.
1258 */
1259 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001260 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1261 }
1262
1263 /**
1264 * Like isOnScreen(), but ignores any force hiding of the window due
1265 * to the keyguard.
1266 */
1267 boolean isOnScreenIgnoringKeyguard() {
1268 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001269 return false;
1270 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001271 final AppWindowToken atoken = mAppToken;
1272 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001273 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001274 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001275 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001276 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001277 }
1278
1279 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001280 * Whether this window's drawn state might affect the drawn states of the app token.
1281 *
1282 * @param visibleOnly Whether we should consider only the windows that's currently
1283 * visible in layout. If true, windows that has not relayout to VISIBLE
1284 * would always return false.
1285 *
1286 * @return true if the window should be considered while evaluating allDrawn flags.
1287 */
1288 boolean mightAffectAllDrawn(boolean visibleOnly) {
Chong Zhange292eb32016-05-21 09:23:55 -07001289 final boolean isViewVisible = (mAppToken == null || !mAppToken.clientHidden)
1290 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001291 return (isOnScreenIgnoringKeyguard() && (!visibleOnly || isViewVisible)
1292 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION)
1293 && !mAnimatingExit && !mDestroying;
1294 }
1295
1296 /**
1297 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1298 * it must be drawn before allDrawn can become true.
1299 */
1300 boolean isInteresting() {
1301 return mAppToken != null && !mAppDied
1302 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1303 }
1304
1305 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001306 * Like isOnScreen(), but we don't return true if the window is part
1307 * of a transition that has not yet been started.
1308 */
1309 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001310 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001311 return false;
1312 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001313 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwale9d147902016-07-16 11:58:55 -07001314 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001315 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001316 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001317 }
1318
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001319 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001320 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1321 * to the keyguard.
1322 */
1323 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001324 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001325 return false;
1326 }
1327 final AppWindowToken atoken = mAppToken;
1328 if (atoken == null && !mPolicyVisibility) {
1329 // If this is not an app window, and the policy has asked to force
1330 // hide, then we really do want to hide.
1331 return false;
1332 }
1333 return mHasSurface && !mDestroying
Wale Ogunwale9d147902016-07-16 11:58:55 -07001334 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001335 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001336 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1337 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001338 }
1339
1340 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 * Like isOnScreen, but returns false if the surface hasn't yet
1342 * been drawn.
1343 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001344 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001345 public boolean isDisplayedLw() {
1346 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001347 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001348 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001350 || mWinAnimator.mAnimating
1351 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001352 }
1353
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001354 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001355 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001356 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001357 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001358 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001359 return mWinAnimator.mAnimation != null
1360 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001361 }
1362
Craig Mautner812d2ca2012-09-27 15:35:34 -07001363 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001364 public boolean isGoneForLayoutLw() {
1365 final AppWindowToken atoken = mAppToken;
1366 return mViewVisibility == View.GONE
1367 || !mRelayoutCalled
1368 || (atoken == null && mRootToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001369 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001370 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001371 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001372 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001373 }
1374
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001375 /**
1376 * Returns true if the window has a surface that it has drawn a
1377 * complete UI in to.
1378 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001379 public boolean isDrawFinishedLw() {
1380 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001381 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1382 || mWinAnimator.mDrawState == READY_TO_SHOW
1383 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001384 }
1385
1386 /**
1387 * Returns true if the window has a surface that it has drawn a
1388 * complete UI in to.
1389 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001390 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001391 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001392 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001393 (mWinAnimator.mDrawState == READY_TO_SHOW
1394 || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001395 }
1396
1397 /**
1398 * Return true if the window is opaque and fully drawn. This indicates
1399 * it may obscure windows behind it.
1400 */
1401 boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001402 // When there is keyguard, wallpaper could be placed over the secure app
1403 // window but invisible. We need to check wallpaper visibility explicitly
1404 // to determine if it's occluding apps.
1405 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1406 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001407 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001408 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001409 }
1410
1411 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001412 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001413 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1414 */
Craig Mautner4557c082015-04-27 13:07:40 -07001415 boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001416 return mHasSurface && (mContentChanged || mMovedByResize)
Jorim Jaggi192086e2016-03-11 17:17:03 +01001417 && !mAnimatingExit && mService.okToDisplay()
Chong Zhangbd0d9372015-12-28 15:18:29 -08001418 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwale7ed4d372016-07-09 15:28:55 -07001419 && (!isChildWindow() || !mParentWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001420 }
1421
Chong Zhang0abb20f2015-11-19 14:17:31 -08001422 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1423 Task task = getTask();
1424 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1425 return false;
1426 }
1427 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1428 return false;
1429 }
1430 return true;
1431 }
1432
1433 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1434 return mFrame.left <= 0 && mFrame.top <= 0
1435 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001436 }
1437
Craig Mautner812d2ca2012-09-27 15:35:34 -07001438 boolean isConfigChanged() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001439 getMergedConfig(mTmpConfig);
1440
1441 // If the merged configuration is still empty, it means that we haven't issues the
1442 // configuration to the client yet and we need to return true so the configuration updates.
1443 boolean configChanged = mMergedConfiguration.equals(Configuration.EMPTY)
1444 || mTmpConfig.diff(mMergedConfiguration) != 0;
Craig Mautnere8552142012-11-07 13:55:47 -08001445
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001446 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001447 // Retain configuration changed status until resetConfiguration called.
1448 mConfigHasChanged |= configChanged;
1449 configChanged = mConfigHasChanged;
1450 }
1451
1452 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001453 }
1454
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001455 boolean isAdjustedForMinimizedDock() {
1456 return mAppToken != null && mAppToken.mTask != null
1457 && mAppToken.mTask.mStack.isAdjustedForMinimizedDock();
1458 }
1459
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001460 void removeLocked() {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001461 if (mRemoved) {
1462 // Nothing to do.
1463 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "WS.removeLocked: " + this + " Already removed...");
1464 return;
1465 }
1466
1467 for (int i = mChildWindows.size() - 1; i >= 0; i--) {
1468 final WindowState child = mChildWindows.get(i);
1469 Slog.w(TAG_WM, "Force-removing child win " + child + " from container " + this);
1470 child.removeLocked();
1471 }
1472
1473 mRemoved = true;
1474
1475 if (mService.mInputMethodTarget == this) {
1476 mService.moveInputMethodWindowsIfNeededLocked(false);
1477 }
1478
1479 final int type = mAttrs.type;
1480 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
1481 final DisplayContent displaycontent = getDisplayContent();
1482 displaycontent.mTapExcludedWindows.remove(this);
1483 }
1484 mPolicy.removeWindowLw(this);
1485
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001486 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001487
Robert Carr51a1b872015-12-08 14:03:13 -08001488 if (isChildWindow()) {
Wale Ogunwale7ed4d372016-07-09 15:28:55 -07001489 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mParentWindow);
1490 mParentWindow.mChildWindows.remove(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001491 }
Craig Mautner96868332012-12-04 14:29:11 -08001492 mWinAnimator.destroyDeferredSurfaceLocked();
1493 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001494 mSession.windowRemovedLocked();
1495 try {
1496 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1497 } catch (RuntimeException e) {
1498 // Ignore if it has already been removed (usually because
1499 // we are doing this as part of processing a death note.)
1500 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001501
1502 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001503 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001504
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001505 void setHasSurface(boolean hasSurface) {
1506 mHasSurface = hasSurface;
1507 }
1508
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001509 int getAnimLayerAdjustment() {
1510 if (mTargetAppToken != null) {
1511 return mTargetAppToken.mAppAnimator.animLayerAdjustment;
1512 } else if (mAppToken != null) {
1513 return mAppToken.mAppAnimator.animLayerAdjustment;
1514 } else {
1515 // Nothing is animating, so there is no animation adjustment.
1516 return 0;
1517 }
1518 }
1519
1520 void scheduleAnimationIfDimming() {
1521 if (mDisplayContent == null) {
1522 return;
1523 }
1524 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1525 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1526 dimLayerUser, mWinAnimator)) {
1527 // Force an animation pass just to update the mDimLayer layer.
1528 mService.scheduleAnimationLocked();
1529 }
1530 }
1531
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001532 /**
1533 * Notifies this window that the corresponding task has just moved in the stack.
1534 * <p>
1535 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
1536 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
1537 * the actual app transition that updates the visibility is delayed by a few transactions.
1538 * Instead of messing around with the ordering and timing how transitions and transactions are
1539 * executed, we introduce this little hack which prevents this window of getting visible again
1540 * with the wrong bounds until the app transitions has started.
1541 * <p>
1542 * This method notifies the window about that we just moved in the stack so we can apply this
1543 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
1544 */
1545 void notifyMovedInStack() {
1546 mJustMovedInStack = true;
1547 }
1548
1549 /**
1550 * See {@link #notifyMovedInStack}.
1551 *
1552 * @return Whether we just got moved in the corresponding stack.
1553 */
1554 boolean hasJustMovedInStack() {
1555 return mJustMovedInStack;
1556 }
1557
1558 /**
1559 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
1560 */
1561 void resetJustMovedInStack() {
1562 mJustMovedInStack = false;
1563 }
1564
Chong Zhangacf11402015-11-04 16:23:10 -08001565 private final class DeadWindowEventReceiver extends InputEventReceiver {
1566 DeadWindowEventReceiver(InputChannel inputChannel) {
1567 super(inputChannel, mService.mH.getLooper());
1568 }
1569 @Override
1570 public void onInputEvent(InputEvent event) {
1571 finishInputEvent(event, true);
1572 }
1573 }
1574 /**
1575 * Dummy event receiver for windows that died visible.
1576 */
1577 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1578
Chong Zhang112eb8c2015-11-02 11:17:00 -08001579 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001580 if (mInputChannel != null) {
1581 throw new IllegalStateException("Window already has an input channel.");
1582 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001583 String name = makeInputChannelName();
1584 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1585 mInputChannel = inputChannels[0];
1586 mClientChannel = inputChannels[1];
1587 mInputWindowHandle.inputChannel = inputChannels[0];
1588 if (outInputChannel != null) {
1589 mClientChannel.transferTo(outInputChannel);
1590 mClientChannel.dispose();
1591 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001592 } else {
1593 // If the window died visible, we setup a dummy input channel, so that taps
1594 // can still detected by input monitor channel, and we can relaunch the app.
1595 // Create dummy event receiver that simply reports all events as handled.
1596 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001597 }
1598 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001599 }
1600
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001601 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001602 if (mDeadWindowEventReceiver != null) {
1603 mDeadWindowEventReceiver.dispose();
1604 mDeadWindowEventReceiver = null;
1605 }
1606
1607 // unregister server channel first otherwise it complains about broken channel
1608 if (mInputChannel != null) {
1609 mService.mInputManager.unregisterInputChannel(mInputChannel);
1610 mInputChannel.dispose();
1611 mInputChannel = null;
1612 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001613 if (mClientChannel != null) {
1614 mClientChannel.dispose();
1615 mClientChannel = null;
1616 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001617 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001618 }
1619
Chong Zhang112eb8c2015-11-02 11:17:00 -08001620 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001621 // When the app is terminated (eg. from Recents), the task might have already been
1622 // removed with the window pending removal. Don't apply dim in such cases, as there
1623 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1624 final AppWindowToken token = mAppToken;
1625 if (token != null && token.removed) {
1626 return;
1627 }
1628
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001629 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001630 // If app died visible, apply a dim over the window to indicate that it's inactive
1631 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1632 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Robert Carr9fe459d2016-04-07 23:32:28 -07001633 && mDisplayContent != null && !mAnimatingExit && isVisibleUnchecked()) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001634 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001635 }
1636 }
1637
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001638 DimLayer.DimLayerUser getDimLayerUser() {
1639 Task task = getTask();
1640 if (task != null) {
1641 return task;
1642 }
1643 return getStack();
1644 }
1645
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001646 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001647 if (mAppToken == null) {
1648 return;
1649 }
1650 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1651 final WindowState win = mAppToken.allAppWindows.get(i);
Robert Carrdcdca582016-04-07 22:59:24 -07001652 if (win.mWillReplaceWindow && win.mReplacingWindow == this && hasDrawnLw()) {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08001653 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
Robert Carr9fe459d2016-04-07 23:32:28 -07001654 if (win.isDimming()) {
1655 win.transferDimToReplacement();
1656 }
Robert Carra1eb4392015-12-10 12:43:51 -08001657 win.mWillReplaceWindow = false;
Wale Ogunwaled0a166a2016-05-09 11:18:18 -07001658 final boolean animateReplacingWindow = win.mAnimateReplacingWindow;
Robert Carra1eb4392015-12-10 12:43:51 -08001659 win.mAnimateReplacingWindow = false;
1660 win.mReplacingRemoveRequested = false;
1661 win.mReplacingWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -07001662 mSkipEnterAnimationForSeamlessReplacement = false;
Wale Ogunwaled0a166a2016-05-09 11:18:18 -07001663 if (win.mAnimatingExit || !animateReplacingWindow) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001664 win.removeLocked();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001665 }
1666 }
1667 }
1668 }
1669
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001670 void setDisplayLayoutNeeded() {
1671 if (mDisplayContent != null) {
1672 mDisplayContent.layoutNeeded = true;
1673 }
1674 }
1675
Robert Carrfed10072016-05-26 11:48:49 -07001676 // TODO: Strange usage of word workspace here and above.
1677 boolean inPinnedWorkspace() {
1678 final Task task = getTask();
1679 return task != null && task.inPinnedWorkspace();
1680 }
1681
Chong Zhang5117e272016-05-03 12:47:34 -07001682 void applyAdjustForImeIfNeeded() {
1683 final Task task = getTask();
1684 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
1685 task.mStack.applyAdjustForImeIfNeeded(task);
1686 }
1687 }
1688
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001689 int getTouchableRegion(Region region, int flags) {
1690 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001691 if (modal && mAppToken != null) {
1692 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001693 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001694 // If this is a modal window we need to dismiss it if it's not full screen and the
1695 // touch happens outside of the frame that displays the content. This means we
1696 // need to intercept touches outside of that window. The dim layer user
1697 // associated with the window (task or stack) will give us the good bounds, as
1698 // they would be used to display the dim layer.
1699 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1700 if (dimLayerUser != null) {
1701 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001702 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001703 getVisibleBounds(mTmpRect);
1704 }
1705 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001706 // For freeform windows we the touch region to include the whole surface for the
1707 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001708 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1709 final int delta = WindowManagerService.dipToPixel(
1710 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1711 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001712 }
1713 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001714 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001715 } else {
1716 // Not modal or full screen modal
1717 getTouchableRegion(region);
1718 }
1719 return flags;
1720 }
1721
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001722 void checkPolicyVisibilityChange() {
1723 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1724 if (DEBUG_VISIBILITY) {
1725 Slog.v(TAG, "Policy visibility changing after anim in " +
1726 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1727 }
1728 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001729 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001730 if (!mPolicyVisibility) {
1731 if (mService.mCurrentFocus == this) {
1732 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1733 "setAnimationLocked: setting mFocusMayChange true");
1734 mService.mFocusMayChange = true;
1735 }
1736 // Window is no longer visible -- make sure if we were waiting
1737 // for it to be displayed before enabling the display, that
1738 // we allow the display to be enabled now.
1739 mService.enableScreenIfNeededLocked();
1740 }
1741 }
1742 }
1743
1744 void setRequestedSize(int requestedWidth, int requestedHeight) {
1745 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1746 mLayoutNeeded = true;
1747 mRequestedWidth = requestedWidth;
1748 mRequestedHeight = requestedHeight;
1749 }
1750 }
1751
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001752 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1753 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1754 == SOFT_INPUT_ADJUST_RESIZE) {
1755 mLayoutNeeded = true;
1756 }
1757 if (isDrawnLw() && mService.okToDisplay()) {
1758 mWinAnimator.applyEnterAnimationLocked();
1759 }
1760 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1761 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1762 mTurnOnScreen = true;
1763 }
1764 if (isConfigChanged()) {
Robert Carrc24d8f92016-02-29 16:24:33 -08001765 final Configuration newConfig = updateConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001766 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Robert Carrc24d8f92016-02-29 16:24:33 -08001767 + newConfig);
1768 outConfig.setTo(newConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001769 }
1770 }
1771
1772 void adjustStartingWindowFlags() {
1773 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1774 && mAppToken.startingWindow != null) {
1775 // Special handling of starting window over the base
1776 // window of the app: propagate lock screen flags to it,
1777 // to provide the correct semantics while starting.
1778 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1779 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1780 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1781 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1782 }
1783 }
1784
1785 void setWindowScale(int requestedWidth, int requestedHeight) {
1786 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1787
1788 if (scaledWindow) {
1789 // requested{Width|Height} Surface's physical size
1790 // attrs.{width|height} Size on screen
1791 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1792 mHScale = (mAttrs.width != requestedWidth) ?
1793 (mAttrs.width / (float)requestedWidth) : 1.0f;
1794 mVScale = (mAttrs.height != requestedHeight) ?
1795 (mAttrs.height / (float)requestedHeight) : 1.0f;
1796 } else {
1797 mHScale = mVScale = 1;
1798 }
1799 }
1800
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001801 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001802 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001803 public void binderDied() {
1804 try {
1805 synchronized(mService.mWindowMap) {
1806 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001807 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001808 if (win != null) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07001809 mService.removeWindowLocked(win, shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001810 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
1811 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08001812 // just in case they have the divider at an unstable position. Better
1813 // also reset drag resizing state, because the owner can't do it
1814 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001815 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
1816 if (stack != null) {
1817 stack.resetDockedStackToMiddle();
1818 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08001819 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001820 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001821 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001822 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001823 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001824 }
1825 }
1826 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07001827 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001828 }
1829 }
1830 }
1831
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001832 /**
1833 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
1834 * because we want to preserve its location on screen to be re-activated later when the user
1835 * interacts with it.
1836 */
1837 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07001838 if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001839 // Not a visible app window or the app isn't dead.
1840 return false;
1841 }
1842
Wale Ogunwale51d1d912016-05-04 13:27:18 -07001843 if (mAttrs.token != mClient.asBinder()) {
1844 // The window was add by a client using another client's app token. We don't want to
1845 // keep the dead window around for this case since this is meant for 'real' apps.
1846 return false;
1847 }
1848
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001849 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1850 // We don't keep starting windows since they were added by the window manager before
1851 // the app even launched.
1852 return false;
1853 }
1854
1855 final TaskStack stack = getStack();
1856 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
1857 }
1858
Wale Ogunwaled045c822015-12-02 09:14:28 -08001859 /** @return true if this window desires key events. */
1860 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001861 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07001862 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08001863 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001864 && (mAppToken == null || mAppToken.windowsAreFocusable())
1865 && !isAdjustedForMinimizedDock();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001866 }
1867
Craig Mautner749a7bb2012-04-02 13:49:53 -07001868 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001869 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001870 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001871 }
1872
Craig Mautner749a7bb2012-04-02 13:49:53 -07001873 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001874 public boolean showLw(boolean doAnimation) {
1875 return showLw(doAnimation, true);
1876 }
1877
1878 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001879 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001880 return false;
1881 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001882 if (!mAppOpVisibility) {
1883 // Being hidden due to app op request.
1884 return false;
1885 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001886 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001887 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001888 return false;
1889 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001890 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001891 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001892 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001893 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001894 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001895 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001896 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001897 // Check for the case where we are currently visible and
1898 // not animating; we do not want to do animation at such a
1899 // point to become visible when we already are.
1900 doAnimation = false;
1901 }
1902 }
1903 mPolicyVisibility = true;
1904 mPolicyVisibilityAfterAnim = true;
1905 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001906 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001907 }
1908 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001909 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001910 }
1911 return true;
1912 }
1913
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001914 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001915 public boolean hideLw(boolean doAnimation) {
1916 return hideLw(doAnimation, true);
1917 }
1918
1919 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1920 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001921 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001922 doAnimation = false;
1923 }
1924 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001925 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1926 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001927 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001928 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001929 return false;
1930 }
1931 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001932 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001933 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001934 doAnimation = false;
1935 }
1936 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001937 if (doAnimation) {
1938 mPolicyVisibilityAfterAnim = false;
1939 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001940 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001941 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001942 mPolicyVisibility = false;
1943 // Window is no longer visible -- make sure if we were waiting
1944 // for it to be displayed before enabling the display, that
1945 // we allow the display to be enabled now.
1946 mService.enableScreenIfNeededLocked();
1947 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001948 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001949 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001950 mService.mFocusMayChange = true;
1951 }
1952 }
1953 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001954 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001955 }
1956 return true;
1957 }
1958
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001959 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001960 if (mAppOpVisibility != state) {
1961 mAppOpVisibility = state;
1962 if (state) {
1963 // If the policy visibility had last been to hide, then this
1964 // will incorrectly show at this point since we lost that
1965 // information. Not a big deal -- for the windows that have app
1966 // ops modifies they should only be hidden by policy due to the
1967 // lock screen, and the user won't be changing this if locked.
1968 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001969 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001970 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001971 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001972 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001973 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001974 }
1975
Jeff Brownc2932a12014-11-20 18:04:05 -08001976 public void pokeDrawLockLw(long timeout) {
1977 if (isVisibleOrAdding()) {
1978 if (mDrawLock == null) {
1979 // We want the tag name to be somewhat stable so that it is easier to correlate
1980 // in wake lock statistics. So in particular, we don't want to include the
1981 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001982 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001983 mDrawLock = mService.mPowerManager.newWakeLock(
1984 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1985 mDrawLock.setReferenceCounted(false);
1986 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1987 }
1988 // Each call to acquire resets the timeout.
1989 if (DEBUG_POWER) {
1990 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1991 + mAttrs.packageName);
1992 }
1993 mDrawLock.acquire(timeout);
1994 } else if (DEBUG_POWER) {
1995 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1996 + "owned by " + mAttrs.packageName);
1997 }
1998 }
1999
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002000 @Override
2001 public boolean isAlive() {
2002 return mClient.asBinder().isBinderAlive();
2003 }
2004
Craig Mautnera987d432012-10-11 14:07:58 -07002005 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002006 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002007 }
2008
Chong Zhangbef461f2015-10-27 11:38:24 -07002009 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002010 return mAnimatingWithSavedSurface;
2011 }
2012
Chong Zhang8e4bda92016-05-04 15:08:18 -07002013 boolean isAnimatingInvisibleWithSavedSurface() {
2014 return mAnimatingWithSavedSurface
2015 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed);
2016 }
2017
Chong Zhang92147042016-05-09 12:47:11 -07002018 public void setVisibleBeforeClientHidden() {
2019 mWasVisibleBeforeClientHidden |=
2020 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
2021 }
2022
2023 public void clearVisibleBeforeClientHidden() {
2024 mWasVisibleBeforeClientHidden = false;
2025 }
2026
2027 public boolean wasVisibleBeforeClientHidden() {
2028 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002029 }
2030
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002031 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002032 if (mWinAnimator.mSurfaceController == null) {
2033 // Don't bother if the surface controller is gone for any reason.
2034 return false;
2035 }
2036
Chong Zhang92147042016-05-09 12:47:11 -07002037 if (!mWasVisibleBeforeClientHidden) {
2038 return false;
2039 }
2040
Wale Ogunwale945d1972016-03-23 13:16:41 -07002041 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2042 // We don't save secure surfaces since their content shouldn't be shown while the app
2043 // isn't on screen and content might leak through during the transition animation with
2044 // saved surface.
2045 return false;
2046 }
2047
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002048 if (ActivityManager.isLowRamDeviceStatic()) {
2049 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002050 return false;
2051 }
2052
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002053 Task task = getTask();
2054 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002055 // Don't save surfaces for home stack apps. These usually resume and draw
2056 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002057 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002058 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002059
2060 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2061 if (taskTop != null && taskTop != mAppToken) {
2062 // Don't save if the window is not the topmost window.
2063 return false;
2064 }
2065
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002066 if (mResizedWhileGone) {
2067 // Somebody resized our window while we were gone for layout, which means that the
2068 // client got an old size, so we have an outdated surface here.
2069 return false;
2070 }
2071
Robert Carr7098dbd2016-02-01 12:31:01 -08002072 if (DEBUG_DISABLE_SAVING_SURFACES) {
2073 return false;
2074 }
2075
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002076 return mAppToken.shouldSaveSurface();
2077 }
2078
Chris Craik3131bde2016-05-06 13:39:08 -07002079 static final Region sEmptyRegion = new Region();
2080
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002081 void destroyOrSaveSurface() {
2082 mSurfaceSaved = shouldSaveSurface();
2083 if (mSurfaceSaved) {
2084 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2085 Slog.v(TAG, "Saving surface: " + this);
2086 }
Chris Craik3131bde2016-05-06 13:39:08 -07002087 // Previous user of the surface may have set a transparent region signaling a portion
2088 // doesn't need to be composited, so reset to default empty state.
2089 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002090
2091 mWinAnimator.hide("saved surface");
2092 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2093 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002094 // The client should have disconnected at this point, but if it doesn't,
2095 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2096 // the client can't reconnect to the buffer queue, and rendering will fail.
2097 if (mWinAnimator.mSurfaceController != null) {
2098 mWinAnimator.mSurfaceController.disconnectInTransaction();
2099 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002100 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002101 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002102 mWinAnimator.destroySurfaceLocked();
2103 }
Chong Zhang92147042016-05-09 12:47:11 -07002104 // Clear animating flags now, since the surface is now gone. (Note this is true even
2105 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2106 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002107 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002108
Chong Zhang92147042016-05-09 12:47:11 -07002109 void destroySavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002110 if (mSurfaceSaved) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002111 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2112 Slog.v(TAG, "Destroying saved surface: " + this);
2113 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08002114 mWinAnimator.destroySurfaceLocked();
2115 }
Chong Zhang92147042016-05-09 12:47:11 -07002116 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002117 }
2118
Chong Zhang92147042016-05-09 12:47:11 -07002119 void restoreSavedSurface() {
Chong Zhang4113ffa2016-02-18 12:39:13 -08002120 if (!mSurfaceSaved) {
2121 return;
2122 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002123 mSurfaceSaved = false;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002124 if (mWinAnimator.mSurfaceController != null) {
2125 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002126 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002127 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002128
2129 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2130 Slog.v(TAG, "Restoring saved surface: " + this);
2131 }
2132 } else {
2133 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2134 // this point. Even if we destroyed the saved surface because of rotation
2135 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2136 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002137 }
2138 }
2139
Chong Zhang92147042016-05-09 12:47:11 -07002140 boolean canRestoreSurface() {
2141 return mWasVisibleBeforeClientHidden && mSurfaceSaved;
2142 }
2143
2144 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002145 return mSurfaceSaved;
2146 }
2147
Chong Zhang92147042016-05-09 12:47:11 -07002148 void clearHasSavedSurface() {
2149 mSurfaceSaved = false;
2150 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002151 if (mWasVisibleBeforeClientHidden) {
2152 mAppToken.destroySavedSurfaces();
2153 }
Chong Zhang92147042016-05-09 12:47:11 -07002154 }
2155
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002156 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002157 if (mAnimatingWithSavedSurface) {
2158 // App has drawn something to its windows, we're no longer animating with
2159 // the saved surfaces.
2160 if (DEBUG_ANIM) Slog.d(TAG,
2161 "clearAnimatingWithSavedSurface(): win=" + this);
2162 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002163 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002164 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002165 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002166 }
2167
Craig Mautner69b08182012-09-05 13:07:13 -07002168 @Override
2169 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002170 final DisplayContent displayContent = getDisplayContent();
2171 if (displayContent == null) {
2172 // Only a window that was on a non-default display can be detached from it.
2173 return false;
2174 }
Winson Chung47a3e652014-05-21 16:03:42 -07002175 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002176 }
2177
Adrian Rooscd3884d2015-02-18 17:25:23 +01002178 @Override
2179 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002180 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2181 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08002182 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002183 }
2184
Craig Mautner88400d32012-09-30 12:35:45 -07002185 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
2186 mShowToOwnerOnly = showToOwnerOnly;
2187 }
2188
Craig Mautner5962b122012-10-05 14:45:52 -07002189 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07002190 // Attached windows are evaluated based on the window that they are attached to.
2191 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08002192 while (win.isChildWindow()) {
Wale Ogunwale7ed4d372016-07-09 15:28:55 -07002193 win = win.mParentWindow;
Craig Mautner341220f2012-10-16 15:20:09 -07002194 }
2195 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07002196 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002197
2198 // All window frames that are fullscreen extend above status bar, but some don't extend
2199 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2200 // bottom right.
2201 if (win.mFrame.left <= win.mDisplayFrame.left
2202 && win.mFrame.top <= win.mDisplayFrame.top
2203 && win.mFrame.right >= win.mStableFrame.right
2204 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002205 // Is a fullscreen window, like the clock alarm. Show to everyone.
2206 return false;
2207 }
2208 }
2209
Craig Mautner341220f2012-10-16 15:20:09 -07002210 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002211 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002212 }
2213
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002214 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2215 outRegion.set(
2216 frame.left + inset.left, frame.top + inset.top,
2217 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002218 }
2219
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002220 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002221 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002222 switch (mTouchableInsets) {
2223 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002224 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002225 outRegion.set(frame);
2226 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002227 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002228 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002229 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002230 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002231 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002232 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002233 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002234 final Region givenTouchableRegion = mGivenTouchableRegion;
2235 outRegion.set(givenTouchableRegion);
2236 outRegion.translate(frame.left, frame.top);
2237 break;
2238 }
2239 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002240 cropRegionToStackBoundsIfNeeded(outRegion);
2241 }
2242
2243 void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002244 final Task task = getTask();
2245 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002246 return;
2247 }
2248
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002249 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002250 if (stack == null) {
2251 return;
2252 }
2253
2254 stack.getDimBounds(mTmpRect);
2255 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002256 }
2257
Craig Mautner59c00972012-07-30 12:10:24 -07002258 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002259 final DisplayContent displayContent = getDisplayContent();
2260 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07002261 }
2262
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002263 /**
2264 * Report a focus change. Must be called with no locks held, and consistently
2265 * from the same serialized thread (such as dispatched from a handler).
2266 */
2267 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
2268 try {
2269 mClient.windowFocusChanged(focused, inTouchMode);
2270 } catch (RemoteException e) {
2271 }
2272 if (mFocusCallbacks != null) {
2273 final int N = mFocusCallbacks.beginBroadcast();
2274 for (int i=0; i<N; i++) {
2275 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2276 try {
2277 if (focused) {
2278 obs.focusGained(mWindowId.asBinder());
2279 } else {
2280 obs.focusLost(mWindowId.asBinder());
2281 }
2282 } catch (RemoteException e) {
2283 }
2284 }
2285 mFocusCallbacks.finishBroadcast();
2286 }
2287 }
2288
Robert Carrc24d8f92016-02-29 16:24:33 -08002289 /**
2290 * Update our current configurations, based on task configuration.
2291 *
2292 * @return A configuration suitable for sending to the client.
2293 */
2294 private Configuration updateConfiguration() {
Robert Carrc24d8f92016-02-29 16:24:33 -08002295 final boolean configChanged = isConfigChanged();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002296 getMergedConfig(mMergedConfiguration);
2297 mConfigHasChanged = false;
Robert Carrc24d8f92016-02-29 16:24:33 -08002298 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
2299 Slog.i(TAG, "Sending new config to window " + this + ": " +
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002300 " / mergedConfig=" + mMergedConfiguration);
Robert Carrc24d8f92016-02-29 16:24:33 -08002301 }
Robert Carrc24d8f92016-02-29 16:24:33 -08002302 return mMergedConfiguration;
2303 }
2304
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002305 private void getMergedConfig(Configuration outConfig) {
2306 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
2307 outConfig.setTo(mAppToken.mFrozenMergedConfig.peek());
2308 return;
2309 }
2310 final Task task = getTask();
2311 final Configuration overrideConfig = task != null
2312 ? task.mOverrideConfig
2313 : Configuration.EMPTY;
2314 final Configuration serviceConfig = mService.mCurConfiguration;
2315 outConfig.setTo(serviceConfig);
2316 if (overrideConfig != Configuration.EMPTY) {
2317 outConfig.updateFrom(overrideConfig);
2318 }
2319 }
2320
Craig Mautnerdf88d732014-01-27 09:21:32 -08002321 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002322 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002323 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002324 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2325 + ": " + mCompatFrame);
Robert Carrc24d8f92016-02-29 16:24:33 -08002326 final Configuration newConfig = isConfigChanged() ? updateConfiguration() : null;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002327 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
2328 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2329
Craig Mautnerdf88d732014-01-27 09:21:32 -08002330 final Rect frame = mFrame;
2331 final Rect overscanInsets = mLastOverscanInsets;
2332 final Rect contentInsets = mLastContentInsets;
2333 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002334 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002335 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002336 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07002337 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2338 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002339 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2340 mService.mH.post(new Runnable() {
2341 @Override
2342 public void run() {
2343 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002344 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
2345 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002346 } catch (RemoteException e) {
2347 // Not a remote call, RemoteException won't be raised.
2348 }
2349 }
2350 });
2351 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002352 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002353 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002354 }
Svetoslav4604abc2014-06-10 18:59:30 -07002355
2356 //TODO (multidisplay): Accessibility supported only for the default display.
2357 if (mService.mAccessibilityController != null
2358 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002359 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002360 }
2361
Craig Mautnerdf88d732014-01-27 09:21:32 -08002362 mOverscanInsetsChanged = false;
2363 mContentInsetsChanged = false;
2364 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002365 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002366 mOutsetsChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002367 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002368 mWinAnimator.mSurfaceResized = false;
2369 } catch (RemoteException e) {
2370 mOrientationChanging = false;
2371 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2372 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002373 // We are assuming the hosting process is dead or in a zombie state.
2374 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2375 + ", removing this window.");
2376 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002377 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002378 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002379 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002380 }
2381
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002382 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002383 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2384 // start even if we haven't received the relayout window, so that the client requests
2385 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2386 // until the window to small size, otherwise the multithread renderer will shift last
2387 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2388 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002389 boolean resizing = isDragResizing() || isDragResizeChanged();
2390 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
2391 return frame;
2392 }
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002393 DisplayInfo displayInfo = getDisplayInfo();
2394 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002395 return mTmpRect;
2396 }
2397
Jorim Jaggi86905582016-02-09 21:36:09 -08002398 @Override
2399 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002400 final TaskStack stack = getStack();
2401 if (stack == null) {
2402 return INVALID_STACK_ID;
2403 }
2404 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002405 }
2406
2407 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2408 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
2409 Configuration newConfig) throws RemoteException {
Chong Zhangedaf3052016-04-22 15:04:31 -07002410 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing;
2411
Jorim Jaggidc249c42015-12-15 14:57:31 -08002412 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08002413 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07002414 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002415 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002416 }
2417
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002418 public void registerFocusObserver(IWindowFocusObserver observer) {
2419 synchronized(mService.mWindowMap) {
2420 if (mFocusCallbacks == null) {
2421 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2422 }
2423 mFocusCallbacks.register(observer);
2424 }
2425 }
2426
2427 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2428 synchronized(mService.mWindowMap) {
2429 if (mFocusCallbacks != null) {
2430 mFocusCallbacks.unregister(observer);
2431 }
2432 }
2433 }
2434
2435 public boolean isFocused() {
2436 synchronized(mService.mWindowMap) {
2437 return mService.mCurrentFocus == this;
2438 }
2439 }
2440
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07002441 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002442 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07002443 return task != null && task.inFreeformWorkspace();
2444 }
2445
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002446 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002447 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002448 final Task task = getTask();
2449 return task != null && !task.isFullscreen();
2450 }
2451
Chong Zhang3005e752015-09-18 18:46:28 -07002452 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002453 return mDragResizing != computeDragResizing();
2454 }
2455
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002456 /**
2457 * @return Whether we reported a drag resize change to the application or not already.
2458 */
2459 boolean isDragResizingChangeReported() {
2460 return mDragResizingChangeReported;
2461 }
2462
2463 /**
2464 * Resets the state whether we reported a drag resize change to the app.
2465 */
2466 void resetDragResizingChangeReported() {
2467 mDragResizingChangeReported = false;
2468 }
2469
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002470 /**
2471 * Set whether we got resized but drag resizing flag was false.
2472 * @see #isResizedWhileNotDragResizing().
2473 */
2474 void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
2475 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
2476 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
2477 }
2478
2479 /**
2480 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
2481 * need to recreate the surface and defer surface bound updates in order to make sure the
2482 * buffer contents and the positioning/size stay in sync.
2483 */
2484 boolean isResizedWhileNotDragResizing() {
2485 return mResizedWhileNotDragResizing;
2486 }
2487
2488 /**
2489 * @return Whether we reported "resize while not drag resizing" to the application.
2490 * @see #isResizedWhileNotDragResizing()
2491 */
2492 boolean isResizedWhileNotDragResizingReported() {
2493 return mResizedWhileNotDragResizingReported;
2494 }
2495
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002496 int getResizeMode() {
2497 return mResizeMode;
2498 }
2499
Jorim Jaggi192086e2016-03-11 17:17:03 +01002500 boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002501 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002502 if (task == null) {
2503 return false;
2504 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08002505 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
2506
2507 // Floating windows never enter drag resize mode.
2508 return false;
2509 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002510 if (task.isDragResizing()) {
2511 return true;
2512 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002513
2514 // If the bounds are currently frozen, it means that the layout size that the app sees
2515 // and the bounds we clip this window to might be different. In order to avoid holes, we
2516 // simulate that we are still resizing so the app fills the hole with the resizing
2517 // background.
2518 return (mDisplayContent.mDividerControllerLocked.isResizing()
2519 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05002520 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002521
Chong Zhang3005e752015-09-18 18:46:28 -07002522 }
2523
2524 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002525 final boolean resizing = computeDragResizing();
2526 if (resizing == mDragResizing) {
2527 return;
2528 }
2529 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01002530 final Task task = getTask();
2531 if (task != null && task.isDragResizing()) {
2532 mResizeMode = task.getDragResizeMode();
2533 } else {
2534 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2535 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2536 : DRAG_RESIZE_MODE_FREEFORM;
2537 }
Chong Zhang3005e752015-09-18 18:46:28 -07002538 }
2539
2540 boolean isDragResizing() {
2541 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002542 }
2543
Robert Carr2487ce72016-04-07 15:18:45 -07002544 boolean isDockedResizing() {
2545 return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
2546 }
2547
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002548 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002549 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002550 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002551 if (stack != null) {
2552 pw.print(" stackId="); pw.print(stack.mStackId);
2553 }
Wale Ogunwale4c5aa5172016-04-19 11:29:05 -07002554 if (mNotOnAppsDisplay) {
2555 pw.print(" mNotOnAppsDisplay="); pw.print(mNotOnAppsDisplay);
2556 }
Craig Mautner59c00972012-07-30 12:10:24 -07002557 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002558 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002559 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002560 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2561 pw.print(" package="); pw.print(mAttrs.packageName);
2562 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002563 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002564 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2565 pw.print(" h="); pw.print(mRequestedHeight);
2566 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002567 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2568 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2569 pw.print(" h="); pw.println(mLastRequestedHeight);
2570 }
Robert Carr51a1b872015-12-08 14:03:13 -08002571 if (isChildWindow() || mLayoutAttached) {
Wale Ogunwale7ed4d372016-07-09 15:28:55 -07002572 pw.print(prefix); pw.print("mParentWindow="); pw.print(mParentWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002573 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2574 }
2575 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2576 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2577 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2578 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2579 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2580 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002581 if (dumpAll) {
2582 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2583 pw.print(" mSubLayer="); pw.print(mSubLayer);
2584 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002585 pw.print((mTargetAppToken != null ?
2586 mTargetAppToken.mAppAnimator.animLayerAdjustment
2587 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002588 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2589 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002590 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002591 if (dumpAll) {
2592 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2593 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2594 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07002595 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
2596 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08002597 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08002598 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002599 }
2600 if (mTargetAppToken != null) {
2601 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2602 }
2603 pw.print(prefix); pw.print("mViewVisibility=0x");
2604 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002605 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2606 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002607 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2608 pw.print(" mSystemUiVisibility=0x");
2609 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002610 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002611 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07002612 || isParentWindowHidden()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002613 pw.print(prefix); pw.print("mPolicyVisibility=");
2614 pw.print(mPolicyVisibility);
2615 pw.print(" mPolicyVisibilityAfterAnim=");
2616 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002617 pw.print(" mAppOpVisibility=");
2618 pw.print(mAppOpVisibility);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002619 pw.print(" parentHidden="); pw.println(isParentWindowHidden());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002620 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002621 if (!mRelayoutCalled || mLayoutNeeded) {
2622 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2623 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002624 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002625 if (mXOffset != 0 || mYOffset != 0) {
2626 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2627 pw.print(" y="); pw.println(mYOffset);
2628 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002629 if (dumpAll) {
2630 pw.print(prefix); pw.print("mGivenContentInsets=");
2631 mGivenContentInsets.printShortString(pw);
2632 pw.print(" mGivenVisibleInsets=");
2633 mGivenVisibleInsets.printShortString(pw);
2634 pw.println();
2635 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2636 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2637 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002638 Region region = new Region();
2639 getTouchableRegion(region);
2640 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002641 }
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002642 pw.print(prefix); pw.print("mMergedConfiguration="); pw.println(mMergedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002643 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002644 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002645 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08002646 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002647 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
2648 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002649 if (dumpAll) {
2650 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2651 pw.print(" last="); mLastFrame.printShortString(pw);
2652 pw.println();
2653 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002654 if (mEnforceSizeCompat) {
2655 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002656 pw.println();
2657 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002658 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002659 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002660 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002661 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002662 pw.println();
2663 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2664 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002665 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002666 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002667 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002668 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002669 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2670 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002671 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2672 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002673 pw.print(prefix); pw.print("Cur insets: overscan=");
2674 mOverscanInsets.printShortString(pw);
2675 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002676 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002677 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07002678 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002679 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002680 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002681 pw.print(prefix); pw.print("Lst insets: overscan=");
2682 mLastOverscanInsets.printShortString(pw);
2683 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002684 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002685 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002686 pw.print(" physical="); mLastOutsets.printShortString(pw);
2687 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002688 pw.println();
2689 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002690 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2691 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002692 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
2693 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002694 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2695 pw.print(" mDestroying="); pw.print(mDestroying);
2696 pw.print(" mRemoved="); pw.println(mRemoved);
2697 }
2698 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2699 pw.print(prefix); pw.print("mOrientationChanging=");
2700 pw.print(mOrientationChanging);
2701 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2702 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2703 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002704 if (mLastFreezeDuration != 0) {
2705 pw.print(prefix); pw.print("mLastFreezeDuration=");
2706 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2707 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002708 if (mHScale != 1 || mVScale != 1) {
2709 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2710 pw.print(" mVScale="); pw.println(mVScale);
2711 }
2712 if (mWallpaperX != -1 || mWallpaperY != -1) {
2713 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2714 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2715 }
2716 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2717 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2718 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2719 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002720 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2721 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2722 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2723 pw.print(mWallpaperDisplayOffsetX);
2724 pw.print(" mWallpaperDisplayOffsetY=");
2725 pw.println(mWallpaperDisplayOffsetY);
2726 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002727 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002728 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002729 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002730 if (isDragResizing()) {
2731 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
2732 }
2733 if (computeDragResizing()) {
2734 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
2735 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002736 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002737
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002738 String makeInputChannelName() {
2739 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002740 + " " + getWindowTag();
2741 }
2742
Robert Carra1eb4392015-12-10 12:43:51 -08002743 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002744 CharSequence tag = mAttrs.getTitle();
2745 if (tag == null || tag.length() <= 0) {
2746 tag = mAttrs.packageName;
2747 }
2748 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002749 }
2750
2751 @Override
2752 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002753 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002754 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08002755 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002756 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002757 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002758 + " u" + UserHandle.getUserId(mSession.mUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002759 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002760 }
2761 return mStringNameCache;
2762 }
Robert Carr58f29132015-10-29 14:19:05 -07002763
Chia-I Wue6bcaf12016-05-27 10:58:48 +08002764 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07002765 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08002766 clipRect.left = (int) (clipRect.left / mHScale);
2767 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07002768 }
2769 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08002770 clipRect.top = (int) (clipRect.top / mVScale);
2771 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07002772 }
2773 }
Robert Carr31e28482015-12-02 16:53:18 -08002774
Jorim Jaggif5834272016-04-04 20:25:41 -07002775 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
2776 final int pw = containingFrame.width();
2777 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08002778 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07002779 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07002780 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
2781
2782 // We need to fit it to the display if either
2783 // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless
2784 // windows)
2785 // b) If it's a child window, we also need to fit it to the display unless
2786 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popup and similar windows on screen,
2787 // but SurfaceViews want to be always at a specific location so we don't fit it to the
2788 // display.
2789 final boolean fitToDisplay = (task == null || !nonFullscreenTask)
2790 || (isChildWindow() && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08002791 float x, y;
2792 int w,h;
2793
2794 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2795 if (mAttrs.width < 0) {
2796 w = pw;
2797 } else if (mEnforceSizeCompat) {
2798 w = (int)(mAttrs.width * mGlobalScale + .5f);
2799 } else {
2800 w = mAttrs.width;
2801 }
2802 if (mAttrs.height < 0) {
2803 h = ph;
2804 } else if (mEnforceSizeCompat) {
2805 h = (int)(mAttrs.height * mGlobalScale + .5f);
2806 } else {
2807 h = mAttrs.height;
2808 }
2809 } else {
2810 if (mAttrs.width == MATCH_PARENT) {
2811 w = pw;
2812 } else if (mEnforceSizeCompat) {
2813 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2814 } else {
2815 w = mRequestedWidth;
2816 }
2817 if (mAttrs.height == MATCH_PARENT) {
2818 h = ph;
2819 } else if (mEnforceSizeCompat) {
2820 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2821 } else {
2822 h = mRequestedHeight;
2823 }
2824 }
2825
2826 if (mEnforceSizeCompat) {
2827 x = mAttrs.x * mGlobalScale;
2828 y = mAttrs.y * mGlobalScale;
2829 } else {
2830 x = mAttrs.x;
2831 y = mAttrs.y;
2832 }
2833
Robert Carr1d2bacb2016-03-30 14:29:35 -07002834 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002835 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002836 // required by {@link Gravity#apply} call.
2837 w = Math.min(w, pw);
2838 h = Math.min(h, ph);
2839 }
2840
2841 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07002842 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08002843 (int) (x + mAttrs.horizontalMargin * pw),
2844 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2845
2846 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08002847 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07002848 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08002849 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08002850
2851 // We need to make sure we update the CompatFrame as it is used for
2852 // cropping decisions, etc, on systems where we lack a decor layer.
2853 mCompatFrame.set(mFrame);
2854 if (mEnforceSizeCompat) {
2855 // See comparable block in computeFrameLw.
2856 mCompatFrame.scale(mInvGlobalScale);
2857 }
Robert Carr31e28482015-12-02 16:53:18 -08002858 }
Robert Carr51a1b872015-12-08 14:03:13 -08002859
2860 boolean isChildWindow() {
Wale Ogunwale7ed4d372016-07-09 15:28:55 -07002861 return mParentWindow != null;
Robert Carr51a1b872015-12-08 14:03:13 -08002862 }
Robert Carra1eb4392015-12-10 12:43:51 -08002863
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07002864 boolean hasChild(WindowState child) {
2865 for (int i = mChildWindows.size() - 1; i >= 0; --i) {
2866 if (mChildWindows.get(i) == child) {
2867 return true;
2868 }
2869 }
2870 return false;
2871 }
2872
2873 /**
2874 * Returns the bottom child window in regards to z-order of this window or null if no children.
2875 */
2876 WindowState getBottomChild() {
2877 // Child windows are z-ordered based on sub-layer using {@link #sWindowSubLayerComparator}
2878 // and the child with the lowest z-order will be at the head of the list.
2879 return mChildWindows.isEmpty() ? null : mChildWindows.get(0);
2880 }
2881
Robert Carrf3b72c72016-03-21 18:16:39 -07002882 boolean layoutInParentFrame() {
2883 return isChildWindow() && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
2884 }
2885
Wale Ogunwale9d147902016-07-16 11:58:55 -07002886 boolean isParentWindowHidden() {
2887 return (mParentWindow != null) ? mParentWindow.mHidden : false;
2888 }
2889
Robert Carra1eb4392015-12-10 12:43:51 -08002890 void setReplacing(boolean animate) {
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002891 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
2892 || mAttrs.type == TYPE_APPLICATION_STARTING) {
2893 // We don't set replacing on starting windows since they are added by window manager and
2894 // not the client so won't be replaced by the client.
2895 return;
Robert Carra1eb4392015-12-10 12:43:51 -08002896 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002897
2898 mWillReplaceWindow = true;
2899 mReplacingWindow = null;
2900 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08002901 }
Chong Zhangf596cd52016-01-05 13:42:44 -08002902
2903 void resetReplacing() {
2904 mWillReplaceWindow = false;
2905 mReplacingWindow = null;
2906 mAnimateReplacingWindow = false;
2907 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08002908
Chong Zhang4d7369a2016-04-25 16:09:14 -07002909 void requestUpdateWallpaperIfNeeded() {
2910 if (mDisplayContent != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
2911 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
2912 mDisplayContent.layoutNeeded = true;
2913 mService.mWindowPlacerLocked.requestTraversal();
2914 }
2915 }
2916
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08002917 float translateToWindowX(float x) {
2918 float winX = x - mFrame.left;
2919 if (mEnforceSizeCompat) {
2920 winX *= mGlobalScale;
2921 }
2922 return winX;
2923 }
2924
2925 float translateToWindowY(float y) {
2926 float winY = y - mFrame.top;
2927 if (mEnforceSizeCompat) {
2928 winY *= mGlobalScale;
2929 }
2930 return winY;
2931 }
Robert Carrd1a010f2016-04-07 22:36:22 -07002932
Robert Carr9fe459d2016-04-07 23:32:28 -07002933 void transferDimToReplacement() {
2934 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2935 if (dimLayerUser != null && mDisplayContent != null) {
2936 mDisplayContent.mDimLayerController.applyDim(dimLayerUser,
2937 mReplacingWindow.mWinAnimator,
2938 (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? true : false);
2939 }
2940 }
2941
Robert Carrd1a010f2016-04-07 22:36:22 -07002942 // During activity relaunch due to resize, we sometimes use window replacement
2943 // for only child windows (as the main window is handled by window preservation)
2944 // and the big surface.
2945 //
2946 // Though windows of TYPE_APPLICATION (as opposed to TYPE_BASE_APPLICATION)
2947 // are not children in the sense of an attached window, we also want to replace
2948 // them at such phases, as they won't be covered by window preservation,
2949 // and in general we expect them to return following relaunch.
2950 boolean shouldBeReplacedWithChildren() {
2951 return isChildWindow() || mAttrs.type == TYPE_APPLICATION;
2952 }
Robert Carrfd10cd12016-06-29 16:41:50 -07002953
2954 public int getRotationAnimationHint() {
2955 if (mAppToken != null) {
2956 return mAppToken.mRotationAnimationHint;
2957 } else {
2958 return -1;
2959 }
2960 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07002961
2962 // This must be called while inside a transaction.
2963 boolean performShowLocked() {
2964 if (isHiddenFromUserLocked()) {
2965 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
2966 hideLw(false);
2967 return false;
2968 }
2969
2970 logPerformShow("performShow on ");
2971
2972 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplayIgnoringKeyguard()) {
2973 return false;
2974 }
2975
2976 logPerformShow("Showing ");
2977
2978 mService.enableScreenIfNeededLocked();
2979 mWinAnimator.applyEnterAnimationLocked();
2980
2981 // Force the show in the next prepareSurfaceLocked() call.
2982 mWinAnimator.mLastAlpha = -1;
2983 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
2984 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
2985 mWinAnimator.mDrawState = HAS_DRAWN;
2986 mService.scheduleAnimationLocked();
2987
2988 if (mHidden) {
2989 mHidden = false;
2990 final DisplayContent displayContent = getDisplayContent();
2991
2992 for (int i = mChildWindows.size(); i >= 0; --i) {
2993 final WindowState c = mChildWindows.get(i);
2994 if (c.mWinAnimator.mSurfaceController != null) {
2995 c.performShowLocked();
2996 // It hadn't been shown, which means layout not performed on it, so now we
2997 // want to make sure to do a layout. If called from within the transaction
2998 // loop, this will cause it to restart with a new layout.
2999 if (displayContent != null) {
3000 displayContent.layoutNeeded = true;
3001 }
3002 }
3003 }
3004 }
3005
3006 if (mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3007 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3008 }
3009
3010 if (mAttrs.type == TYPE_INPUT_METHOD) {
3011 mDisplayContent.mDividerControllerLocked.resetImeHideRequested();
3012 }
3013
3014 return true;
3015 }
3016
3017 void logPerformShow(String prefix) {
3018 if (DEBUG_VISIBILITY
3019 || (DEBUG_STARTING_WINDOW && mAttrs.type == TYPE_APPLICATION_STARTING)) {
3020 Slog.v(TAG, prefix + this
3021 + ": mDrawState=" + mWinAnimator.drawStateToString()
3022 + " readyForDisplay=" + isReadyForDisplayIgnoringKeyguard()
3023 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3024 + " during animation: policyVis=" + mPolicyVisibility
3025 + " parentHidden=" + isParentWindowHidden()
3026 + " tok.hiddenRequested="
3027 + (mAppToken != null ? mAppToken.hiddenRequested : false)
3028 + " tok.hidden=" + (mAppToken != null ? mAppToken.hidden : false)
3029 + " animating=" + mWinAnimator.mAnimating
3030 + " tok animating="
3031 + (mWinAnimator.mAppAnimator != null ? mWinAnimator.mAppAnimator.animating : false)
3032 + " Callers=" + Debug.getCallers(4));
3033 }
3034 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003035
3036 WindowInfo getWindowInfo() {
3037 WindowInfo windowInfo = WindowInfo.obtain();
3038 windowInfo.type = mAttrs.type;
3039 windowInfo.layer = mLayer;
3040 windowInfo.token = mClient.asBinder();
3041 windowInfo.title = mAttrs.accessibilityTitle;
3042 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3043 windowInfo.focused = isFocused();
3044
3045 if (isChildWindow()) {
3046 windowInfo.parentToken = mParentWindow.mClient.asBinder();
3047 }
3048
3049 final int childCount = mChildWindows.size();
3050 if (childCount > 0) {
3051 if (windowInfo.childTokens == null) {
3052 windowInfo.childTokens = new ArrayList<>();
3053 }
3054 for (int j = 0; j < childCount; j++) {
3055 final WindowState child = mChildWindows.get(j);
3056 windowInfo.childTokens.add(child.mClient.asBinder());
3057 }
3058 }
3059
3060 return windowInfo;
3061 }
3062
3063 void adjustAnimLayer(int adj) {
3064 mWinAnimator.mAnimLayer = mLayer + adj;
3065 if (DEBUG_LAYERS) Slog.v(TAG_WM, "win=" + this + " anim layer: " + mWinAnimator.mAnimLayer);
3066 for (int i = mChildWindows.size() - 1; i >= 0; i--) {
3067 final WindowState child = mChildWindows.get(i);
3068 child.adjustAnimLayer(adj);
3069 }
3070 }
3071
3072 // TODO: come-up with a better name for this method that represents what it does.
3073 // Or, it is probably not going to matter anyways if we are successful in getting rid of
3074 // the WindowList concept.
3075 int reAddWindowLocked(int index) {
3076 final WindowList windows = getWindowList();
3077 // Adding child windows relies on child windows being ordered by mSubLayer using
3078 // {@link #sWindowSubLayerComparator}.
3079 final int childCount = mChildWindows.size();
3080 boolean winAdded = false;
3081 for (int j = 0; j < childCount; j++) {
3082 WindowState child = mChildWindows.get(j);
3083 if (!winAdded && child.mSubLayer >= 0) {
3084 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3085 "Re-adding child window at " + index + ": " + child);
3086 mRebuilding = false;
3087 windows.add(index, this);
3088 index++;
3089 winAdded = true;
3090 }
3091 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + child);
3092 child.mRebuilding = false;
3093 windows.add(index, child);
3094 index++;
3095 }
3096 if (!winAdded) {
3097 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + this);
3098 mRebuilding = false;
3099 windows.add(index, this);
3100 index++;
3101 }
3102 mService.mWindowsChanged = true;
3103 return index;
3104 }
3105
3106 int removeFromWindowList(int interestingPos) {
3107 final WindowList windows = getWindowList();
3108 int wpos = windows.indexOf(this);
3109 if (wpos < 0) {
3110 return interestingPos;
3111 }
3112
3113 if (wpos < interestingPos) interestingPos--;
3114 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this);
3115 windows.remove(wpos);
3116 mService.mWindowsChanged = true;
3117 int childCount = mChildWindows.size();
3118 while (childCount > 0) {
3119 childCount--;
3120 final WindowState cw = mChildWindows.get(childCount);
3121 int cpos = windows.indexOf(cw);
3122 if (cpos >= 0) {
3123 if (cpos < interestingPos) interestingPos--;
3124 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3125 "Temp removing child at " + cpos + ": " + cw);
3126 windows.remove(cpos);
3127 }
3128 }
3129 return interestingPos;
3130 }
3131
3132 void onExitAnimationDone() {
3133 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3134 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
3135 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
3136
3137 if (!mChildWindows.isEmpty()) {
3138 // Copying to a different list as multiple children can be removed.
3139 final WindowList childWindows = new WindowList(mChildWindows);
3140 for (int i = childWindows.size() - 1; i >= 0; i--) {
3141 childWindows.get(i).onExitAnimationDone();
3142 }
3143 }
3144
3145 if (mWinAnimator.mEnteringAnimation) {
3146 mWinAnimator.mEnteringAnimation = false;
3147 mService.requestTraversal();
3148 // System windows don't have an activity and an app token as a result, but need a way
3149 // to be informed about their entrance animation end.
3150 if (mAppToken == null) {
3151 try {
3152 mClient.dispatchWindowShown();
3153 } catch (RemoteException e) {
3154 }
3155 }
3156 }
3157
3158 if (!mWinAnimator.isWindowAnimationSet()) {
3159 //TODO (multidisplay): Accessibility is supported only for the default display.
3160 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3161 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3162 }
3163 }
3164
3165 if (!mAnimatingExit) {
3166 return;
3167 }
3168
3169 if (mWinAnimator.isWindowAnimationSet()) {
3170 return;
3171 }
3172
3173 if (WindowManagerService.localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
3174 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3175
3176 mDestroying = true;
3177
3178 final boolean hasSurface = mWinAnimator.hasSurface();
3179 if (hasSurface) {
3180 mWinAnimator.hide("onExitAnimationDone");
3181 }
3182
3183 // If we have an app token, we ask it to destroy the surface for us, so that it can take
3184 // care to ensure the activity has actually stopped and the surface is not still in use.
3185 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
3186 // transaction.
3187 if (mAppToken != null) {
3188 mAppToken.destroySurfaces();
3189 } else {
3190 if (hasSurface) {
3191 mService.mDestroySurface.add(this);
3192 }
3193 if (mRemoveOnExit) {
3194 mService.mPendingRemove.add(this);
3195 mRemoveOnExit = false;
3196 }
3197 }
3198 mAnimatingExit = false;
3199 mService.mWallpaperControllerLocked.hideWallpapers(this);
3200 }
satokcef37fb2011-10-24 21:49:38 +09003201}