blob: 3cecc6130a7b529abc3a512f7f45928739009b97 [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;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070020import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070021import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080022import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
23import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080024import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
25import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
26import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
27import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
28import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080029import static com.android.server.wm.WindowManagerService.DEBUG_CONFIGURATION;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -070030import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080031import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
Jeff Brownc2932a12014-11-20 18:04:05 -080032import static com.android.server.wm.WindowManagerService.DEBUG_POWER;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080033import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
34import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080035
Dianne Hackbornc2293022013-02-06 23:14:49 -080036import android.app.AppOpsManager;
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;
Skuhne81c524a2015-08-12 13:34:14 -070041import android.util.DisplayMetrics;
Dianne Hackborna57c6952013-03-29 14:46:40 -070042import android.util.TimeUtils;
Svetoslav4604abc2014-06-10 18:59:30 -070043import android.view.Display;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080044import android.view.IWindowFocusObserver;
45import android.view.IWindowId;
Jeff Brownc2932a12014-11-20 18:04:05 -080046
Jeff Brown4532e612012-04-05 14:27:12 -070047import com.android.server.input.InputWindowHandle;
48
Craig Mautnere7ae2502012-03-26 17:11:19 -070049import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050import android.content.res.Configuration;
51import android.graphics.Matrix;
52import android.graphics.PixelFormat;
53import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070054import android.graphics.RectF;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055import android.graphics.Region;
56import android.os.IBinder;
57import android.os.RemoteException;
Craig Mautner9dc52bc2012-08-06 14:15:42 -070058import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070060import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061import android.view.Gravity;
62import android.view.IApplicationToken;
63import android.view.IWindow;
64import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065import android.view.View;
66import android.view.ViewTreeObserver;
67import android.view.WindowManager;
68import android.view.WindowManagerPolicy;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080069
70import java.io.PrintWriter;
71import java.util.ArrayList;
72
Craig Mautner59c00972012-07-30 12:10:24 -070073class WindowList extends ArrayList<WindowState> {
74}
75
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076/**
77 * A window in the window manager.
78 */
Craig Mautnere32c3072012-03-12 15:25:35 -070079final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070080 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -080081
Skuhne81c524a2015-08-12 13:34:14 -070082 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -070083 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
84 // use hard-coded min sizes for now.
85 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
86 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -070087
88 // The thickness of a window resize handle outside the window bounds on the free form workspace
89 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -070090 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -070091
92 static final boolean BOUNDS_FOR_TOUCH = true;
Skuhne81c524a2015-08-12 13:34:14 -070093
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080094 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -070095 final WindowManagerPolicy mPolicy;
96 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080097 final Session mSession;
98 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -080099 final int mAppOp;
100 // UserId and appId of the owner. Don't display windows of non-current user.
101 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800102 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800103 WindowToken mToken;
104 WindowToken mRootToken;
105 AppWindowToken mAppToken;
106 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700107
108 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
109 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
111 final DeathRecipient mDeathRecipient;
112 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800113 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114 final int mBaseLayer;
115 final int mSubLayer;
116 final boolean mLayoutAttached;
117 final boolean mIsImWindow;
118 final boolean mIsWallpaper;
119 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700120 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700121 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700123 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800124 boolean mPolicyVisibility = true;
125 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800126 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800128 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800129 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700130 boolean mDragResizing;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700131
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800132 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
133
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700134 /**
135 * The window size that was requested by the application. These are in
136 * the application's coordinate space (without compatibility scale applied).
137 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138 int mRequestedWidth;
139 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700140 int mLastRequestedWidth;
141 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700142
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 boolean mHaveFrame;
145 boolean mObscured;
146 boolean mTurnOnScreen;
147
148 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700149
Wale Ogunwale60454db2015-01-23 16:05:07 -0800150 private Configuration mConfiguration = Configuration.EMPTY;
151 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800152 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
153 // Used only on {@link #TYPE_KEYGUARD}.
154 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700155
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700156 /**
157 * Actual frame shown on-screen (may be modified by animation). These
158 * are in the screen's coordinate space (WITH the compatibility scale
159 * applied).
160 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700161 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162
163 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700164 * Insets that determine the actually visible area. These are in the application's
165 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166 */
167 final Rect mVisibleInsets = new Rect();
168 final Rect mLastVisibleInsets = new Rect();
169 boolean mVisibleInsetsChanged;
170
171 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700172 * Insets that are covered by system windows (such as the status bar) and
173 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700174 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175 */
176 final Rect mContentInsets = new Rect();
177 final Rect mLastContentInsets = new Rect();
178 boolean mContentInsetsChanged;
179
180 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800181 * Insets that determine the area covered by the display overscan region. These are in the
182 * application's coordinate space (without compatibility scale applied).
183 */
184 final Rect mOverscanInsets = new Rect();
185 final Rect mLastOverscanInsets = new Rect();
186 boolean mOverscanInsetsChanged;
187
188 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700189 * Insets that determine the area covered by the stable system windows. These are in the
190 * application's coordinate space (without compatibility scale applied).
191 */
192 final Rect mStableInsets = new Rect();
193 final Rect mLastStableInsets = new Rect();
194 boolean mStableInsetsChanged;
195
196 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700197 * Outsets determine the area outside of the surface where we want to pretend that it's possible
198 * to draw anyway.
199 */
200 final Rect mOutsets = new Rect();
201 final Rect mLastOutsets = new Rect();
202 boolean mOutsetsChanged = false;
203
204 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800205 * Set to true if we are waiting for this window to receive its
206 * given internal insets before laying out other windows based on it.
207 */
208 boolean mGivenInsetsPending;
209
210 /**
211 * These are the content insets that were given during layout for
212 * this window, to be applied to windows behind it.
213 */
214 final Rect mGivenContentInsets = new Rect();
215
216 /**
217 * These are the visible insets that were given during layout for
218 * this window, to be applied to windows behind it.
219 */
220 final Rect mGivenVisibleInsets = new Rect();
221
222 /**
223 * This is the given touchable area relative to the window frame, or null if none.
224 */
225 final Region mGivenTouchableRegion = new Region();
226
227 /**
228 * Flag indicating whether the touchable region should be adjusted by
229 * the visible insets; if false the area outside the visible insets is
230 * NOT touchable, so we must use those to adjust the frame during hit
231 * tests.
232 */
233 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
234
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700235 /**
236 * This is rectangle of the window's surface that is not covered by
237 * system decorations.
238 */
239 final Rect mSystemDecorRect = new Rect();
240 final Rect mLastSystemDecorRect = new Rect();
241
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400243 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700244 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 float mHScale=1, mVScale=1;
246 float mLastHScale=1, mLastVScale=1;
247 final Matrix mTmpMatrix = new Matrix();
248
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700249 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800250 final Rect mFrame = new Rect();
251 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700252 // Frame that is scaled to the application's coordinate space when in
253 // screen size compatibility mode.
254 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255
256 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700257
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800258 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700259
Wale Ogunwale94596652015-02-06 19:27:34 -0800260 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
261 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700262 final Rect mDisplayFrame = new Rect();
263
264 // The region of the display frame that the display type supports displaying content on. This
265 // is mostly a special case for TV where some displays don’t have the entire display usable.
266 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
267 // window display contents to extend into the overscan region.
268 final Rect mOverscanFrame = new Rect();
269
270 // The display frame minus the stable insets. This value is always constant regardless of if
271 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700272 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800273
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700274 // The area not occupied by the status and navigation bars. So, if both status and navigation
275 // bars are visible, the decor frame is equal to the stable frame.
276 final Rect mDecorFrame = new Rect();
277
278 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
279 // minus the area occupied by the IME if the IME is present.
280 final Rect mContentFrame = new Rect();
281
282 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
283 // displays hint text.
284 final Rect mVisibleFrame = new Rect();
285
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700286 // Frame that includes dead area outside of the surface but where we want to pretend that it's
287 // possible to draw.
288 final Rect mOutsetFrame = new Rect();
289
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800290 boolean mContentChanged;
291
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800292 // If a window showing a wallpaper: the requested offset for the
293 // wallpaper; if a wallpaper window: the currently applied offset.
294 float mWallpaperX = -1;
295 float mWallpaperY = -1;
296
297 // If a window showing a wallpaper: what fraction of the offset
298 // range corresponds to a full virtual screen.
299 float mWallpaperXStep = -1;
300 float mWallpaperYStep = -1;
301
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700302 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
303 // to its window; if a wallpaper window: not used.
304 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
305 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
306
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800307 // Wallpaper windows: pixels offset based on above variables.
308 int mXOffset;
309 int mYOffset;
310
Craig Mautner2268e7e2012-12-13 15:40:00 -0800311 /**
312 * This is set after IWindowSession.relayout() has been called at
313 * least once for the window. It allows us to detect the situation
314 * where we don't yet have a surface, but should have one soon, so
315 * we can give the window focus before waiting for the relayout.
316 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800317 boolean mRelayoutCalled;
318
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800319 /**
320 * If the application has called relayout() with changes that can
321 * impact its window's size, we need to perform a layout pass on it
322 * even if it is not currently visible for layout. This is set
323 * when in that case until the layout is done.
324 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800325 boolean mLayoutNeeded;
326
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800327 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800328 boolean mExiting;
329
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800330 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 boolean mDestroying;
332
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800333 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 boolean mRemoveOnExit;
335
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800336 /**
337 * Set when the orientation is changing and this window has not yet
338 * been updated for the new orientation.
339 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 boolean mOrientationChanging;
341
Dianne Hackborna57c6952013-03-29 14:46:40 -0700342 /**
343 * How long we last kept the screen frozen.
344 */
345 int mLastFreezeDuration;
346
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800347 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800348 boolean mRemoved;
349
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800350 /**
351 * Temp for keeping track of windows that have been removed when
352 * rebuilding window list.
353 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800354 boolean mRebuilding;
355
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700357 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800359
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 // Used to improve performance of toString()
361 String mStringNameCache;
362 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700363 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800364
Craig Mautnera2c77052012-03-26 12:14:43 -0700365 final WindowStateAnimator mWinAnimator;
366
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700367 boolean mHasSurface = false;
368
Craig Mautner19ab8282014-05-07 10:35:34 -0700369 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700370 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700371
Craig Mautner88400d32012-09-30 12:35:45 -0700372 /** When true this window can be displayed on screens owther than mOwnerUid's */
373 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700374
Jeff Brownc2932a12014-11-20 18:04:05 -0800375 /**
376 * Wake lock for drawing.
377 * Even though it's slightly more expensive to do so, we will use a separate wake lock
378 * for each app that is requesting to draw while dozing so that we can accurately track
379 * who is preventing the system from suspending.
380 * This lock is only acquired on first use.
381 */
382 PowerManager.WakeLock mDrawLock;
383
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800385 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700386 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 mService = service;
388 mSession = s;
389 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800390 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800391 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700392 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800393 mWindowId = new IWindowId.Stub() {
394 @Override
395 public void registerFocusObserver(IWindowFocusObserver observer) {
396 WindowState.this.registerFocusObserver(observer);
397 }
398 @Override
399 public void unregisterFocusObserver(IWindowFocusObserver observer) {
400 WindowState.this.unregisterFocusObserver(observer);
401 }
402 @Override
403 public boolean isFocused() {
404 return WindowState.this.isFocused();
405 }
406 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800407 mAttrs.copyFrom(a);
408 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700409 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700410 mPolicy = mService.mPolicy;
411 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800412 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700413 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700414 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800415 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700416 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700417 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800418 try {
419 c.asBinder().linkToDeath(deathRecipient, 0);
420 } catch (RemoteException e) {
421 mDeathRecipient = null;
422 mAttachedWindow = null;
423 mLayoutAttached = false;
424 mIsImWindow = false;
425 mIsWallpaper = false;
426 mIsFloatingLayer = false;
427 mBaseLayer = 0;
428 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700429 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700430 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800431 return;
432 }
433 mDeathRecipient = deathRecipient;
434
435 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
436 mAttrs.type <= LAST_SUB_WINDOW)) {
437 // The multiplier here is to reserve space for multiple
438 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700439 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800440 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
441 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700442 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800443 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700444 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900445
tiger_huange2a98a72014-11-13 19:46:28 +0800446 final WindowList childWindows = mAttachedWindow.mChildWindows;
447 final int numChildWindows = childWindows.size();
448 if (numChildWindows == 0) {
449 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900450 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800451 boolean added = false;
452 for (int i = 0; i < numChildWindows; i++) {
453 final int childSubLayer = childWindows.get(i).mSubLayer;
454 if (mSubLayer < childSubLayer
455 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
456 // We insert the child window into the list ordered by the sub-layer. For
457 // same sub-layers, the negative one should go below others; the positive
458 // one should go above others.
459 childWindows.add(i, this);
460 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900461 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900462 }
463 }
tiger_huange2a98a72014-11-13 19:46:28 +0800464 if (!added) {
465 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900466 }
467 }
468
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 mLayoutAttached = mAttrs.type !=
470 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
471 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
472 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
473 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
474 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
475 } else {
476 // The multiplier here is to reserve space for multiple
477 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700478 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800479 * WindowManagerService.TYPE_LAYER_MULTIPLIER
480 + WindowManagerService.TYPE_LAYER_OFFSET;
481 mSubLayer = 0;
482 mAttachedWindow = null;
483 mLayoutAttached = false;
484 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
485 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
486 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
487 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
488 }
489
490 WindowState appWin = this;
491 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700492 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800493 }
494 WindowToken appToken = appWin.mToken;
495 while (appToken.appWindowToken == null) {
496 WindowToken parent = mService.mTokenMap.get(appToken.token);
497 if (parent == null || appToken == parent) {
498 break;
499 }
500 appToken = parent;
501 }
502 mRootToken = appToken;
503 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700504 if (mAppToken != null) {
505 final DisplayContent appDisplay = getDisplayContent();
506 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700507
508 if (mAppToken.showForAllUsers) {
509 // Windows for apps that can show for all users should also show when the
510 // device is locked.
511 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
512 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700513 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800514
Craig Mautner322e4032012-07-13 13:35:20 -0700515 mWinAnimator = new WindowStateAnimator(this);
516 mWinAnimator.mAlpha = a.alpha;
517
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800518 mRequestedWidth = 0;
519 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700520 mLastRequestedWidth = 0;
521 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800522 mXOffset = 0;
523 mYOffset = 0;
524 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800525 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700526 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
527 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800528 }
529
530 void attach() {
531 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700532 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800533 + ", list=" + mToken.windows);
534 mSession.windowAddedLocked();
535 }
536
Craig Mautnera2c77052012-03-26 12:14:43 -0700537 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800538 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800539 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800540 }
541
542 @Override
543 public String getOwningPackage() {
544 return mAttrs.packageName;
545 }
546
547 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700548 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
549 Rect osf) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700550 if (mAppToken != null && mAppToken.mReplacingWindow
551 && (mExiting || !mAppToken.mReplacingRemoveRequested)) {
552 // This window is being replaced and either already got information that it's being
553 // removed or we are still waiting for some information. Because of this we don't
554 // want to apply any more changes to it, so it remains in this state until new window
555 // appears.
556 return;
557 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800558 mHaveFrame = true;
559
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700560 final Task task = mAppToken != null ? getTask() : null;
561 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
Chong Zhang09b21ef2015-09-14 10:20:21 -0700562 final boolean freeformWorkspace = task != null && task.inFreeformWorkspace();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700563 if (nonFullscreenTask) {
564 task.getBounds(mContainingFrame);
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800565 final WindowState imeWin = mService.mInputMethodWindow;
566 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
567 && mContainingFrame.bottom > cf.bottom) {
568 // IME is up and obscuring this window. Adjust the window position so it is visible.
569 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700570 }
Skuhne81c524a2015-08-12 13:34:14 -0700571
Skuhnef932e562015-08-20 12:07:30 -0700572 if (freeformWorkspace) {
Skuhne81c524a2015-08-12 13:34:14 -0700573 // In free form mode we have only to set the rectangle if it wasn't set already. No
574 // need to intersect it with the (visible) "content frame" since it is allowed to
575 // be outside the visible desktop.
576 if (mContainingFrame.isEmpty()) {
577 mContainingFrame.set(cf);
578 }
579 } else {
580 // Make sure the containing frame is within the content frame so we don't layout
581 // resized window under screen decorations.
582 if (!mContainingFrame.intersect(cf)) {
583 mContainingFrame.set(cf);
584 }
Doris Liu06d582d2015-06-01 13:18:43 -0700585 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800586 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700587 } else {
588 mContainingFrame.set(pf);
Wale Ogunwale94596652015-02-06 19:27:34 -0800589 mDisplayFrame.set(df);
Craig Mautner967212c2013-04-13 21:10:58 -0700590 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800591
Craig Mautner967212c2013-04-13 21:10:58 -0700592 final int pw = mContainingFrame.width();
593 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800594
595 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700596 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
597 if (mAttrs.width < 0) {
598 w = pw;
599 } else if (mEnforceSizeCompat) {
600 w = (int)(mAttrs.width * mGlobalScale + .5f);
601 } else {
602 w = mAttrs.width;
603 }
604 if (mAttrs.height < 0) {
605 h = ph;
606 } else if (mEnforceSizeCompat) {
607 h = (int)(mAttrs.height * mGlobalScale + .5f);
608 } else {
609 h = mAttrs.height;
610 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800611 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700612 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
613 w = pw;
614 } else if (mEnforceSizeCompat) {
615 w = (int)(mRequestedWidth * mGlobalScale + .5f);
616 } else {
617 w = mRequestedWidth;
618 }
619 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
620 h = ph;
621 } else if (mEnforceSizeCompat) {
622 h = (int)(mRequestedHeight * mGlobalScale + .5f);
623 } else {
624 h = mRequestedHeight;
625 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800626 }
627
628 if (!mParentFrame.equals(pf)) {
629 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
630 // + " to " + pf);
631 mParentFrame.set(pf);
632 mContentChanged = true;
633 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700634 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
635 mLastRequestedWidth = mRequestedWidth;
636 mLastRequestedHeight = mRequestedHeight;
637 mContentChanged = true;
638 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800639
Craig Mautnereda67292013-04-28 13:50:14 -0700640 mOverscanFrame.set(of);
641 mContentFrame.set(cf);
642 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400643 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700644 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700645 final boolean hasOutsets = osf != null;
646 if (hasOutsets) {
647 mOutsetFrame.set(osf);
648 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800649
Craig Mautnereda67292013-04-28 13:50:14 -0700650 final int fw = mFrame.width();
651 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800652
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700653 float x, y;
654 if (mEnforceSizeCompat) {
655 x = mAttrs.x * mGlobalScale;
656 y = mAttrs.y * mGlobalScale;
657 } else {
658 x = mAttrs.x;
659 y = mAttrs.y;
660 }
661
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700662 if (nonFullscreenTask) {
Wale Ogunwaleb171abb2015-04-22 12:47:17 -0700663 // Make sure window fits in containing frame since it is in a non-fullscreen stack as
664 // required by {@link Gravity#apply} call.
665 w = Math.min(w, pw);
666 h = Math.min(h, ph);
667 }
668
Craig Mautner967212c2013-04-13 21:10:58 -0700669 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700670 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700671 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672
Wale Ogunwale94596652015-02-06 19:27:34 -0800673 // Now make sure the window fits in the overall display frame.
674 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800675
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700676 // Calculate the outsets before the content frame gets shrinked to the window frame.
677 if (hasOutsets) {
678 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
679 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
680 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
681 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
682 } else {
683 mOutsets.set(0, 0, 0, 0);
684 }
685
Craig Mautnera248eee2013-05-07 11:41:27 -0700686 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800687 // final window frame.
Skuhnef932e562015-08-20 12:07:30 -0700688 if (freeformWorkspace && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700689 // Keep the frame out of the blocked system area, limit it in size to the content area
690 // and make sure that there is always a minimum visible so that the user can drag it
691 // into a usable area..
692 final int height = Math.min(mFrame.height(), mContentFrame.height());
693 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700694 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
695 final int minVisibleHeight =
696 mService.dipToPixel(MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
697 final int minVisibleWidth =
698 mService.dipToPixel(MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700699 final int top = Math.max(mContentFrame.top,
700 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
701 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
702 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
703 mFrame.set(left, top, left + width, top + height);
704 mContentFrame.set(mFrame);
705 mVisibleFrame.set(mContentFrame);
706 mStableFrame.set(mContentFrame);
707 } else {
708 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
709 Math.max(mContentFrame.top, mFrame.top),
710 Math.min(mContentFrame.right, mFrame.right),
711 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800712
Skuhne81c524a2015-08-12 13:34:14 -0700713 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
714 Math.max(mVisibleFrame.top, mFrame.top),
715 Math.min(mVisibleFrame.right, mFrame.right),
716 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800717
Skuhne81c524a2015-08-12 13:34:14 -0700718 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
719 Math.max(mStableFrame.top, mFrame.top),
720 Math.min(mStableFrame.right, mFrame.right),
721 Math.min(mStableFrame.bottom, mFrame.bottom));
722 }
Adrian Roosfa104232014-06-20 16:10:14 -0700723
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700724 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
725 Math.max(mOverscanFrame.top - mFrame.top, 0),
Adrian Roos3236f3a2014-12-09 15:06:40 +0000726 Math.max(mFrame.right - mOverscanFrame.right, 0),
727 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800728
Craig Mautnereda67292013-04-28 13:50:14 -0700729 mContentInsets.set(mContentFrame.left - mFrame.left,
730 mContentFrame.top - mFrame.top,
731 mFrame.right - mContentFrame.right,
732 mFrame.bottom - mContentFrame.bottom);
733
734 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
735 mVisibleFrame.top - mFrame.top,
736 mFrame.right - mVisibleFrame.right,
737 mFrame.bottom - mVisibleFrame.bottom);
738
Adrian Roosfa104232014-06-20 16:10:14 -0700739 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
740 Math.max(mStableFrame.top - mFrame.top, 0),
741 Math.max(mFrame.right - mStableFrame.right, 0),
742 Math.max(mFrame.bottom - mStableFrame.bottom, 0));
743
Craig Mautnereda67292013-04-28 13:50:14 -0700744 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400745 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700746 // If there is a size compatibility scale being applied to the
747 // window, we need to apply this to its insets so that they are
748 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700749 mOverscanInsets.scale(mInvGlobalScale);
750 mContentInsets.scale(mInvGlobalScale);
751 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700752 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700753 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700754
755 // Also the scaled frame that we report to the app needs to be
756 // adjusted to be in its coordinate space.
757 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400758 }
759
Craig Mautnereda67292013-04-28 13:50:14 -0700760 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800761 final DisplayContent displayContent = getDisplayContent();
762 if (displayContent != null) {
763 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700764 mService.mWallpaperControllerLocked.updateWallpaperOffset(
765 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800766 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800767 }
768
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700769 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
770 "Resolving (mRequestedWidth="
771 + mRequestedWidth + ", mRequestedheight="
772 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
773 + "): frame=" + mFrame.toShortString()
774 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700775 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700776 + " vi=" + mStableInsets.toShortString()
777 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800778 }
779
Craig Mautnera2c77052012-03-26 12:14:43 -0700780 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800781 public Rect getFrameLw() {
782 return mFrame;
783 }
784
Craig Mautnera2c77052012-03-26 12:14:43 -0700785 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700786 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800787 return mShownFrame;
788 }
789
Craig Mautnera2c77052012-03-26 12:14:43 -0700790 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800791 public Rect getDisplayFrameLw() {
792 return mDisplayFrame;
793 }
794
Craig Mautnera2c77052012-03-26 12:14:43 -0700795 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800796 public Rect getOverscanFrameLw() {
797 return mOverscanFrame;
798 }
799
800 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800801 public Rect getContentFrameLw() {
802 return mContentFrame;
803 }
804
Craig Mautnera2c77052012-03-26 12:14:43 -0700805 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800806 public Rect getVisibleFrameLw() {
807 return mVisibleFrame;
808 }
809
Craig Mautnera2c77052012-03-26 12:14:43 -0700810 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800811 public boolean getGivenInsetsPendingLw() {
812 return mGivenInsetsPending;
813 }
814
Craig Mautnera2c77052012-03-26 12:14:43 -0700815 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800816 public Rect getGivenContentInsetsLw() {
817 return mGivenContentInsets;
818 }
819
Craig Mautnera2c77052012-03-26 12:14:43 -0700820 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800821 public Rect getGivenVisibleInsetsLw() {
822 return mGivenVisibleInsets;
823 }
824
Craig Mautnera2c77052012-03-26 12:14:43 -0700825 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800826 public WindowManager.LayoutParams getAttrs() {
827 return mAttrs;
828 }
829
Craig Mautner812d2ca2012-09-27 15:35:34 -0700830 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800831 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
832 int index = -1;
833 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700834 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800835 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700836 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
837 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800838 }
839 // If we reached the bottom of the range of windows we are considering,
840 // assume no menu is needed.
841 if (ws == bottom) {
842 return false;
843 }
844 // The current window hasn't specified whether menu key is needed;
845 // look behind it.
846 // First, we may need to determine the starting position.
847 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700848 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800849 }
850 index--;
851 if (index < 0) {
852 return false;
853 }
Craig Mautner59c00972012-07-30 12:10:24 -0700854 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800855 }
856 }
857
Craig Mautner19d59bc2012-09-04 11:15:56 -0700858 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700859 public int getSystemUiVisibility() {
860 return mSystemUiVisibility;
861 }
862
Craig Mautner19d59bc2012-09-04 11:15:56 -0700863 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800864 public int getSurfaceLayer() {
865 return mLayer;
866 }
867
Craig Mautner812d2ca2012-09-27 15:35:34 -0700868 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700869 public int getBaseType() {
870 WindowState win = this;
871 while (win.mAttachedWindow != null) {
872 win = win.mAttachedWindow;
873 }
874 return win.mAttrs.type;
875 }
876
877 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800878 public IApplicationToken getAppToken() {
879 return mAppToken != null ? mAppToken.appToken : null;
880 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700881
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700882 @Override
883 public boolean isVoiceInteraction() {
884 return mAppToken != null ? mAppToken.voiceInteraction : false;
885 }
886
Craig Mautner4c5eb222013-11-18 12:59:05 -0800887 boolean setInsetsChanged() {
888 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
889 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
890 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700891 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700892 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
893 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
894 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800895 }
896
Craig Mautnerdf88d732014-01-27 09:21:32 -0800897 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700898 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700899 return mDisplayContent;
900 }
901 final TaskStack stack = getStack();
902 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800903 }
904
Chong Zhang09b21ef2015-09-14 10:20:21 -0700905 public DisplayInfo getDisplayInfo() {
906 final DisplayContent displayContent = getDisplayContent();
907 return displayContent != null ? displayContent.getDisplayInfo() : null;
908 }
909
Craig Mautner19d59bc2012-09-04 11:15:56 -0700910 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800911 final DisplayContent displayContent = getDisplayContent();
912 if (displayContent == null) {
913 return -1;
914 }
915 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700916 }
917
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700918 Task getTask() {
Craig Mautner05d29032013-05-03 13:40:13 -0700919 AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700920 if (wtoken == null) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700921 return null;
922 }
923 final Task task = wtoken.mTask;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700924 return task;
925 }
926
927 TaskStack getStack() {
928 Task task = getTask();
929 if (task != null) {
930 if (task.mStack != null) {
931 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700932 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700933 }
Craig Mautner05d29032013-05-03 13:40:13 -0700934 return mDisplayContent.getHomeStack();
Craig Mautnerd9a22882013-03-16 15:00:36 -0700935 }
936
Skuhnef932e562015-08-20 12:07:30 -0700937 /**
938 * Retrieves the bounds for a task.
939 * @param bounds The rect which gets the bounds.
940 * @param forTouch Pass in BOUNDS_FOR_TOUCH to get touch related bounds, otherwise visible
941 * bounds will be returned.
942 */
943 void getTaskBounds(Rect bounds, boolean forTouch) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700944 final Task task = getTask();
945 if (task != null) {
946 task.getBounds(bounds);
Skuhnef932e562015-08-20 12:07:30 -0700947 if (forTouch == BOUNDS_FOR_TOUCH) {
Chong Zhang09b21ef2015-09-14 10:20:21 -0700948 if (task.inFreeformWorkspace()) {
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700949 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
950 final int delta =
951 mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
Skuhnef932e562015-08-20 12:07:30 -0700952 bounds.inset(-delta, -delta);
953 }
954 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800955 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700956 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800957 bounds.set(mFrame);
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700958 }
959
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800960 public long getInputDispatchingTimeoutNanos() {
961 return mAppToken != null
962 ? mAppToken.inputDispatchingTimeoutNanos
963 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
964 }
965
Craig Mautnere8552142012-11-07 13:55:47 -0800966 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800967 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700968 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800969 }
970
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800971 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
972 if (dsdx < .99999f || dsdx > 1.00001f) return false;
973 if (dtdy < .99999f || dtdy > 1.00001f) return false;
974 if (dtdx < -.000001f || dtdx > .000001f) return false;
975 if (dsdy < -.000001f || dsdy > .000001f) return false;
976 return true;
977 }
978
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400979 void prelayout() {
980 if (mEnforceSizeCompat) {
981 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700982 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400983 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700984 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400985 }
986 }
987
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800988 /**
989 * Is this window visible? It is not visible if there is no
990 * surface, or we are in the process of running an exit animation
991 * that will remove the surface, or its app token has been hidden.
992 */
Craig Mautner88400d32012-09-30 12:35:45 -0700993 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800994 public boolean isVisibleLw() {
995 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700996 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997 && (atoken == null || !atoken.hiddenRequested)
998 && !mExiting && !mDestroying;
999 }
1000
1001 /**
1002 * Like {@link #isVisibleLw}, but also counts a window that is currently
1003 * "hidden" behind the keyguard as visible. This allows us to apply
1004 * things like window flags that impact the keyguard.
1005 * XXX I am starting to think we need to have ANOTHER visibility flag
1006 * for this "hidden behind keyguard" state rather than overloading
1007 * mPolicyVisibility. Ungh.
1008 */
Craig Mautner88400d32012-09-30 12:35:45 -07001009 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001010 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001011 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -08001012 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001013 return false;
1014 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001015 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001016 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -07001017 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001018 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001019 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001020 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1021 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001022 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001023 }
1024
1025 /**
1026 * Is this window visible, ignoring its app token? It is not visible
1027 * if there is no surface, or we are in the process of running an exit animation
1028 * that will remove the surface.
1029 */
1030 public boolean isWinVisibleLw() {
1031 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001032 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -07001033 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001034 && !mExiting && !mDestroying;
1035 }
1036
1037 /**
1038 * The same as isVisible(), but follows the current hidden state of
1039 * the associated app token, not the pending requested hidden state.
1040 */
1041 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001042 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07001043 && (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1044 && !mExiting && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001045 }
1046
1047 /**
1048 * Can this window possibly be a drag/drop target? The test here is
1049 * a combination of the above "visible now" with the check that the
1050 * Input Manager uses when discarding windows from input consideration.
1051 */
1052 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001053 return isVisibleNow() && !mRemoved
1054 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001055 }
1056
1057 /**
1058 * Same as isVisible(), but we also count it as visible between the
1059 * call to IWindowSession.add() and the first relayout().
1060 */
1061 boolean isVisibleOrAdding() {
1062 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001063 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001064 && mPolicyVisibility && !mAttachedHidden
1065 && (atoken == null || !atoken.hiddenRequested)
1066 && !mExiting && !mDestroying;
1067 }
1068
1069 /**
1070 * Is this window currently on-screen? It is on-screen either if it
1071 * is visible or it is currently running an animation before no longer
1072 * being visible.
1073 */
1074 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001075 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1076 }
1077
1078 /**
1079 * Like isOnScreen(), but ignores any force hiding of the window due
1080 * to the keyguard.
1081 */
1082 boolean isOnScreenIgnoringKeyguard() {
1083 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001084 return false;
1085 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001086 final AppWindowToken atoken = mAppToken;
1087 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001088 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001089 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001090 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001091 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001092 }
1093
1094 /**
1095 * Like isOnScreen(), but we don't return true if the window is part
1096 * of a transition that has not yet been started.
1097 */
1098 boolean isReadyForDisplay() {
1099 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -08001100 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001101 return false;
1102 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001103 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001104 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1105 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001106 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001107 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001108 }
1109
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001110 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001111 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1112 * to the keyguard.
1113 */
1114 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001115 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001116 return false;
1117 }
1118 final AppWindowToken atoken = mAppToken;
1119 if (atoken == null && !mPolicyVisibility) {
1120 // If this is not an app window, and the policy has asked to force
1121 // hide, then we really do want to hide.
1122 return false;
1123 }
1124 return mHasSurface && !mDestroying
1125 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1126 && !mRootToken.hidden)
1127 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001128 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1129 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001130 }
1131
1132 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001133 * Like isOnScreen, but returns false if the surface hasn't yet
1134 * been drawn.
1135 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001136 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001137 public boolean isDisplayedLw() {
1138 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001139 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001140 && ((!mAttachedHidden &&
1141 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001142 || mWinAnimator.mAnimating
1143 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001144 }
1145
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001146 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001147 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001148 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001149 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001150 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001151 return mWinAnimator.mAnimation != null
1152 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001153 }
1154
Craig Mautner812d2ca2012-09-27 15:35:34 -07001155 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001156 public boolean isGoneForLayoutLw() {
1157 final AppWindowToken atoken = mAppToken;
1158 return mViewVisibility == View.GONE
1159 || !mRelayoutCalled
1160 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001161 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001162 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001163 || (mExiting && !isAnimatingLw())
1164 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001165 }
1166
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001167 /**
1168 * Returns true if the window has a surface that it has drawn a
1169 * complete UI in to.
1170 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001171 public boolean isDrawFinishedLw() {
1172 return mHasSurface && !mDestroying &&
1173 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1174 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1175 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1176 }
1177
1178 /**
1179 * Returns true if the window has a surface that it has drawn a
1180 * complete UI in to.
1181 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001182 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001183 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001184 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001185 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1186 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001187 }
1188
1189 /**
1190 * Return true if the window is opaque and fully drawn. This indicates
1191 * it may obscure windows behind it.
1192 */
1193 boolean isOpaqueDrawn() {
1194 return (mAttrs.format == PixelFormat.OPAQUE
1195 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001196 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001197 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001198 }
1199
1200 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001201 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001202 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1203 */
Craig Mautner4557c082015-04-27 13:07:40 -07001204 boolean hasMoved() {
1205 return mHasSurface && mContentChanged && !mExiting && !mWinAnimator.mLastHidden
1206 && mService.okToDisplay() && (mFrame.top != mLastFrame.top
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001207 || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001208 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001209 }
1210
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001211 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001212 return mFrame.left <= 0 && mFrame.top <= 0 &&
1213 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001214 }
1215
Craig Mautner812d2ca2012-09-27 15:35:34 -07001216 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001217 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001218 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001219 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001220 final Configuration serviceConfig = mService.mCurConfiguration;
1221 boolean configChanged =
1222 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1223 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001224
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001225 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001226 // Retain configuration changed status until resetConfiguration called.
1227 mConfigHasChanged |= configChanged;
1228 configChanged = mConfigHasChanged;
1229 }
1230
1231 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001232 }
1233
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001234 void removeLocked() {
1235 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001236
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001237 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001238 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001239 mAttachedWindow.mChildWindows.remove(this);
1240 }
Craig Mautner96868332012-12-04 14:29:11 -08001241 mWinAnimator.destroyDeferredSurfaceLocked();
1242 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001243 mSession.windowRemovedLocked();
1244 try {
1245 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1246 } catch (RuntimeException e) {
1247 // Ignore if it has already been removed (usually because
1248 // we are doing this as part of processing a death note.)
1249 }
1250 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001251
Wale Ogunwale60454db2015-01-23 16:05:07 -08001252 private void setConfiguration(
1253 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001254 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001255 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001256 mConfigHasChanged = false;
1257 }
1258
Jeff Browncc4f7db2011-08-30 20:34:48 -07001259 void setInputChannel(InputChannel inputChannel) {
1260 if (mInputChannel != null) {
1261 throw new IllegalStateException("Window already has an input channel.");
1262 }
1263
1264 mInputChannel = inputChannel;
1265 mInputWindowHandle.inputChannel = inputChannel;
1266 }
1267
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001268 void disposeInputChannel() {
1269 if (mInputChannel != null) {
1270 mService.mInputManager.unregisterInputChannel(mInputChannel);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001271
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001272 mInputChannel.dispose();
1273 mInputChannel = null;
1274 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001275
1276 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001277 }
1278
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001279 void handleFlagDimBehind() {
1280 if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isDisplayedLw() && !mExiting) {
1281 final Task task = getTask();
1282 if (task == null) {
1283 return;
1284 }
1285 task.setContinueDimming();
1286 if (!task.isDimming(mWinAnimator)) {
1287 if (WindowManagerService.localLOGV) Slog.v(TAG, "Win " + this + " start dimming.");
1288 task.startDimmingIfNeeded(mWinAnimator);
1289 }
1290 }
1291 }
1292
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001293 void maybeRemoveReplacedWindow() {
1294 AppWindowToken token = mAppToken;
1295 if (token != null && token.mReplacingWindow) {
1296 token.mReplacingWindow = false;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001297 token.mAnimateReplacingWindow = false;
1298 token.mReplacingRemoveRequested = false;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001299 for (int i = token.allAppWindows.size() - 1; i >= 0; i--) {
1300 WindowState win = token.allAppWindows.get(i);
1301 if (win.mExiting) {
1302 mService.removeWindowInnerLocked(win);
1303 }
1304 }
1305 }
1306 }
1307
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001308 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001309 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001310 public void binderDied() {
1311 try {
1312 synchronized(mService.mWindowMap) {
1313 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001314 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001315 if (win != null) {
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001316 mService.removeWindowLocked(win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001317 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001318 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001319 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001320 }
1321 }
1322 } catch (IllegalArgumentException ex) {
1323 // This will happen if the window has already been
1324 // removed.
1325 }
1326 }
1327 }
1328
Craig Mautner58106812012-12-28 12:27:40 -08001329 /**
1330 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001331 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001332 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001333 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001334 && (mViewVisibility == View.VISIBLE)
1335 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1336 }
1337
Craig Mautner749a7bb2012-04-02 13:49:53 -07001338 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001339 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001340 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 }
1342
Craig Mautner749a7bb2012-04-02 13:49:53 -07001343 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001344 public boolean showLw(boolean doAnimation) {
1345 return showLw(doAnimation, true);
1346 }
1347
1348 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001349 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001350 return false;
1351 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001352 if (!mAppOpVisibility) {
1353 // Being hidden due to app op request.
1354 return false;
1355 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001356 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001357 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001358 return false;
1359 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001360 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001361 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001362 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001363 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001364 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001365 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001366 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001367 // Check for the case where we are currently visible and
1368 // not animating; we do not want to do animation at such a
1369 // point to become visible when we already are.
1370 doAnimation = false;
1371 }
1372 }
1373 mPolicyVisibility = true;
1374 mPolicyVisibilityAfterAnim = true;
1375 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001376 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001377 }
1378 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001379 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001380 }
1381 return true;
1382 }
1383
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001384 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001385 public boolean hideLw(boolean doAnimation) {
1386 return hideLw(doAnimation, true);
1387 }
1388
1389 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1390 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001391 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001392 doAnimation = false;
1393 }
1394 }
1395 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1396 : mPolicyVisibility;
1397 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001398 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001399 return false;
1400 }
1401 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001402 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001403 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001404 doAnimation = false;
1405 }
1406 }
1407 if (doAnimation) {
1408 mPolicyVisibilityAfterAnim = false;
1409 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001410 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001411 mPolicyVisibilityAfterAnim = false;
1412 mPolicyVisibility = false;
1413 // Window is no longer visible -- make sure if we were waiting
1414 // for it to be displayed before enabling the display, that
1415 // we allow the display to be enabled now.
1416 mService.enableScreenIfNeededLocked();
1417 if (mService.mCurrentFocus == this) {
Craig Mautner58458122013-09-14 14:59:50 -07001418 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1419 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001420 mService.mFocusMayChange = true;
1421 }
1422 }
1423 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001424 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001425 }
1426 return true;
1427 }
1428
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001429 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001430 if (mAppOpVisibility != state) {
1431 mAppOpVisibility = state;
1432 if (state) {
1433 // If the policy visibility had last been to hide, then this
1434 // will incorrectly show at this point since we lost that
1435 // information. Not a big deal -- for the windows that have app
1436 // ops modifies they should only be hidden by policy due to the
1437 // lock screen, and the user won't be changing this if locked.
1438 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001439 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001440 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001441 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001442 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001443 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001444 }
1445
Jeff Brownc2932a12014-11-20 18:04:05 -08001446 public void pokeDrawLockLw(long timeout) {
1447 if (isVisibleOrAdding()) {
1448 if (mDrawLock == null) {
1449 // We want the tag name to be somewhat stable so that it is easier to correlate
1450 // in wake lock statistics. So in particular, we don't want to include the
1451 // window's hash code as in toString().
1452 CharSequence tag = mAttrs.getTitle();
1453 if (tag == null) {
1454 tag = mAttrs.packageName;
1455 }
1456 mDrawLock = mService.mPowerManager.newWakeLock(
1457 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1458 mDrawLock.setReferenceCounted(false);
1459 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1460 }
1461 // Each call to acquire resets the timeout.
1462 if (DEBUG_POWER) {
1463 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1464 + mAttrs.packageName);
1465 }
1466 mDrawLock.acquire(timeout);
1467 } else if (DEBUG_POWER) {
1468 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1469 + "owned by " + mAttrs.packageName);
1470 }
1471 }
1472
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001473 @Override
1474 public boolean isAlive() {
1475 return mClient.asBinder().isBinderAlive();
1476 }
1477
Craig Mautnera987d432012-10-11 14:07:58 -07001478 boolean isClosing() {
1479 return mExiting || (mService.mClosingApps.contains(mAppToken));
1480 }
1481
Craig Mautner69b08182012-09-05 13:07:13 -07001482 @Override
1483 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001484 final DisplayContent displayContent = getDisplayContent();
1485 if (displayContent == null) {
1486 // Only a window that was on a non-default display can be detached from it.
1487 return false;
1488 }
Winson Chung47a3e652014-05-21 16:03:42 -07001489 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001490 }
1491
Adrian Rooscd3884d2015-02-18 17:25:23 +01001492 @Override
1493 public boolean isDimming() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001494 Task task = getTask();
1495 if (task == null) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01001496 return false;
1497 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001498 return task.isDimming(mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001499 }
1500
Craig Mautner88400d32012-09-30 12:35:45 -07001501 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1502 mShowToOwnerOnly = showToOwnerOnly;
1503 }
1504
Craig Mautner5962b122012-10-05 14:45:52 -07001505 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001506 // Attached windows are evaluated based on the window that they are attached to.
1507 WindowState win = this;
1508 while (win.mAttachedWindow != null) {
1509 win = win.mAttachedWindow;
1510 }
1511 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001512 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001513 // Save some cycles by not calling getDisplayInfo unless it is an application
1514 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001515 final DisplayContent displayContent = win.getDisplayContent();
1516 if (displayContent == null) {
1517 return true;
1518 }
1519 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001520 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1521 && win.mFrame.right >= displayInfo.appWidth
1522 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001523 // Is a fullscreen window, like the clock alarm. Show to everyone.
1524 return false;
1525 }
1526 }
1527
Craig Mautner341220f2012-10-16 15:20:09 -07001528 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001529 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001530 }
1531
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001532 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1533 outRegion.set(
1534 frame.left + inset.left, frame.top + inset.top,
1535 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001536 }
1537
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001538 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001539 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001540 switch (mTouchableInsets) {
1541 default:
1542 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1543 outRegion.set(frame);
1544 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001545 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001546 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001547 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001548 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001549 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001550 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001551 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1552 final Region givenTouchableRegion = mGivenTouchableRegion;
1553 outRegion.set(givenTouchableRegion);
1554 outRegion.translate(frame.left, frame.top);
1555 break;
1556 }
1557 }
1558 }
1559
Craig Mautner59c00972012-07-30 12:10:24 -07001560 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001561 final DisplayContent displayContent = getDisplayContent();
1562 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001563 }
1564
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001565 /**
1566 * Report a focus change. Must be called with no locks held, and consistently
1567 * from the same serialized thread (such as dispatched from a handler).
1568 */
1569 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1570 try {
1571 mClient.windowFocusChanged(focused, inTouchMode);
1572 } catch (RemoteException e) {
1573 }
1574 if (mFocusCallbacks != null) {
1575 final int N = mFocusCallbacks.beginBroadcast();
1576 for (int i=0; i<N; i++) {
1577 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1578 try {
1579 if (focused) {
1580 obs.focusGained(mWindowId.asBinder());
1581 } else {
1582 obs.focusLost(mWindowId.asBinder());
1583 }
1584 } catch (RemoteException e) {
1585 }
1586 }
1587 mFocusCallbacks.finishBroadcast();
1588 }
1589 }
1590
Craig Mautnerdf88d732014-01-27 09:21:32 -08001591 void reportResized() {
1592 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001593 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1594 + ": " + mCompatFrame);
1595 boolean configChanged = isConfigChanged();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001596 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001597 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001598 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001599 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1600 Slog.i(TAG, "Sending new config to window " + this + ": "
Wale Ogunwale60454db2015-01-23 16:05:07 -08001601 + mWinAnimator.mSurfaceW + "x" + mWinAnimator.mSurfaceH + " / config="
1602 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001603 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001604 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001605 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1606 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1607
Craig Mautnerdf88d732014-01-27 09:21:32 -08001608 final Rect frame = mFrame;
1609 final Rect overscanInsets = mLastOverscanInsets;
1610 final Rect contentInsets = mLastContentInsets;
1611 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001612 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001613 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001614 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1615 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07001616 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1617 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001618 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1619 mService.mH.post(new Runnable() {
1620 @Override
1621 public void run() {
1622 try {
1623 mClient.resized(frame, overscanInsets, contentInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001624 visibleInsets, stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001625 } catch (RemoteException e) {
1626 // Not a remote call, RemoteException won't be raised.
1627 }
1628 }
1629 });
1630 } else {
Adrian Roosfa104232014-06-20 16:10:14 -07001631 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001632 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001633 }
Svetoslav4604abc2014-06-10 18:59:30 -07001634
1635 //TODO (multidisplay): Accessibility supported only for the default display.
1636 if (mService.mAccessibilityController != null
1637 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07001638 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07001639 }
1640
Craig Mautnerdf88d732014-01-27 09:21:32 -08001641 mOverscanInsetsChanged = false;
1642 mContentInsetsChanged = false;
1643 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07001644 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001645 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001646 mWinAnimator.mSurfaceResized = false;
1647 } catch (RemoteException e) {
1648 mOrientationChanging = false;
1649 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1650 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08001651 // We are assuming the hosting process is dead or in a zombie state.
1652 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
1653 + ", removing this window.");
1654 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001655 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001656 }
1657 }
1658
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001659 public void registerFocusObserver(IWindowFocusObserver observer) {
1660 synchronized(mService.mWindowMap) {
1661 if (mFocusCallbacks == null) {
1662 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1663 }
1664 mFocusCallbacks.register(observer);
1665 }
1666 }
1667
1668 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1669 synchronized(mService.mWindowMap) {
1670 if (mFocusCallbacks != null) {
1671 mFocusCallbacks.unregister(observer);
1672 }
1673 }
1674 }
1675
1676 public boolean isFocused() {
1677 synchronized(mService.mWindowMap) {
1678 return mService.mCurrentFocus == this;
1679 }
1680 }
1681
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07001682 boolean inFreeformWorkspace() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001683 final Task task = mAppToken != null ? getTask() : null;
1684 return task != null && task.inFreeformWorkspace();
1685 }
1686
1687 boolean isDragResizing() {
1688 final Task task = mAppToken != null ? getTask() : null;
1689 return mService.mTaskPositioner != null && mService.mTaskPositioner.isTaskResizing(task);
Skuhnef932e562015-08-20 12:07:30 -07001690 }
1691
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001692 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001693 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001694 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001695 if (stack != null) {
1696 pw.print(" stackId="); pw.print(stack.mStackId);
1697 }
Craig Mautner59c00972012-07-30 12:10:24 -07001698 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001699 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001700 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001701 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1702 pw.print(" package="); pw.print(mAttrs.packageName);
1703 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001704 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001705 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1706 pw.print(" h="); pw.print(mRequestedHeight);
1707 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001708 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1709 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1710 pw.print(" h="); pw.println(mLastRequestedHeight);
1711 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001712 if (mAttachedWindow != null || mLayoutAttached) {
1713 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1714 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1715 }
1716 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1717 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1718 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1719 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1720 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1721 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001722 if (dumpAll) {
1723 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1724 pw.print(" mSubLayer="); pw.print(mSubLayer);
1725 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001726 pw.print((mTargetAppToken != null ?
1727 mTargetAppToken.mAppAnimator.animLayerAdjustment
1728 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001729 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1730 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001731 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001732 if (dumpAll) {
1733 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1734 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1735 if (mAppToken != null) {
1736 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1737 }
1738 if (mTargetAppToken != null) {
1739 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1740 }
1741 pw.print(prefix); pw.print("mViewVisibility=0x");
1742 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001743 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1744 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001745 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1746 pw.print(" mSystemUiVisibility=0x");
1747 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001748 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001749 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1750 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001751 pw.print(prefix); pw.print("mPolicyVisibility=");
1752 pw.print(mPolicyVisibility);
1753 pw.print(" mPolicyVisibilityAfterAnim=");
1754 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001755 pw.print(" mAppOpVisibility=");
1756 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001757 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1758 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001759 if (!mRelayoutCalled || mLayoutNeeded) {
1760 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1761 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001762 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001763 if (mXOffset != 0 || mYOffset != 0) {
1764 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1765 pw.print(" y="); pw.println(mYOffset);
1766 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001767 if (dumpAll) {
1768 pw.print(prefix); pw.print("mGivenContentInsets=");
1769 mGivenContentInsets.printShortString(pw);
1770 pw.print(" mGivenVisibleInsets=");
1771 mGivenVisibleInsets.printShortString(pw);
1772 pw.println();
1773 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1774 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1775 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001776 Region region = new Region();
1777 getTouchableRegion(region);
1778 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001779 }
1780 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08001781 if (mOverrideConfig != Configuration.EMPTY) {
1782 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
1783 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001784 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001785 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001786 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1787 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001788 if (dumpAll) {
1789 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1790 pw.print(" last="); mLastFrame.printShortString(pw);
1791 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001792 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1793 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
Craig Mautner80b1f642015-04-22 10:59:09 -07001794 if (mWinAnimator.mHasClipRect) {
1795 pw.print(" mLastClipRect=");
1796 mWinAnimator.mLastClipRect.printShortString(pw);
1797 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001798 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001799 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001800 if (mEnforceSizeCompat) {
1801 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001802 pw.println();
1803 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001804 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001805 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001806 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001807 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001808 pw.println();
1809 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1810 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001811 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001812 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001813 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001814 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04001815 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
1816 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001817 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
1818 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001819 pw.print(prefix); pw.print("Cur insets: overscan=");
1820 mOverscanInsets.printShortString(pw);
1821 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001822 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07001823 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001824 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001825 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001826 pw.print(prefix); pw.print("Lst insets: overscan=");
1827 mLastOverscanInsets.printShortString(pw);
1828 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001829 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07001830 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001831 pw.print(" physical="); mLastOutsets.printShortString(pw);
1832 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001833 pw.println();
1834 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001835 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1836 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001837 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1838 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1839 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1840 pw.print(" mDestroying="); pw.print(mDestroying);
1841 pw.print(" mRemoved="); pw.println(mRemoved);
1842 }
1843 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1844 pw.print(prefix); pw.print("mOrientationChanging=");
1845 pw.print(mOrientationChanging);
1846 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1847 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1848 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07001849 if (mLastFreezeDuration != 0) {
1850 pw.print(prefix); pw.print("mLastFreezeDuration=");
1851 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
1852 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001853 if (mHScale != 1 || mVScale != 1) {
1854 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1855 pw.print(" mVScale="); pw.println(mVScale);
1856 }
1857 if (mWallpaperX != -1 || mWallpaperY != -1) {
1858 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1859 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1860 }
1861 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1862 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1863 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1864 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07001865 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
1866 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
1867 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
1868 pw.print(mWallpaperDisplayOffsetX);
1869 pw.print(" mWallpaperDisplayOffsetY=");
1870 pw.println(mWallpaperDisplayOffsetY);
1871 }
Jeff Brownc2932a12014-11-20 18:04:05 -08001872 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07001873 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08001874 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001875 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001876
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001877 String makeInputChannelName() {
1878 return Integer.toHexString(System.identityHashCode(this))
1879 + " " + mAttrs.getTitle();
1880 }
1881
1882 @Override
1883 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001884 CharSequence title = mAttrs.getTitle();
1885 if (title == null || title.length() <= 0) {
1886 title = mAttrs.packageName;
1887 }
1888 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1889 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001890 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001891 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001892 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001893 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001894 }
1895 return mStringNameCache;
1896 }
satokcef37fb2011-10-24 21:49:38 +09001897}