blob: dff79a855c5bf20654890b2ccfd3332937249a3b [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
Craig Mautnerd1c2c542014-02-06 10:31:41 -080019import static com.android.server.wm.WindowManagerService.DEBUG_CONFIGURATION;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -070020import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080021import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
Jeff Brownc2932a12014-11-20 18:04:05 -080022import static com.android.server.wm.WindowManagerService.DEBUG_POWER;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080023import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
24import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080025import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Jorim Jaggi380ecb82014-03-14 17:25:20 +010026import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Adam Lesinski6a591f52013-10-01 18:11:17 -070027import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080028import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Dianne Hackborn1c5383c2013-04-15 15:07:21 -070029import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080030import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
31import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -070032import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080033import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
34
Dianne Hackbornc2293022013-02-06 23:14:49 -080035import android.app.AppOpsManager;
Craig Mautnerdf88d732014-01-27 09:21:32 -080036import android.os.Debug;
Jeff Brownc2932a12014-11-20 18:04:05 -080037import android.os.PowerManager;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080038import android.os.RemoteCallbackList;
Craig Mautnerdf88d732014-01-27 09:21:32 -080039import android.os.SystemClock;
Jeff Brownc2932a12014-11-20 18:04:05 -080040import android.os.WorkSource;
Dianne Hackborna57c6952013-03-29 14:46:40 -070041import android.util.TimeUtils;
Svetoslav4604abc2014-06-10 18:59:30 -070042import android.view.Display;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080043import android.view.IWindowFocusObserver;
44import android.view.IWindowId;
Jeff Brownc2932a12014-11-20 18:04:05 -080045
Jeff Brown4532e612012-04-05 14:27:12 -070046import com.android.server.input.InputWindowHandle;
47
Craig Mautnere7ae2502012-03-26 17:11:19 -070048import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049import android.content.res.Configuration;
50import android.graphics.Matrix;
51import android.graphics.PixelFormat;
52import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070053import android.graphics.RectF;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080054import android.graphics.Region;
55import android.os.IBinder;
56import android.os.RemoteException;
Craig Mautner9dc52bc2012-08-06 14:15:42 -070057import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080058import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070059import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060import android.view.Gravity;
61import android.view.IApplicationToken;
62import android.view.IWindow;
63import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064import android.view.View;
65import android.view.ViewTreeObserver;
66import android.view.WindowManager;
67import android.view.WindowManagerPolicy;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080068
69import java.io.PrintWriter;
70import java.util.ArrayList;
71
Craig Mautner59c00972012-07-30 12:10:24 -070072class WindowList extends ArrayList<WindowState> {
73}
74
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080075/**
76 * A window in the window manager.
77 */
Craig Mautnere32c3072012-03-12 15:25:35 -070078final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070079 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -080080
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080081 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -070082 final WindowManagerPolicy mPolicy;
83 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080084 final Session mSession;
85 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -080086 final int mAppOp;
87 // UserId and appId of the owner. Don't display windows of non-current user.
88 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080089 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080090 WindowToken mToken;
91 WindowToken mRootToken;
92 AppWindowToken mAppToken;
93 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070094
95 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
96 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080097 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
98 final DeathRecipient mDeathRecipient;
99 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800100 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800101 final int mBaseLayer;
102 final int mSubLayer;
103 final boolean mLayoutAttached;
104 final boolean mIsImWindow;
105 final boolean mIsWallpaper;
106 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700107 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700108 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700110 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111 boolean mPolicyVisibility = true;
112 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800113 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800115 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800116 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700117
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800118 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
119
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700120 /**
121 * The window size that was requested by the application. These are in
122 * the application's coordinate space (without compatibility scale applied).
123 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800124 int mRequestedWidth;
125 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700126 int mLastRequestedWidth;
127 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700128
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800129 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 boolean mHaveFrame;
131 boolean mObscured;
132 boolean mTurnOnScreen;
133
134 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700135
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 Configuration mConfiguration = null;
Craig Mautnere8552142012-11-07 13:55:47 -0800137 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
138 // Used only on {@link #TYPE_KEYGUARD}.
139 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700140
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700141 /**
142 * Actual frame shown on-screen (may be modified by animation). These
143 * are in the screen's coordinate space (WITH the compatibility scale
144 * applied).
145 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700146 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147
148 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700149 * Insets that determine the actually visible area. These are in the application's
150 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 */
152 final Rect mVisibleInsets = new Rect();
153 final Rect mLastVisibleInsets = new Rect();
154 boolean mVisibleInsetsChanged;
155
156 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700157 * Insets that are covered by system windows (such as the status bar) and
158 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700159 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160 */
161 final Rect mContentInsets = new Rect();
162 final Rect mLastContentInsets = new Rect();
163 boolean mContentInsetsChanged;
164
165 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800166 * Insets that determine the area covered by the display overscan region. These are in the
167 * application's coordinate space (without compatibility scale applied).
168 */
169 final Rect mOverscanInsets = new Rect();
170 final Rect mLastOverscanInsets = new Rect();
171 boolean mOverscanInsetsChanged;
172
173 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700174 * Insets that determine the area covered by the stable system windows. These are in the
175 * application's coordinate space (without compatibility scale applied).
176 */
177 final Rect mStableInsets = new Rect();
178 final Rect mLastStableInsets = new Rect();
179 boolean mStableInsetsChanged;
180
181 /**
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -0700182 * Outsets determine the area outside of the surface where we want to pretend that it's possible
183 * to draw anyway.
184 */
185 final Rect mOutsets = new Rect();
186 final Rect mLastOutsets = new Rect();
187 boolean mOutsetsChanged = false;
188
189 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 * Set to true if we are waiting for this window to receive its
191 * given internal insets before laying out other windows based on it.
192 */
193 boolean mGivenInsetsPending;
194
195 /**
196 * These are the content insets that were given during layout for
197 * this window, to be applied to windows behind it.
198 */
199 final Rect mGivenContentInsets = new Rect();
200
201 /**
202 * These are the visible insets that were given during layout for
203 * this window, to be applied to windows behind it.
204 */
205 final Rect mGivenVisibleInsets = new Rect();
206
207 /**
208 * This is the given touchable area relative to the window frame, or null if none.
209 */
210 final Region mGivenTouchableRegion = new Region();
211
212 /**
213 * Flag indicating whether the touchable region should be adjusted by
214 * the visible insets; if false the area outside the visible insets is
215 * NOT touchable, so we must use those to adjust the frame during hit
216 * tests.
217 */
218 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
219
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700220 /**
221 * This is rectangle of the window's surface that is not covered by
222 * system decorations.
223 */
224 final Rect mSystemDecorRect = new Rect();
225 final Rect mLastSystemDecorRect = new Rect();
226
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800227 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400228 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700229 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 float mHScale=1, mVScale=1;
231 float mLastHScale=1, mLastVScale=1;
232 final Matrix mTmpMatrix = new Matrix();
233
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700234 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 final Rect mFrame = new Rect();
236 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700237 // Frame that is scaled to the application's coordinate space when in
238 // screen size compatibility mode.
239 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240
241 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700242
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700244
245 // The entire screen area of the device.
246 final Rect mDisplayFrame = new Rect();
247
248 // The region of the display frame that the display type supports displaying content on. This
249 // is mostly a special case for TV where some displays don’t have the entire display usable.
250 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
251 // window display contents to extend into the overscan region.
252 final Rect mOverscanFrame = new Rect();
253
254 // The display frame minus the stable insets. This value is always constant regardless of if
255 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700256 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700258 // The area not occupied by the status and navigation bars. So, if both status and navigation
259 // bars are visible, the decor frame is equal to the stable frame.
260 final Rect mDecorFrame = new Rect();
261
262 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
263 // minus the area occupied by the IME if the IME is present.
264 final Rect mContentFrame = new Rect();
265
266 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
267 // displays hint text.
268 final Rect mVisibleFrame = new Rect();
269
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -0700270 // Frame that includes dead area outside of the surface but where we want to pretend that it's
271 // possible to draw.
272 final Rect mOutsetFrame = new Rect();
273
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800274 boolean mContentChanged;
275
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276 // If a window showing a wallpaper: the requested offset for the
277 // wallpaper; if a wallpaper window: the currently applied offset.
278 float mWallpaperX = -1;
279 float mWallpaperY = -1;
280
281 // If a window showing a wallpaper: what fraction of the offset
282 // range corresponds to a full virtual screen.
283 float mWallpaperXStep = -1;
284 float mWallpaperYStep = -1;
285
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700286 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
287 // to its window; if a wallpaper window: not used.
288 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
289 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
290
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 // Wallpaper windows: pixels offset based on above variables.
292 int mXOffset;
293 int mYOffset;
294
Craig Mautner2268e7e2012-12-13 15:40:00 -0800295 /**
296 * This is set after IWindowSession.relayout() has been called at
297 * least once for the window. It allows us to detect the situation
298 * where we don't yet have a surface, but should have one soon, so
299 * we can give the window focus before waiting for the relayout.
300 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800301 boolean mRelayoutCalled;
302
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800303 /**
304 * If the application has called relayout() with changes that can
305 * impact its window's size, we need to perform a layout pass on it
306 * even if it is not currently visible for layout. This is set
307 * when in that case until the layout is done.
308 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800309 boolean mLayoutNeeded;
310
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800311 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312 boolean mExiting;
313
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800314 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315 boolean mDestroying;
316
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800317 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 boolean mRemoveOnExit;
319
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800320 /**
321 * Set when the orientation is changing and this window has not yet
322 * been updated for the new orientation.
323 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 boolean mOrientationChanging;
325
Dianne Hackborna57c6952013-03-29 14:46:40 -0700326 /**
327 * How long we last kept the screen frozen.
328 */
329 int mLastFreezeDuration;
330
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800331 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332 boolean mRemoved;
333
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800334 /**
335 * Temp for keeping track of windows that have been removed when
336 * rebuilding window list.
337 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800338 boolean mRebuilding;
339
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700341 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800342 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800343
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344 // Used to improve performance of toString()
345 String mStringNameCache;
346 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700347 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800348
Craig Mautnera2c77052012-03-26 12:14:43 -0700349 final WindowStateAnimator mWinAnimator;
350
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700351 boolean mHasSurface = false;
352
Craig Mautner19ab8282014-05-07 10:35:34 -0700353 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700354 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700355
Craig Mautner88400d32012-09-30 12:35:45 -0700356 /** When true this window can be displayed on screens owther than mOwnerUid's */
357 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700358
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700359 /** When true this window is at the top of the screen and should be layed out to extend under
360 * the status bar */
361 boolean mUnderStatusBar = true;
362
Jeff Brownc2932a12014-11-20 18:04:05 -0800363 /**
364 * Wake lock for drawing.
365 * Even though it's slightly more expensive to do so, we will use a separate wake lock
366 * for each app that is requesting to draw while dozing so that we can accurately track
367 * who is preventing the system from suspending.
368 * This lock is only acquired on first use.
369 */
370 PowerManager.WakeLock mDrawLock;
371
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800372 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800373 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700374 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 mService = service;
376 mSession = s;
377 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800378 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800379 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700380 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800381 mWindowId = new IWindowId.Stub() {
382 @Override
383 public void registerFocusObserver(IWindowFocusObserver observer) {
384 WindowState.this.registerFocusObserver(observer);
385 }
386 @Override
387 public void unregisterFocusObserver(IWindowFocusObserver observer) {
388 WindowState.this.unregisterFocusObserver(observer);
389 }
390 @Override
391 public boolean isFocused() {
392 return WindowState.this.isFocused();
393 }
394 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800395 mAttrs.copyFrom(a);
396 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700397 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700398 mPolicy = mService.mPolicy;
399 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800400 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700401 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700402 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800403 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700404 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700405 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800406 try {
407 c.asBinder().linkToDeath(deathRecipient, 0);
408 } catch (RemoteException e) {
409 mDeathRecipient = null;
410 mAttachedWindow = null;
411 mLayoutAttached = false;
412 mIsImWindow = false;
413 mIsWallpaper = false;
414 mIsFloatingLayer = false;
415 mBaseLayer = 0;
416 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700417 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700418 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419 return;
420 }
421 mDeathRecipient = deathRecipient;
422
423 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
424 mAttrs.type <= LAST_SUB_WINDOW)) {
425 // The multiplier here is to reserve space for multiple
426 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700427 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800428 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
429 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700430 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800431 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700432 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900433
434 int children_size = mAttachedWindow.mChildWindows.size();
435 if (children_size == 0) {
436 mAttachedWindow.mChildWindows.add(this);
437 } else {
438 for (int i = 0; i < children_size; i++) {
439 WindowState child = (WindowState)mAttachedWindow.mChildWindows.get(i);
440 if (this.mSubLayer < child.mSubLayer) {
441 mAttachedWindow.mChildWindows.add(i, this);
442 break;
443 } else if (this.mSubLayer > child.mSubLayer) {
444 continue;
445 }
446
447 if (this.mBaseLayer <= child.mBaseLayer) {
448 mAttachedWindow.mChildWindows.add(i, this);
449 break;
450 } else {
451 continue;
452 }
453 }
454 if (children_size == mAttachedWindow.mChildWindows.size()) {
455 mAttachedWindow.mChildWindows.add(this);
456 }
457 }
458
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800459 mLayoutAttached = mAttrs.type !=
460 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
461 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
462 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
463 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
464 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
465 } else {
466 // The multiplier here is to reserve space for multiple
467 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700468 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 * WindowManagerService.TYPE_LAYER_MULTIPLIER
470 + WindowManagerService.TYPE_LAYER_OFFSET;
471 mSubLayer = 0;
472 mAttachedWindow = null;
473 mLayoutAttached = false;
474 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
475 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
476 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
477 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
478 }
479
480 WindowState appWin = this;
481 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700482 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800483 }
484 WindowToken appToken = appWin.mToken;
485 while (appToken.appWindowToken == null) {
486 WindowToken parent = mService.mTokenMap.get(appToken.token);
487 if (parent == null || appToken == parent) {
488 break;
489 }
490 appToken = parent;
491 }
492 mRootToken = appToken;
493 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700494 if (mAppToken != null) {
495 final DisplayContent appDisplay = getDisplayContent();
496 mNotOnAppsDisplay = displayContent != appDisplay;
497 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800498
Craig Mautner322e4032012-07-13 13:35:20 -0700499 mWinAnimator = new WindowStateAnimator(this);
500 mWinAnimator.mAlpha = a.alpha;
501
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800502 mRequestedWidth = 0;
503 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700504 mLastRequestedWidth = 0;
505 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800506 mXOffset = 0;
507 mYOffset = 0;
508 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800509 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700510 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
511 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800512 }
513
514 void attach() {
515 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700516 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800517 + ", list=" + mToken.windows);
518 mSession.windowAddedLocked();
519 }
520
Craig Mautnera2c77052012-03-26 12:14:43 -0700521 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800522 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800523 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800524 }
525
526 @Override
527 public String getOwningPackage() {
528 return mAttrs.packageName;
529 }
530
531 @Override
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -0700532 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
533 Rect osf) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800534 mHaveFrame = true;
535
John Spurlock7045aaa2013-07-16 17:38:54 -0400536 TaskStack stack = mAppToken != null ? getStack() : null;
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800537 if (stack != null && !stack.isFullscreen()) {
538 getStackBounds(stack, mContainingFrame);
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700539 if (mUnderStatusBar) {
540 mContainingFrame.top = pf.top;
541 }
Craig Mautner967212c2013-04-13 21:10:58 -0700542 } else {
543 mContainingFrame.set(pf);
544 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800545
Craig Mautnereda67292013-04-28 13:50:14 -0700546 mDisplayFrame.set(df);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800547
Craig Mautner967212c2013-04-13 21:10:58 -0700548 final int pw = mContainingFrame.width();
549 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800550
551 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700552 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
553 if (mAttrs.width < 0) {
554 w = pw;
555 } else if (mEnforceSizeCompat) {
556 w = (int)(mAttrs.width * mGlobalScale + .5f);
557 } else {
558 w = mAttrs.width;
559 }
560 if (mAttrs.height < 0) {
561 h = ph;
562 } else if (mEnforceSizeCompat) {
563 h = (int)(mAttrs.height * mGlobalScale + .5f);
564 } else {
565 h = mAttrs.height;
566 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800567 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700568 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
569 w = pw;
570 } else if (mEnforceSizeCompat) {
571 w = (int)(mRequestedWidth * mGlobalScale + .5f);
572 } else {
573 w = mRequestedWidth;
574 }
575 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
576 h = ph;
577 } else if (mEnforceSizeCompat) {
578 h = (int)(mRequestedHeight * mGlobalScale + .5f);
579 } else {
580 h = mRequestedHeight;
581 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800582 }
583
584 if (!mParentFrame.equals(pf)) {
585 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
586 // + " to " + pf);
587 mParentFrame.set(pf);
588 mContentChanged = true;
589 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700590 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
591 mLastRequestedWidth = mRequestedWidth;
592 mLastRequestedHeight = mRequestedHeight;
593 mContentChanged = true;
594 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800595
Craig Mautnereda67292013-04-28 13:50:14 -0700596 mOverscanFrame.set(of);
597 mContentFrame.set(cf);
598 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400599 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700600 mStableFrame.set(sf);
Filip Gruszczynski35a803b2015-05-27 15:38:29 -0700601 final boolean hasOutsets = osf != null;
602 if (hasOutsets) {
603 mOutsetFrame.set(osf);
604 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800605
Craig Mautnereda67292013-04-28 13:50:14 -0700606 final int fw = mFrame.width();
607 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800608
609 //System.out.println("In: w=" + w + " h=" + h + " container=" +
610 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
611
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700612 float x, y;
613 if (mEnforceSizeCompat) {
614 x = mAttrs.x * mGlobalScale;
615 y = mAttrs.y * mGlobalScale;
616 } else {
617 x = mAttrs.x;
618 y = mAttrs.y;
619 }
620
Craig Mautner967212c2013-04-13 21:10:58 -0700621 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700622 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700623 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800624
625 //System.out.println("Out: " + mFrame);
626
627 // Now make sure the window fits in the overall display.
Craig Mautnereda67292013-04-28 13:50:14 -0700628 Gravity.applyDisplay(mAttrs.gravity, df, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800629
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700630 // Calculate the outsets before the content frame gets shrinked to the window frame.
631 if (hasOutsets) {
632 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
633 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
634 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
635 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
636 } else {
637 mOutsets.set(0, 0, 0, 0);
638 }
639
Craig Mautnera248eee2013-05-07 11:41:27 -0700640 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800641 // final window frame.
Craig Mautnereda67292013-04-28 13:50:14 -0700642 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
643 Math.max(mContentFrame.top, mFrame.top),
644 Math.min(mContentFrame.right, mFrame.right),
645 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800646
Craig Mautnereda67292013-04-28 13:50:14 -0700647 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
648 Math.max(mVisibleFrame.top, mFrame.top),
649 Math.min(mVisibleFrame.right, mFrame.right),
650 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651
Adrian Roosfa104232014-06-20 16:10:14 -0700652 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
653 Math.max(mStableFrame.top, mFrame.top),
654 Math.min(mStableFrame.right, mFrame.right),
655 Math.min(mStableFrame.bottom, mFrame.bottom));
656
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700657 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
658 Math.max(mOverscanFrame.top - mFrame.top, 0),
Adrian Roos3236f3a2014-12-09 15:06:40 +0000659 Math.max(mFrame.right - mOverscanFrame.right, 0),
660 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800661
Craig Mautnereda67292013-04-28 13:50:14 -0700662 mContentInsets.set(mContentFrame.left - mFrame.left,
663 mContentFrame.top - mFrame.top,
664 mFrame.right - mContentFrame.right,
665 mFrame.bottom - mContentFrame.bottom);
666
667 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
668 mVisibleFrame.top - mFrame.top,
669 mFrame.right - mVisibleFrame.right,
670 mFrame.bottom - mVisibleFrame.bottom);
671
Adrian Roosfa104232014-06-20 16:10:14 -0700672 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
673 Math.max(mStableFrame.top - mFrame.top, 0),
674 Math.max(mFrame.right - mStableFrame.right, 0),
675 Math.max(mFrame.bottom - mStableFrame.bottom, 0));
676
Craig Mautnereda67292013-04-28 13:50:14 -0700677 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400678 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700679 // If there is a size compatibility scale being applied to the
680 // window, we need to apply this to its insets so that they are
681 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700682 mOverscanInsets.scale(mInvGlobalScale);
683 mContentInsets.scale(mInvGlobalScale);
684 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700685 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -0700686 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700687
688 // Also the scaled frame that we report to the app needs to be
689 // adjusted to be in its coordinate space.
690 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400691 }
692
Craig Mautnereda67292013-04-28 13:50:14 -0700693 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800694 final DisplayContent displayContent = getDisplayContent();
695 if (displayContent != null) {
696 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
697 mService.updateWallpaperOffsetLocked(this,
698 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
699 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800700 }
701
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700702 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
703 "Resolving (mRequestedWidth="
704 + mRequestedWidth + ", mRequestedheight="
705 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
706 + "): frame=" + mFrame.toShortString()
707 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700708 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -0700709 + " vi=" + mStableInsets.toShortString()
710 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800711 }
712
Craig Mautnera2c77052012-03-26 12:14:43 -0700713 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800714 public Rect getFrameLw() {
715 return mFrame;
716 }
717
Craig Mautnera2c77052012-03-26 12:14:43 -0700718 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700719 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800720 return mShownFrame;
721 }
722
Craig Mautnera2c77052012-03-26 12:14:43 -0700723 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800724 public Rect getDisplayFrameLw() {
725 return mDisplayFrame;
726 }
727
Craig Mautnera2c77052012-03-26 12:14:43 -0700728 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800729 public Rect getOverscanFrameLw() {
730 return mOverscanFrame;
731 }
732
733 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800734 public Rect getContentFrameLw() {
735 return mContentFrame;
736 }
737
Craig Mautnera2c77052012-03-26 12:14:43 -0700738 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800739 public Rect getVisibleFrameLw() {
740 return mVisibleFrame;
741 }
742
Craig Mautnera2c77052012-03-26 12:14:43 -0700743 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800744 public boolean getGivenInsetsPendingLw() {
745 return mGivenInsetsPending;
746 }
747
Craig Mautnera2c77052012-03-26 12:14:43 -0700748 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800749 public Rect getGivenContentInsetsLw() {
750 return mGivenContentInsets;
751 }
752
Craig Mautnera2c77052012-03-26 12:14:43 -0700753 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800754 public Rect getGivenVisibleInsetsLw() {
755 return mGivenVisibleInsets;
756 }
757
Craig Mautnera2c77052012-03-26 12:14:43 -0700758 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800759 public WindowManager.LayoutParams getAttrs() {
760 return mAttrs;
761 }
762
Craig Mautner812d2ca2012-09-27 15:35:34 -0700763 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800764 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
765 int index = -1;
766 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700767 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800768 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700769 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
770 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800771 }
772 // If we reached the bottom of the range of windows we are considering,
773 // assume no menu is needed.
774 if (ws == bottom) {
775 return false;
776 }
777 // The current window hasn't specified whether menu key is needed;
778 // look behind it.
779 // First, we may need to determine the starting position.
780 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700781 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800782 }
783 index--;
784 if (index < 0) {
785 return false;
786 }
Craig Mautner59c00972012-07-30 12:10:24 -0700787 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800788 }
789 }
790
Craig Mautner19d59bc2012-09-04 11:15:56 -0700791 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700792 public int getSystemUiVisibility() {
793 return mSystemUiVisibility;
794 }
795
Craig Mautner19d59bc2012-09-04 11:15:56 -0700796 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800797 public int getSurfaceLayer() {
798 return mLayer;
799 }
800
Craig Mautner812d2ca2012-09-27 15:35:34 -0700801 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800802 public IApplicationToken getAppToken() {
803 return mAppToken != null ? mAppToken.appToken : null;
804 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700805
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700806 @Override
807 public boolean isVoiceInteraction() {
808 return mAppToken != null ? mAppToken.voiceInteraction : false;
809 }
810
Craig Mautner4c5eb222013-11-18 12:59:05 -0800811 boolean setInsetsChanged() {
812 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
813 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
814 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700815 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -0700816 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
817 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
818 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800819 }
820
Craig Mautnerdf88d732014-01-27 09:21:32 -0800821 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700822 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700823 return mDisplayContent;
824 }
825 final TaskStack stack = getStack();
826 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800827 }
828
Craig Mautner19d59bc2012-09-04 11:15:56 -0700829 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800830 final DisplayContent displayContent = getDisplayContent();
831 if (displayContent == null) {
832 return -1;
833 }
834 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700835 }
836
Craig Mautnerd9a22882013-03-16 15:00:36 -0700837 TaskStack getStack() {
Craig Mautner05d29032013-05-03 13:40:13 -0700838 AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken;
839 if (wtoken != null) {
840 Task task = mService.mTaskIdToTask.get(wtoken.groupId);
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700841 if (task != null) {
Craig Mautnere0a38842013-12-16 16:14:02 -0800842 if (task.mStack != null) {
843 return task.mStack;
844 }
845 Slog.e(TAG, "getStack: mStack null for task=" + task);
846 } else {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800847 Slog.e(TAG, "getStack: " + this + " couldn't find taskId=" + wtoken.groupId
848 + " Callers=" + Debug.getCallers(4));
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700849 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700850 }
Craig Mautner05d29032013-05-03 13:40:13 -0700851 return mDisplayContent.getHomeStack();
Craig Mautnerd9a22882013-03-16 15:00:36 -0700852 }
853
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800854 void getStackBounds(Rect bounds) {
855 getStackBounds(getStack(), bounds);
John Spurlock7045aaa2013-07-16 17:38:54 -0400856 }
857
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800858 private void getStackBounds(TaskStack stack, Rect bounds) {
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700859 if (stack != null) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800860 stack.getBounds(bounds);
861 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700862 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800863 bounds.set(mFrame);
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700864 }
865
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800866 public long getInputDispatchingTimeoutNanos() {
867 return mAppToken != null
868 ? mAppToken.inputDispatchingTimeoutNanos
869 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
870 }
871
Craig Mautnere8552142012-11-07 13:55:47 -0800872 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800873 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700874 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800875 }
876
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800877 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
878 if (dsdx < .99999f || dsdx > 1.00001f) return false;
879 if (dtdy < .99999f || dtdy > 1.00001f) return false;
880 if (dtdx < -.000001f || dtdx > .000001f) return false;
881 if (dsdy < -.000001f || dsdy > .000001f) return false;
882 return true;
883 }
884
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400885 void prelayout() {
886 if (mEnforceSizeCompat) {
887 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700888 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400889 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700890 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400891 }
892 }
893
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800894 /**
895 * Is this window visible? It is not visible if there is no
896 * surface, or we are in the process of running an exit animation
897 * that will remove the surface, or its app token has been hidden.
898 */
Craig Mautner88400d32012-09-30 12:35:45 -0700899 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800900 public boolean isVisibleLw() {
901 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700902 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800903 && (atoken == null || !atoken.hiddenRequested)
904 && !mExiting && !mDestroying;
905 }
906
907 /**
908 * Like {@link #isVisibleLw}, but also counts a window that is currently
909 * "hidden" behind the keyguard as visible. This allows us to apply
910 * things like window flags that impact the keyguard.
911 * XXX I am starting to think we need to have ANOTHER visibility flag
912 * for this "hidden behind keyguard" state rather than overloading
913 * mPolicyVisibility. Ungh.
914 */
Craig Mautner88400d32012-09-30 12:35:45 -0700915 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800916 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700917 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800918 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700919 return false;
920 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800921 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700922 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -0700923 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700924 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800925 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700926 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
927 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700928 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800929 }
930
931 /**
932 * Is this window visible, ignoring its app token? It is not visible
933 * if there is no surface, or we are in the process of running an exit animation
934 * that will remove the surface.
935 */
936 public boolean isWinVisibleLw() {
937 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700938 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -0700939 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800940 && !mExiting && !mDestroying;
941 }
942
943 /**
944 * The same as isVisible(), but follows the current hidden state of
945 * the associated app token, not the pending requested hidden state.
946 */
947 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700948 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700949 && (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
950 && !mExiting && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800951 }
952
953 /**
954 * Can this window possibly be a drag/drop target? The test here is
955 * a combination of the above "visible now" with the check that the
956 * Input Manager uses when discarding windows from input consideration.
957 */
958 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700959 return isVisibleNow() && !mRemoved
960 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800961 }
962
963 /**
964 * Same as isVisible(), but we also count it as visible between the
965 * call to IWindowSession.add() and the first relayout().
966 */
967 boolean isVisibleOrAdding() {
968 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700969 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800970 && mPolicyVisibility && !mAttachedHidden
971 && (atoken == null || !atoken.hiddenRequested)
972 && !mExiting && !mDestroying;
973 }
974
975 /**
976 * Is this window currently on-screen? It is on-screen either if it
977 * is visible or it is currently running an animation before no longer
978 * being visible.
979 */
980 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100981 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
982 }
983
984 /**
985 * Like isOnScreen(), but ignores any force hiding of the window due
986 * to the keyguard.
987 */
988 boolean isOnScreenIgnoringKeyguard() {
989 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700990 return false;
991 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800992 final AppWindowToken atoken = mAppToken;
993 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700994 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800995 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800996 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700997 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800998 }
999
1000 /**
1001 * Like isOnScreen(), but we don't return true if the window is part
1002 * of a transition that has not yet been started.
1003 */
1004 boolean isReadyForDisplay() {
1005 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -08001006 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001007 return false;
1008 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001009 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001010 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1011 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001012 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001013 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001014 }
1015
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001016 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001017 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1018 * to the keyguard.
1019 */
1020 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001021 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001022 return false;
1023 }
1024 final AppWindowToken atoken = mAppToken;
1025 if (atoken == null && !mPolicyVisibility) {
1026 // If this is not an app window, and the policy has asked to force
1027 // hide, then we really do want to hide.
1028 return false;
1029 }
1030 return mHasSurface && !mDestroying
1031 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1032 && !mRootToken.hidden)
1033 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001034 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1035 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001036 }
1037
1038 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001039 * Like isOnScreen, but returns false if the surface hasn't yet
1040 * been drawn.
1041 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001042 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001043 public boolean isDisplayedLw() {
1044 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001045 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001046 && ((!mAttachedHidden &&
1047 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001048 || mWinAnimator.mAnimating
1049 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001050 }
1051
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001052 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001053 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001054 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001055 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001056 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001057 return mWinAnimator.mAnimation != null
1058 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001059 }
1060
Craig Mautner812d2ca2012-09-27 15:35:34 -07001061 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001062 public boolean isGoneForLayoutLw() {
1063 final AppWindowToken atoken = mAppToken;
1064 return mViewVisibility == View.GONE
1065 || !mRelayoutCalled
1066 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001067 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001068 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001069 || (mExiting && !isAnimatingLw())
1070 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001071 }
1072
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001073 /**
1074 * Returns true if the window has a surface that it has drawn a
1075 * complete UI in to.
1076 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001077 public boolean isDrawFinishedLw() {
1078 return mHasSurface && !mDestroying &&
1079 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1080 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1081 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1082 }
1083
1084 /**
1085 * Returns true if the window has a surface that it has drawn a
1086 * complete UI in to.
1087 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001088 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001089 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001090 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1091 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001092 }
1093
1094 /**
1095 * Return true if the window is opaque and fully drawn. This indicates
1096 * it may obscure windows behind it.
1097 */
1098 boolean isOpaqueDrawn() {
1099 return (mAttrs.format == PixelFormat.OPAQUE
1100 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001101 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001102 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001103 }
1104
1105 /**
1106 * Return whether this window is wanting to have a translation
1107 * animation applied to it for an in-progress move. (Only makes
1108 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1109 */
1110 boolean shouldAnimateMove() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001111 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001112 && (mFrame.top != mLastFrame.top
1113 || mFrame.left != mLastFrame.left)
Dianne Hackborn1c5383c2013-04-15 15:07:21 -07001114 && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Craig Mautner2fb98b12012-03-20 17:24:00 -07001115 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001116 }
1117
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001118 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001119 return mFrame.left <= 0 && mFrame.top <= 0 &&
1120 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001121 }
1122
Craig Mautner812d2ca2012-09-27 15:35:34 -07001123 boolean isConfigChanged() {
Craig Mautnere8552142012-11-07 13:55:47 -08001124 boolean configChanged = mConfiguration != mService.mCurConfiguration
Craig Mautner812d2ca2012-09-27 15:35:34 -07001125 && (mConfiguration == null
1126 || (mConfiguration.diff(mService.mCurConfiguration) != 0));
Craig Mautnere8552142012-11-07 13:55:47 -08001127
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001128 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001129 // Retain configuration changed status until resetConfiguration called.
1130 mConfigHasChanged |= configChanged;
1131 configChanged = mConfigHasChanged;
1132 }
1133
1134 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001135 }
1136
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001137 void removeLocked() {
1138 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001139
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001140 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001141 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001142 mAttachedWindow.mChildWindows.remove(this);
1143 }
Craig Mautner96868332012-12-04 14:29:11 -08001144 mWinAnimator.destroyDeferredSurfaceLocked();
1145 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001146 mSession.windowRemovedLocked();
1147 try {
1148 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1149 } catch (RuntimeException e) {
1150 // Ignore if it has already been removed (usually because
1151 // we are doing this as part of processing a death note.)
1152 }
1153 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001154
Craig Mautnere8552142012-11-07 13:55:47 -08001155 void setConfiguration(final Configuration newConfig) {
1156 mConfiguration = newConfig;
1157 mConfigHasChanged = false;
1158 }
1159
Jeff Browncc4f7db2011-08-30 20:34:48 -07001160 void setInputChannel(InputChannel inputChannel) {
1161 if (mInputChannel != null) {
1162 throw new IllegalStateException("Window already has an input channel.");
1163 }
1164
1165 mInputChannel = inputChannel;
1166 mInputWindowHandle.inputChannel = inputChannel;
1167 }
1168
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001169 void disposeInputChannel() {
1170 if (mInputChannel != null) {
1171 mService.mInputManager.unregisterInputChannel(mInputChannel);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001172
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001173 mInputChannel.dispose();
1174 mInputChannel = null;
1175 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001176
1177 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001178 }
1179
1180 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001181 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001182 public void binderDied() {
1183 try {
1184 synchronized(mService.mWindowMap) {
1185 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001186 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001187 if (win != null) {
1188 mService.removeWindowLocked(mSession, win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001189 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001190 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
1191 mService.removeWindowLocked(mSession, WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001192 }
1193 }
1194 } catch (IllegalArgumentException ex) {
1195 // This will happen if the window has already been
1196 // removed.
1197 }
1198 }
1199 }
1200
Craig Mautner58106812012-12-28 12:27:40 -08001201 /**
1202 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001203 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001204 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001205 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001206 && (mViewVisibility == View.VISIBLE)
1207 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1208 }
1209
Craig Mautner749a7bb2012-04-02 13:49:53 -07001210 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001211 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001212 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001213 }
1214
Craig Mautner749a7bb2012-04-02 13:49:53 -07001215 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001216 public boolean showLw(boolean doAnimation) {
1217 return showLw(doAnimation, true);
1218 }
1219
1220 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001221 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001222 return false;
1223 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001224 if (!mAppOpVisibility) {
1225 // Being hidden due to app op request.
1226 return false;
1227 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001228 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001229 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001230 return false;
1231 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001232 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001233 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001234 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001235 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001236 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001237 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001238 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001239 // Check for the case where we are currently visible and
1240 // not animating; we do not want to do animation at such a
1241 // point to become visible when we already are.
1242 doAnimation = false;
1243 }
1244 }
1245 mPolicyVisibility = true;
1246 mPolicyVisibilityAfterAnim = true;
1247 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001248 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001249 }
1250 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001251 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001252 }
1253 return true;
1254 }
1255
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001256 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001257 public boolean hideLw(boolean doAnimation) {
1258 return hideLw(doAnimation, true);
1259 }
1260
1261 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1262 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001263 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001264 doAnimation = false;
1265 }
1266 }
1267 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1268 : mPolicyVisibility;
1269 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001270 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001271 return false;
1272 }
1273 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001274 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001275 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001276 doAnimation = false;
1277 }
1278 }
1279 if (doAnimation) {
1280 mPolicyVisibilityAfterAnim = false;
1281 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001282 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001283 mPolicyVisibilityAfterAnim = false;
1284 mPolicyVisibility = false;
1285 // Window is no longer visible -- make sure if we were waiting
1286 // for it to be displayed before enabling the display, that
1287 // we allow the display to be enabled now.
1288 mService.enableScreenIfNeededLocked();
1289 if (mService.mCurrentFocus == this) {
Craig Mautner58458122013-09-14 14:59:50 -07001290 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1291 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001292 mService.mFocusMayChange = true;
1293 }
1294 }
1295 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001296 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001297 }
1298 return true;
1299 }
1300
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001301 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001302 if (mAppOpVisibility != state) {
1303 mAppOpVisibility = state;
1304 if (state) {
1305 // If the policy visibility had last been to hide, then this
1306 // will incorrectly show at this point since we lost that
1307 // information. Not a big deal -- for the windows that have app
1308 // ops modifies they should only be hidden by policy due to the
1309 // lock screen, and the user won't be changing this if locked.
1310 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001311 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001312 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001313 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001314 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001315 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001316 }
1317
Jeff Brownc2932a12014-11-20 18:04:05 -08001318 public void pokeDrawLockLw(long timeout) {
1319 if (isVisibleOrAdding()) {
1320 if (mDrawLock == null) {
1321 // We want the tag name to be somewhat stable so that it is easier to correlate
1322 // in wake lock statistics. So in particular, we don't want to include the
1323 // window's hash code as in toString().
1324 CharSequence tag = mAttrs.getTitle();
1325 if (tag == null) {
1326 tag = mAttrs.packageName;
1327 }
1328 mDrawLock = mService.mPowerManager.newWakeLock(
1329 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1330 mDrawLock.setReferenceCounted(false);
1331 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1332 }
1333 // Each call to acquire resets the timeout.
1334 if (DEBUG_POWER) {
1335 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1336 + mAttrs.packageName);
1337 }
1338 mDrawLock.acquire(timeout);
1339 } else if (DEBUG_POWER) {
1340 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1341 + "owned by " + mAttrs.packageName);
1342 }
1343 }
1344
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001345 @Override
1346 public boolean isAlive() {
1347 return mClient.asBinder().isBinderAlive();
1348 }
1349
Craig Mautnera987d432012-10-11 14:07:58 -07001350 boolean isClosing() {
1351 return mExiting || (mService.mClosingApps.contains(mAppToken));
1352 }
1353
Craig Mautner69b08182012-09-05 13:07:13 -07001354 @Override
1355 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001356 final DisplayContent displayContent = getDisplayContent();
1357 if (displayContent == null) {
1358 // Only a window that was on a non-default display can be detached from it.
1359 return false;
1360 }
Winson Chung47a3e652014-05-21 16:03:42 -07001361 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001362 }
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -07001363
Craig Mautner88400d32012-09-30 12:35:45 -07001364 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1365 mShowToOwnerOnly = showToOwnerOnly;
1366 }
1367
Craig Mautner5962b122012-10-05 14:45:52 -07001368 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001369 // Attached windows are evaluated based on the window that they are attached to.
1370 WindowState win = this;
1371 while (win.mAttachedWindow != null) {
1372 win = win.mAttachedWindow;
1373 }
1374 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1375 && win.mAppToken != null && win.mAppToken.showWhenLocked) {
1376 // Save some cycles by not calling getDisplayInfo unless it is an application
1377 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001378 final DisplayContent displayContent = win.getDisplayContent();
1379 if (displayContent == null) {
1380 return true;
1381 }
1382 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001383 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1384 && win.mFrame.right >= displayInfo.appWidth
1385 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001386 // Is a fullscreen window, like the clock alarm. Show to everyone.
1387 return false;
1388 }
1389 }
1390
Craig Mautner341220f2012-10-16 15:20:09 -07001391 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001392 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001393 }
1394
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001395 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1396 outRegion.set(
1397 frame.left + inset.left, frame.top + inset.top,
1398 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001399 }
1400
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001401 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001402 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001403 switch (mTouchableInsets) {
1404 default:
1405 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1406 outRegion.set(frame);
1407 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001408 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001409 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001410 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001411 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001412 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001413 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001414 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1415 final Region givenTouchableRegion = mGivenTouchableRegion;
1416 outRegion.set(givenTouchableRegion);
1417 outRegion.translate(frame.left, frame.top);
1418 break;
1419 }
1420 }
1421 }
1422
Craig Mautner59c00972012-07-30 12:10:24 -07001423 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001424 final DisplayContent displayContent = getDisplayContent();
1425 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001426 }
1427
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001428 /**
1429 * Report a focus change. Must be called with no locks held, and consistently
1430 * from the same serialized thread (such as dispatched from a handler).
1431 */
1432 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1433 try {
1434 mClient.windowFocusChanged(focused, inTouchMode);
1435 } catch (RemoteException e) {
1436 }
1437 if (mFocusCallbacks != null) {
1438 final int N = mFocusCallbacks.beginBroadcast();
1439 for (int i=0; i<N; i++) {
1440 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1441 try {
1442 if (focused) {
1443 obs.focusGained(mWindowId.asBinder());
1444 } else {
1445 obs.focusLost(mWindowId.asBinder());
1446 }
1447 } catch (RemoteException e) {
1448 }
1449 }
1450 mFocusCallbacks.finishBroadcast();
1451 }
1452 }
1453
Craig Mautnerdf88d732014-01-27 09:21:32 -08001454 void reportResized() {
1455 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001456 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1457 + ": " + mCompatFrame);
1458 boolean configChanged = isConfigChanged();
1459 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1460 Slog.i(TAG, "Sending new config to window " + this + ": "
1461 + mWinAnimator.mSurfaceW + "x" + mWinAnimator.mSurfaceH
1462 + " / " + mService.mCurConfiguration);
1463 }
1464 setConfiguration(mService.mCurConfiguration);
1465 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1466 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1467
Craig Mautnerdf88d732014-01-27 09:21:32 -08001468 final Rect frame = mFrame;
1469 final Rect overscanInsets = mLastOverscanInsets;
1470 final Rect contentInsets = mLastContentInsets;
1471 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001472 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -07001473 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001474 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1475 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07001476 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1477 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001478 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1479 mService.mH.post(new Runnable() {
1480 @Override
1481 public void run() {
1482 try {
1483 mClient.resized(frame, overscanInsets, contentInsets,
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -07001484 visibleInsets, stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001485 } catch (RemoteException e) {
1486 // Not a remote call, RemoteException won't be raised.
1487 }
1488 }
1489 });
1490 } else {
Adrian Roosfa104232014-06-20 16:10:14 -07001491 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -07001492 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001493 }
Svetoslav4604abc2014-06-10 18:59:30 -07001494
1495 //TODO (multidisplay): Accessibility supported only for the default display.
1496 if (mService.mAccessibilityController != null
1497 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07001498 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07001499 }
1500
Craig Mautnerdf88d732014-01-27 09:21:32 -08001501 mOverscanInsetsChanged = false;
1502 mContentInsetsChanged = false;
1503 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07001504 mStableInsetsChanged = false;
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -07001505 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001506 mWinAnimator.mSurfaceResized = false;
1507 } catch (RemoteException e) {
1508 mOrientationChanging = false;
1509 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1510 - mService.mDisplayFreezeTime);
1511 }
1512 }
1513
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001514 public void registerFocusObserver(IWindowFocusObserver observer) {
1515 synchronized(mService.mWindowMap) {
1516 if (mFocusCallbacks == null) {
1517 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1518 }
1519 mFocusCallbacks.register(observer);
1520 }
1521 }
1522
1523 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1524 synchronized(mService.mWindowMap) {
1525 if (mFocusCallbacks != null) {
1526 mFocusCallbacks.unregister(observer);
1527 }
1528 }
1529 }
1530
1531 public boolean isFocused() {
1532 synchronized(mService.mWindowMap) {
1533 return mService.mCurrentFocus == this;
1534 }
1535 }
1536
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001537 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001538 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Craig Mautner59c00972012-07-30 12:10:24 -07001539 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001540 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001541 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001542 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1543 pw.print(" package="); pw.print(mAttrs.packageName);
1544 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001545 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001546 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1547 pw.print(" h="); pw.print(mRequestedHeight);
1548 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001549 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1550 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1551 pw.print(" h="); pw.println(mLastRequestedHeight);
1552 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001553 if (mAttachedWindow != null || mLayoutAttached) {
1554 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1555 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1556 }
1557 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1558 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1559 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1560 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1561 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1562 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001563 if (dumpAll) {
1564 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1565 pw.print(" mSubLayer="); pw.print(mSubLayer);
1566 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001567 pw.print((mTargetAppToken != null ?
1568 mTargetAppToken.mAppAnimator.animLayerAdjustment
1569 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001570 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1571 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001572 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001573 if (dumpAll) {
1574 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1575 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1576 if (mAppToken != null) {
1577 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1578 }
1579 if (mTargetAppToken != null) {
1580 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1581 }
1582 pw.print(prefix); pw.print("mViewVisibility=0x");
1583 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001584 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1585 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001586 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1587 pw.print(" mSystemUiVisibility=0x");
1588 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001589 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001590 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1591 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001592 pw.print(prefix); pw.print("mPolicyVisibility=");
1593 pw.print(mPolicyVisibility);
1594 pw.print(" mPolicyVisibilityAfterAnim=");
1595 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001596 pw.print(" mAppOpVisibility=");
1597 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001598 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1599 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001600 if (!mRelayoutCalled || mLayoutNeeded) {
1601 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1602 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001603 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001604 if (mXOffset != 0 || mYOffset != 0) {
1605 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1606 pw.print(" y="); pw.println(mYOffset);
1607 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001608 if (dumpAll) {
1609 pw.print(prefix); pw.print("mGivenContentInsets=");
1610 mGivenContentInsets.printShortString(pw);
1611 pw.print(" mGivenVisibleInsets=");
1612 mGivenVisibleInsets.printShortString(pw);
1613 pw.println();
1614 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1615 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1616 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001617 Region region = new Region();
1618 getTouchableRegion(region);
1619 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001620 }
1621 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001622 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001623 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001624 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1625 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001626 if (dumpAll) {
1627 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1628 pw.print(" last="); mLastFrame.printShortString(pw);
1629 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001630 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1631 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1632 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001633 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001634 if (mEnforceSizeCompat) {
1635 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001636 pw.println();
1637 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001638 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001639 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001640 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001641 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001642 pw.println();
1643 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1644 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001645 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001646 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001647 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001648 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04001649 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
1650 pw.println();
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -07001651 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
1652 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001653 pw.print(prefix); pw.print("Cur insets: overscan=");
1654 mOverscanInsets.printShortString(pw);
1655 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001656 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07001657 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -07001658 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001659 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001660 pw.print(prefix); pw.print("Lst insets: overscan=");
1661 mLastOverscanInsets.printShortString(pw);
1662 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001663 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07001664 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski3e11bf32015-04-20 08:40:57 -07001665 pw.print(" physical="); mLastOutsets.printShortString(pw);
1666 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001667 pw.println();
1668 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001669 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1670 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001671 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1672 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1673 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1674 pw.print(" mDestroying="); pw.print(mDestroying);
1675 pw.print(" mRemoved="); pw.println(mRemoved);
1676 }
1677 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1678 pw.print(prefix); pw.print("mOrientationChanging=");
1679 pw.print(mOrientationChanging);
1680 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1681 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1682 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07001683 if (mLastFreezeDuration != 0) {
1684 pw.print(prefix); pw.print("mLastFreezeDuration=");
1685 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
1686 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001687 if (mHScale != 1 || mVScale != 1) {
1688 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1689 pw.print(" mVScale="); pw.println(mVScale);
1690 }
1691 if (mWallpaperX != -1 || mWallpaperY != -1) {
1692 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1693 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1694 }
1695 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1696 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1697 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1698 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07001699 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
1700 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
1701 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
1702 pw.print(mWallpaperDisplayOffsetX);
1703 pw.print(" mWallpaperDisplayOffsetY=");
1704 pw.println(mWallpaperDisplayOffsetY);
1705 }
Jeff Brownc2932a12014-11-20 18:04:05 -08001706 if (mDrawLock != null) {
1707 pw.println("mDrawLock=" + mDrawLock);
1708 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001709 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001710
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001711 String makeInputChannelName() {
1712 return Integer.toHexString(System.identityHashCode(this))
1713 + " " + mAttrs.getTitle();
1714 }
1715
1716 @Override
1717 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001718 CharSequence title = mAttrs.getTitle();
1719 if (title == null || title.length() <= 0) {
1720 title = mAttrs.packageName;
1721 }
1722 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1723 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001724 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001725 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001726 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001727 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001728 }
1729 return mStringNameCache;
1730 }
satokcef37fb2011-10-24 21:49:38 +09001731}