blob: f94ed776e3d8428afc680e9a612ed78ea405a11b [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;
20import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
22import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
23import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
24import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
25import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
26import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
27import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080028import static com.android.server.wm.WindowManagerService.DEBUG_CONFIGURATION;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -070029import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080030import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
Jeff Brownc2932a12014-11-20 18:04:05 -080031import static com.android.server.wm.WindowManagerService.DEBUG_POWER;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080032import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
33import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080034
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
Wale Ogunwale60454db2015-01-23 16:05:07 -0800136 private Configuration mConfiguration = Configuration.EMPTY;
137 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800138 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
139 // Used only on {@link #TYPE_KEYGUARD}.
140 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700141
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700142 /**
143 * Actual frame shown on-screen (may be modified by animation). These
144 * are in the screen's coordinate space (WITH the compatibility scale
145 * applied).
146 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700147 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148
149 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700150 * Insets that determine the actually visible area. These are in the application's
151 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152 */
153 final Rect mVisibleInsets = new Rect();
154 final Rect mLastVisibleInsets = new Rect();
155 boolean mVisibleInsetsChanged;
156
157 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700158 * Insets that are covered by system windows (such as the status bar) and
159 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700160 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 */
162 final Rect mContentInsets = new Rect();
163 final Rect mLastContentInsets = new Rect();
164 boolean mContentInsetsChanged;
165
166 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800167 * Insets that determine the area covered by the display overscan region. These are in the
168 * application's coordinate space (without compatibility scale applied).
169 */
170 final Rect mOverscanInsets = new Rect();
171 final Rect mLastOverscanInsets = new Rect();
172 boolean mOverscanInsetsChanged;
173
174 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700175 * Insets that determine the area covered by the stable system windows. These are in the
176 * application's coordinate space (without compatibility scale applied).
177 */
178 final Rect mStableInsets = new Rect();
179 final Rect mLastStableInsets = new Rect();
180 boolean mStableInsetsChanged;
181
182 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 * Set to true if we are waiting for this window to receive its
184 * given internal insets before laying out other windows based on it.
185 */
186 boolean mGivenInsetsPending;
187
188 /**
189 * These are the content insets that were given during layout for
190 * this window, to be applied to windows behind it.
191 */
192 final Rect mGivenContentInsets = new Rect();
193
194 /**
195 * These are the visible insets that were given during layout for
196 * this window, to be applied to windows behind it.
197 */
198 final Rect mGivenVisibleInsets = new Rect();
199
200 /**
201 * This is the given touchable area relative to the window frame, or null if none.
202 */
203 final Region mGivenTouchableRegion = new Region();
204
205 /**
206 * Flag indicating whether the touchable region should be adjusted by
207 * the visible insets; if false the area outside the visible insets is
208 * NOT touchable, so we must use those to adjust the frame during hit
209 * tests.
210 */
211 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
212
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700213 /**
214 * This is rectangle of the window's surface that is not covered by
215 * system decorations.
216 */
217 final Rect mSystemDecorRect = new Rect();
218 final Rect mLastSystemDecorRect = new Rect();
219
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400221 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700222 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 float mHScale=1, mVScale=1;
224 float mLastHScale=1, mLastVScale=1;
225 final Matrix mTmpMatrix = new Matrix();
226
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700227 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228 final Rect mFrame = new Rect();
229 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700230 // Frame that is scaled to the application's coordinate space when in
231 // screen size compatibility mode.
232 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233
234 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700235
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700237
Wale Ogunwale94596652015-02-06 19:27:34 -0800238 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
239 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700240 final Rect mDisplayFrame = new Rect();
241
242 // The region of the display frame that the display type supports displaying content on. This
243 // is mostly a special case for TV where some displays don’t have the entire display usable.
244 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
245 // window display contents to extend into the overscan region.
246 final Rect mOverscanFrame = new Rect();
247
248 // The display frame minus the stable insets. This value is always constant regardless of if
249 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700250 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700252 // The area not occupied by the status and navigation bars. So, if both status and navigation
253 // bars are visible, the decor frame is equal to the stable frame.
254 final Rect mDecorFrame = new Rect();
255
256 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
257 // minus the area occupied by the IME if the IME is present.
258 final Rect mContentFrame = new Rect();
259
260 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
261 // displays hint text.
262 final Rect mVisibleFrame = new Rect();
263
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264 boolean mContentChanged;
265
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 // If a window showing a wallpaper: the requested offset for the
267 // wallpaper; if a wallpaper window: the currently applied offset.
268 float mWallpaperX = -1;
269 float mWallpaperY = -1;
270
271 // If a window showing a wallpaper: what fraction of the offset
272 // range corresponds to a full virtual screen.
273 float mWallpaperXStep = -1;
274 float mWallpaperYStep = -1;
275
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700276 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
277 // to its window; if a wallpaper window: not used.
278 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
279 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
280
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 // Wallpaper windows: pixels offset based on above variables.
282 int mXOffset;
283 int mYOffset;
284
Craig Mautner2268e7e2012-12-13 15:40:00 -0800285 /**
286 * This is set after IWindowSession.relayout() has been called at
287 * least once for the window. It allows us to detect the situation
288 * where we don't yet have a surface, but should have one soon, so
289 * we can give the window focus before waiting for the relayout.
290 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 boolean mRelayoutCalled;
292
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800293 /**
294 * If the application has called relayout() with changes that can
295 * impact its window's size, we need to perform a layout pass on it
296 * even if it is not currently visible for layout. This is set
297 * when in that case until the layout is done.
298 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800299 boolean mLayoutNeeded;
300
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800301 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800302 boolean mExiting;
303
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800304 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 boolean mDestroying;
306
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800307 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308 boolean mRemoveOnExit;
309
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800310 /**
311 * Set when the orientation is changing and this window has not yet
312 * been updated for the new orientation.
313 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800314 boolean mOrientationChanging;
315
Dianne Hackborna57c6952013-03-29 14:46:40 -0700316 /**
317 * How long we last kept the screen frozen.
318 */
319 int mLastFreezeDuration;
320
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800321 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322 boolean mRemoved;
323
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800324 /**
325 * Temp for keeping track of windows that have been removed when
326 * rebuilding window list.
327 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800328 boolean mRebuilding;
329
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700331 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800333
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 // Used to improve performance of toString()
335 String mStringNameCache;
336 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700337 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800338
Craig Mautnera2c77052012-03-26 12:14:43 -0700339 final WindowStateAnimator mWinAnimator;
340
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700341 boolean mHasSurface = false;
342
Craig Mautner19ab8282014-05-07 10:35:34 -0700343 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700344 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700345
Craig Mautner88400d32012-09-30 12:35:45 -0700346 /** When true this window can be displayed on screens owther than mOwnerUid's */
347 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700348
Jeff Brownc2932a12014-11-20 18:04:05 -0800349 /**
350 * Wake lock for drawing.
351 * Even though it's slightly more expensive to do so, we will use a separate wake lock
352 * for each app that is requesting to draw while dozing so that we can accurately track
353 * who is preventing the system from suspending.
354 * This lock is only acquired on first use.
355 */
356 PowerManager.WakeLock mDrawLock;
357
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800359 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700360 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800361 mService = service;
362 mSession = s;
363 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800364 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800365 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700366 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800367 mWindowId = new IWindowId.Stub() {
368 @Override
369 public void registerFocusObserver(IWindowFocusObserver observer) {
370 WindowState.this.registerFocusObserver(observer);
371 }
372 @Override
373 public void unregisterFocusObserver(IWindowFocusObserver observer) {
374 WindowState.this.unregisterFocusObserver(observer);
375 }
376 @Override
377 public boolean isFocused() {
378 return WindowState.this.isFocused();
379 }
380 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800381 mAttrs.copyFrom(a);
382 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700383 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700384 mPolicy = mService.mPolicy;
385 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800386 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700387 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700388 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800389 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700390 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700391 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392 try {
393 c.asBinder().linkToDeath(deathRecipient, 0);
394 } catch (RemoteException e) {
395 mDeathRecipient = null;
396 mAttachedWindow = null;
397 mLayoutAttached = false;
398 mIsImWindow = false;
399 mIsWallpaper = false;
400 mIsFloatingLayer = false;
401 mBaseLayer = 0;
402 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700403 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700404 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800405 return;
406 }
407 mDeathRecipient = deathRecipient;
408
409 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
410 mAttrs.type <= LAST_SUB_WINDOW)) {
411 // The multiplier here is to reserve space for multiple
412 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700413 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
415 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700416 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800417 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700418 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900419
tiger_huange2a98a72014-11-13 19:46:28 +0800420 final WindowList childWindows = mAttachedWindow.mChildWindows;
421 final int numChildWindows = childWindows.size();
422 if (numChildWindows == 0) {
423 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900424 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800425 boolean added = false;
426 for (int i = 0; i < numChildWindows; i++) {
427 final int childSubLayer = childWindows.get(i).mSubLayer;
428 if (mSubLayer < childSubLayer
429 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
430 // We insert the child window into the list ordered by the sub-layer. For
431 // same sub-layers, the negative one should go below others; the positive
432 // one should go above others.
433 childWindows.add(i, this);
434 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900435 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900436 }
437 }
tiger_huange2a98a72014-11-13 19:46:28 +0800438 if (!added) {
439 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900440 }
441 }
442
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800443 mLayoutAttached = mAttrs.type !=
444 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
445 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
446 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
447 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
448 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
449 } else {
450 // The multiplier here is to reserve space for multiple
451 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700452 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800453 * WindowManagerService.TYPE_LAYER_MULTIPLIER
454 + WindowManagerService.TYPE_LAYER_OFFSET;
455 mSubLayer = 0;
456 mAttachedWindow = null;
457 mLayoutAttached = false;
458 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
459 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
460 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
461 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
462 }
463
464 WindowState appWin = this;
465 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700466 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800467 }
468 WindowToken appToken = appWin.mToken;
469 while (appToken.appWindowToken == null) {
470 WindowToken parent = mService.mTokenMap.get(appToken.token);
471 if (parent == null || appToken == parent) {
472 break;
473 }
474 appToken = parent;
475 }
476 mRootToken = appToken;
477 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700478 if (mAppToken != null) {
479 final DisplayContent appDisplay = getDisplayContent();
480 mNotOnAppsDisplay = displayContent != appDisplay;
481 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800482
Craig Mautner322e4032012-07-13 13:35:20 -0700483 mWinAnimator = new WindowStateAnimator(this);
484 mWinAnimator.mAlpha = a.alpha;
485
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800486 mRequestedWidth = 0;
487 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700488 mLastRequestedWidth = 0;
489 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800490 mXOffset = 0;
491 mYOffset = 0;
492 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800493 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700494 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
495 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800496 }
497
498 void attach() {
499 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700500 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800501 + ", list=" + mToken.windows);
502 mSession.windowAddedLocked();
503 }
504
Craig Mautnera2c77052012-03-26 12:14:43 -0700505 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800506 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800507 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800508 }
509
510 @Override
511 public String getOwningPackage() {
512 return mAttrs.packageName;
513 }
514
515 @Override
Adrian Roosfa104232014-06-20 16:10:14 -0700516 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800517 mHaveFrame = true;
518
John Spurlock7045aaa2013-07-16 17:38:54 -0400519 TaskStack stack = mAppToken != null ? getStack() : null;
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800520 if (stack != null && !stack.isFullscreen()) {
Wale Ogunwaledd11d4d2015-02-03 14:49:20 -0800521 stack.getBounds(mContainingFrame);
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800522 final WindowState imeWin = mService.mInputMethodWindow;
523 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
524 && mContainingFrame.bottom > cf.bottom) {
525 // IME is up and obscuring this window. Adjust the window position so it is visible.
526 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700527 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800528 // Make sure the containing frame is within the content frame so we don't layout
529 // resized window under screen decorations.
530 mContainingFrame.intersect(cf);
Wale Ogunwale94596652015-02-06 19:27:34 -0800531 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700532 } else {
533 mContainingFrame.set(pf);
Wale Ogunwale94596652015-02-06 19:27:34 -0800534 mDisplayFrame.set(df);
Craig Mautner967212c2013-04-13 21:10:58 -0700535 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800536
Craig Mautner967212c2013-04-13 21:10:58 -0700537 final int pw = mContainingFrame.width();
538 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800539
540 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700541 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
542 if (mAttrs.width < 0) {
543 w = pw;
544 } else if (mEnforceSizeCompat) {
545 w = (int)(mAttrs.width * mGlobalScale + .5f);
546 } else {
547 w = mAttrs.width;
548 }
549 if (mAttrs.height < 0) {
550 h = ph;
551 } else if (mEnforceSizeCompat) {
552 h = (int)(mAttrs.height * mGlobalScale + .5f);
553 } else {
554 h = mAttrs.height;
555 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800556 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700557 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
558 w = pw;
559 } else if (mEnforceSizeCompat) {
560 w = (int)(mRequestedWidth * mGlobalScale + .5f);
561 } else {
562 w = mRequestedWidth;
563 }
564 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
565 h = ph;
566 } else if (mEnforceSizeCompat) {
567 h = (int)(mRequestedHeight * mGlobalScale + .5f);
568 } else {
569 h = mRequestedHeight;
570 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800571 }
572
573 if (!mParentFrame.equals(pf)) {
574 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
575 // + " to " + pf);
576 mParentFrame.set(pf);
577 mContentChanged = true;
578 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700579 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
580 mLastRequestedWidth = mRequestedWidth;
581 mLastRequestedHeight = mRequestedHeight;
582 mContentChanged = true;
583 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800584
Craig Mautnereda67292013-04-28 13:50:14 -0700585 mOverscanFrame.set(of);
586 mContentFrame.set(cf);
587 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400588 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700589 mStableFrame.set(sf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800590
Craig Mautnereda67292013-04-28 13:50:14 -0700591 final int fw = mFrame.width();
592 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800593
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700594 float x, y;
595 if (mEnforceSizeCompat) {
596 x = mAttrs.x * mGlobalScale;
597 y = mAttrs.y * mGlobalScale;
598 } else {
599 x = mAttrs.x;
600 y = mAttrs.y;
601 }
602
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -0800603 // Make sure window fits in containing frame required by {@link Gravity#apply} call.
604 w = Math.min(w, pw);
605 h = Math.min(h, ph);
Craig Mautner967212c2013-04-13 21:10:58 -0700606 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700607 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700608 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800609
Wale Ogunwale94596652015-02-06 19:27:34 -0800610 // Now make sure the window fits in the overall display frame.
611 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800612
Craig Mautnera248eee2013-05-07 11:41:27 -0700613 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800614 // final window frame.
Craig Mautnereda67292013-04-28 13:50:14 -0700615 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
616 Math.max(mContentFrame.top, mFrame.top),
617 Math.min(mContentFrame.right, mFrame.right),
618 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800619
Craig Mautnereda67292013-04-28 13:50:14 -0700620 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
621 Math.max(mVisibleFrame.top, mFrame.top),
622 Math.min(mVisibleFrame.right, mFrame.right),
623 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800624
Adrian Roosfa104232014-06-20 16:10:14 -0700625 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
626 Math.max(mStableFrame.top, mFrame.top),
627 Math.min(mStableFrame.right, mFrame.right),
628 Math.min(mStableFrame.bottom, mFrame.bottom));
629
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700630 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
631 Math.max(mOverscanFrame.top - mFrame.top, 0),
Adrian Roos3236f3a2014-12-09 15:06:40 +0000632 Math.max(mFrame.right - mOverscanFrame.right, 0),
633 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800634
Craig Mautnereda67292013-04-28 13:50:14 -0700635 mContentInsets.set(mContentFrame.left - mFrame.left,
636 mContentFrame.top - mFrame.top,
637 mFrame.right - mContentFrame.right,
638 mFrame.bottom - mContentFrame.bottom);
639
640 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
641 mVisibleFrame.top - mFrame.top,
642 mFrame.right - mVisibleFrame.right,
643 mFrame.bottom - mVisibleFrame.bottom);
644
Adrian Roosfa104232014-06-20 16:10:14 -0700645 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
646 Math.max(mStableFrame.top - mFrame.top, 0),
647 Math.max(mFrame.right - mStableFrame.right, 0),
648 Math.max(mFrame.bottom - mStableFrame.bottom, 0));
649
Craig Mautnereda67292013-04-28 13:50:14 -0700650 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400651 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700652 // If there is a size compatibility scale being applied to the
653 // window, we need to apply this to its insets so that they are
654 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700655 mOverscanInsets.scale(mInvGlobalScale);
656 mContentInsets.scale(mInvGlobalScale);
657 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700658 mStableInsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700659
660 // Also the scaled frame that we report to the app needs to be
661 // adjusted to be in its coordinate space.
662 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400663 }
664
Craig Mautnereda67292013-04-28 13:50:14 -0700665 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800666 final DisplayContent displayContent = getDisplayContent();
667 if (displayContent != null) {
668 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
669 mService.updateWallpaperOffsetLocked(this,
670 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
671 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672 }
673
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700674 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
675 "Resolving (mRequestedWidth="
676 + mRequestedWidth + ", mRequestedheight="
677 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
678 + "): frame=" + mFrame.toShortString()
679 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700680 + " vi=" + mVisibleInsets.toShortString()
681 + " vi=" + mStableInsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800682 }
683
Craig Mautnera2c77052012-03-26 12:14:43 -0700684 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800685 public Rect getFrameLw() {
686 return mFrame;
687 }
688
Craig Mautnera2c77052012-03-26 12:14:43 -0700689 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700690 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800691 return mShownFrame;
692 }
693
Craig Mautnera2c77052012-03-26 12:14:43 -0700694 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800695 public Rect getDisplayFrameLw() {
696 return mDisplayFrame;
697 }
698
Craig Mautnera2c77052012-03-26 12:14:43 -0700699 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800700 public Rect getOverscanFrameLw() {
701 return mOverscanFrame;
702 }
703
704 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800705 public Rect getContentFrameLw() {
706 return mContentFrame;
707 }
708
Craig Mautnera2c77052012-03-26 12:14:43 -0700709 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800710 public Rect getVisibleFrameLw() {
711 return mVisibleFrame;
712 }
713
Craig Mautnera2c77052012-03-26 12:14:43 -0700714 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800715 public boolean getGivenInsetsPendingLw() {
716 return mGivenInsetsPending;
717 }
718
Craig Mautnera2c77052012-03-26 12:14:43 -0700719 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800720 public Rect getGivenContentInsetsLw() {
721 return mGivenContentInsets;
722 }
723
Craig Mautnera2c77052012-03-26 12:14:43 -0700724 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800725 public Rect getGivenVisibleInsetsLw() {
726 return mGivenVisibleInsets;
727 }
728
Craig Mautnera2c77052012-03-26 12:14:43 -0700729 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800730 public WindowManager.LayoutParams getAttrs() {
731 return mAttrs;
732 }
733
Craig Mautner812d2ca2012-09-27 15:35:34 -0700734 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800735 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
736 int index = -1;
737 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700738 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800739 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700740 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
741 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800742 }
743 // If we reached the bottom of the range of windows we are considering,
744 // assume no menu is needed.
745 if (ws == bottom) {
746 return false;
747 }
748 // The current window hasn't specified whether menu key is needed;
749 // look behind it.
750 // First, we may need to determine the starting position.
751 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700752 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800753 }
754 index--;
755 if (index < 0) {
756 return false;
757 }
Craig Mautner59c00972012-07-30 12:10:24 -0700758 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800759 }
760 }
761
Craig Mautner19d59bc2012-09-04 11:15:56 -0700762 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700763 public int getSystemUiVisibility() {
764 return mSystemUiVisibility;
765 }
766
Craig Mautner19d59bc2012-09-04 11:15:56 -0700767 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800768 public int getSurfaceLayer() {
769 return mLayer;
770 }
771
Craig Mautner812d2ca2012-09-27 15:35:34 -0700772 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800773 public IApplicationToken getAppToken() {
774 return mAppToken != null ? mAppToken.appToken : null;
775 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700776
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700777 @Override
778 public boolean isVoiceInteraction() {
779 return mAppToken != null ? mAppToken.voiceInteraction : false;
780 }
781
Craig Mautner4c5eb222013-11-18 12:59:05 -0800782 boolean setInsetsChanged() {
783 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
784 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
785 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700786 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Craig Mautner4c5eb222013-11-18 12:59:05 -0800787 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged;
788 }
789
Craig Mautnerdf88d732014-01-27 09:21:32 -0800790 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700791 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700792 return mDisplayContent;
793 }
794 final TaskStack stack = getStack();
795 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800796 }
797
Craig Mautner19d59bc2012-09-04 11:15:56 -0700798 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800799 final DisplayContent displayContent = getDisplayContent();
800 if (displayContent == null) {
801 return -1;
802 }
803 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700804 }
805
Craig Mautnerd9a22882013-03-16 15:00:36 -0700806 TaskStack getStack() {
Craig Mautner05d29032013-05-03 13:40:13 -0700807 AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken;
808 if (wtoken != null) {
Craig Mautner83162a92015-01-26 14:43:30 -0800809 Task task = wtoken.mTask;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700810 if (task != null) {
Craig Mautnere0a38842013-12-16 16:14:02 -0800811 if (task.mStack != null) {
812 return task.mStack;
813 }
814 Slog.e(TAG, "getStack: mStack null for task=" + task);
815 } else {
Craig Mautner83162a92015-01-26 14:43:30 -0800816 Slog.e(TAG, "getStack: " + this + " couldn't find task for " + wtoken
Craig Mautnerdf88d732014-01-27 09:21:32 -0800817 + " Callers=" + Debug.getCallers(4));
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700818 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700819 }
Craig Mautner05d29032013-05-03 13:40:13 -0700820 return mDisplayContent.getHomeStack();
Craig Mautnerd9a22882013-03-16 15:00:36 -0700821 }
822
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800823 void getStackBounds(Rect bounds) {
Wale Ogunwaledd11d4d2015-02-03 14:49:20 -0800824 final TaskStack stack = getStack();
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700825 if (stack != null) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800826 stack.getBounds(bounds);
827 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700828 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800829 bounds.set(mFrame);
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700830 }
831
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800832 public long getInputDispatchingTimeoutNanos() {
833 return mAppToken != null
834 ? mAppToken.inputDispatchingTimeoutNanos
835 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
836 }
837
Craig Mautnere8552142012-11-07 13:55:47 -0800838 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800839 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700840 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800841 }
842
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800843 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
844 if (dsdx < .99999f || dsdx > 1.00001f) return false;
845 if (dtdy < .99999f || dtdy > 1.00001f) return false;
846 if (dtdx < -.000001f || dtdx > .000001f) return false;
847 if (dsdy < -.000001f || dsdy > .000001f) return false;
848 return true;
849 }
850
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400851 void prelayout() {
852 if (mEnforceSizeCompat) {
853 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700854 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400855 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700856 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400857 }
858 }
859
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800860 /**
861 * Is this window visible? It is not visible if there is no
862 * surface, or we are in the process of running an exit animation
863 * that will remove the surface, or its app token has been hidden.
864 */
Craig Mautner88400d32012-09-30 12:35:45 -0700865 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800866 public boolean isVisibleLw() {
867 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700868 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800869 && (atoken == null || !atoken.hiddenRequested)
870 && !mExiting && !mDestroying;
871 }
872
873 /**
874 * Like {@link #isVisibleLw}, but also counts a window that is currently
875 * "hidden" behind the keyguard as visible. This allows us to apply
876 * things like window flags that impact the keyguard.
877 * XXX I am starting to think we need to have ANOTHER visibility flag
878 * for this "hidden behind keyguard" state rather than overloading
879 * mPolicyVisibility. Ungh.
880 */
Craig Mautner88400d32012-09-30 12:35:45 -0700881 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800882 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700883 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800884 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700885 return false;
886 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800887 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700888 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -0700889 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700890 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800891 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700892 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
893 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700894 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800895 }
896
897 /**
898 * Is this window visible, ignoring its app token? It is not visible
899 * if there is no surface, or we are in the process of running an exit animation
900 * that will remove the surface.
901 */
902 public boolean isWinVisibleLw() {
903 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700904 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -0700905 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800906 && !mExiting && !mDestroying;
907 }
908
909 /**
910 * The same as isVisible(), but follows the current hidden state of
911 * the associated app token, not the pending requested hidden state.
912 */
913 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700914 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700915 && (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
916 && !mExiting && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800917 }
918
919 /**
920 * Can this window possibly be a drag/drop target? The test here is
921 * a combination of the above "visible now" with the check that the
922 * Input Manager uses when discarding windows from input consideration.
923 */
924 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700925 return isVisibleNow() && !mRemoved
926 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800927 }
928
929 /**
930 * Same as isVisible(), but we also count it as visible between the
931 * call to IWindowSession.add() and the first relayout().
932 */
933 boolean isVisibleOrAdding() {
934 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700935 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800936 && mPolicyVisibility && !mAttachedHidden
937 && (atoken == null || !atoken.hiddenRequested)
938 && !mExiting && !mDestroying;
939 }
940
941 /**
942 * Is this window currently on-screen? It is on-screen either if it
943 * is visible or it is currently running an animation before no longer
944 * being visible.
945 */
946 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100947 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
948 }
949
950 /**
951 * Like isOnScreen(), but ignores any force hiding of the window due
952 * to the keyguard.
953 */
954 boolean isOnScreenIgnoringKeyguard() {
955 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700956 return false;
957 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800958 final AppWindowToken atoken = mAppToken;
959 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700960 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800961 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800962 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700963 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800964 }
965
966 /**
967 * Like isOnScreen(), but we don't return true if the window is part
968 * of a transition that has not yet been started.
969 */
970 boolean isReadyForDisplay() {
971 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800972 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800973 return false;
974 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700975 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800976 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
977 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700978 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -0700979 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800980 }
981
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800982 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700983 * Like isReadyForDisplay(), but ignores any force hiding of the window due
984 * to the keyguard.
985 */
986 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800987 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700988 return false;
989 }
990 final AppWindowToken atoken = mAppToken;
991 if (atoken == null && !mPolicyVisibility) {
992 // If this is not an app window, and the policy has asked to force
993 // hide, then we really do want to hide.
994 return false;
995 }
996 return mHasSurface && !mDestroying
997 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
998 && !mRootToken.hidden)
999 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001000 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1001 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001002 }
1003
1004 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001005 * Like isOnScreen, but returns false if the surface hasn't yet
1006 * been drawn.
1007 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001008 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001009 public boolean isDisplayedLw() {
1010 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001011 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001012 && ((!mAttachedHidden &&
1013 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001014 || mWinAnimator.mAnimating
1015 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001016 }
1017
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001018 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001019 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001020 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001021 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001022 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001023 return mWinAnimator.mAnimation != null
1024 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001025 }
1026
Craig Mautner812d2ca2012-09-27 15:35:34 -07001027 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001028 public boolean isGoneForLayoutLw() {
1029 final AppWindowToken atoken = mAppToken;
1030 return mViewVisibility == View.GONE
1031 || !mRelayoutCalled
1032 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001033 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001034 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001035 || (mExiting && !isAnimatingLw())
1036 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001037 }
1038
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001039 /**
1040 * Returns true if the window has a surface that it has drawn a
1041 * complete UI in to.
1042 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001043 public boolean isDrawFinishedLw() {
1044 return mHasSurface && !mDestroying &&
1045 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1046 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1047 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1048 }
1049
1050 /**
1051 * Returns true if the window has a surface that it has drawn a
1052 * complete UI in to.
1053 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001054 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001055 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001056 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1057 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001058 }
1059
1060 /**
1061 * Return true if the window is opaque and fully drawn. This indicates
1062 * it may obscure windows behind it.
1063 */
1064 boolean isOpaqueDrawn() {
1065 return (mAttrs.format == PixelFormat.OPAQUE
1066 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001067 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001068 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001069 }
1070
1071 /**
1072 * Return whether this window is wanting to have a translation
1073 * animation applied to it for an in-progress move. (Only makes
1074 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1075 */
1076 boolean shouldAnimateMove() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001077 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001078 && (mFrame.top != mLastFrame.top
1079 || mFrame.left != mLastFrame.left)
Dianne Hackborn1c5383c2013-04-15 15:07:21 -07001080 && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Craig Mautner2fb98b12012-03-20 17:24:00 -07001081 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001082 }
1083
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001084 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001085 return mFrame.left <= 0 && mFrame.top <= 0 &&
1086 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001087 }
1088
Craig Mautner812d2ca2012-09-27 15:35:34 -07001089 boolean isConfigChanged() {
Wale Ogunwale60454db2015-01-23 16:05:07 -08001090 final TaskStack stack = getStack();
1091 final Configuration overrideConfig =
1092 (stack != null) ? stack.mOverrideConfig : Configuration.EMPTY;
1093 final Configuration serviceConfig = mService.mCurConfiguration;
1094 boolean configChanged =
1095 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1096 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001097
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001098 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001099 // Retain configuration changed status until resetConfiguration called.
1100 mConfigHasChanged |= configChanged;
1101 configChanged = mConfigHasChanged;
1102 }
1103
1104 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001105 }
1106
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001107 void removeLocked() {
1108 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001109
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001110 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001111 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001112 mAttachedWindow.mChildWindows.remove(this);
1113 }
Craig Mautner96868332012-12-04 14:29:11 -08001114 mWinAnimator.destroyDeferredSurfaceLocked();
1115 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001116 mSession.windowRemovedLocked();
1117 try {
1118 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1119 } catch (RuntimeException e) {
1120 // Ignore if it has already been removed (usually because
1121 // we are doing this as part of processing a death note.)
1122 }
1123 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001124
Wale Ogunwale60454db2015-01-23 16:05:07 -08001125 private void setConfiguration(
1126 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001127 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001128 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001129 mConfigHasChanged = false;
1130 }
1131
Jeff Browncc4f7db2011-08-30 20:34:48 -07001132 void setInputChannel(InputChannel inputChannel) {
1133 if (mInputChannel != null) {
1134 throw new IllegalStateException("Window already has an input channel.");
1135 }
1136
1137 mInputChannel = inputChannel;
1138 mInputWindowHandle.inputChannel = inputChannel;
1139 }
1140
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001141 void disposeInputChannel() {
1142 if (mInputChannel != null) {
1143 mService.mInputManager.unregisterInputChannel(mInputChannel);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001144
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001145 mInputChannel.dispose();
1146 mInputChannel = null;
1147 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001148
1149 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001150 }
1151
1152 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001153 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001154 public void binderDied() {
1155 try {
1156 synchronized(mService.mWindowMap) {
1157 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001158 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001159 if (win != null) {
1160 mService.removeWindowLocked(mSession, win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001161 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001162 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
1163 mService.removeWindowLocked(mSession, WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001164 }
1165 }
1166 } catch (IllegalArgumentException ex) {
1167 // This will happen if the window has already been
1168 // removed.
1169 }
1170 }
1171 }
1172
Craig Mautner58106812012-12-28 12:27:40 -08001173 /**
1174 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001175 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001176 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001177 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001178 && (mViewVisibility == View.VISIBLE)
1179 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1180 }
1181
Craig Mautner749a7bb2012-04-02 13:49:53 -07001182 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001183 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001184 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001185 }
1186
Craig Mautner749a7bb2012-04-02 13:49:53 -07001187 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001188 public boolean showLw(boolean doAnimation) {
1189 return showLw(doAnimation, true);
1190 }
1191
1192 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001193 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001194 return false;
1195 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001196 if (!mAppOpVisibility) {
1197 // Being hidden due to app op request.
1198 return false;
1199 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001200 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001201 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001202 return false;
1203 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001204 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001205 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001206 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001207 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001208 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001209 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001210 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001211 // Check for the case where we are currently visible and
1212 // not animating; we do not want to do animation at such a
1213 // point to become visible when we already are.
1214 doAnimation = false;
1215 }
1216 }
1217 mPolicyVisibility = true;
1218 mPolicyVisibilityAfterAnim = true;
1219 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001220 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001221 }
1222 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001223 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001224 }
1225 return true;
1226 }
1227
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001228 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001229 public boolean hideLw(boolean doAnimation) {
1230 return hideLw(doAnimation, true);
1231 }
1232
1233 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1234 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001235 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001236 doAnimation = false;
1237 }
1238 }
1239 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1240 : mPolicyVisibility;
1241 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001242 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001243 return false;
1244 }
1245 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001246 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001247 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001248 doAnimation = false;
1249 }
1250 }
1251 if (doAnimation) {
1252 mPolicyVisibilityAfterAnim = false;
1253 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001254 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001255 mPolicyVisibilityAfterAnim = false;
1256 mPolicyVisibility = false;
1257 // Window is no longer visible -- make sure if we were waiting
1258 // for it to be displayed before enabling the display, that
1259 // we allow the display to be enabled now.
1260 mService.enableScreenIfNeededLocked();
1261 if (mService.mCurrentFocus == this) {
Craig Mautner58458122013-09-14 14:59:50 -07001262 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1263 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001264 mService.mFocusMayChange = true;
1265 }
1266 }
1267 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001268 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001269 }
1270 return true;
1271 }
1272
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001273 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001274 if (mAppOpVisibility != state) {
1275 mAppOpVisibility = state;
1276 if (state) {
1277 // If the policy visibility had last been to hide, then this
1278 // will incorrectly show at this point since we lost that
1279 // information. Not a big deal -- for the windows that have app
1280 // ops modifies they should only be hidden by policy due to the
1281 // lock screen, and the user won't be changing this if locked.
1282 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001283 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001284 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001285 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001286 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001287 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001288 }
1289
Jeff Brownc2932a12014-11-20 18:04:05 -08001290 public void pokeDrawLockLw(long timeout) {
1291 if (isVisibleOrAdding()) {
1292 if (mDrawLock == null) {
1293 // We want the tag name to be somewhat stable so that it is easier to correlate
1294 // in wake lock statistics. So in particular, we don't want to include the
1295 // window's hash code as in toString().
1296 CharSequence tag = mAttrs.getTitle();
1297 if (tag == null) {
1298 tag = mAttrs.packageName;
1299 }
1300 mDrawLock = mService.mPowerManager.newWakeLock(
1301 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1302 mDrawLock.setReferenceCounted(false);
1303 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1304 }
1305 // Each call to acquire resets the timeout.
1306 if (DEBUG_POWER) {
1307 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1308 + mAttrs.packageName);
1309 }
1310 mDrawLock.acquire(timeout);
1311 } else if (DEBUG_POWER) {
1312 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1313 + "owned by " + mAttrs.packageName);
1314 }
1315 }
1316
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001317 @Override
1318 public boolean isAlive() {
1319 return mClient.asBinder().isBinderAlive();
1320 }
1321
Craig Mautnera987d432012-10-11 14:07:58 -07001322 boolean isClosing() {
1323 return mExiting || (mService.mClosingApps.contains(mAppToken));
1324 }
1325
Craig Mautner69b08182012-09-05 13:07:13 -07001326 @Override
1327 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001328 final DisplayContent displayContent = getDisplayContent();
1329 if (displayContent == null) {
1330 // Only a window that was on a non-default display can be detached from it.
1331 return false;
1332 }
Winson Chung47a3e652014-05-21 16:03:42 -07001333 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001334 }
1335
Adrian Rooscd3884d2015-02-18 17:25:23 +01001336 @Override
1337 public boolean isDimming() {
1338 TaskStack stack = getStack();
1339 if (stack == null) {
1340 return false;
1341 }
1342 return stack.isDimming(mWinAnimator);
1343 }
1344
Craig Mautner88400d32012-09-30 12:35:45 -07001345 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1346 mShowToOwnerOnly = showToOwnerOnly;
1347 }
1348
Craig Mautner5962b122012-10-05 14:45:52 -07001349 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001350 // Attached windows are evaluated based on the window that they are attached to.
1351 WindowState win = this;
1352 while (win.mAttachedWindow != null) {
1353 win = win.mAttachedWindow;
1354 }
1355 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1356 && win.mAppToken != null && win.mAppToken.showWhenLocked) {
1357 // Save some cycles by not calling getDisplayInfo unless it is an application
1358 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001359 final DisplayContent displayContent = win.getDisplayContent();
1360 if (displayContent == null) {
1361 return true;
1362 }
1363 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001364 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1365 && win.mFrame.right >= displayInfo.appWidth
1366 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001367 // Is a fullscreen window, like the clock alarm. Show to everyone.
1368 return false;
1369 }
1370 }
1371
Craig Mautner341220f2012-10-16 15:20:09 -07001372 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001373 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001374 }
1375
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001376 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1377 outRegion.set(
1378 frame.left + inset.left, frame.top + inset.top,
1379 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001380 }
1381
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001382 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001383 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001384 switch (mTouchableInsets) {
1385 default:
1386 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1387 outRegion.set(frame);
1388 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001389 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001390 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001391 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001392 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001393 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001394 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001395 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1396 final Region givenTouchableRegion = mGivenTouchableRegion;
1397 outRegion.set(givenTouchableRegion);
1398 outRegion.translate(frame.left, frame.top);
1399 break;
1400 }
1401 }
1402 }
1403
Craig Mautner59c00972012-07-30 12:10:24 -07001404 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001405 final DisplayContent displayContent = getDisplayContent();
1406 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001407 }
1408
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001409 /**
1410 * Report a focus change. Must be called with no locks held, and consistently
1411 * from the same serialized thread (such as dispatched from a handler).
1412 */
1413 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1414 try {
1415 mClient.windowFocusChanged(focused, inTouchMode);
1416 } catch (RemoteException e) {
1417 }
1418 if (mFocusCallbacks != null) {
1419 final int N = mFocusCallbacks.beginBroadcast();
1420 for (int i=0; i<N; i++) {
1421 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1422 try {
1423 if (focused) {
1424 obs.focusGained(mWindowId.asBinder());
1425 } else {
1426 obs.focusLost(mWindowId.asBinder());
1427 }
1428 } catch (RemoteException e) {
1429 }
1430 }
1431 mFocusCallbacks.finishBroadcast();
1432 }
1433 }
1434
Craig Mautnerdf88d732014-01-27 09:21:32 -08001435 void reportResized() {
1436 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001437 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1438 + ": " + mCompatFrame);
1439 boolean configChanged = isConfigChanged();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001440 final TaskStack stack = getStack();
1441 final Configuration overrideConfig =
1442 (stack != null) ? stack.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001443 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1444 Slog.i(TAG, "Sending new config to window " + this + ": "
Wale Ogunwale60454db2015-01-23 16:05:07 -08001445 + mWinAnimator.mSurfaceW + "x" + mWinAnimator.mSurfaceH + " / config="
1446 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001447 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001448 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001449 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1450 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1451
Craig Mautnerdf88d732014-01-27 09:21:32 -08001452 final Rect frame = mFrame;
1453 final Rect overscanInsets = mLastOverscanInsets;
1454 final Rect contentInsets = mLastContentInsets;
1455 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001456 final Rect stableInsets = mLastStableInsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001457 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1458 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07001459 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1460 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001461 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1462 mService.mH.post(new Runnable() {
1463 @Override
1464 public void run() {
1465 try {
1466 mClient.resized(frame, overscanInsets, contentInsets,
Adrian Roosfa104232014-06-20 16:10:14 -07001467 visibleInsets, stableInsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001468 } catch (RemoteException e) {
1469 // Not a remote call, RemoteException won't be raised.
1470 }
1471 }
1472 });
1473 } else {
Adrian Roosfa104232014-06-20 16:10:14 -07001474 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
1475 reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001476 }
Svetoslav4604abc2014-06-10 18:59:30 -07001477
1478 //TODO (multidisplay): Accessibility supported only for the default display.
1479 if (mService.mAccessibilityController != null
1480 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07001481 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07001482 }
1483
Craig Mautnerdf88d732014-01-27 09:21:32 -08001484 mOverscanInsetsChanged = false;
1485 mContentInsetsChanged = false;
1486 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07001487 mStableInsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001488 mWinAnimator.mSurfaceResized = false;
1489 } catch (RemoteException e) {
1490 mOrientationChanging = false;
1491 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1492 - mService.mDisplayFreezeTime);
1493 }
1494 }
1495
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001496 public void registerFocusObserver(IWindowFocusObserver observer) {
1497 synchronized(mService.mWindowMap) {
1498 if (mFocusCallbacks == null) {
1499 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1500 }
1501 mFocusCallbacks.register(observer);
1502 }
1503 }
1504
1505 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1506 synchronized(mService.mWindowMap) {
1507 if (mFocusCallbacks != null) {
1508 mFocusCallbacks.unregister(observer);
1509 }
1510 }
1511 }
1512
1513 public boolean isFocused() {
1514 synchronized(mService.mWindowMap) {
1515 return mService.mCurrentFocus == this;
1516 }
1517 }
1518
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001519 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001520 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001521 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001522 if (stack != null) {
1523 pw.print(" stackId="); pw.print(stack.mStackId);
1524 }
Craig Mautner59c00972012-07-30 12:10:24 -07001525 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001526 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001527 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001528 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1529 pw.print(" package="); pw.print(mAttrs.packageName);
1530 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001531 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001532 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1533 pw.print(" h="); pw.print(mRequestedHeight);
1534 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001535 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1536 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1537 pw.print(" h="); pw.println(mLastRequestedHeight);
1538 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001539 if (mAttachedWindow != null || mLayoutAttached) {
1540 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1541 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1542 }
1543 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1544 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1545 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1546 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1547 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1548 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001549 if (dumpAll) {
1550 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1551 pw.print(" mSubLayer="); pw.print(mSubLayer);
1552 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001553 pw.print((mTargetAppToken != null ?
1554 mTargetAppToken.mAppAnimator.animLayerAdjustment
1555 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001556 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1557 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001558 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001559 if (dumpAll) {
1560 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1561 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1562 if (mAppToken != null) {
1563 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1564 }
1565 if (mTargetAppToken != null) {
1566 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1567 }
1568 pw.print(prefix); pw.print("mViewVisibility=0x");
1569 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001570 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1571 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001572 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1573 pw.print(" mSystemUiVisibility=0x");
1574 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001575 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001576 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1577 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001578 pw.print(prefix); pw.print("mPolicyVisibility=");
1579 pw.print(mPolicyVisibility);
1580 pw.print(" mPolicyVisibilityAfterAnim=");
1581 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001582 pw.print(" mAppOpVisibility=");
1583 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001584 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1585 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001586 if (!mRelayoutCalled || mLayoutNeeded) {
1587 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1588 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001589 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001590 if (mXOffset != 0 || mYOffset != 0) {
1591 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1592 pw.print(" y="); pw.println(mYOffset);
1593 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001594 if (dumpAll) {
1595 pw.print(prefix); pw.print("mGivenContentInsets=");
1596 mGivenContentInsets.printShortString(pw);
1597 pw.print(" mGivenVisibleInsets=");
1598 mGivenVisibleInsets.printShortString(pw);
1599 pw.println();
1600 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1601 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1602 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001603 Region region = new Region();
1604 getTouchableRegion(region);
1605 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001606 }
1607 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08001608 if (mOverrideConfig != Configuration.EMPTY) {
1609 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
1610 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001611 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001612 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001613 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1614 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001615 if (dumpAll) {
1616 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1617 pw.print(" last="); mLastFrame.printShortString(pw);
1618 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001619 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1620 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1621 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001622 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001623 if (mEnforceSizeCompat) {
1624 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001625 pw.println();
1626 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001627 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001628 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001629 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001630 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001631 pw.println();
1632 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1633 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001634 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001635 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001636 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001637 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04001638 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
1639 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001640 pw.print(prefix); pw.print("Cur insets: overscan=");
1641 mOverscanInsets.printShortString(pw);
1642 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001643 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07001644 pw.print(" stable="); mStableInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001645 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001646 pw.print(prefix); pw.print("Lst insets: overscan=");
1647 mLastOverscanInsets.printShortString(pw);
1648 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001649 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07001650 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001651 pw.println();
1652 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001653 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1654 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001655 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1656 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1657 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1658 pw.print(" mDestroying="); pw.print(mDestroying);
1659 pw.print(" mRemoved="); pw.println(mRemoved);
1660 }
1661 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1662 pw.print(prefix); pw.print("mOrientationChanging=");
1663 pw.print(mOrientationChanging);
1664 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1665 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1666 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07001667 if (mLastFreezeDuration != 0) {
1668 pw.print(prefix); pw.print("mLastFreezeDuration=");
1669 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
1670 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001671 if (mHScale != 1 || mVScale != 1) {
1672 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1673 pw.print(" mVScale="); pw.println(mVScale);
1674 }
1675 if (mWallpaperX != -1 || mWallpaperY != -1) {
1676 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1677 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1678 }
1679 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1680 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1681 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1682 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07001683 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
1684 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
1685 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
1686 pw.print(mWallpaperDisplayOffsetX);
1687 pw.print(" mWallpaperDisplayOffsetY=");
1688 pw.println(mWallpaperDisplayOffsetY);
1689 }
Jeff Brownc2932a12014-11-20 18:04:05 -08001690 if (mDrawLock != null) {
1691 pw.println("mDrawLock=" + mDrawLock);
1692 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001693 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001694
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001695 String makeInputChannelName() {
1696 return Integer.toHexString(System.identityHashCode(this))
1697 + " " + mAttrs.getTitle();
1698 }
1699
1700 @Override
1701 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001702 CharSequence title = mAttrs.getTitle();
1703 if (title == null || title.length() <= 0) {
1704 title = mAttrs.packageName;
1705 }
1706 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1707 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001708 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001709 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001710 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001711 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001712 }
1713 return mStringNameCache;
1714 }
satokcef37fb2011-10-24 21:49:38 +09001715}