blob: 4f795a65a9db31545377819bf9fa026b6c537f37 [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 Ogunwalef9c81492015-02-25 18:06:17 -080019import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070020import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080021import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
22import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
23import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
24import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
25import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
26import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
27import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
28import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080029import static com.android.server.wm.WindowManagerService.DEBUG_CONFIGURATION;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -070030import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080031import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
Jeff Brownc2932a12014-11-20 18:04:05 -080032import static com.android.server.wm.WindowManagerService.DEBUG_POWER;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080033import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
34import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080035
Dianne Hackbornc2293022013-02-06 23:14:49 -080036import android.app.AppOpsManager;
Craig Mautnerdf88d732014-01-27 09:21:32 -080037import android.os.Debug;
Jeff Brownc2932a12014-11-20 18:04:05 -080038import android.os.PowerManager;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080039import android.os.RemoteCallbackList;
Craig Mautnerdf88d732014-01-27 09:21:32 -080040import android.os.SystemClock;
Jeff Brownc2932a12014-11-20 18:04:05 -080041import android.os.WorkSource;
Dianne Hackborna57c6952013-03-29 14:46:40 -070042import android.util.TimeUtils;
Svetoslav4604abc2014-06-10 18:59:30 -070043import android.view.Display;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080044import android.view.IWindowFocusObserver;
45import android.view.IWindowId;
Jeff Brownc2932a12014-11-20 18:04:05 -080046
Jeff Brown4532e612012-04-05 14:27:12 -070047import com.android.server.input.InputWindowHandle;
48
Craig Mautnere7ae2502012-03-26 17:11:19 -070049import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050import android.content.res.Configuration;
51import android.graphics.Matrix;
52import android.graphics.PixelFormat;
53import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070054import android.graphics.RectF;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055import android.graphics.Region;
56import android.os.IBinder;
57import android.os.RemoteException;
Craig Mautner9dc52bc2012-08-06 14:15:42 -070058import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070060import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061import android.view.Gravity;
62import android.view.IApplicationToken;
63import android.view.IWindow;
64import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065import android.view.View;
66import android.view.ViewTreeObserver;
67import android.view.WindowManager;
68import android.view.WindowManagerPolicy;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080069
70import java.io.PrintWriter;
71import java.util.ArrayList;
72
Craig Mautner59c00972012-07-30 12:10:24 -070073class WindowList extends ArrayList<WindowState> {
74}
75
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076/**
77 * A window in the window manager.
78 */
Craig Mautnere32c3072012-03-12 15:25:35 -070079final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070080 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -080081
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080082 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -070083 final WindowManagerPolicy mPolicy;
84 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080085 final Session mSession;
86 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -080087 final int mAppOp;
88 // UserId and appId of the owner. Don't display windows of non-current user.
89 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080090 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080091 WindowToken mToken;
92 WindowToken mRootToken;
93 AppWindowToken mAppToken;
94 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070095
96 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
97 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
99 final DeathRecipient mDeathRecipient;
100 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800101 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800102 final int mBaseLayer;
103 final int mSubLayer;
104 final boolean mLayoutAttached;
105 final boolean mIsImWindow;
106 final boolean mIsWallpaper;
107 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700108 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700109 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700111 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112 boolean mPolicyVisibility = true;
113 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800114 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800115 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800116 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800117 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700118
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800119 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
120
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700121 /**
122 * The window size that was requested by the application. These are in
123 * the application's coordinate space (without compatibility scale applied).
124 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 int mRequestedWidth;
126 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700127 int mLastRequestedWidth;
128 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700129
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800131 boolean mHaveFrame;
132 boolean mObscured;
133 boolean mTurnOnScreen;
134
135 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700136
Wale Ogunwale60454db2015-01-23 16:05:07 -0800137 private Configuration mConfiguration = Configuration.EMPTY;
138 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800139 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
140 // Used only on {@link #TYPE_KEYGUARD}.
141 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700142
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700143 /**
144 * Actual frame shown on-screen (may be modified by animation). These
145 * are in the screen's coordinate space (WITH the compatibility scale
146 * applied).
147 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700148 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149
150 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700151 * Insets that determine the actually visible area. These are in the application's
152 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 */
154 final Rect mVisibleInsets = new Rect();
155 final Rect mLastVisibleInsets = new Rect();
156 boolean mVisibleInsetsChanged;
157
158 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700159 * Insets that are covered by system windows (such as the status bar) and
160 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700161 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 */
163 final Rect mContentInsets = new Rect();
164 final Rect mLastContentInsets = new Rect();
165 boolean mContentInsetsChanged;
166
167 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800168 * Insets that determine the area covered by the display overscan region. These are in the
169 * application's coordinate space (without compatibility scale applied).
170 */
171 final Rect mOverscanInsets = new Rect();
172 final Rect mLastOverscanInsets = new Rect();
173 boolean mOverscanInsetsChanged;
174
175 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700176 * Insets that determine the area covered by the stable system windows. These are in the
177 * application's coordinate space (without compatibility scale applied).
178 */
179 final Rect mStableInsets = new Rect();
180 final Rect mLastStableInsets = new Rect();
181 boolean mStableInsetsChanged;
182
183 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 * Set to true if we are waiting for this window to receive its
185 * given internal insets before laying out other windows based on it.
186 */
187 boolean mGivenInsetsPending;
188
189 /**
190 * These are the content insets that were given during layout for
191 * this window, to be applied to windows behind it.
192 */
193 final Rect mGivenContentInsets = new Rect();
194
195 /**
196 * These are the visible insets that were given during layout for
197 * this window, to be applied to windows behind it.
198 */
199 final Rect mGivenVisibleInsets = new Rect();
200
201 /**
202 * This is the given touchable area relative to the window frame, or null if none.
203 */
204 final Region mGivenTouchableRegion = new Region();
205
206 /**
207 * Flag indicating whether the touchable region should be adjusted by
208 * the visible insets; if false the area outside the visible insets is
209 * NOT touchable, so we must use those to adjust the frame during hit
210 * tests.
211 */
212 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
213
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700214 /**
215 * This is rectangle of the window's surface that is not covered by
216 * system decorations.
217 */
218 final Rect mSystemDecorRect = new Rect();
219 final Rect mLastSystemDecorRect = new Rect();
220
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400222 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700223 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 float mHScale=1, mVScale=1;
225 float mLastHScale=1, mLastVScale=1;
226 final Matrix mTmpMatrix = new Matrix();
227
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700228 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229 final Rect mFrame = new Rect();
230 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700231 // Frame that is scaled to the application's coordinate space when in
232 // screen size compatibility mode.
233 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234
235 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700236
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700238
Wale Ogunwale94596652015-02-06 19:27:34 -0800239 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
240 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700241 final Rect mDisplayFrame = new Rect();
242
243 // The region of the display frame that the display type supports displaying content on. This
244 // is mostly a special case for TV where some displays don’t have the entire display usable.
245 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
246 // window display contents to extend into the overscan region.
247 final Rect mOverscanFrame = new Rect();
248
249 // The display frame minus the stable insets. This value is always constant regardless of if
250 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700251 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700253 // The area not occupied by the status and navigation bars. So, if both status and navigation
254 // bars are visible, the decor frame is equal to the stable frame.
255 final Rect mDecorFrame = new Rect();
256
257 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
258 // minus the area occupied by the IME if the IME is present.
259 final Rect mContentFrame = new Rect();
260
261 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
262 // displays hint text.
263 final Rect mVisibleFrame = new Rect();
264
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 boolean mContentChanged;
266
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267 // If a window showing a wallpaper: the requested offset for the
268 // wallpaper; if a wallpaper window: the currently applied offset.
269 float mWallpaperX = -1;
270 float mWallpaperY = -1;
271
272 // If a window showing a wallpaper: what fraction of the offset
273 // range corresponds to a full virtual screen.
274 float mWallpaperXStep = -1;
275 float mWallpaperYStep = -1;
276
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700277 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
278 // to its window; if a wallpaper window: not used.
279 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
280 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
281
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 // Wallpaper windows: pixels offset based on above variables.
283 int mXOffset;
284 int mYOffset;
285
Craig Mautner2268e7e2012-12-13 15:40:00 -0800286 /**
287 * This is set after IWindowSession.relayout() has been called at
288 * least once for the window. It allows us to detect the situation
289 * where we don't yet have a surface, but should have one soon, so
290 * we can give the window focus before waiting for the relayout.
291 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800292 boolean mRelayoutCalled;
293
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800294 /**
295 * If the application has called relayout() with changes that can
296 * impact its window's size, we need to perform a layout pass on it
297 * even if it is not currently visible for layout. This is set
298 * when in that case until the layout is done.
299 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800300 boolean mLayoutNeeded;
301
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800302 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 boolean mExiting;
304
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800305 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 boolean mDestroying;
307
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800308 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309 boolean mRemoveOnExit;
310
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800311 /**
312 * Set when the orientation is changing and this window has not yet
313 * been updated for the new orientation.
314 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315 boolean mOrientationChanging;
316
Dianne Hackborna57c6952013-03-29 14:46:40 -0700317 /**
318 * How long we last kept the screen frozen.
319 */
320 int mLastFreezeDuration;
321
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800322 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 boolean mRemoved;
324
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800325 /**
326 * Temp for keeping track of windows that have been removed when
327 * rebuilding window list.
328 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800329 boolean mRebuilding;
330
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700332 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800333 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800334
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800335 // Used to improve performance of toString()
336 String mStringNameCache;
337 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700338 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339
Craig Mautnera2c77052012-03-26 12:14:43 -0700340 final WindowStateAnimator mWinAnimator;
341
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700342 boolean mHasSurface = false;
343
Craig Mautner19ab8282014-05-07 10:35:34 -0700344 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700345 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700346
Craig Mautner88400d32012-09-30 12:35:45 -0700347 /** When true this window can be displayed on screens owther than mOwnerUid's */
348 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700349
Jeff Brownc2932a12014-11-20 18:04:05 -0800350 /**
351 * Wake lock for drawing.
352 * Even though it's slightly more expensive to do so, we will use a separate wake lock
353 * for each app that is requesting to draw while dozing so that we can accurately track
354 * who is preventing the system from suspending.
355 * This lock is only acquired on first use.
356 */
357 PowerManager.WakeLock mDrawLock;
358
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800359 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800360 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700361 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 mService = service;
363 mSession = s;
364 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800365 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800366 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700367 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800368 mWindowId = new IWindowId.Stub() {
369 @Override
370 public void registerFocusObserver(IWindowFocusObserver observer) {
371 WindowState.this.registerFocusObserver(observer);
372 }
373 @Override
374 public void unregisterFocusObserver(IWindowFocusObserver observer) {
375 WindowState.this.unregisterFocusObserver(observer);
376 }
377 @Override
378 public boolean isFocused() {
379 return WindowState.this.isFocused();
380 }
381 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800382 mAttrs.copyFrom(a);
383 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700384 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700385 mPolicy = mService.mPolicy;
386 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700388 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700389 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800390 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700391 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700392 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800393 try {
394 c.asBinder().linkToDeath(deathRecipient, 0);
395 } catch (RemoteException e) {
396 mDeathRecipient = null;
397 mAttachedWindow = null;
398 mLayoutAttached = false;
399 mIsImWindow = false;
400 mIsWallpaper = false;
401 mIsFloatingLayer = false;
402 mBaseLayer = 0;
403 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700404 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700405 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800406 return;
407 }
408 mDeathRecipient = deathRecipient;
409
410 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
411 mAttrs.type <= LAST_SUB_WINDOW)) {
412 // The multiplier here is to reserve space for multiple
413 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700414 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800415 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
416 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700417 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800418 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700419 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900420
tiger_huange2a98a72014-11-13 19:46:28 +0800421 final WindowList childWindows = mAttachedWindow.mChildWindows;
422 final int numChildWindows = childWindows.size();
423 if (numChildWindows == 0) {
424 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900425 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800426 boolean added = false;
427 for (int i = 0; i < numChildWindows; i++) {
428 final int childSubLayer = childWindows.get(i).mSubLayer;
429 if (mSubLayer < childSubLayer
430 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
431 // We insert the child window into the list ordered by the sub-layer. For
432 // same sub-layers, the negative one should go below others; the positive
433 // one should go above others.
434 childWindows.add(i, this);
435 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900436 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900437 }
438 }
tiger_huange2a98a72014-11-13 19:46:28 +0800439 if (!added) {
440 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900441 }
442 }
443
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800444 mLayoutAttached = mAttrs.type !=
445 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
446 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
447 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
448 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
449 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
450 } else {
451 // The multiplier here is to reserve space for multiple
452 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700453 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800454 * WindowManagerService.TYPE_LAYER_MULTIPLIER
455 + WindowManagerService.TYPE_LAYER_OFFSET;
456 mSubLayer = 0;
457 mAttachedWindow = null;
458 mLayoutAttached = false;
459 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
460 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
461 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
462 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
463 }
464
465 WindowState appWin = this;
466 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700467 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800468 }
469 WindowToken appToken = appWin.mToken;
470 while (appToken.appWindowToken == null) {
471 WindowToken parent = mService.mTokenMap.get(appToken.token);
472 if (parent == null || appToken == parent) {
473 break;
474 }
475 appToken = parent;
476 }
477 mRootToken = appToken;
478 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700479 if (mAppToken != null) {
480 final DisplayContent appDisplay = getDisplayContent();
481 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700482
483 if (mAppToken.showForAllUsers) {
484 // Windows for apps that can show for all users should also show when the
485 // device is locked.
486 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
487 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700488 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489
Craig Mautner322e4032012-07-13 13:35:20 -0700490 mWinAnimator = new WindowStateAnimator(this);
491 mWinAnimator.mAlpha = a.alpha;
492
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800493 mRequestedWidth = 0;
494 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700495 mLastRequestedWidth = 0;
496 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800497 mXOffset = 0;
498 mYOffset = 0;
499 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800500 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700501 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
502 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800503 }
504
505 void attach() {
506 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700507 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800508 + ", list=" + mToken.windows);
509 mSession.windowAddedLocked();
510 }
511
Craig Mautnera2c77052012-03-26 12:14:43 -0700512 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800513 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800514 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800515 }
516
517 @Override
518 public String getOwningPackage() {
519 return mAttrs.packageName;
520 }
521
522 @Override
Adrian Roosfa104232014-06-20 16:10:14 -0700523 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800524 mHaveFrame = true;
525
John Spurlock7045aaa2013-07-16 17:38:54 -0400526 TaskStack stack = mAppToken != null ? getStack() : null;
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800527 if (stack != null && !stack.isFullscreen()) {
Wale Ogunwaledd11d4d2015-02-03 14:49:20 -0800528 stack.getBounds(mContainingFrame);
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800529 final WindowState imeWin = mService.mInputMethodWindow;
530 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
531 && mContainingFrame.bottom > cf.bottom) {
532 // IME is up and obscuring this window. Adjust the window position so it is visible.
533 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700534 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800535 // Make sure the containing frame is within the content frame so we don't layout
536 // resized window under screen decorations.
537 mContainingFrame.intersect(cf);
Wale Ogunwale94596652015-02-06 19:27:34 -0800538 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700539 } else {
540 mContainingFrame.set(pf);
Wale Ogunwale94596652015-02-06 19:27:34 -0800541 mDisplayFrame.set(df);
Craig Mautner967212c2013-04-13 21:10:58 -0700542 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800543
Craig Mautner967212c2013-04-13 21:10:58 -0700544 final int pw = mContainingFrame.width();
545 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546
547 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700548 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
549 if (mAttrs.width < 0) {
550 w = pw;
551 } else if (mEnforceSizeCompat) {
552 w = (int)(mAttrs.width * mGlobalScale + .5f);
553 } else {
554 w = mAttrs.width;
555 }
556 if (mAttrs.height < 0) {
557 h = ph;
558 } else if (mEnforceSizeCompat) {
559 h = (int)(mAttrs.height * mGlobalScale + .5f);
560 } else {
561 h = mAttrs.height;
562 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800563 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700564 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
565 w = pw;
566 } else if (mEnforceSizeCompat) {
567 w = (int)(mRequestedWidth * mGlobalScale + .5f);
568 } else {
569 w = mRequestedWidth;
570 }
571 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
572 h = ph;
573 } else if (mEnforceSizeCompat) {
574 h = (int)(mRequestedHeight * mGlobalScale + .5f);
575 } else {
576 h = mRequestedHeight;
577 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800578 }
579
580 if (!mParentFrame.equals(pf)) {
581 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
582 // + " to " + pf);
583 mParentFrame.set(pf);
584 mContentChanged = true;
585 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700586 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
587 mLastRequestedWidth = mRequestedWidth;
588 mLastRequestedHeight = mRequestedHeight;
589 mContentChanged = true;
590 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800591
Craig Mautnereda67292013-04-28 13:50:14 -0700592 mOverscanFrame.set(of);
593 mContentFrame.set(cf);
594 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400595 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700596 mStableFrame.set(sf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800597
Craig Mautnereda67292013-04-28 13:50:14 -0700598 final int fw = mFrame.width();
599 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800600
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700601 float x, y;
602 if (mEnforceSizeCompat) {
603 x = mAttrs.x * mGlobalScale;
604 y = mAttrs.y * mGlobalScale;
605 } else {
606 x = mAttrs.x;
607 y = mAttrs.y;
608 }
609
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -0800610 // Make sure window fits in containing frame required by {@link Gravity#apply} call.
611 w = Math.min(w, pw);
612 h = Math.min(h, ph);
Craig Mautner967212c2013-04-13 21:10:58 -0700613 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700614 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700615 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800616
Wale Ogunwale94596652015-02-06 19:27:34 -0800617 // Now make sure the window fits in the overall display frame.
618 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800619
Craig Mautnera248eee2013-05-07 11:41:27 -0700620 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800621 // final window frame.
Craig Mautnereda67292013-04-28 13:50:14 -0700622 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
623 Math.max(mContentFrame.top, mFrame.top),
624 Math.min(mContentFrame.right, mFrame.right),
625 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800626
Craig Mautnereda67292013-04-28 13:50:14 -0700627 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
628 Math.max(mVisibleFrame.top, mFrame.top),
629 Math.min(mVisibleFrame.right, mFrame.right),
630 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800631
Adrian Roosfa104232014-06-20 16:10:14 -0700632 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
633 Math.max(mStableFrame.top, mFrame.top),
634 Math.min(mStableFrame.right, mFrame.right),
635 Math.min(mStableFrame.bottom, mFrame.bottom));
636
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700637 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
638 Math.max(mOverscanFrame.top - mFrame.top, 0),
Adrian Roos3236f3a2014-12-09 15:06:40 +0000639 Math.max(mFrame.right - mOverscanFrame.right, 0),
640 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800641
Craig Mautnereda67292013-04-28 13:50:14 -0700642 mContentInsets.set(mContentFrame.left - mFrame.left,
643 mContentFrame.top - mFrame.top,
644 mFrame.right - mContentFrame.right,
645 mFrame.bottom - mContentFrame.bottom);
646
647 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
648 mVisibleFrame.top - mFrame.top,
649 mFrame.right - mVisibleFrame.right,
650 mFrame.bottom - mVisibleFrame.bottom);
651
Adrian Roosfa104232014-06-20 16:10:14 -0700652 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
653 Math.max(mStableFrame.top - mFrame.top, 0),
654 Math.max(mFrame.right - mStableFrame.right, 0),
655 Math.max(mFrame.bottom - mStableFrame.bottom, 0));
656
Craig Mautnereda67292013-04-28 13:50:14 -0700657 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400658 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700659 // If there is a size compatibility scale being applied to the
660 // window, we need to apply this to its insets so that they are
661 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700662 mOverscanInsets.scale(mInvGlobalScale);
663 mContentInsets.scale(mInvGlobalScale);
664 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700665 mStableInsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700666
667 // Also the scaled frame that we report to the app needs to be
668 // adjusted to be in its coordinate space.
669 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400670 }
671
Craig Mautnereda67292013-04-28 13:50:14 -0700672 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800673 final DisplayContent displayContent = getDisplayContent();
674 if (displayContent != null) {
675 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
676 mService.updateWallpaperOffsetLocked(this,
677 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
678 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800679 }
680
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700681 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
682 "Resolving (mRequestedWidth="
683 + mRequestedWidth + ", mRequestedheight="
684 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
685 + "): frame=" + mFrame.toShortString()
686 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700687 + " vi=" + mVisibleInsets.toShortString()
688 + " vi=" + mStableInsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800689 }
690
Craig Mautnera2c77052012-03-26 12:14:43 -0700691 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800692 public Rect getFrameLw() {
693 return mFrame;
694 }
695
Craig Mautnera2c77052012-03-26 12:14:43 -0700696 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700697 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800698 return mShownFrame;
699 }
700
Craig Mautnera2c77052012-03-26 12:14:43 -0700701 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800702 public Rect getDisplayFrameLw() {
703 return mDisplayFrame;
704 }
705
Craig Mautnera2c77052012-03-26 12:14:43 -0700706 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800707 public Rect getOverscanFrameLw() {
708 return mOverscanFrame;
709 }
710
711 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800712 public Rect getContentFrameLw() {
713 return mContentFrame;
714 }
715
Craig Mautnera2c77052012-03-26 12:14:43 -0700716 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800717 public Rect getVisibleFrameLw() {
718 return mVisibleFrame;
719 }
720
Craig Mautnera2c77052012-03-26 12:14:43 -0700721 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800722 public boolean getGivenInsetsPendingLw() {
723 return mGivenInsetsPending;
724 }
725
Craig Mautnera2c77052012-03-26 12:14:43 -0700726 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800727 public Rect getGivenContentInsetsLw() {
728 return mGivenContentInsets;
729 }
730
Craig Mautnera2c77052012-03-26 12:14:43 -0700731 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800732 public Rect getGivenVisibleInsetsLw() {
733 return mGivenVisibleInsets;
734 }
735
Craig Mautnera2c77052012-03-26 12:14:43 -0700736 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800737 public WindowManager.LayoutParams getAttrs() {
738 return mAttrs;
739 }
740
Craig Mautner812d2ca2012-09-27 15:35:34 -0700741 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800742 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
743 int index = -1;
744 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700745 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800746 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700747 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
748 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800749 }
750 // If we reached the bottom of the range of windows we are considering,
751 // assume no menu is needed.
752 if (ws == bottom) {
753 return false;
754 }
755 // The current window hasn't specified whether menu key is needed;
756 // look behind it.
757 // First, we may need to determine the starting position.
758 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700759 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800760 }
761 index--;
762 if (index < 0) {
763 return false;
764 }
Craig Mautner59c00972012-07-30 12:10:24 -0700765 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800766 }
767 }
768
Craig Mautner19d59bc2012-09-04 11:15:56 -0700769 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700770 public int getSystemUiVisibility() {
771 return mSystemUiVisibility;
772 }
773
Craig Mautner19d59bc2012-09-04 11:15:56 -0700774 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800775 public int getSurfaceLayer() {
776 return mLayer;
777 }
778
Craig Mautner812d2ca2012-09-27 15:35:34 -0700779 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800780 public IApplicationToken getAppToken() {
781 return mAppToken != null ? mAppToken.appToken : null;
782 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700783
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700784 @Override
785 public boolean isVoiceInteraction() {
786 return mAppToken != null ? mAppToken.voiceInteraction : false;
787 }
788
Craig Mautner4c5eb222013-11-18 12:59:05 -0800789 boolean setInsetsChanged() {
790 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
791 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
792 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700793 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Craig Mautner4c5eb222013-11-18 12:59:05 -0800794 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged;
795 }
796
Craig Mautnerdf88d732014-01-27 09:21:32 -0800797 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700798 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700799 return mDisplayContent;
800 }
801 final TaskStack stack = getStack();
802 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800803 }
804
Craig Mautner19d59bc2012-09-04 11:15:56 -0700805 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800806 final DisplayContent displayContent = getDisplayContent();
807 if (displayContent == null) {
808 return -1;
809 }
810 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700811 }
812
Craig Mautnerd9a22882013-03-16 15:00:36 -0700813 TaskStack getStack() {
Craig Mautner05d29032013-05-03 13:40:13 -0700814 AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken;
815 if (wtoken != null) {
Craig Mautner83162a92015-01-26 14:43:30 -0800816 Task task = wtoken.mTask;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700817 if (task != null) {
Craig Mautnere0a38842013-12-16 16:14:02 -0800818 if (task.mStack != null) {
819 return task.mStack;
820 }
821 Slog.e(TAG, "getStack: mStack null for task=" + task);
822 } else {
Craig Mautner83162a92015-01-26 14:43:30 -0800823 Slog.e(TAG, "getStack: " + this + " couldn't find task for " + wtoken
Craig Mautnerdf88d732014-01-27 09:21:32 -0800824 + " Callers=" + Debug.getCallers(4));
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700825 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700826 }
Craig Mautner05d29032013-05-03 13:40:13 -0700827 return mDisplayContent.getHomeStack();
Craig Mautnerd9a22882013-03-16 15:00:36 -0700828 }
829
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800830 void getStackBounds(Rect bounds) {
Wale Ogunwaledd11d4d2015-02-03 14:49:20 -0800831 final TaskStack stack = getStack();
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700832 if (stack != null) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800833 stack.getBounds(bounds);
834 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700835 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800836 bounds.set(mFrame);
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700837 }
838
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800839 public long getInputDispatchingTimeoutNanos() {
840 return mAppToken != null
841 ? mAppToken.inputDispatchingTimeoutNanos
842 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
843 }
844
Craig Mautnere8552142012-11-07 13:55:47 -0800845 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800846 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700847 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800848 }
849
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800850 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
851 if (dsdx < .99999f || dsdx > 1.00001f) return false;
852 if (dtdy < .99999f || dtdy > 1.00001f) return false;
853 if (dtdx < -.000001f || dtdx > .000001f) return false;
854 if (dsdy < -.000001f || dsdy > .000001f) return false;
855 return true;
856 }
857
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400858 void prelayout() {
859 if (mEnforceSizeCompat) {
860 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700861 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400862 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700863 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400864 }
865 }
866
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800867 /**
868 * Is this window visible? It is not visible if there is no
869 * surface, or we are in the process of running an exit animation
870 * that will remove the surface, or its app token has been hidden.
871 */
Craig Mautner88400d32012-09-30 12:35:45 -0700872 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800873 public boolean isVisibleLw() {
874 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700875 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800876 && (atoken == null || !atoken.hiddenRequested)
877 && !mExiting && !mDestroying;
878 }
879
880 /**
881 * Like {@link #isVisibleLw}, but also counts a window that is currently
882 * "hidden" behind the keyguard as visible. This allows us to apply
883 * things like window flags that impact the keyguard.
884 * XXX I am starting to think we need to have ANOTHER visibility flag
885 * for this "hidden behind keyguard" state rather than overloading
886 * mPolicyVisibility. Ungh.
887 */
Craig Mautner88400d32012-09-30 12:35:45 -0700888 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800889 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700890 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800891 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700892 return false;
893 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800894 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700895 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -0700896 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700897 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800898 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700899 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
900 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700901 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800902 }
903
904 /**
905 * Is this window visible, ignoring its app token? It is not visible
906 * if there is no surface, or we are in the process of running an exit animation
907 * that will remove the surface.
908 */
909 public boolean isWinVisibleLw() {
910 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700911 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -0700912 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800913 && !mExiting && !mDestroying;
914 }
915
916 /**
917 * The same as isVisible(), but follows the current hidden state of
918 * the associated app token, not the pending requested hidden state.
919 */
920 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700921 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700922 && (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
923 && !mExiting && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800924 }
925
926 /**
927 * Can this window possibly be a drag/drop target? The test here is
928 * a combination of the above "visible now" with the check that the
929 * Input Manager uses when discarding windows from input consideration.
930 */
931 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700932 return isVisibleNow() && !mRemoved
933 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800934 }
935
936 /**
937 * Same as isVisible(), but we also count it as visible between the
938 * call to IWindowSession.add() and the first relayout().
939 */
940 boolean isVisibleOrAdding() {
941 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700942 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800943 && mPolicyVisibility && !mAttachedHidden
944 && (atoken == null || !atoken.hiddenRequested)
945 && !mExiting && !mDestroying;
946 }
947
948 /**
949 * Is this window currently on-screen? It is on-screen either if it
950 * is visible or it is currently running an animation before no longer
951 * being visible.
952 */
953 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100954 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
955 }
956
957 /**
958 * Like isOnScreen(), but ignores any force hiding of the window due
959 * to the keyguard.
960 */
961 boolean isOnScreenIgnoringKeyguard() {
962 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700963 return false;
964 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800965 final AppWindowToken atoken = mAppToken;
966 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700967 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800968 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800969 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700970 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800971 }
972
973 /**
974 * Like isOnScreen(), but we don't return true if the window is part
975 * of a transition that has not yet been started.
976 */
977 boolean isReadyForDisplay() {
978 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800979 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800980 return false;
981 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700982 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800983 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
984 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700985 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -0700986 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800987 }
988
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800989 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700990 * Like isReadyForDisplay(), but ignores any force hiding of the window due
991 * to the keyguard.
992 */
993 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800994 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700995 return false;
996 }
997 final AppWindowToken atoken = mAppToken;
998 if (atoken == null && !mPolicyVisibility) {
999 // If this is not an app window, and the policy has asked to force
1000 // hide, then we really do want to hide.
1001 return false;
1002 }
1003 return mHasSurface && !mDestroying
1004 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1005 && !mRootToken.hidden)
1006 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001007 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1008 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001009 }
1010
1011 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001012 * Like isOnScreen, but returns false if the surface hasn't yet
1013 * been drawn.
1014 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001015 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001016 public boolean isDisplayedLw() {
1017 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001018 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001019 && ((!mAttachedHidden &&
1020 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001021 || mWinAnimator.mAnimating
1022 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001023 }
1024
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001025 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001026 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001027 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001028 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001029 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001030 return mWinAnimator.mAnimation != null
1031 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001032 }
1033
Craig Mautner812d2ca2012-09-27 15:35:34 -07001034 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001035 public boolean isGoneForLayoutLw() {
1036 final AppWindowToken atoken = mAppToken;
1037 return mViewVisibility == View.GONE
1038 || !mRelayoutCalled
1039 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001040 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001041 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001042 || (mExiting && !isAnimatingLw())
1043 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001044 }
1045
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001046 /**
1047 * Returns true if the window has a surface that it has drawn a
1048 * complete UI in to.
1049 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001050 public boolean isDrawFinishedLw() {
1051 return mHasSurface && !mDestroying &&
1052 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1053 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1054 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1055 }
1056
1057 /**
1058 * Returns true if the window has a surface that it has drawn a
1059 * complete UI in to.
1060 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001061 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001062 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001063 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1064 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001065 }
1066
1067 /**
1068 * Return true if the window is opaque and fully drawn. This indicates
1069 * it may obscure windows behind it.
1070 */
1071 boolean isOpaqueDrawn() {
1072 return (mAttrs.format == PixelFormat.OPAQUE
1073 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001074 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001075 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001076 }
1077
1078 /**
1079 * Return whether this window is wanting to have a translation
1080 * animation applied to it for an in-progress move. (Only makes
1081 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1082 */
1083 boolean shouldAnimateMove() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001084 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001085 && (mFrame.top != mLastFrame.top
1086 || mFrame.left != mLastFrame.left)
Dianne Hackborn1c5383c2013-04-15 15:07:21 -07001087 && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Craig Mautner2fb98b12012-03-20 17:24:00 -07001088 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001089 }
1090
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001091 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001092 return mFrame.left <= 0 && mFrame.top <= 0 &&
1093 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001094 }
1095
Craig Mautner812d2ca2012-09-27 15:35:34 -07001096 boolean isConfigChanged() {
Wale Ogunwale60454db2015-01-23 16:05:07 -08001097 final TaskStack stack = getStack();
1098 final Configuration overrideConfig =
1099 (stack != null) ? stack.mOverrideConfig : Configuration.EMPTY;
1100 final Configuration serviceConfig = mService.mCurConfiguration;
1101 boolean configChanged =
1102 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1103 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001104
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001105 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001106 // Retain configuration changed status until resetConfiguration called.
1107 mConfigHasChanged |= configChanged;
1108 configChanged = mConfigHasChanged;
1109 }
1110
1111 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001112 }
1113
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001114 void removeLocked() {
1115 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001116
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001117 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001118 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001119 mAttachedWindow.mChildWindows.remove(this);
1120 }
Craig Mautner96868332012-12-04 14:29:11 -08001121 mWinAnimator.destroyDeferredSurfaceLocked();
1122 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001123 mSession.windowRemovedLocked();
1124 try {
1125 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1126 } catch (RuntimeException e) {
1127 // Ignore if it has already been removed (usually because
1128 // we are doing this as part of processing a death note.)
1129 }
1130 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001131
Wale Ogunwale60454db2015-01-23 16:05:07 -08001132 private void setConfiguration(
1133 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001134 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001135 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001136 mConfigHasChanged = false;
1137 }
1138
Jeff Browncc4f7db2011-08-30 20:34:48 -07001139 void setInputChannel(InputChannel inputChannel) {
1140 if (mInputChannel != null) {
1141 throw new IllegalStateException("Window already has an input channel.");
1142 }
1143
1144 mInputChannel = inputChannel;
1145 mInputWindowHandle.inputChannel = inputChannel;
1146 }
1147
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001148 void disposeInputChannel() {
1149 if (mInputChannel != null) {
1150 mService.mInputManager.unregisterInputChannel(mInputChannel);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001151
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001152 mInputChannel.dispose();
1153 mInputChannel = null;
1154 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001155
1156 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001157 }
1158
1159 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001160 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001161 public void binderDied() {
1162 try {
1163 synchronized(mService.mWindowMap) {
1164 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001165 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001166 if (win != null) {
1167 mService.removeWindowLocked(mSession, win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001168 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001169 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
1170 mService.removeWindowLocked(mSession, WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001171 }
1172 }
1173 } catch (IllegalArgumentException ex) {
1174 // This will happen if the window has already been
1175 // removed.
1176 }
1177 }
1178 }
1179
Craig Mautner58106812012-12-28 12:27:40 -08001180 /**
1181 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001182 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001183 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001184 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001185 && (mViewVisibility == View.VISIBLE)
1186 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1187 }
1188
Craig Mautner749a7bb2012-04-02 13:49:53 -07001189 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001190 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001191 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001192 }
1193
Craig Mautner749a7bb2012-04-02 13:49:53 -07001194 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001195 public boolean showLw(boolean doAnimation) {
1196 return showLw(doAnimation, true);
1197 }
1198
1199 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001200 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001201 return false;
1202 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001203 if (!mAppOpVisibility) {
1204 // Being hidden due to app op request.
1205 return false;
1206 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001207 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001208 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001209 return false;
1210 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001211 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001212 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001213 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001214 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001215 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001216 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001217 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001218 // Check for the case where we are currently visible and
1219 // not animating; we do not want to do animation at such a
1220 // point to become visible when we already are.
1221 doAnimation = false;
1222 }
1223 }
1224 mPolicyVisibility = true;
1225 mPolicyVisibilityAfterAnim = true;
1226 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001227 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001228 }
1229 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001230 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001231 }
1232 return true;
1233 }
1234
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001235 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001236 public boolean hideLw(boolean doAnimation) {
1237 return hideLw(doAnimation, true);
1238 }
1239
1240 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1241 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001242 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001243 doAnimation = false;
1244 }
1245 }
1246 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1247 : mPolicyVisibility;
1248 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001249 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001250 return false;
1251 }
1252 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001253 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001254 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001255 doAnimation = false;
1256 }
1257 }
1258 if (doAnimation) {
1259 mPolicyVisibilityAfterAnim = false;
1260 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001261 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001262 mPolicyVisibilityAfterAnim = false;
1263 mPolicyVisibility = false;
1264 // Window is no longer visible -- make sure if we were waiting
1265 // for it to be displayed before enabling the display, that
1266 // we allow the display to be enabled now.
1267 mService.enableScreenIfNeededLocked();
1268 if (mService.mCurrentFocus == this) {
Craig Mautner58458122013-09-14 14:59:50 -07001269 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1270 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001271 mService.mFocusMayChange = true;
1272 }
1273 }
1274 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001275 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001276 }
1277 return true;
1278 }
1279
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001280 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001281 if (mAppOpVisibility != state) {
1282 mAppOpVisibility = state;
1283 if (state) {
1284 // If the policy visibility had last been to hide, then this
1285 // will incorrectly show at this point since we lost that
1286 // information. Not a big deal -- for the windows that have app
1287 // ops modifies they should only be hidden by policy due to the
1288 // lock screen, and the user won't be changing this if locked.
1289 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001290 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001291 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001292 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001293 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001294 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001295 }
1296
Jeff Brownc2932a12014-11-20 18:04:05 -08001297 public void pokeDrawLockLw(long timeout) {
1298 if (isVisibleOrAdding()) {
1299 if (mDrawLock == null) {
1300 // We want the tag name to be somewhat stable so that it is easier to correlate
1301 // in wake lock statistics. So in particular, we don't want to include the
1302 // window's hash code as in toString().
1303 CharSequence tag = mAttrs.getTitle();
1304 if (tag == null) {
1305 tag = mAttrs.packageName;
1306 }
1307 mDrawLock = mService.mPowerManager.newWakeLock(
1308 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1309 mDrawLock.setReferenceCounted(false);
1310 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1311 }
1312 // Each call to acquire resets the timeout.
1313 if (DEBUG_POWER) {
1314 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1315 + mAttrs.packageName);
1316 }
1317 mDrawLock.acquire(timeout);
1318 } else if (DEBUG_POWER) {
1319 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1320 + "owned by " + mAttrs.packageName);
1321 }
1322 }
1323
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001324 @Override
1325 public boolean isAlive() {
1326 return mClient.asBinder().isBinderAlive();
1327 }
1328
Craig Mautnera987d432012-10-11 14:07:58 -07001329 boolean isClosing() {
1330 return mExiting || (mService.mClosingApps.contains(mAppToken));
1331 }
1332
Craig Mautner69b08182012-09-05 13:07:13 -07001333 @Override
1334 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001335 final DisplayContent displayContent = getDisplayContent();
1336 if (displayContent == null) {
1337 // Only a window that was on a non-default display can be detached from it.
1338 return false;
1339 }
Winson Chung47a3e652014-05-21 16:03:42 -07001340 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001341 }
1342
Adrian Rooscd3884d2015-02-18 17:25:23 +01001343 @Override
1344 public boolean isDimming() {
1345 TaskStack stack = getStack();
1346 if (stack == null) {
1347 return false;
1348 }
1349 return stack.isDimming(mWinAnimator);
1350 }
1351
Craig Mautner88400d32012-09-30 12:35:45 -07001352 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1353 mShowToOwnerOnly = showToOwnerOnly;
1354 }
1355
Craig Mautner5962b122012-10-05 14:45:52 -07001356 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001357 // Attached windows are evaluated based on the window that they are attached to.
1358 WindowState win = this;
1359 while (win.mAttachedWindow != null) {
1360 win = win.mAttachedWindow;
1361 }
1362 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001363 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001364 // Save some cycles by not calling getDisplayInfo unless it is an application
1365 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001366 final DisplayContent displayContent = win.getDisplayContent();
1367 if (displayContent == null) {
1368 return true;
1369 }
1370 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001371 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1372 && win.mFrame.right >= displayInfo.appWidth
1373 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001374 // Is a fullscreen window, like the clock alarm. Show to everyone.
1375 return false;
1376 }
1377 }
1378
Craig Mautner341220f2012-10-16 15:20:09 -07001379 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001380 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001381 }
1382
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001383 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1384 outRegion.set(
1385 frame.left + inset.left, frame.top + inset.top,
1386 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001387 }
1388
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001389 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001390 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001391 switch (mTouchableInsets) {
1392 default:
1393 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1394 outRegion.set(frame);
1395 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001396 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001397 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001398 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001399 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001400 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001401 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001402 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1403 final Region givenTouchableRegion = mGivenTouchableRegion;
1404 outRegion.set(givenTouchableRegion);
1405 outRegion.translate(frame.left, frame.top);
1406 break;
1407 }
1408 }
1409 }
1410
Craig Mautner59c00972012-07-30 12:10:24 -07001411 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001412 final DisplayContent displayContent = getDisplayContent();
1413 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001414 }
1415
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001416 /**
1417 * Report a focus change. Must be called with no locks held, and consistently
1418 * from the same serialized thread (such as dispatched from a handler).
1419 */
1420 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1421 try {
1422 mClient.windowFocusChanged(focused, inTouchMode);
1423 } catch (RemoteException e) {
1424 }
1425 if (mFocusCallbacks != null) {
1426 final int N = mFocusCallbacks.beginBroadcast();
1427 for (int i=0; i<N; i++) {
1428 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1429 try {
1430 if (focused) {
1431 obs.focusGained(mWindowId.asBinder());
1432 } else {
1433 obs.focusLost(mWindowId.asBinder());
1434 }
1435 } catch (RemoteException e) {
1436 }
1437 }
1438 mFocusCallbacks.finishBroadcast();
1439 }
1440 }
1441
Craig Mautnerdf88d732014-01-27 09:21:32 -08001442 void reportResized() {
1443 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001444 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1445 + ": " + mCompatFrame);
1446 boolean configChanged = isConfigChanged();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001447 final TaskStack stack = getStack();
1448 final Configuration overrideConfig =
1449 (stack != null) ? stack.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001450 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1451 Slog.i(TAG, "Sending new config to window " + this + ": "
Wale Ogunwale60454db2015-01-23 16:05:07 -08001452 + mWinAnimator.mSurfaceW + "x" + mWinAnimator.mSurfaceH + " / config="
1453 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001454 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001455 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001456 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1457 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1458
Craig Mautnerdf88d732014-01-27 09:21:32 -08001459 final Rect frame = mFrame;
1460 final Rect overscanInsets = mLastOverscanInsets;
1461 final Rect contentInsets = mLastContentInsets;
1462 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001463 final Rect stableInsets = mLastStableInsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001464 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1465 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07001466 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1467 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001468 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1469 mService.mH.post(new Runnable() {
1470 @Override
1471 public void run() {
1472 try {
1473 mClient.resized(frame, overscanInsets, contentInsets,
Adrian Roosfa104232014-06-20 16:10:14 -07001474 visibleInsets, stableInsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001475 } catch (RemoteException e) {
1476 // Not a remote call, RemoteException won't be raised.
1477 }
1478 }
1479 });
1480 } else {
Adrian Roosfa104232014-06-20 16:10:14 -07001481 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
1482 reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001483 }
Svetoslav4604abc2014-06-10 18:59:30 -07001484
1485 //TODO (multidisplay): Accessibility supported only for the default display.
1486 if (mService.mAccessibilityController != null
1487 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07001488 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07001489 }
1490
Craig Mautnerdf88d732014-01-27 09:21:32 -08001491 mOverscanInsetsChanged = false;
1492 mContentInsetsChanged = false;
1493 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07001494 mStableInsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001495 mWinAnimator.mSurfaceResized = false;
1496 } catch (RemoteException e) {
1497 mOrientationChanging = false;
1498 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1499 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08001500 // We are assuming the hosting process is dead or in a zombie state.
1501 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
1502 + ", removing this window.");
1503 mService.mPendingRemove.add(this);
1504 mService.requestTraversalLocked();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001505 }
1506 }
1507
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001508 public void registerFocusObserver(IWindowFocusObserver observer) {
1509 synchronized(mService.mWindowMap) {
1510 if (mFocusCallbacks == null) {
1511 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1512 }
1513 mFocusCallbacks.register(observer);
1514 }
1515 }
1516
1517 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1518 synchronized(mService.mWindowMap) {
1519 if (mFocusCallbacks != null) {
1520 mFocusCallbacks.unregister(observer);
1521 }
1522 }
1523 }
1524
1525 public boolean isFocused() {
1526 synchronized(mService.mWindowMap) {
1527 return mService.mCurrentFocus == this;
1528 }
1529 }
1530
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001531 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001532 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001533 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001534 if (stack != null) {
1535 pw.print(" stackId="); pw.print(stack.mStackId);
1536 }
Craig Mautner59c00972012-07-30 12:10:24 -07001537 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001538 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001539 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001540 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1541 pw.print(" package="); pw.print(mAttrs.packageName);
1542 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001543 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001544 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1545 pw.print(" h="); pw.print(mRequestedHeight);
1546 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001547 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1548 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1549 pw.print(" h="); pw.println(mLastRequestedHeight);
1550 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001551 if (mAttachedWindow != null || mLayoutAttached) {
1552 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1553 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1554 }
1555 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1556 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1557 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1558 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1559 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1560 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001561 if (dumpAll) {
1562 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1563 pw.print(" mSubLayer="); pw.print(mSubLayer);
1564 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001565 pw.print((mTargetAppToken != null ?
1566 mTargetAppToken.mAppAnimator.animLayerAdjustment
1567 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001568 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1569 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001570 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001571 if (dumpAll) {
1572 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1573 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1574 if (mAppToken != null) {
1575 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1576 }
1577 if (mTargetAppToken != null) {
1578 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1579 }
1580 pw.print(prefix); pw.print("mViewVisibility=0x");
1581 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001582 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1583 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001584 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1585 pw.print(" mSystemUiVisibility=0x");
1586 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001587 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001588 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1589 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001590 pw.print(prefix); pw.print("mPolicyVisibility=");
1591 pw.print(mPolicyVisibility);
1592 pw.print(" mPolicyVisibilityAfterAnim=");
1593 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001594 pw.print(" mAppOpVisibility=");
1595 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001596 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1597 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001598 if (!mRelayoutCalled || mLayoutNeeded) {
1599 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1600 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001601 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001602 if (mXOffset != 0 || mYOffset != 0) {
1603 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1604 pw.print(" y="); pw.println(mYOffset);
1605 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001606 if (dumpAll) {
1607 pw.print(prefix); pw.print("mGivenContentInsets=");
1608 mGivenContentInsets.printShortString(pw);
1609 pw.print(" mGivenVisibleInsets=");
1610 mGivenVisibleInsets.printShortString(pw);
1611 pw.println();
1612 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1613 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1614 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001615 Region region = new Region();
1616 getTouchableRegion(region);
1617 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001618 }
1619 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08001620 if (mOverrideConfig != Configuration.EMPTY) {
1621 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
1622 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001623 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001624 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001625 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1626 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001627 if (dumpAll) {
1628 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1629 pw.print(" last="); mLastFrame.printShortString(pw);
1630 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001631 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1632 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1633 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001634 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001635 if (mEnforceSizeCompat) {
1636 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001637 pw.println();
1638 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001639 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001640 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001641 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001642 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001643 pw.println();
1644 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1645 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001646 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001647 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001648 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001649 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04001650 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
1651 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001652 pw.print(prefix); pw.print("Cur insets: overscan=");
1653 mOverscanInsets.printShortString(pw);
1654 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001655 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07001656 pw.print(" stable="); mStableInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001657 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001658 pw.print(prefix); pw.print("Lst insets: overscan=");
1659 mLastOverscanInsets.printShortString(pw);
1660 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001661 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07001662 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001663 pw.println();
1664 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001665 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1666 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001667 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1668 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1669 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1670 pw.print(" mDestroying="); pw.print(mDestroying);
1671 pw.print(" mRemoved="); pw.println(mRemoved);
1672 }
1673 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1674 pw.print(prefix); pw.print("mOrientationChanging=");
1675 pw.print(mOrientationChanging);
1676 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1677 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1678 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07001679 if (mLastFreezeDuration != 0) {
1680 pw.print(prefix); pw.print("mLastFreezeDuration=");
1681 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
1682 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001683 if (mHScale != 1 || mVScale != 1) {
1684 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1685 pw.print(" mVScale="); pw.println(mVScale);
1686 }
1687 if (mWallpaperX != -1 || mWallpaperY != -1) {
1688 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1689 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1690 }
1691 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1692 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1693 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1694 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07001695 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
1696 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
1697 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
1698 pw.print(mWallpaperDisplayOffsetX);
1699 pw.print(" mWallpaperDisplayOffsetY=");
1700 pw.println(mWallpaperDisplayOffsetY);
1701 }
Jeff Brownc2932a12014-11-20 18:04:05 -08001702 if (mDrawLock != null) {
1703 pw.println("mDrawLock=" + mDrawLock);
1704 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001705 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001706
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001707 String makeInputChannelName() {
1708 return Integer.toHexString(System.identityHashCode(this))
1709 + " " + mAttrs.getTitle();
1710 }
1711
1712 @Override
1713 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001714 CharSequence title = mAttrs.getTitle();
1715 if (title == null || title.length() <= 0) {
1716 title = mAttrs.packageName;
1717 }
1718 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1719 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001720 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001721 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001722 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001723 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001724 }
1725 return mStringNameCache;
1726 }
satokcef37fb2011-10-24 21:49:38 +09001727}