blob: fe771dcddb4540749d241d8dd66fdd8e3a7e9550 [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;
Jorim Jaggi380ecb82014-03-14 17:25:20 +010026import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Adam Lesinski6a591f52013-10-01 18:11:17 -070027import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080028import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Dianne Hackborn1c5383c2013-04-15 15:07:21 -070029import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080030import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
31import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
32import 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;
Svetoslav4604abc2014-06-10 18:59:30 -070039import android.view.Display;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080040import android.view.IWindowFocusObserver;
41import android.view.IWindowId;
Jeff Brown4532e612012-04-05 14:27:12 -070042import com.android.server.input.InputWindowHandle;
43
Craig Mautnere7ae2502012-03-26 17:11:19 -070044import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080045import android.content.res.Configuration;
46import android.graphics.Matrix;
47import android.graphics.PixelFormat;
48import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070049import android.graphics.RectF;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050import android.graphics.Region;
51import android.os.IBinder;
52import android.os.RemoteException;
Craig Mautner9dc52bc2012-08-06 14:15:42 -070053import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080054import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070055import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056import android.view.Gravity;
57import android.view.IApplicationToken;
58import android.view.IWindow;
59import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060import android.view.View;
61import android.view.ViewTreeObserver;
62import android.view.WindowManager;
63import android.view.WindowManagerPolicy;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064
65import java.io.PrintWriter;
66import java.util.ArrayList;
67
Craig Mautner59c00972012-07-30 12:10:24 -070068class WindowList extends ArrayList<WindowState> {
69}
70
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080071/**
72 * A window in the window manager.
73 */
Craig Mautnere32c3072012-03-12 15:25:35 -070074final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070075 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -080076
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080077 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -070078 final WindowManagerPolicy mPolicy;
79 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080080 final Session mSession;
81 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -080082 final int mAppOp;
83 // UserId and appId of the owner. Don't display windows of non-current user.
84 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080085 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080086 WindowToken mToken;
87 WindowToken mRootToken;
88 AppWindowToken mAppToken;
89 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070090
91 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
92 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
94 final DeathRecipient mDeathRecipient;
95 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -080096 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080097 final int mBaseLayer;
98 final int mSubLayer;
99 final boolean mLayoutAttached;
100 final boolean mIsImWindow;
101 final boolean mIsWallpaper;
102 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700103 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700104 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700106 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107 boolean mPolicyVisibility = true;
108 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800109 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700113
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800114 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
115
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700116 /**
117 * The window size that was requested by the application. These are in
118 * the application's coordinate space (without compatibility scale applied).
119 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120 int mRequestedWidth;
121 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700122 int mLastRequestedWidth;
123 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700124
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 boolean mHaveFrame;
127 boolean mObscured;
128 boolean mTurnOnScreen;
129
130 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700131
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132 Configuration mConfiguration = null;
Craig Mautnere8552142012-11-07 13:55:47 -0800133 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
134 // Used only on {@link #TYPE_KEYGUARD}.
135 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700136
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700137 /**
138 * Actual frame shown on-screen (may be modified by animation). These
139 * are in the screen's coordinate space (WITH the compatibility scale
140 * applied).
141 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700142 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143
144 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700145 * Insets that determine the actually visible area. These are in the application's
146 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 */
148 final Rect mVisibleInsets = new Rect();
149 final Rect mLastVisibleInsets = new Rect();
150 boolean mVisibleInsetsChanged;
151
152 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700153 * Insets that are covered by system windows (such as the status bar) and
154 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700155 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 */
157 final Rect mContentInsets = new Rect();
158 final Rect mLastContentInsets = new Rect();
159 boolean mContentInsetsChanged;
160
161 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800162 * Insets that determine the area covered by the display overscan region. These are in the
163 * application's coordinate space (without compatibility scale applied).
164 */
165 final Rect mOverscanInsets = new Rect();
166 final Rect mLastOverscanInsets = new Rect();
167 boolean mOverscanInsetsChanged;
168
169 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 * Set to true if we are waiting for this window to receive its
171 * given internal insets before laying out other windows based on it.
172 */
173 boolean mGivenInsetsPending;
174
175 /**
176 * These are the content insets that were given during layout for
177 * this window, to be applied to windows behind it.
178 */
179 final Rect mGivenContentInsets = new Rect();
180
181 /**
182 * These are the visible insets that were given during layout for
183 * this window, to be applied to windows behind it.
184 */
185 final Rect mGivenVisibleInsets = new Rect();
186
187 /**
188 * This is the given touchable area relative to the window frame, or null if none.
189 */
190 final Region mGivenTouchableRegion = new Region();
191
192 /**
193 * Flag indicating whether the touchable region should be adjusted by
194 * the visible insets; if false the area outside the visible insets is
195 * NOT touchable, so we must use those to adjust the frame during hit
196 * tests.
197 */
198 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
199
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700200 /**
201 * This is rectangle of the window's surface that is not covered by
202 * system decorations.
203 */
204 final Rect mSystemDecorRect = new Rect();
205 final Rect mLastSystemDecorRect = new Rect();
206
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800207 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400208 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700209 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800210 float mHScale=1, mVScale=1;
211 float mLastHScale=1, mLastVScale=1;
212 final Matrix mTmpMatrix = new Matrix();
213
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700214 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800215 final Rect mFrame = new Rect();
216 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700217 // Frame that is scaled to the application's coordinate space when in
218 // screen size compatibility mode.
219 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220
221 final Rect mContainingFrame = new Rect();
222 final Rect mDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800223 final Rect mOverscanFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 final Rect mContentFrame = new Rect();
225 final Rect mParentFrame = new Rect();
226 final Rect mVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400227 final Rect mDecorFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228
229 boolean mContentChanged;
230
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231 // If a window showing a wallpaper: the requested offset for the
232 // wallpaper; if a wallpaper window: the currently applied offset.
233 float mWallpaperX = -1;
234 float mWallpaperY = -1;
235
236 // If a window showing a wallpaper: what fraction of the offset
237 // range corresponds to a full virtual screen.
238 float mWallpaperXStep = -1;
239 float mWallpaperYStep = -1;
240
241 // Wallpaper windows: pixels offset based on above variables.
242 int mXOffset;
243 int mYOffset;
244
Craig Mautner2268e7e2012-12-13 15:40:00 -0800245 /**
246 * This is set after IWindowSession.relayout() has been called at
247 * least once for the window. It allows us to detect the situation
248 * where we don't yet have a surface, but should have one soon, so
249 * we can give the window focus before waiting for the relayout.
250 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 boolean mRelayoutCalled;
252
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800253 /**
254 * If the application has called relayout() with changes that can
255 * impact its window's size, we need to perform a layout pass on it
256 * even if it is not currently visible for layout. This is set
257 * when in that case until the layout is done.
258 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800259 boolean mLayoutNeeded;
260
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800261 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800262 boolean mExiting;
263
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800264 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 boolean mDestroying;
266
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800267 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 boolean mRemoveOnExit;
269
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800270 /**
271 * Set when the orientation is changing and this window has not yet
272 * been updated for the new orientation.
273 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800274 boolean mOrientationChanging;
275
Dianne Hackborna57c6952013-03-29 14:46:40 -0700276 /**
277 * How long we last kept the screen frozen.
278 */
279 int mLastFreezeDuration;
280
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800281 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 boolean mRemoved;
283
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800284 /**
285 * Temp for keeping track of windows that have been removed when
286 * rebuilding window list.
287 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800288 boolean mRebuilding;
289
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800290 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700291 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800292 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800293
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294 // Used to improve performance of toString()
295 String mStringNameCache;
296 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700297 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298
Craig Mautnera2c77052012-03-26 12:14:43 -0700299 final WindowStateAnimator mWinAnimator;
300
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700301 boolean mHasSurface = false;
302
Craig Mautner19ab8282014-05-07 10:35:34 -0700303 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700304 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700305
Craig Mautner88400d32012-09-30 12:35:45 -0700306 /** When true this window can be displayed on screens owther than mOwnerUid's */
307 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700308
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700309 /** When true this window is at the top of the screen and should be layed out to extend under
310 * the status bar */
311 boolean mUnderStatusBar = true;
312
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800314 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700315 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800316 mService = service;
317 mSession = s;
318 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800319 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800320 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700321 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800322 mWindowId = new IWindowId.Stub() {
323 @Override
324 public void registerFocusObserver(IWindowFocusObserver observer) {
325 WindowState.this.registerFocusObserver(observer);
326 }
327 @Override
328 public void unregisterFocusObserver(IWindowFocusObserver observer) {
329 WindowState.this.unregisterFocusObserver(observer);
330 }
331 @Override
332 public boolean isFocused() {
333 return WindowState.this.isFocused();
334 }
335 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336 mAttrs.copyFrom(a);
337 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700338 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700339 mPolicy = mService.mPolicy;
340 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800341 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700342 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700343 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700345 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700346 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800347 try {
348 c.asBinder().linkToDeath(deathRecipient, 0);
349 } catch (RemoteException e) {
350 mDeathRecipient = null;
351 mAttachedWindow = null;
352 mLayoutAttached = false;
353 mIsImWindow = false;
354 mIsWallpaper = false;
355 mIsFloatingLayer = false;
356 mBaseLayer = 0;
357 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700358 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700359 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 return;
361 }
362 mDeathRecipient = deathRecipient;
363
364 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
365 mAttrs.type <= LAST_SUB_WINDOW)) {
366 // The multiplier here is to reserve space for multiple
367 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700368 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800369 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
370 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700371 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800372 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700373 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900374
375 int children_size = mAttachedWindow.mChildWindows.size();
376 if (children_size == 0) {
377 mAttachedWindow.mChildWindows.add(this);
378 } else {
379 for (int i = 0; i < children_size; i++) {
380 WindowState child = (WindowState)mAttachedWindow.mChildWindows.get(i);
381 if (this.mSubLayer < child.mSubLayer) {
382 mAttachedWindow.mChildWindows.add(i, this);
383 break;
384 } else if (this.mSubLayer > child.mSubLayer) {
385 continue;
386 }
387
388 if (this.mBaseLayer <= child.mBaseLayer) {
389 mAttachedWindow.mChildWindows.add(i, this);
390 break;
391 } else {
392 continue;
393 }
394 }
395 if (children_size == mAttachedWindow.mChildWindows.size()) {
396 mAttachedWindow.mChildWindows.add(this);
397 }
398 }
399
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800400 mLayoutAttached = mAttrs.type !=
401 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
402 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
403 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
404 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
405 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
406 } else {
407 // The multiplier here is to reserve space for multiple
408 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700409 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800410 * WindowManagerService.TYPE_LAYER_MULTIPLIER
411 + WindowManagerService.TYPE_LAYER_OFFSET;
412 mSubLayer = 0;
413 mAttachedWindow = null;
414 mLayoutAttached = false;
415 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
416 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
417 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
418 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
419 }
420
421 WindowState appWin = this;
422 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700423 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800424 }
425 WindowToken appToken = appWin.mToken;
426 while (appToken.appWindowToken == null) {
427 WindowToken parent = mService.mTokenMap.get(appToken.token);
428 if (parent == null || appToken == parent) {
429 break;
430 }
431 appToken = parent;
432 }
433 mRootToken = appToken;
434 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700435 if (mAppToken != null) {
436 final DisplayContent appDisplay = getDisplayContent();
437 mNotOnAppsDisplay = displayContent != appDisplay;
438 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800439
Craig Mautner322e4032012-07-13 13:35:20 -0700440 mWinAnimator = new WindowStateAnimator(this);
441 mWinAnimator.mAlpha = a.alpha;
442
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800443 mRequestedWidth = 0;
444 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700445 mLastRequestedWidth = 0;
446 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800447 mXOffset = 0;
448 mYOffset = 0;
449 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800450 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700451 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
452 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800453 }
454
455 void attach() {
456 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700457 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800458 + ", list=" + mToken.windows);
459 mSession.windowAddedLocked();
460 }
461
Craig Mautnera2c77052012-03-26 12:14:43 -0700462 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800463 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800464 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800465 }
466
467 @Override
468 public String getOwningPackage() {
469 return mAttrs.packageName;
470 }
471
472 @Override
John Spurlock46646232013-09-30 22:32:42 -0400473 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800474 mHaveFrame = true;
475
John Spurlock7045aaa2013-07-16 17:38:54 -0400476 TaskStack stack = mAppToken != null ? getStack() : null;
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800477 if (stack != null && !stack.isFullscreen()) {
478 getStackBounds(stack, mContainingFrame);
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700479 if (mUnderStatusBar) {
480 mContainingFrame.top = pf.top;
481 }
Craig Mautner967212c2013-04-13 21:10:58 -0700482 } else {
483 mContainingFrame.set(pf);
484 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800485
Craig Mautnereda67292013-04-28 13:50:14 -0700486 mDisplayFrame.set(df);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800487
Craig Mautner967212c2013-04-13 21:10:58 -0700488 final int pw = mContainingFrame.width();
489 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800490
491 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700492 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
493 if (mAttrs.width < 0) {
494 w = pw;
495 } else if (mEnforceSizeCompat) {
496 w = (int)(mAttrs.width * mGlobalScale + .5f);
497 } else {
498 w = mAttrs.width;
499 }
500 if (mAttrs.height < 0) {
501 h = ph;
502 } else if (mEnforceSizeCompat) {
503 h = (int)(mAttrs.height * mGlobalScale + .5f);
504 } else {
505 h = mAttrs.height;
506 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800507 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700508 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
509 w = pw;
510 } else if (mEnforceSizeCompat) {
511 w = (int)(mRequestedWidth * mGlobalScale + .5f);
512 } else {
513 w = mRequestedWidth;
514 }
515 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
516 h = ph;
517 } else if (mEnforceSizeCompat) {
518 h = (int)(mRequestedHeight * mGlobalScale + .5f);
519 } else {
520 h = mRequestedHeight;
521 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800522 }
523
524 if (!mParentFrame.equals(pf)) {
525 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
526 // + " to " + pf);
527 mParentFrame.set(pf);
528 mContentChanged = true;
529 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700530 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
531 mLastRequestedWidth = mRequestedWidth;
532 mLastRequestedHeight = mRequestedHeight;
533 mContentChanged = true;
534 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800535
Craig Mautnereda67292013-04-28 13:50:14 -0700536 mOverscanFrame.set(of);
537 mContentFrame.set(cf);
538 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400539 mDecorFrame.set(dcf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800540
Craig Mautnereda67292013-04-28 13:50:14 -0700541 final int fw = mFrame.width();
542 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800543
544 //System.out.println("In: w=" + w + " h=" + h + " container=" +
545 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
546
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700547 float x, y;
548 if (mEnforceSizeCompat) {
549 x = mAttrs.x * mGlobalScale;
550 y = mAttrs.y * mGlobalScale;
551 } else {
552 x = mAttrs.x;
553 y = mAttrs.y;
554 }
555
Craig Mautner967212c2013-04-13 21:10:58 -0700556 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700557 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700558 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800559
560 //System.out.println("Out: " + mFrame);
561
562 // Now make sure the window fits in the overall display.
Craig Mautnereda67292013-04-28 13:50:14 -0700563 Gravity.applyDisplay(mAttrs.gravity, df, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800564
Craig Mautnera248eee2013-05-07 11:41:27 -0700565 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800566 // final window frame.
Craig Mautnereda67292013-04-28 13:50:14 -0700567 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
568 Math.max(mContentFrame.top, mFrame.top),
569 Math.min(mContentFrame.right, mFrame.right),
570 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800571
Craig Mautnereda67292013-04-28 13:50:14 -0700572 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
573 Math.max(mVisibleFrame.top, mFrame.top),
574 Math.min(mVisibleFrame.right, mFrame.right),
575 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800576
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700577 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
578 Math.max(mOverscanFrame.top - mFrame.top, 0),
579 Math.max(mFrame.right - mOverscanFrame.right, 0),
580 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800581
Craig Mautnereda67292013-04-28 13:50:14 -0700582 mContentInsets.set(mContentFrame.left - mFrame.left,
583 mContentFrame.top - mFrame.top,
584 mFrame.right - mContentFrame.right,
585 mFrame.bottom - mContentFrame.bottom);
586
587 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
588 mVisibleFrame.top - mFrame.top,
589 mFrame.right - mVisibleFrame.right,
590 mFrame.bottom - mVisibleFrame.bottom);
591
592 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400593 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700594 // If there is a size compatibility scale being applied to the
595 // window, we need to apply this to its insets so that they are
596 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700597 mOverscanInsets.scale(mInvGlobalScale);
598 mContentInsets.scale(mInvGlobalScale);
599 mVisibleInsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700600
601 // Also the scaled frame that we report to the app needs to be
602 // adjusted to be in its coordinate space.
603 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400604 }
605
Craig Mautnereda67292013-04-28 13:50:14 -0700606 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800607 final DisplayContent displayContent = getDisplayContent();
608 if (displayContent != null) {
609 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
610 mService.updateWallpaperOffsetLocked(this,
611 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
612 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800613 }
614
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700615 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
616 "Resolving (mRequestedWidth="
617 + mRequestedWidth + ", mRequestedheight="
618 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
619 + "): frame=" + mFrame.toShortString()
620 + " ci=" + mContentInsets.toShortString()
621 + " vi=" + mVisibleInsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800622 }
623
Craig Mautnera2c77052012-03-26 12:14:43 -0700624 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800625 public Rect getFrameLw() {
626 return mFrame;
627 }
628
Craig Mautnera2c77052012-03-26 12:14:43 -0700629 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700630 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800631 return mShownFrame;
632 }
633
Craig Mautnera2c77052012-03-26 12:14:43 -0700634 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800635 public Rect getDisplayFrameLw() {
636 return mDisplayFrame;
637 }
638
Craig Mautnera2c77052012-03-26 12:14:43 -0700639 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800640 public Rect getOverscanFrameLw() {
641 return mOverscanFrame;
642 }
643
644 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800645 public Rect getContentFrameLw() {
646 return mContentFrame;
647 }
648
Craig Mautnera2c77052012-03-26 12:14:43 -0700649 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800650 public Rect getVisibleFrameLw() {
651 return mVisibleFrame;
652 }
653
Craig Mautnera2c77052012-03-26 12:14:43 -0700654 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800655 public boolean getGivenInsetsPendingLw() {
656 return mGivenInsetsPending;
657 }
658
Craig Mautnera2c77052012-03-26 12:14:43 -0700659 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800660 public Rect getGivenContentInsetsLw() {
661 return mGivenContentInsets;
662 }
663
Craig Mautnera2c77052012-03-26 12:14:43 -0700664 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800665 public Rect getGivenVisibleInsetsLw() {
666 return mGivenVisibleInsets;
667 }
668
Craig Mautnera2c77052012-03-26 12:14:43 -0700669 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800670 public WindowManager.LayoutParams getAttrs() {
671 return mAttrs;
672 }
673
Craig Mautner812d2ca2012-09-27 15:35:34 -0700674 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800675 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
676 int index = -1;
677 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700678 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800679 while (true) {
680 if ((ws.mAttrs.privateFlags
681 & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
682 return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
683 }
684 // If we reached the bottom of the range of windows we are considering,
685 // assume no menu is needed.
686 if (ws == bottom) {
687 return false;
688 }
689 // The current window hasn't specified whether menu key is needed;
690 // look behind it.
691 // First, we may need to determine the starting position.
692 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700693 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800694 }
695 index--;
696 if (index < 0) {
697 return false;
698 }
Craig Mautner59c00972012-07-30 12:10:24 -0700699 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800700 }
701 }
702
Craig Mautner19d59bc2012-09-04 11:15:56 -0700703 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700704 public int getSystemUiVisibility() {
705 return mSystemUiVisibility;
706 }
707
Craig Mautner19d59bc2012-09-04 11:15:56 -0700708 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800709 public int getSurfaceLayer() {
710 return mLayer;
711 }
712
Craig Mautner812d2ca2012-09-27 15:35:34 -0700713 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800714 public IApplicationToken getAppToken() {
715 return mAppToken != null ? mAppToken.appToken : null;
716 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700717
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700718 @Override
719 public boolean isVoiceInteraction() {
720 return mAppToken != null ? mAppToken.voiceInteraction : false;
721 }
722
Craig Mautner4c5eb222013-11-18 12:59:05 -0800723 boolean setInsetsChanged() {
724 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
725 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
726 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
727 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged;
728 }
729
Craig Mautnerdf88d732014-01-27 09:21:32 -0800730 public DisplayContent getDisplayContent() {
Craig Mautner19ab8282014-05-07 10:35:34 -0700731 return mAppToken == null || mNotOnAppsDisplay ?
732 mDisplayContent : getStack().getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800733 }
734
Craig Mautner19d59bc2012-09-04 11:15:56 -0700735 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800736 final DisplayContent displayContent = getDisplayContent();
737 if (displayContent == null) {
738 return -1;
739 }
740 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700741 }
742
Craig Mautnerd9a22882013-03-16 15:00:36 -0700743 TaskStack getStack() {
Craig Mautner05d29032013-05-03 13:40:13 -0700744 AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken;
745 if (wtoken != null) {
746 Task task = mService.mTaskIdToTask.get(wtoken.groupId);
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700747 if (task != null) {
Craig Mautnere0a38842013-12-16 16:14:02 -0800748 if (task.mStack != null) {
749 return task.mStack;
750 }
751 Slog.e(TAG, "getStack: mStack null for task=" + task);
752 } else {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800753 Slog.e(TAG, "getStack: " + this + " couldn't find taskId=" + wtoken.groupId
754 + " Callers=" + Debug.getCallers(4));
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700755 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700756 }
Craig Mautner05d29032013-05-03 13:40:13 -0700757 return mDisplayContent.getHomeStack();
Craig Mautnerd9a22882013-03-16 15:00:36 -0700758 }
759
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800760 void getStackBounds(Rect bounds) {
761 getStackBounds(getStack(), bounds);
John Spurlock7045aaa2013-07-16 17:38:54 -0400762 }
763
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800764 private void getStackBounds(TaskStack stack, Rect bounds) {
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700765 if (stack != null) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800766 stack.getBounds(bounds);
767 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700768 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800769 bounds.set(mFrame);
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700770 }
771
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800772 public long getInputDispatchingTimeoutNanos() {
773 return mAppToken != null
774 ? mAppToken.inputDispatchingTimeoutNanos
775 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
776 }
777
Craig Mautnere8552142012-11-07 13:55:47 -0800778 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800779 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700780 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800781 }
782
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800783 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
784 if (dsdx < .99999f || dsdx > 1.00001f) return false;
785 if (dtdy < .99999f || dtdy > 1.00001f) return false;
786 if (dtdx < -.000001f || dtdx > .000001f) return false;
787 if (dsdy < -.000001f || dsdy > .000001f) return false;
788 return true;
789 }
790
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400791 void prelayout() {
792 if (mEnforceSizeCompat) {
793 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700794 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400795 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700796 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400797 }
798 }
799
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800800 /**
801 * Is this window visible? It is not visible if there is no
802 * surface, or we are in the process of running an exit animation
803 * that will remove the surface, or its app token has been hidden.
804 */
Craig Mautner88400d32012-09-30 12:35:45 -0700805 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800806 public boolean isVisibleLw() {
807 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700808 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800809 && (atoken == null || !atoken.hiddenRequested)
810 && !mExiting && !mDestroying;
811 }
812
813 /**
814 * Like {@link #isVisibleLw}, but also counts a window that is currently
815 * "hidden" behind the keyguard as visible. This allows us to apply
816 * things like window flags that impact the keyguard.
817 * XXX I am starting to think we need to have ANOTHER visibility flag
818 * for this "hidden behind keyguard" state rather than overloading
819 * mPolicyVisibility. Ungh.
820 */
Craig Mautner88400d32012-09-30 12:35:45 -0700821 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800822 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700823 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800824 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700825 return false;
826 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800827 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700828 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -0700829 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700830 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800831 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700832 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
833 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700834 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800835 }
836
837 /**
838 * Is this window visible, ignoring its app token? It is not visible
839 * if there is no surface, or we are in the process of running an exit animation
840 * that will remove the surface.
841 */
842 public boolean isWinVisibleLw() {
843 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700844 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -0700845 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800846 && !mExiting && !mDestroying;
847 }
848
849 /**
850 * The same as isVisible(), but follows the current hidden state of
851 * the associated app token, not the pending requested hidden state.
852 */
853 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700854 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800855 && !mRootToken.hidden && !mExiting && !mDestroying;
856 }
857
858 /**
859 * Can this window possibly be a drag/drop target? The test here is
860 * a combination of the above "visible now" with the check that the
861 * Input Manager uses when discarding windows from input consideration.
862 */
863 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700864 return isVisibleNow() && !mRemoved
865 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800866 }
867
868 /**
869 * Same as isVisible(), but we also count it as visible between the
870 * call to IWindowSession.add() and the first relayout().
871 */
872 boolean isVisibleOrAdding() {
873 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700874 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800875 && mPolicyVisibility && !mAttachedHidden
876 && (atoken == null || !atoken.hiddenRequested)
877 && !mExiting && !mDestroying;
878 }
879
880 /**
881 * Is this window currently on-screen? It is on-screen either if it
882 * is visible or it is currently running an animation before no longer
883 * being visible.
884 */
885 boolean isOnScreen() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700886 if (!mHasSurface || !mPolicyVisibility || mDestroying) {
887 return false;
888 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800889 final AppWindowToken atoken = mAppToken;
890 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700891 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800892 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800893 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700894 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800895 }
896
897 /**
898 * Like isOnScreen(), but we don't return true if the window is part
899 * of a transition that has not yet been started.
900 */
901 boolean isReadyForDisplay() {
902 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800903 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800904 return false;
905 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700906 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800907 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
908 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700909 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -0700910 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800911 }
912
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800913 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700914 * Like isReadyForDisplay(), but ignores any force hiding of the window due
915 * to the keyguard.
916 */
917 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800918 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700919 return false;
920 }
921 final AppWindowToken atoken = mAppToken;
922 if (atoken == null && !mPolicyVisibility) {
923 // If this is not an app window, and the policy has asked to force
924 // hide, then we really do want to hide.
925 return false;
926 }
927 return mHasSurface && !mDestroying
928 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
929 && !mRootToken.hidden)
930 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -0700931 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
932 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700933 }
934
935 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800936 * Like isOnScreen, but returns false if the surface hasn't yet
937 * been drawn.
938 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700939 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800940 public boolean isDisplayedLw() {
941 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700942 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800943 && ((!mAttachedHidden &&
944 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700945 || mWinAnimator.mAnimating
946 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800947 }
948
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700949 /**
Craig Mautnerae446592012-12-06 19:05:05 -0800950 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700951 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700952 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700953 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -0800954 return mWinAnimator.mAnimation != null
955 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700956 }
957
Craig Mautner812d2ca2012-09-27 15:35:34 -0700958 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800959 public boolean isGoneForLayoutLw() {
960 final AppWindowToken atoken = mAppToken;
961 return mViewVisibility == View.GONE
962 || !mRelayoutCalled
963 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -0700964 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800965 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -0700966 || (mExiting && !isAnimatingLw())
967 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800968 }
969
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800970 /**
971 * Returns true if the window has a surface that it has drawn a
972 * complete UI in to.
973 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800974 public boolean isDrawFinishedLw() {
975 return mHasSurface && !mDestroying &&
976 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
977 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
978 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
979 }
980
981 /**
982 * Returns true if the window has a surface that it has drawn a
983 * complete UI in to.
984 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800985 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700986 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -0700987 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
988 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800989 }
990
991 /**
992 * Return true if the window is opaque and fully drawn. This indicates
993 * it may obscure windows behind it.
994 */
995 boolean isOpaqueDrawn() {
996 return (mAttrs.format == PixelFormat.OPAQUE
997 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -0700998 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -0700999 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001000 }
1001
1002 /**
1003 * Return whether this window is wanting to have a translation
1004 * animation applied to it for an in-progress move. (Only makes
1005 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1006 */
1007 boolean shouldAnimateMove() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001008 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001009 && (mFrame.top != mLastFrame.top
1010 || mFrame.left != mLastFrame.left)
Dianne Hackborn1c5383c2013-04-15 15:07:21 -07001011 && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Craig Mautner2fb98b12012-03-20 17:24:00 -07001012 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001013 }
1014
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001015 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001016 return mFrame.left <= 0 && mFrame.top <= 0 &&
1017 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001018 }
1019
Craig Mautner812d2ca2012-09-27 15:35:34 -07001020 boolean isConfigChanged() {
Craig Mautnere8552142012-11-07 13:55:47 -08001021 boolean configChanged = mConfiguration != mService.mCurConfiguration
Craig Mautner812d2ca2012-09-27 15:35:34 -07001022 && (mConfiguration == null
1023 || (mConfiguration.diff(mService.mCurConfiguration) != 0));
Craig Mautnere8552142012-11-07 13:55:47 -08001024
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001025 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001026 // Retain configuration changed status until resetConfiguration called.
1027 mConfigHasChanged |= configChanged;
1028 configChanged = mConfigHasChanged;
1029 }
1030
1031 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001032 }
1033
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001034 void removeLocked() {
1035 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001036
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001037 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001038 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001039 mAttachedWindow.mChildWindows.remove(this);
1040 }
Craig Mautner96868332012-12-04 14:29:11 -08001041 mWinAnimator.destroyDeferredSurfaceLocked();
1042 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001043 mSession.windowRemovedLocked();
1044 try {
1045 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1046 } catch (RuntimeException e) {
1047 // Ignore if it has already been removed (usually because
1048 // we are doing this as part of processing a death note.)
1049 }
1050 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001051
Craig Mautnere8552142012-11-07 13:55:47 -08001052 void setConfiguration(final Configuration newConfig) {
1053 mConfiguration = newConfig;
1054 mConfigHasChanged = false;
1055 }
1056
Jeff Browncc4f7db2011-08-30 20:34:48 -07001057 void setInputChannel(InputChannel inputChannel) {
1058 if (mInputChannel != null) {
1059 throw new IllegalStateException("Window already has an input channel.");
1060 }
1061
1062 mInputChannel = inputChannel;
1063 mInputWindowHandle.inputChannel = inputChannel;
1064 }
1065
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001066 void disposeInputChannel() {
1067 if (mInputChannel != null) {
1068 mService.mInputManager.unregisterInputChannel(mInputChannel);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001069
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001070 mInputChannel.dispose();
1071 mInputChannel = null;
1072 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001073
1074 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001075 }
1076
1077 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001078 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001079 public void binderDied() {
1080 try {
1081 synchronized(mService.mWindowMap) {
1082 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001083 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001084 if (win != null) {
1085 mService.removeWindowLocked(mSession, win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001086 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001087 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
1088 mService.removeWindowLocked(mSession, WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001089 }
1090 }
1091 } catch (IllegalArgumentException ex) {
1092 // This will happen if the window has already been
1093 // removed.
1094 }
1095 }
1096 }
1097
Craig Mautner58106812012-12-28 12:27:40 -08001098 /**
1099 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001100 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001101 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001102 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001103 && (mViewVisibility == View.VISIBLE)
1104 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1105 }
1106
Craig Mautner749a7bb2012-04-02 13:49:53 -07001107 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001108 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001109 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001110 }
1111
Craig Mautner749a7bb2012-04-02 13:49:53 -07001112 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001113 public boolean showLw(boolean doAnimation) {
1114 return showLw(doAnimation, true);
1115 }
1116
1117 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001118 if (isHiddenFromUserLocked()) {
Craig Mautner88400d32012-09-30 12:35:45 -07001119 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
Craig Mautnera2d7b112012-08-21 15:12:20 -07001120 + this + ", type " + mAttrs.type + ", belonging to " + mOwnerUid);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001121 return false;
1122 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001123 if (!mAppOpVisibility) {
1124 // Being hidden due to app op request.
1125 return false;
1126 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001127 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001128 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001129 return false;
1130 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001131 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001132 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001133 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001134 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001135 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001136 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001137 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001138 // Check for the case where we are currently visible and
1139 // not animating; we do not want to do animation at such a
1140 // point to become visible when we already are.
1141 doAnimation = false;
1142 }
1143 }
1144 mPolicyVisibility = true;
1145 mPolicyVisibilityAfterAnim = true;
1146 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001147 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001148 }
1149 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001150 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001151 }
1152 return true;
1153 }
1154
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001155 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001156 public boolean hideLw(boolean doAnimation) {
1157 return hideLw(doAnimation, true);
1158 }
1159
1160 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1161 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001162 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001163 doAnimation = false;
1164 }
1165 }
1166 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1167 : mPolicyVisibility;
1168 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001169 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001170 return false;
1171 }
1172 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001173 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001174 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001175 doAnimation = false;
1176 }
1177 }
1178 if (doAnimation) {
1179 mPolicyVisibilityAfterAnim = false;
1180 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001181 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001182 mPolicyVisibilityAfterAnim = false;
1183 mPolicyVisibility = false;
1184 // Window is no longer visible -- make sure if we were waiting
1185 // for it to be displayed before enabling the display, that
1186 // we allow the display to be enabled now.
1187 mService.enableScreenIfNeededLocked();
1188 if (mService.mCurrentFocus == this) {
Craig Mautner58458122013-09-14 14:59:50 -07001189 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1190 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001191 mService.mFocusMayChange = true;
1192 }
1193 }
1194 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001195 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001196 }
1197 return true;
1198 }
1199
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001200 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001201 if (mAppOpVisibility != state) {
1202 mAppOpVisibility = state;
1203 if (state) {
1204 // If the policy visibility had last been to hide, then this
1205 // will incorrectly show at this point since we lost that
1206 // information. Not a big deal -- for the windows that have app
1207 // ops modifies they should only be hidden by policy due to the
1208 // lock screen, and the user won't be changing this if locked.
1209 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001210 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001211 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001212 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001213 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001214 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001215 }
1216
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001217 @Override
1218 public boolean isAlive() {
1219 return mClient.asBinder().isBinderAlive();
1220 }
1221
Craig Mautnera987d432012-10-11 14:07:58 -07001222 boolean isClosing() {
1223 return mExiting || (mService.mClosingApps.contains(mAppToken));
1224 }
1225
Craig Mautner69b08182012-09-05 13:07:13 -07001226 @Override
1227 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001228 final DisplayContent displayContent = getDisplayContent();
1229 if (displayContent == null) {
1230 // Only a window that was on a non-default display can be detached from it.
1231 return false;
1232 }
Winson Chung47a3e652014-05-21 16:03:42 -07001233 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001234 }
1235
Craig Mautner88400d32012-09-30 12:35:45 -07001236 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1237 mShowToOwnerOnly = showToOwnerOnly;
1238 }
1239
Craig Mautner5962b122012-10-05 14:45:52 -07001240 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001241 // Attached windows are evaluated based on the window that they are attached to.
1242 WindowState win = this;
1243 while (win.mAttachedWindow != null) {
1244 win = win.mAttachedWindow;
1245 }
1246 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1247 && win.mAppToken != null && win.mAppToken.showWhenLocked) {
1248 // Save some cycles by not calling getDisplayInfo unless it is an application
1249 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001250 final DisplayContent displayContent = win.getDisplayContent();
1251 if (displayContent == null) {
1252 return true;
1253 }
1254 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001255 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1256 && win.mFrame.right >= displayInfo.appWidth
1257 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001258 // Is a fullscreen window, like the clock alarm. Show to everyone.
1259 return false;
1260 }
1261 }
1262
Craig Mautner341220f2012-10-16 15:20:09 -07001263 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001264 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001265 }
1266
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001267 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1268 outRegion.set(
1269 frame.left + inset.left, frame.top + inset.top,
1270 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001271 }
1272
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001273 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001274 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001275 switch (mTouchableInsets) {
1276 default:
1277 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1278 outRegion.set(frame);
1279 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001280 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001281 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001282 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001283 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001284 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001285 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001286 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1287 final Region givenTouchableRegion = mGivenTouchableRegion;
1288 outRegion.set(givenTouchableRegion);
1289 outRegion.translate(frame.left, frame.top);
1290 break;
1291 }
1292 }
1293 }
1294
Craig Mautner59c00972012-07-30 12:10:24 -07001295 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001296 final DisplayContent displayContent = getDisplayContent();
1297 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001298 }
1299
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001300 /**
1301 * Report a focus change. Must be called with no locks held, and consistently
1302 * from the same serialized thread (such as dispatched from a handler).
1303 */
1304 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1305 try {
1306 mClient.windowFocusChanged(focused, inTouchMode);
1307 } catch (RemoteException e) {
1308 }
1309 if (mFocusCallbacks != null) {
1310 final int N = mFocusCallbacks.beginBroadcast();
1311 for (int i=0; i<N; i++) {
1312 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1313 try {
1314 if (focused) {
1315 obs.focusGained(mWindowId.asBinder());
1316 } else {
1317 obs.focusLost(mWindowId.asBinder());
1318 }
1319 } catch (RemoteException e) {
1320 }
1321 }
1322 mFocusCallbacks.finishBroadcast();
1323 }
1324 }
1325
Craig Mautnerdf88d732014-01-27 09:21:32 -08001326 void reportResized() {
1327 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001328 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1329 + ": " + mCompatFrame);
1330 boolean configChanged = isConfigChanged();
1331 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1332 Slog.i(TAG, "Sending new config to window " + this + ": "
1333 + mWinAnimator.mSurfaceW + "x" + mWinAnimator.mSurfaceH
1334 + " / " + mService.mCurConfiguration);
1335 }
1336 setConfiguration(mService.mCurConfiguration);
1337 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1338 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1339
Craig Mautnerdf88d732014-01-27 09:21:32 -08001340 final Rect frame = mFrame;
1341 final Rect overscanInsets = mLastOverscanInsets;
1342 final Rect contentInsets = mLastContentInsets;
1343 final Rect visibleInsets = mLastVisibleInsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001344 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1345 final Configuration newConfig = configChanged ? mConfiguration : null;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001346 if (mClient instanceof IWindow.Stub) {
1347 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1348 mService.mH.post(new Runnable() {
1349 @Override
1350 public void run() {
1351 try {
1352 mClient.resized(frame, overscanInsets, contentInsets,
1353 visibleInsets, reportDraw, newConfig);
1354 } catch (RemoteException e) {
1355 // Not a remote call, RemoteException won't be raised.
1356 }
1357 }
1358 });
1359 } else {
1360 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, reportDraw,
1361 newConfig);
1362 }
Svetoslav4604abc2014-06-10 18:59:30 -07001363
1364 //TODO (multidisplay): Accessibility supported only for the default display.
1365 if (mService.mAccessibilityController != null
1366 && getDisplayId() == Display.DEFAULT_DISPLAY) {
1367 mService.mAccessibilityController.onSomeWindowResizedOrMoved();
1368 }
1369
Craig Mautnerdf88d732014-01-27 09:21:32 -08001370 mOverscanInsetsChanged = false;
1371 mContentInsetsChanged = false;
1372 mVisibleInsetsChanged = false;
1373 mWinAnimator.mSurfaceResized = false;
1374 } catch (RemoteException e) {
1375 mOrientationChanging = false;
1376 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1377 - mService.mDisplayFreezeTime);
1378 }
1379 }
1380
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001381 public void registerFocusObserver(IWindowFocusObserver observer) {
1382 synchronized(mService.mWindowMap) {
1383 if (mFocusCallbacks == null) {
1384 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1385 }
1386 mFocusCallbacks.register(observer);
1387 }
1388 }
1389
1390 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1391 synchronized(mService.mWindowMap) {
1392 if (mFocusCallbacks != null) {
1393 mFocusCallbacks.unregister(observer);
1394 }
1395 }
1396 }
1397
1398 public boolean isFocused() {
1399 synchronized(mService.mWindowMap) {
1400 return mService.mCurrentFocus == this;
1401 }
1402 }
1403
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001404 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001405 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Craig Mautner59c00972012-07-30 12:10:24 -07001406 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001407 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001408 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001409 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1410 pw.print(" package="); pw.print(mAttrs.packageName);
1411 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001413 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1414 pw.print(" h="); pw.print(mRequestedHeight);
1415 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001416 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1417 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1418 pw.print(" h="); pw.println(mLastRequestedHeight);
1419 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001420 if (mAttachedWindow != null || mLayoutAttached) {
1421 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1422 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1423 }
1424 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1425 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1426 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1427 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1428 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1429 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001430 if (dumpAll) {
1431 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1432 pw.print(" mSubLayer="); pw.print(mSubLayer);
1433 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001434 pw.print((mTargetAppToken != null ?
1435 mTargetAppToken.mAppAnimator.animLayerAdjustment
1436 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001437 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1438 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001439 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001440 if (dumpAll) {
1441 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1442 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1443 if (mAppToken != null) {
1444 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1445 }
1446 if (mTargetAppToken != null) {
1447 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1448 }
1449 pw.print(prefix); pw.print("mViewVisibility=0x");
1450 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001451 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1452 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001453 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1454 pw.print(" mSystemUiVisibility=0x");
1455 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001456 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001457 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1458 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001459 pw.print(prefix); pw.print("mPolicyVisibility=");
1460 pw.print(mPolicyVisibility);
1461 pw.print(" mPolicyVisibilityAfterAnim=");
1462 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001463 pw.print(" mAppOpVisibility=");
1464 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001465 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1466 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001467 if (!mRelayoutCalled || mLayoutNeeded) {
1468 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1469 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001470 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001471 if (mXOffset != 0 || mYOffset != 0) {
1472 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1473 pw.print(" y="); pw.println(mYOffset);
1474 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001475 if (dumpAll) {
1476 pw.print(prefix); pw.print("mGivenContentInsets=");
1477 mGivenContentInsets.printShortString(pw);
1478 pw.print(" mGivenVisibleInsets=");
1479 mGivenVisibleInsets.printShortString(pw);
1480 pw.println();
1481 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1482 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1483 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001484 Region region = new Region();
1485 getTouchableRegion(region);
1486 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001487 }
1488 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001490 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001491 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1492 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001493 if (dumpAll) {
1494 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1495 pw.print(" last="); mLastFrame.printShortString(pw);
1496 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001497 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1498 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1499 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001500 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001501 if (mEnforceSizeCompat) {
1502 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001503 pw.println();
1504 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001505 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001506 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001507 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001508 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001509 pw.println();
1510 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1511 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001512 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001513 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001514 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001515 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04001516 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
1517 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001518 pw.print(prefix); pw.print("Cur insets: overscan=");
1519 mOverscanInsets.printShortString(pw);
1520 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001521 pw.print(" visible="); mVisibleInsets.printShortString(pw);
1522 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001523 pw.print(prefix); pw.print("Lst insets: overscan=");
1524 mLastOverscanInsets.printShortString(pw);
1525 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001526 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001527 pw.println();
1528 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001529 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1530 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001531 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1532 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1533 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1534 pw.print(" mDestroying="); pw.print(mDestroying);
1535 pw.print(" mRemoved="); pw.println(mRemoved);
1536 }
1537 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1538 pw.print(prefix); pw.print("mOrientationChanging=");
1539 pw.print(mOrientationChanging);
1540 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1541 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1542 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07001543 if (mLastFreezeDuration != 0) {
1544 pw.print(prefix); pw.print("mLastFreezeDuration=");
1545 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
1546 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001547 if (mHScale != 1 || mVScale != 1) {
1548 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1549 pw.print(" mVScale="); pw.println(mVScale);
1550 }
1551 if (mWallpaperX != -1 || mWallpaperY != -1) {
1552 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1553 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1554 }
1555 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1556 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1557 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1558 }
1559 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001560
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001561 String makeInputChannelName() {
1562 return Integer.toHexString(System.identityHashCode(this))
1563 + " " + mAttrs.getTitle();
1564 }
1565
1566 @Override
1567 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001568 CharSequence title = mAttrs.getTitle();
1569 if (title == null || title.length() <= 0) {
1570 title = mAttrs.packageName;
1571 }
1572 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1573 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001574 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001575 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001576 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001577 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001578 }
1579 return mStringNameCache;
1580 }
satokcef37fb2011-10-24 21:49:38 +09001581}