blob: a8e45c4e3323af1affddc5f1c998c4b3ee9ea8c3 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Craig Mautnerd1c2c542014-02-06 10:31:41 -080019import static com.android.server.wm.WindowManagerService.DEBUG_CONFIGURATION;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -070020import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080021import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
22import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
23import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -070024
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080025import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Adam Lesinski6a591f52013-10-01 18:11:17 -070026import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080027import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Dianne Hackborn1c5383c2013-04-15 15:07:21 -070028import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080029import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
30import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Craig Mautnere8552142012-11-07 13:55:47 -080031import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080032import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
33
Dianne Hackbornc2293022013-02-06 23:14:49 -080034import android.app.AppOpsManager;
Craig Mautnerdf88d732014-01-27 09:21:32 -080035import android.os.Debug;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080036import android.os.RemoteCallbackList;
Craig Mautnerdf88d732014-01-27 09:21:32 -080037import android.os.SystemClock;
Dianne Hackborna57c6952013-03-29 14:46:40 -070038import android.util.TimeUtils;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080039import android.view.IWindowFocusObserver;
40import android.view.IWindowId;
Jeff Brown4532e612012-04-05 14:27:12 -070041import com.android.server.input.InputWindowHandle;
42
Craig Mautnere7ae2502012-03-26 17:11:19 -070043import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080044import android.content.res.Configuration;
45import android.graphics.Matrix;
46import android.graphics.PixelFormat;
47import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070048import android.graphics.RectF;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049import android.graphics.Region;
50import android.os.IBinder;
51import android.os.RemoteException;
Craig Mautner9dc52bc2012-08-06 14:15:42 -070052import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080053import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070054import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055import android.view.Gravity;
56import android.view.IApplicationToken;
57import android.view.IWindow;
58import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059import android.view.View;
60import android.view.ViewTreeObserver;
61import android.view.WindowManager;
62import android.view.WindowManagerPolicy;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063
64import java.io.PrintWriter;
65import java.util.ArrayList;
66
Craig Mautner59c00972012-07-30 12:10:24 -070067class WindowList extends ArrayList<WindowState> {
68}
69
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080070/**
71 * A window in the window manager.
72 */
Craig Mautnere32c3072012-03-12 15:25:35 -070073final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070074 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -080075
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -070077 final WindowManagerPolicy mPolicy;
78 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080079 final Session mSession;
80 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -080081 final int mAppOp;
82 // UserId and appId of the owner. Don't display windows of non-current user.
83 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080084 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080085 WindowToken mToken;
86 WindowToken mRootToken;
87 AppWindowToken mAppToken;
88 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070089
90 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
91 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
93 final DeathRecipient mDeathRecipient;
94 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -080095 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 final int mBaseLayer;
97 final int mSubLayer;
98 final boolean mLayoutAttached;
99 final boolean mIsImWindow;
100 final boolean mIsWallpaper;
101 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700102 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700103 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800104 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700105 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 boolean mPolicyVisibility = true;
107 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800108 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700112
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800113 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
114
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700115 /**
116 * The window size that was requested by the application. These are in
117 * the application's coordinate space (without compatibility scale applied).
118 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800119 int mRequestedWidth;
120 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700121 int mLastRequestedWidth;
122 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700123
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800124 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 boolean mHaveFrame;
126 boolean mObscured;
127 boolean mTurnOnScreen;
128
129 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700130
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800131 Configuration mConfiguration = null;
Craig Mautnere8552142012-11-07 13:55:47 -0800132 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
133 // Used only on {@link #TYPE_KEYGUARD}.
134 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700135
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700136 /**
137 * Actual frame shown on-screen (may be modified by animation). These
138 * are in the screen's coordinate space (WITH the compatibility scale
139 * applied).
140 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700141 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142
143 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700144 * Insets that determine the actually visible area. These are in the application's
145 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800146 */
147 final Rect mVisibleInsets = new Rect();
148 final Rect mLastVisibleInsets = new Rect();
149 boolean mVisibleInsetsChanged;
150
151 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700152 * Insets that are covered by system windows (such as the status bar) and
153 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700154 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 */
156 final Rect mContentInsets = new Rect();
157 final Rect mLastContentInsets = new Rect();
158 boolean mContentInsetsChanged;
159
160 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800161 * Insets that determine the area covered by the display overscan region. These are in the
162 * application's coordinate space (without compatibility scale applied).
163 */
164 final Rect mOverscanInsets = new Rect();
165 final Rect mLastOverscanInsets = new Rect();
166 boolean mOverscanInsetsChanged;
167
168 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169 * Set to true if we are waiting for this window to receive its
170 * given internal insets before laying out other windows based on it.
171 */
172 boolean mGivenInsetsPending;
173
174 /**
175 * These are the content insets that were given during layout for
176 * this window, to be applied to windows behind it.
177 */
178 final Rect mGivenContentInsets = new Rect();
179
180 /**
181 * These are the visible insets that were given during layout for
182 * this window, to be applied to windows behind it.
183 */
184 final Rect mGivenVisibleInsets = new Rect();
185
186 /**
187 * This is the given touchable area relative to the window frame, or null if none.
188 */
189 final Region mGivenTouchableRegion = new Region();
190
191 /**
192 * Flag indicating whether the touchable region should be adjusted by
193 * the visible insets; if false the area outside the visible insets is
194 * NOT touchable, so we must use those to adjust the frame during hit
195 * tests.
196 */
197 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
198
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700199 /**
200 * This is rectangle of the window's surface that is not covered by
201 * system decorations.
202 */
203 final Rect mSystemDecorRect = new Rect();
204 final Rect mLastSystemDecorRect = new Rect();
205
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400207 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700208 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209 float mHScale=1, mVScale=1;
210 float mLastHScale=1, mLastVScale=1;
211 final Matrix mTmpMatrix = new Matrix();
212
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700213 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800214 final Rect mFrame = new Rect();
215 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700216 // Frame that is scaled to the application's coordinate space when in
217 // screen size compatibility mode.
218 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800219
220 final Rect mContainingFrame = new Rect();
221 final Rect mDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800222 final Rect mOverscanFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 final Rect mContentFrame = new Rect();
224 final Rect mParentFrame = new Rect();
225 final Rect mVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400226 final Rect mDecorFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800227
228 boolean mContentChanged;
229
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 // If a window showing a wallpaper: the requested offset for the
231 // wallpaper; if a wallpaper window: the currently applied offset.
232 float mWallpaperX = -1;
233 float mWallpaperY = -1;
234
235 // If a window showing a wallpaper: what fraction of the offset
236 // range corresponds to a full virtual screen.
237 float mWallpaperXStep = -1;
238 float mWallpaperYStep = -1;
239
240 // Wallpaper windows: pixels offset based on above variables.
241 int mXOffset;
242 int mYOffset;
243
Craig Mautner2268e7e2012-12-13 15:40:00 -0800244 /**
245 * This is set after IWindowSession.relayout() has been called at
246 * least once for the window. It allows us to detect the situation
247 * where we don't yet have a surface, but should have one soon, so
248 * we can give the window focus before waiting for the relayout.
249 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800250 boolean mRelayoutCalled;
251
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800252 /**
253 * If the application has called relayout() with changes that can
254 * impact its window's size, we need to perform a layout pass on it
255 * even if it is not currently visible for layout. This is set
256 * when in that case until the layout is done.
257 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800258 boolean mLayoutNeeded;
259
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800260 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 boolean mExiting;
262
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800263 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264 boolean mDestroying;
265
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800266 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267 boolean mRemoveOnExit;
268
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800269 /**
270 * Set when the orientation is changing and this window has not yet
271 * been updated for the new orientation.
272 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800273 boolean mOrientationChanging;
274
Dianne Hackborna57c6952013-03-29 14:46:40 -0700275 /**
276 * How long we last kept the screen frozen.
277 */
278 int mLastFreezeDuration;
279
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800280 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 boolean mRemoved;
282
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800283 /**
284 * Temp for keeping track of windows that have been removed when
285 * rebuilding window list.
286 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 boolean mRebuilding;
288
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700290 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800292
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293 // Used to improve performance of toString()
294 String mStringNameCache;
295 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700296 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297
Craig Mautnera2c77052012-03-26 12:14:43 -0700298 final WindowStateAnimator mWinAnimator;
299
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700300 boolean mHasSurface = false;
301
Craig Mautner59c00972012-07-30 12:10:24 -0700302 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700303
Craig Mautner88400d32012-09-30 12:35:45 -0700304 /** When true this window can be displayed on screens owther than mOwnerUid's */
305 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700306
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700307 /** When true this window is at the top of the screen and should be layed out to extend under
308 * the status bar */
309 boolean mUnderStatusBar = true;
310
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800311 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800312 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700313 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800314 mService = service;
315 mSession = s;
316 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800317 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700319 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800320 mWindowId = new IWindowId.Stub() {
321 @Override
322 public void registerFocusObserver(IWindowFocusObserver observer) {
323 WindowState.this.registerFocusObserver(observer);
324 }
325 @Override
326 public void unregisterFocusObserver(IWindowFocusObserver observer) {
327 WindowState.this.unregisterFocusObserver(observer);
328 }
329 @Override
330 public boolean isFocused() {
331 return WindowState.this.isFocused();
332 }
333 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 mAttrs.copyFrom(a);
335 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700336 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700337 mPolicy = mService.mPolicy;
338 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700340 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700341 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800342 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700343 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700344 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345 try {
346 c.asBinder().linkToDeath(deathRecipient, 0);
347 } catch (RemoteException e) {
348 mDeathRecipient = null;
349 mAttachedWindow = null;
350 mLayoutAttached = false;
351 mIsImWindow = false;
352 mIsWallpaper = false;
353 mIsFloatingLayer = false;
354 mBaseLayer = 0;
355 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700356 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700357 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 return;
359 }
360 mDeathRecipient = deathRecipient;
361
362 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
363 mAttrs.type <= LAST_SUB_WINDOW)) {
364 // The multiplier here is to reserve space for multiple
365 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700366 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
368 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700369 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800370 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700371 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900372
373 int children_size = mAttachedWindow.mChildWindows.size();
374 if (children_size == 0) {
375 mAttachedWindow.mChildWindows.add(this);
376 } else {
377 for (int i = 0; i < children_size; i++) {
378 WindowState child = (WindowState)mAttachedWindow.mChildWindows.get(i);
379 if (this.mSubLayer < child.mSubLayer) {
380 mAttachedWindow.mChildWindows.add(i, this);
381 break;
382 } else if (this.mSubLayer > child.mSubLayer) {
383 continue;
384 }
385
386 if (this.mBaseLayer <= child.mBaseLayer) {
387 mAttachedWindow.mChildWindows.add(i, this);
388 break;
389 } else {
390 continue;
391 }
392 }
393 if (children_size == mAttachedWindow.mChildWindows.size()) {
394 mAttachedWindow.mChildWindows.add(this);
395 }
396 }
397
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800398 mLayoutAttached = mAttrs.type !=
399 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
400 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
401 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
402 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
403 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
404 } else {
405 // The multiplier here is to reserve space for multiple
406 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700407 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408 * WindowManagerService.TYPE_LAYER_MULTIPLIER
409 + WindowManagerService.TYPE_LAYER_OFFSET;
410 mSubLayer = 0;
411 mAttachedWindow = null;
412 mLayoutAttached = false;
413 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
414 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
415 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
416 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
417 }
418
419 WindowState appWin = this;
420 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700421 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800422 }
423 WindowToken appToken = appWin.mToken;
424 while (appToken.appWindowToken == null) {
425 WindowToken parent = mService.mTokenMap.get(appToken.token);
426 if (parent == null || appToken == parent) {
427 break;
428 }
429 appToken = parent;
430 }
431 mRootToken = appToken;
432 mAppToken = appToken.appWindowToken;
433
Craig Mautner322e4032012-07-13 13:35:20 -0700434 mWinAnimator = new WindowStateAnimator(this);
435 mWinAnimator.mAlpha = a.alpha;
436
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800437 mRequestedWidth = 0;
438 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700439 mLastRequestedWidth = 0;
440 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800441 mXOffset = 0;
442 mYOffset = 0;
443 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800444 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700445 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
446 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800447 }
448
449 void attach() {
450 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700451 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800452 + ", list=" + mToken.windows);
453 mSession.windowAddedLocked();
454 }
455
Craig Mautnera2c77052012-03-26 12:14:43 -0700456 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800457 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800458 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800459 }
460
461 @Override
462 public String getOwningPackage() {
463 return mAttrs.packageName;
464 }
465
466 @Override
John Spurlock46646232013-09-30 22:32:42 -0400467 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800468 mHaveFrame = true;
469
John Spurlock7045aaa2013-07-16 17:38:54 -0400470 TaskStack stack = mAppToken != null ? getStack() : null;
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800471 if (stack != null && !stack.isFullscreen()) {
472 getStackBounds(stack, mContainingFrame);
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700473 if (mUnderStatusBar) {
474 mContainingFrame.top = pf.top;
475 }
Craig Mautner967212c2013-04-13 21:10:58 -0700476 } else {
477 mContainingFrame.set(pf);
478 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800479
Craig Mautnereda67292013-04-28 13:50:14 -0700480 mDisplayFrame.set(df);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800481
Craig Mautner967212c2013-04-13 21:10:58 -0700482 final int pw = mContainingFrame.width();
483 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800484
485 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700486 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
487 if (mAttrs.width < 0) {
488 w = pw;
489 } else if (mEnforceSizeCompat) {
490 w = (int)(mAttrs.width * mGlobalScale + .5f);
491 } else {
492 w = mAttrs.width;
493 }
494 if (mAttrs.height < 0) {
495 h = ph;
496 } else if (mEnforceSizeCompat) {
497 h = (int)(mAttrs.height * mGlobalScale + .5f);
498 } else {
499 h = mAttrs.height;
500 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800501 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700502 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
503 w = pw;
504 } else if (mEnforceSizeCompat) {
505 w = (int)(mRequestedWidth * mGlobalScale + .5f);
506 } else {
507 w = mRequestedWidth;
508 }
509 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
510 h = ph;
511 } else if (mEnforceSizeCompat) {
512 h = (int)(mRequestedHeight * mGlobalScale + .5f);
513 } else {
514 h = mRequestedHeight;
515 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800516 }
517
518 if (!mParentFrame.equals(pf)) {
519 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
520 // + " to " + pf);
521 mParentFrame.set(pf);
522 mContentChanged = true;
523 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700524 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
525 mLastRequestedWidth = mRequestedWidth;
526 mLastRequestedHeight = mRequestedHeight;
527 mContentChanged = true;
528 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800529
Craig Mautnereda67292013-04-28 13:50:14 -0700530 mOverscanFrame.set(of);
531 mContentFrame.set(cf);
532 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400533 mDecorFrame.set(dcf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800534
Craig Mautnereda67292013-04-28 13:50:14 -0700535 final int fw = mFrame.width();
536 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800537
538 //System.out.println("In: w=" + w + " h=" + h + " container=" +
539 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
540
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700541 float x, y;
542 if (mEnforceSizeCompat) {
543 x = mAttrs.x * mGlobalScale;
544 y = mAttrs.y * mGlobalScale;
545 } else {
546 x = mAttrs.x;
547 y = mAttrs.y;
548 }
549
Craig Mautner967212c2013-04-13 21:10:58 -0700550 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700551 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700552 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800553
554 //System.out.println("Out: " + mFrame);
555
556 // Now make sure the window fits in the overall display.
Craig Mautnereda67292013-04-28 13:50:14 -0700557 Gravity.applyDisplay(mAttrs.gravity, df, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800558
Craig Mautnera248eee2013-05-07 11:41:27 -0700559 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800560 // final window frame.
Craig Mautnereda67292013-04-28 13:50:14 -0700561 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
562 Math.max(mContentFrame.top, mFrame.top),
563 Math.min(mContentFrame.right, mFrame.right),
564 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800565
Craig Mautnereda67292013-04-28 13:50:14 -0700566 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
567 Math.max(mVisibleFrame.top, mFrame.top),
568 Math.min(mVisibleFrame.right, mFrame.right),
569 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800570
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700571 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
572 Math.max(mOverscanFrame.top - mFrame.top, 0),
573 Math.max(mFrame.right - mOverscanFrame.right, 0),
574 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800575
Craig Mautnereda67292013-04-28 13:50:14 -0700576 mContentInsets.set(mContentFrame.left - mFrame.left,
577 mContentFrame.top - mFrame.top,
578 mFrame.right - mContentFrame.right,
579 mFrame.bottom - mContentFrame.bottom);
580
581 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
582 mVisibleFrame.top - mFrame.top,
583 mFrame.right - mVisibleFrame.right,
584 mFrame.bottom - mVisibleFrame.bottom);
585
586 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400587 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700588 // If there is a size compatibility scale being applied to the
589 // window, we need to apply this to its insets so that they are
590 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700591 mOverscanInsets.scale(mInvGlobalScale);
592 mContentInsets.scale(mInvGlobalScale);
593 mVisibleInsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700594
595 // Also the scaled frame that we report to the app needs to be
596 // adjusted to be in its coordinate space.
597 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400598 }
599
Craig Mautnereda67292013-04-28 13:50:14 -0700600 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800601 final DisplayContent displayContent = getDisplayContent();
602 if (displayContent != null) {
603 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
604 mService.updateWallpaperOffsetLocked(this,
605 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
606 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800607 }
608
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700609 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
610 "Resolving (mRequestedWidth="
611 + mRequestedWidth + ", mRequestedheight="
612 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
613 + "): frame=" + mFrame.toShortString()
614 + " ci=" + mContentInsets.toShortString()
615 + " vi=" + mVisibleInsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800616 }
617
Craig Mautnera2c77052012-03-26 12:14:43 -0700618 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800619 public Rect getFrameLw() {
620 return mFrame;
621 }
622
Craig Mautnera2c77052012-03-26 12:14:43 -0700623 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700624 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800625 return mShownFrame;
626 }
627
Craig Mautnera2c77052012-03-26 12:14:43 -0700628 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800629 public Rect getDisplayFrameLw() {
630 return mDisplayFrame;
631 }
632
Craig Mautnera2c77052012-03-26 12:14:43 -0700633 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800634 public Rect getOverscanFrameLw() {
635 return mOverscanFrame;
636 }
637
638 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800639 public Rect getContentFrameLw() {
640 return mContentFrame;
641 }
642
Craig Mautnera2c77052012-03-26 12:14:43 -0700643 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800644 public Rect getVisibleFrameLw() {
645 return mVisibleFrame;
646 }
647
Craig Mautnera2c77052012-03-26 12:14:43 -0700648 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800649 public boolean getGivenInsetsPendingLw() {
650 return mGivenInsetsPending;
651 }
652
Craig Mautnera2c77052012-03-26 12:14:43 -0700653 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800654 public Rect getGivenContentInsetsLw() {
655 return mGivenContentInsets;
656 }
657
Craig Mautnera2c77052012-03-26 12:14:43 -0700658 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800659 public Rect getGivenVisibleInsetsLw() {
660 return mGivenVisibleInsets;
661 }
662
Craig Mautnera2c77052012-03-26 12:14:43 -0700663 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664 public WindowManager.LayoutParams getAttrs() {
665 return mAttrs;
666 }
667
Craig Mautner812d2ca2012-09-27 15:35:34 -0700668 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800669 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
670 int index = -1;
671 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700672 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800673 while (true) {
674 if ((ws.mAttrs.privateFlags
675 & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
676 return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
677 }
678 // If we reached the bottom of the range of windows we are considering,
679 // assume no menu is needed.
680 if (ws == bottom) {
681 return false;
682 }
683 // The current window hasn't specified whether menu key is needed;
684 // look behind it.
685 // First, we may need to determine the starting position.
686 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700687 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800688 }
689 index--;
690 if (index < 0) {
691 return false;
692 }
Craig Mautner59c00972012-07-30 12:10:24 -0700693 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800694 }
695 }
696
Craig Mautner19d59bc2012-09-04 11:15:56 -0700697 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700698 public int getSystemUiVisibility() {
699 return mSystemUiVisibility;
700 }
701
Craig Mautner19d59bc2012-09-04 11:15:56 -0700702 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800703 public int getSurfaceLayer() {
704 return mLayer;
705 }
706
Craig Mautner812d2ca2012-09-27 15:35:34 -0700707 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800708 public IApplicationToken getAppToken() {
709 return mAppToken != null ? mAppToken.appToken : null;
710 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700711
Craig Mautner4c5eb222013-11-18 12:59:05 -0800712 boolean setInsetsChanged() {
713 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
714 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
715 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
716 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged;
717 }
718
Craig Mautnerdf88d732014-01-27 09:21:32 -0800719 public DisplayContent getDisplayContent() {
720 return mAppToken == null ? mDisplayContent : getStack().getDisplayContent();
721 }
722
Craig Mautner19d59bc2012-09-04 11:15:56 -0700723 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800724 final DisplayContent displayContent = getDisplayContent();
725 if (displayContent == null) {
726 return -1;
727 }
728 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700729 }
730
Craig Mautnerd9a22882013-03-16 15:00:36 -0700731 TaskStack getStack() {
Craig Mautner05d29032013-05-03 13:40:13 -0700732 AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken;
733 if (wtoken != null) {
734 Task task = mService.mTaskIdToTask.get(wtoken.groupId);
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700735 if (task != null) {
Craig Mautnere0a38842013-12-16 16:14:02 -0800736 if (task.mStack != null) {
737 return task.mStack;
738 }
739 Slog.e(TAG, "getStack: mStack null for task=" + task);
740 } else {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800741 Slog.e(TAG, "getStack: " + this + " couldn't find taskId=" + wtoken.groupId
742 + " Callers=" + Debug.getCallers(4));
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700743 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700744 }
Craig Mautner05d29032013-05-03 13:40:13 -0700745 return mDisplayContent.getHomeStack();
Craig Mautnerd9a22882013-03-16 15:00:36 -0700746 }
747
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800748 void getStackBounds(Rect bounds) {
749 getStackBounds(getStack(), bounds);
John Spurlock7045aaa2013-07-16 17:38:54 -0400750 }
751
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800752 private void getStackBounds(TaskStack stack, Rect bounds) {
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700753 if (stack != null) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800754 stack.getBounds(bounds);
755 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700756 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800757 bounds.set(mFrame);
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700758 }
759
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800760 public long getInputDispatchingTimeoutNanos() {
761 return mAppToken != null
762 ? mAppToken.inputDispatchingTimeoutNanos
763 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
764 }
765
Craig Mautnere8552142012-11-07 13:55:47 -0800766 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800767 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700768 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800769 }
770
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800771 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
772 if (dsdx < .99999f || dsdx > 1.00001f) return false;
773 if (dtdy < .99999f || dtdy > 1.00001f) return false;
774 if (dtdx < -.000001f || dtdx > .000001f) return false;
775 if (dsdy < -.000001f || dsdy > .000001f) return false;
776 return true;
777 }
778
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400779 void prelayout() {
780 if (mEnforceSizeCompat) {
781 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700782 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400783 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700784 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400785 }
786 }
787
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800788 /**
789 * Is this window visible? It is not visible if there is no
790 * surface, or we are in the process of running an exit animation
791 * that will remove the surface, or its app token has been hidden.
792 */
Craig Mautner88400d32012-09-30 12:35:45 -0700793 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800794 public boolean isVisibleLw() {
795 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700796 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800797 && (atoken == null || !atoken.hiddenRequested)
798 && !mExiting && !mDestroying;
799 }
800
801 /**
802 * Like {@link #isVisibleLw}, but also counts a window that is currently
803 * "hidden" behind the keyguard as visible. This allows us to apply
804 * things like window flags that impact the keyguard.
805 * XXX I am starting to think we need to have ANOTHER visibility flag
806 * for this "hidden behind keyguard" state rather than overloading
807 * mPolicyVisibility. Ungh.
808 */
Craig Mautner88400d32012-09-30 12:35:45 -0700809 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800810 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700811 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800812 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700813 return false;
814 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800815 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700816 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -0700817 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700818 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800819 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700820 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
821 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700822 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800823 }
824
825 /**
826 * Is this window visible, ignoring its app token? It is not visible
827 * if there is no surface, or we are in the process of running an exit animation
828 * that will remove the surface.
829 */
830 public boolean isWinVisibleLw() {
831 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700832 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -0700833 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800834 && !mExiting && !mDestroying;
835 }
836
837 /**
838 * The same as isVisible(), but follows the current hidden state of
839 * the associated app token, not the pending requested hidden state.
840 */
841 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700842 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800843 && !mRootToken.hidden && !mExiting && !mDestroying;
844 }
845
846 /**
847 * Can this window possibly be a drag/drop target? The test here is
848 * a combination of the above "visible now" with the check that the
849 * Input Manager uses when discarding windows from input consideration.
850 */
851 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700852 return isVisibleNow() && !mRemoved
853 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800854 }
855
856 /**
857 * Same as isVisible(), but we also count it as visible between the
858 * call to IWindowSession.add() and the first relayout().
859 */
860 boolean isVisibleOrAdding() {
861 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700862 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800863 && mPolicyVisibility && !mAttachedHidden
864 && (atoken == null || !atoken.hiddenRequested)
865 && !mExiting && !mDestroying;
866 }
867
868 /**
869 * Is this window currently on-screen? It is on-screen either if it
870 * is visible or it is currently running an animation before no longer
871 * being visible.
872 */
873 boolean isOnScreen() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700874 if (!mHasSurface || !mPolicyVisibility || mDestroying) {
875 return false;
876 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800877 final AppWindowToken atoken = mAppToken;
878 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700879 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800880 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800881 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700882 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800883 }
884
885 /**
886 * Like isOnScreen(), but we don't return true if the window is part
887 * of a transition that has not yet been started.
888 */
889 boolean isReadyForDisplay() {
890 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800891 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800892 return false;
893 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700894 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800895 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
896 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700897 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -0700898 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800899 }
900
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800901 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700902 * Like isReadyForDisplay(), but ignores any force hiding of the window due
903 * to the keyguard.
904 */
905 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800906 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700907 return false;
908 }
909 final AppWindowToken atoken = mAppToken;
910 if (atoken == null && !mPolicyVisibility) {
911 // If this is not an app window, and the policy has asked to force
912 // hide, then we really do want to hide.
913 return false;
914 }
915 return mHasSurface && !mDestroying
916 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
917 && !mRootToken.hidden)
918 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -0700919 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
920 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700921 }
922
923 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800924 * Like isOnScreen, but returns false if the surface hasn't yet
925 * been drawn.
926 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700927 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800928 public boolean isDisplayedLw() {
929 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700930 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800931 && ((!mAttachedHidden &&
932 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700933 || mWinAnimator.mAnimating
934 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800935 }
936
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700937 /**
Craig Mautnerae446592012-12-06 19:05:05 -0800938 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700939 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700940 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700941 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -0800942 return mWinAnimator.mAnimation != null
943 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700944 }
945
Craig Mautner812d2ca2012-09-27 15:35:34 -0700946 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800947 public boolean isGoneForLayoutLw() {
948 final AppWindowToken atoken = mAppToken;
949 return mViewVisibility == View.GONE
950 || !mRelayoutCalled
951 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -0700952 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800953 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -0700954 || (mExiting && !isAnimatingLw())
955 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800956 }
957
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800958 /**
959 * Returns true if the window has a surface that it has drawn a
960 * complete UI in to.
961 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800962 public boolean isDrawFinishedLw() {
963 return mHasSurface && !mDestroying &&
964 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
965 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
966 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
967 }
968
969 /**
970 * Returns true if the window has a surface that it has drawn a
971 * complete UI in to.
972 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800973 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700974 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -0700975 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
976 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800977 }
978
979 /**
980 * Return true if the window is opaque and fully drawn. This indicates
981 * it may obscure windows behind it.
982 */
983 boolean isOpaqueDrawn() {
984 return (mAttrs.format == PixelFormat.OPAQUE
985 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -0700986 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -0700987 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800988 }
989
990 /**
991 * Return whether this window is wanting to have a translation
992 * animation applied to it for an in-progress move. (Only makes
993 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
994 */
995 boolean shouldAnimateMove() {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700996 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997 && (mFrame.top != mLastFrame.top
998 || mFrame.left != mLastFrame.left)
Dianne Hackborn1c5383c2013-04-15 15:07:21 -0700999 && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Craig Mautner2fb98b12012-03-20 17:24:00 -07001000 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001001 }
1002
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001003 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001004 return mFrame.left <= 0 && mFrame.top <= 0 &&
1005 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001006 }
1007
Craig Mautner812d2ca2012-09-27 15:35:34 -07001008 boolean isConfigChanged() {
Craig Mautnere8552142012-11-07 13:55:47 -08001009 boolean configChanged = mConfiguration != mService.mCurConfiguration
Craig Mautner812d2ca2012-09-27 15:35:34 -07001010 && (mConfiguration == null
1011 || (mConfiguration.diff(mService.mCurConfiguration) != 0));
Craig Mautnere8552142012-11-07 13:55:47 -08001012
1013 if (mAttrs.type == TYPE_KEYGUARD) {
1014 // Retain configuration changed status until resetConfiguration called.
1015 mConfigHasChanged |= configChanged;
1016 configChanged = mConfigHasChanged;
1017 }
1018
1019 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001020 }
1021
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001022 void removeLocked() {
1023 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001024
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001025 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001026 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001027 mAttachedWindow.mChildWindows.remove(this);
1028 }
Craig Mautner96868332012-12-04 14:29:11 -08001029 mWinAnimator.destroyDeferredSurfaceLocked();
1030 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001031 mSession.windowRemovedLocked();
1032 try {
1033 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1034 } catch (RuntimeException e) {
1035 // Ignore if it has already been removed (usually because
1036 // we are doing this as part of processing a death note.)
1037 }
1038 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001039
Craig Mautnere8552142012-11-07 13:55:47 -08001040 void setConfiguration(final Configuration newConfig) {
1041 mConfiguration = newConfig;
1042 mConfigHasChanged = false;
1043 }
1044
Jeff Browncc4f7db2011-08-30 20:34:48 -07001045 void setInputChannel(InputChannel inputChannel) {
1046 if (mInputChannel != null) {
1047 throw new IllegalStateException("Window already has an input channel.");
1048 }
1049
1050 mInputChannel = inputChannel;
1051 mInputWindowHandle.inputChannel = inputChannel;
1052 }
1053
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001054 void disposeInputChannel() {
1055 if (mInputChannel != null) {
1056 mService.mInputManager.unregisterInputChannel(mInputChannel);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001057
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001058 mInputChannel.dispose();
1059 mInputChannel = null;
1060 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001061
1062 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001063 }
1064
1065 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001066 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001067 public void binderDied() {
1068 try {
1069 synchronized(mService.mWindowMap) {
1070 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001071 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001072 if (win != null) {
1073 mService.removeWindowLocked(mSession, win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001074 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001075 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
1076 mService.removeWindowLocked(mSession, WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001077 }
1078 }
1079 } catch (IllegalArgumentException ex) {
1080 // This will happen if the window has already been
1081 // removed.
1082 }
1083 }
1084 }
1085
Craig Mautner58106812012-12-28 12:27:40 -08001086 /**
1087 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001088 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001089 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001090 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001091 && (mViewVisibility == View.VISIBLE)
1092 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1093 }
1094
Craig Mautner749a7bb2012-04-02 13:49:53 -07001095 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001096 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001097 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001098 }
1099
Craig Mautner749a7bb2012-04-02 13:49:53 -07001100 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001101 public boolean showLw(boolean doAnimation) {
1102 return showLw(doAnimation, true);
1103 }
1104
1105 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001106 if (isHiddenFromUserLocked()) {
Craig Mautner88400d32012-09-30 12:35:45 -07001107 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
Craig Mautnera2d7b112012-08-21 15:12:20 -07001108 + this + ", type " + mAttrs.type + ", belonging to " + mOwnerUid);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001109 return false;
1110 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001111 if (!mAppOpVisibility) {
1112 // Being hidden due to app op request.
1113 return false;
1114 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001115 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001116 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001117 return false;
1118 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001119 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001120 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001121 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001122 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001123 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001124 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001125 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001126 // Check for the case where we are currently visible and
1127 // not animating; we do not want to do animation at such a
1128 // point to become visible when we already are.
1129 doAnimation = false;
1130 }
1131 }
1132 mPolicyVisibility = true;
1133 mPolicyVisibilityAfterAnim = true;
1134 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001135 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001136 }
1137 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001138 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001139 }
1140 return true;
1141 }
1142
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001143 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001144 public boolean hideLw(boolean doAnimation) {
1145 return hideLw(doAnimation, true);
1146 }
1147
1148 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1149 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001150 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001151 doAnimation = false;
1152 }
1153 }
1154 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1155 : mPolicyVisibility;
1156 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001157 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001158 return false;
1159 }
1160 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001161 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001162 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001163 doAnimation = false;
1164 }
1165 }
1166 if (doAnimation) {
1167 mPolicyVisibilityAfterAnim = false;
1168 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001169 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001170 mPolicyVisibilityAfterAnim = false;
1171 mPolicyVisibility = false;
1172 // Window is no longer visible -- make sure if we were waiting
1173 // for it to be displayed before enabling the display, that
1174 // we allow the display to be enabled now.
1175 mService.enableScreenIfNeededLocked();
1176 if (mService.mCurrentFocus == this) {
Craig Mautner58458122013-09-14 14:59:50 -07001177 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1178 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001179 mService.mFocusMayChange = true;
1180 }
1181 }
1182 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001183 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001184 }
1185 return true;
1186 }
1187
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001188 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001189 if (mAppOpVisibility != state) {
1190 mAppOpVisibility = state;
1191 if (state) {
1192 // If the policy visibility had last been to hide, then this
1193 // will incorrectly show at this point since we lost that
1194 // information. Not a big deal -- for the windows that have app
1195 // ops modifies they should only be hidden by policy due to the
1196 // lock screen, and the user won't be changing this if locked.
1197 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001198 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001199 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001200 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001201 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001202 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001203 }
1204
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001205 @Override
1206 public boolean isAlive() {
1207 return mClient.asBinder().isBinderAlive();
1208 }
1209
Craig Mautnera987d432012-10-11 14:07:58 -07001210 boolean isClosing() {
1211 return mExiting || (mService.mClosingApps.contains(mAppToken));
1212 }
1213
Craig Mautner69b08182012-09-05 13:07:13 -07001214 @Override
1215 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001216 final DisplayContent displayContent = getDisplayContent();
1217 if (displayContent == null) {
1218 // Only a window that was on a non-default display can be detached from it.
1219 return false;
1220 }
1221 return getDisplayContent().isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001222 }
1223
Craig Mautner88400d32012-09-30 12:35:45 -07001224 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1225 mShowToOwnerOnly = showToOwnerOnly;
1226 }
1227
Craig Mautner5962b122012-10-05 14:45:52 -07001228 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001229 // Attached windows are evaluated based on the window that they are attached to.
1230 WindowState win = this;
1231 while (win.mAttachedWindow != null) {
1232 win = win.mAttachedWindow;
1233 }
1234 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1235 && win.mAppToken != null && win.mAppToken.showWhenLocked) {
1236 // Save some cycles by not calling getDisplayInfo unless it is an application
1237 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001238 final DisplayContent displayContent = win.getDisplayContent();
1239 if (displayContent == null) {
1240 return true;
1241 }
1242 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001243 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1244 && win.mFrame.right >= displayInfo.appWidth
1245 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001246 // Is a fullscreen window, like the clock alarm. Show to everyone.
1247 return false;
1248 }
1249 }
1250
Craig Mautner341220f2012-10-16 15:20:09 -07001251 return win.mShowToOwnerOnly
1252 && UserHandle.getUserId(win.mOwnerUid) != mService.mCurrentUserId;
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001253 }
1254
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001255 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1256 outRegion.set(
1257 frame.left + inset.left, frame.top + inset.top,
1258 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001259 }
1260
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001261 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001262 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001263 switch (mTouchableInsets) {
1264 default:
1265 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1266 outRegion.set(frame);
1267 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001268 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001269 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001270 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001271 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001272 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001273 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001274 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1275 final Region givenTouchableRegion = mGivenTouchableRegion;
1276 outRegion.set(givenTouchableRegion);
1277 outRegion.translate(frame.left, frame.top);
1278 break;
1279 }
1280 }
1281 }
1282
Craig Mautner59c00972012-07-30 12:10:24 -07001283 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001284 final DisplayContent displayContent = getDisplayContent();
1285 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001286 }
1287
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001288 /**
1289 * Report a focus change. Must be called with no locks held, and consistently
1290 * from the same serialized thread (such as dispatched from a handler).
1291 */
1292 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1293 try {
1294 mClient.windowFocusChanged(focused, inTouchMode);
1295 } catch (RemoteException e) {
1296 }
1297 if (mFocusCallbacks != null) {
1298 final int N = mFocusCallbacks.beginBroadcast();
1299 for (int i=0; i<N; i++) {
1300 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1301 try {
1302 if (focused) {
1303 obs.focusGained(mWindowId.asBinder());
1304 } else {
1305 obs.focusLost(mWindowId.asBinder());
1306 }
1307 } catch (RemoteException e) {
1308 }
1309 }
1310 mFocusCallbacks.finishBroadcast();
1311 }
1312 }
1313
Craig Mautnerdf88d732014-01-27 09:21:32 -08001314 void reportResized() {
1315 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001316 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1317 + ": " + mCompatFrame);
1318 boolean configChanged = isConfigChanged();
1319 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1320 Slog.i(TAG, "Sending new config to window " + this + ": "
1321 + mWinAnimator.mSurfaceW + "x" + mWinAnimator.mSurfaceH
1322 + " / " + mService.mCurConfiguration);
1323 }
1324 setConfiguration(mService.mCurConfiguration);
1325 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1326 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1327
Craig Mautnerdf88d732014-01-27 09:21:32 -08001328 final Rect frame = mFrame;
1329 final Rect overscanInsets = mLastOverscanInsets;
1330 final Rect contentInsets = mLastContentInsets;
1331 final Rect visibleInsets = mLastVisibleInsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001332 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1333 final Configuration newConfig = configChanged ? mConfiguration : null;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001334 if (mClient instanceof IWindow.Stub) {
1335 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1336 mService.mH.post(new Runnable() {
1337 @Override
1338 public void run() {
1339 try {
1340 mClient.resized(frame, overscanInsets, contentInsets,
1341 visibleInsets, reportDraw, newConfig);
1342 } catch (RemoteException e) {
1343 // Not a remote call, RemoteException won't be raised.
1344 }
1345 }
1346 });
1347 } else {
1348 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, reportDraw,
1349 newConfig);
1350 }
1351 mOverscanInsetsChanged = false;
1352 mContentInsetsChanged = false;
1353 mVisibleInsetsChanged = false;
1354 mWinAnimator.mSurfaceResized = false;
1355 } catch (RemoteException e) {
1356 mOrientationChanging = false;
1357 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1358 - mService.mDisplayFreezeTime);
1359 }
1360 }
1361
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001362 public void registerFocusObserver(IWindowFocusObserver observer) {
1363 synchronized(mService.mWindowMap) {
1364 if (mFocusCallbacks == null) {
1365 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1366 }
1367 mFocusCallbacks.register(observer);
1368 }
1369 }
1370
1371 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1372 synchronized(mService.mWindowMap) {
1373 if (mFocusCallbacks != null) {
1374 mFocusCallbacks.unregister(observer);
1375 }
1376 }
1377 }
1378
1379 public boolean isFocused() {
1380 synchronized(mService.mWindowMap) {
1381 return mService.mCurrentFocus == this;
1382 }
1383 }
1384
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001385 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001386 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Craig Mautner59c00972012-07-30 12:10:24 -07001387 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001388 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001389 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001390 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1391 pw.print(" package="); pw.print(mAttrs.packageName);
1392 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001393 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001394 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1395 pw.print(" h="); pw.print(mRequestedHeight);
1396 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001397 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1398 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1399 pw.print(" h="); pw.println(mLastRequestedHeight);
1400 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001401 if (mAttachedWindow != null || mLayoutAttached) {
1402 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1403 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1404 }
1405 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1406 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1407 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1408 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1409 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1410 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001411 if (dumpAll) {
1412 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1413 pw.print(" mSubLayer="); pw.print(mSubLayer);
1414 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001415 pw.print((mTargetAppToken != null ?
1416 mTargetAppToken.mAppAnimator.animLayerAdjustment
1417 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001418 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1419 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001420 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001421 if (dumpAll) {
1422 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1423 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1424 if (mAppToken != null) {
1425 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1426 }
1427 if (mTargetAppToken != null) {
1428 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1429 }
1430 pw.print(prefix); pw.print("mViewVisibility=0x");
1431 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001432 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1433 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001434 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1435 pw.print(" mSystemUiVisibility=0x");
1436 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001437 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001438 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1439 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001440 pw.print(prefix); pw.print("mPolicyVisibility=");
1441 pw.print(mPolicyVisibility);
1442 pw.print(" mPolicyVisibilityAfterAnim=");
1443 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001444 pw.print(" mAppOpVisibility=");
1445 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001446 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1447 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001448 if (!mRelayoutCalled || mLayoutNeeded) {
1449 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1450 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001451 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001452 if (mXOffset != 0 || mYOffset != 0) {
1453 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1454 pw.print(" y="); pw.println(mYOffset);
1455 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001456 if (dumpAll) {
1457 pw.print(prefix); pw.print("mGivenContentInsets=");
1458 mGivenContentInsets.printShortString(pw);
1459 pw.print(" mGivenVisibleInsets=");
1460 mGivenVisibleInsets.printShortString(pw);
1461 pw.println();
1462 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1463 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1464 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001465 Region region = new Region();
1466 getTouchableRegion(region);
1467 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001468 }
1469 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001470 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001471 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001472 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1473 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001474 if (dumpAll) {
1475 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1476 pw.print(" last="); mLastFrame.printShortString(pw);
1477 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001478 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1479 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1480 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001481 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001482 if (mEnforceSizeCompat) {
1483 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001484 pw.println();
1485 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001486 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001487 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001488 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001489 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001490 pw.println();
1491 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1492 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001493 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001494 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001495 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001496 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04001497 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
1498 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001499 pw.print(prefix); pw.print("Cur insets: overscan=");
1500 mOverscanInsets.printShortString(pw);
1501 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001502 pw.print(" visible="); mVisibleInsets.printShortString(pw);
1503 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001504 pw.print(prefix); pw.print("Lst insets: overscan=");
1505 mLastOverscanInsets.printShortString(pw);
1506 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001507 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001508 pw.println();
1509 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001510 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1511 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001512 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1513 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1514 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1515 pw.print(" mDestroying="); pw.print(mDestroying);
1516 pw.print(" mRemoved="); pw.println(mRemoved);
1517 }
1518 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1519 pw.print(prefix); pw.print("mOrientationChanging=");
1520 pw.print(mOrientationChanging);
1521 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1522 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1523 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07001524 if (mLastFreezeDuration != 0) {
1525 pw.print(prefix); pw.print("mLastFreezeDuration=");
1526 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
1527 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001528 if (mHScale != 1 || mVScale != 1) {
1529 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1530 pw.print(" mVScale="); pw.println(mVScale);
1531 }
1532 if (mWallpaperX != -1 || mWallpaperY != -1) {
1533 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1534 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1535 }
1536 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1537 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1538 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1539 }
1540 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001541
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001542 String makeInputChannelName() {
1543 return Integer.toHexString(System.identityHashCode(this))
1544 + " " + mAttrs.getTitle();
1545 }
1546
1547 @Override
1548 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001549 CharSequence title = mAttrs.getTitle();
1550 if (title == null || title.length() <= 0) {
1551 title = mAttrs.packageName;
1552 }
1553 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1554 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001555 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001556 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001557 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001558 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001559 }
1560 return mStringNameCache;
1561 }
satokcef37fb2011-10-24 21:49:38 +09001562}