blob: 894dca5458dde587d9c907d056ae34ac6c944c44 [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 Mautnerb3b36ba2013-05-20 13:21:10 -070019import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
20import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT;
21
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080022import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Adam Lesinski6a591f52013-10-01 18:11:17 -070023import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080024import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Dianne Hackborn1c5383c2013-04-15 15:07:21 -070025import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080026import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
27import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Craig Mautnere8552142012-11-07 13:55:47 -080028import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080029import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
30
Dianne Hackbornc2293022013-02-06 23:14:49 -080031import android.app.AppOpsManager;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080032import android.os.RemoteCallbackList;
Dianne Hackborna57c6952013-03-29 14:46:40 -070033import android.util.TimeUtils;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080034import android.view.IWindowFocusObserver;
35import android.view.IWindowId;
Jeff Brown4532e612012-04-05 14:27:12 -070036import com.android.server.input.InputWindowHandle;
37
Craig Mautnere7ae2502012-03-26 17:11:19 -070038import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080039import android.content.res.Configuration;
40import android.graphics.Matrix;
41import android.graphics.PixelFormat;
42import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070043import android.graphics.RectF;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080044import android.graphics.Region;
45import android.os.IBinder;
46import android.os.RemoteException;
Craig Mautner9dc52bc2012-08-06 14:15:42 -070047import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070049import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050import android.view.Gravity;
51import android.view.IApplicationToken;
52import android.view.IWindow;
53import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080054import android.view.View;
55import android.view.ViewTreeObserver;
56import android.view.WindowManager;
57import android.view.WindowManagerPolicy;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080058
59import java.io.PrintWriter;
60import java.util.ArrayList;
61
Craig Mautner59c00972012-07-30 12:10:24 -070062class WindowList extends ArrayList<WindowState> {
63}
64
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065/**
66 * A window in the window manager.
67 */
Craig Mautnere32c3072012-03-12 15:25:35 -070068final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070069 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -080070
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080071 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -070072 final WindowManagerPolicy mPolicy;
73 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074 final Session mSession;
75 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -080076 final int mAppOp;
77 // UserId and appId of the owner. Don't display windows of non-current user.
78 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080079 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080080 WindowToken mToken;
81 WindowToken mRootToken;
82 AppWindowToken mAppToken;
83 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070084
85 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
86 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080087 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
88 final DeathRecipient mDeathRecipient;
89 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -080090 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080091 final int mBaseLayer;
92 final int mSubLayer;
93 final boolean mLayoutAttached;
94 final boolean mIsImWindow;
95 final boolean mIsWallpaper;
96 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -070097 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -070098 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700100 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800101 boolean mPolicyVisibility = true;
102 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800103 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800104 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700107
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800108 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
109
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700110 /**
111 * The window size that was requested by the application. These are in
112 * the application's coordinate space (without compatibility scale applied).
113 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114 int mRequestedWidth;
115 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700116 int mLastRequestedWidth;
117 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700118
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800119 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120 boolean mHaveFrame;
121 boolean mObscured;
122 boolean mTurnOnScreen;
123
124 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700125
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 Configuration mConfiguration = null;
Craig Mautnere8552142012-11-07 13:55:47 -0800127 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
128 // Used only on {@link #TYPE_KEYGUARD}.
129 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700130
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700131 /**
132 * Actual frame shown on-screen (may be modified by animation). These
133 * are in the screen's coordinate space (WITH the compatibility scale
134 * applied).
135 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700136 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137
138 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700139 * Insets that determine the actually visible area. These are in the application's
140 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 */
142 final Rect mVisibleInsets = new Rect();
143 final Rect mLastVisibleInsets = new Rect();
144 boolean mVisibleInsetsChanged;
145
146 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700147 * Insets that are covered by system windows (such as the status bar) and
148 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700149 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150 */
151 final Rect mContentInsets = new Rect();
152 final Rect mLastContentInsets = new Rect();
153 boolean mContentInsetsChanged;
154
155 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800156 * Insets that determine the area covered by the display overscan region. These are in the
157 * application's coordinate space (without compatibility scale applied).
158 */
159 final Rect mOverscanInsets = new Rect();
160 final Rect mLastOverscanInsets = new Rect();
161 boolean mOverscanInsetsChanged;
162
163 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164 * Set to true if we are waiting for this window to receive its
165 * given internal insets before laying out other windows based on it.
166 */
167 boolean mGivenInsetsPending;
168
169 /**
170 * These are the content insets that were given during layout for
171 * this window, to be applied to windows behind it.
172 */
173 final Rect mGivenContentInsets = new Rect();
174
175 /**
176 * These are the visible insets that were given during layout for
177 * this window, to be applied to windows behind it.
178 */
179 final Rect mGivenVisibleInsets = new Rect();
180
181 /**
182 * This is the given touchable area relative to the window frame, or null if none.
183 */
184 final Region mGivenTouchableRegion = new Region();
185
186 /**
187 * Flag indicating whether the touchable region should be adjusted by
188 * the visible insets; if false the area outside the visible insets is
189 * NOT touchable, so we must use those to adjust the frame during hit
190 * tests.
191 */
192 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
193
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700194 /**
195 * This is rectangle of the window's surface that is not covered by
196 * system decorations.
197 */
198 final Rect mSystemDecorRect = new Rect();
199 final Rect mLastSystemDecorRect = new Rect();
200
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400202 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700203 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 float mHScale=1, mVScale=1;
205 float mLastHScale=1, mLastVScale=1;
206 final Matrix mTmpMatrix = new Matrix();
207
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700208 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209 final Rect mFrame = new Rect();
210 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700211 // Frame that is scaled to the application's coordinate space when in
212 // screen size compatibility mode.
213 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800214
215 final Rect mContainingFrame = new Rect();
216 final Rect mDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800217 final Rect mOverscanFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800218 final Rect mContentFrame = new Rect();
219 final Rect mParentFrame = new Rect();
220 final Rect mVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400221 final Rect mDecorFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222
223 boolean mContentChanged;
224
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 // If a window showing a wallpaper: the requested offset for the
226 // wallpaper; if a wallpaper window: the currently applied offset.
227 float mWallpaperX = -1;
228 float mWallpaperY = -1;
229
230 // If a window showing a wallpaper: what fraction of the offset
231 // range corresponds to a full virtual screen.
232 float mWallpaperXStep = -1;
233 float mWallpaperYStep = -1;
234
235 // Wallpaper windows: pixels offset based on above variables.
236 int mXOffset;
237 int mYOffset;
238
Craig Mautner2268e7e2012-12-13 15:40:00 -0800239 /**
240 * This is set after IWindowSession.relayout() has been called at
241 * least once for the window. It allows us to detect the situation
242 * where we don't yet have a surface, but should have one soon, so
243 * we can give the window focus before waiting for the relayout.
244 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 boolean mRelayoutCalled;
246
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800247 /**
248 * If the application has called relayout() with changes that can
249 * impact its window's size, we need to perform a layout pass on it
250 * even if it is not currently visible for layout. This is set
251 * when in that case until the layout is done.
252 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800253 boolean mLayoutNeeded;
254
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800255 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256 boolean mExiting;
257
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800258 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259 boolean mDestroying;
260
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800261 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800262 boolean mRemoveOnExit;
263
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800264 /**
265 * Set when the orientation is changing and this window has not yet
266 * been updated for the new orientation.
267 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 boolean mOrientationChanging;
269
Dianne Hackborna57c6952013-03-29 14:46:40 -0700270 /**
271 * How long we last kept the screen frozen.
272 */
273 int mLastFreezeDuration;
274
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800275 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276 boolean mRemoved;
277
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800278 /**
279 * Temp for keeping track of windows that have been removed when
280 * rebuilding window list.
281 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 boolean mRebuilding;
283
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700285 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800287
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800288 // Used to improve performance of toString()
289 String mStringNameCache;
290 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700291 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800292
Craig Mautnera2c77052012-03-26 12:14:43 -0700293 final WindowStateAnimator mWinAnimator;
294
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700295 boolean mHasSurface = false;
296
Craig Mautner59c00972012-07-30 12:10:24 -0700297 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700298
Craig Mautner88400d32012-09-30 12:35:45 -0700299 /** When true this window can be displayed on screens owther than mOwnerUid's */
300 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700301
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700302 /** When true this window is at the top of the screen and should be layed out to extend under
303 * the status bar */
304 boolean mUnderStatusBar = true;
305
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800307 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700308 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309 mService = service;
310 mSession = s;
311 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800312 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700314 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800315 mWindowId = new IWindowId.Stub() {
316 @Override
317 public void registerFocusObserver(IWindowFocusObserver observer) {
318 WindowState.this.registerFocusObserver(observer);
319 }
320 @Override
321 public void unregisterFocusObserver(IWindowFocusObserver observer) {
322 WindowState.this.unregisterFocusObserver(observer);
323 }
324 @Override
325 public boolean isFocused() {
326 return WindowState.this.isFocused();
327 }
328 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800329 mAttrs.copyFrom(a);
330 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700331 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700332 mPolicy = mService.mPolicy;
333 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700335 mSeq = seq;
Adam Lesinski6a591f52013-10-01 18:11:17 -0700336 mEnforceSizeCompat = (mAttrs.flags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700338 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700339 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 try {
341 c.asBinder().linkToDeath(deathRecipient, 0);
342 } catch (RemoteException e) {
343 mDeathRecipient = null;
344 mAttachedWindow = null;
345 mLayoutAttached = false;
346 mIsImWindow = false;
347 mIsWallpaper = false;
348 mIsFloatingLayer = false;
349 mBaseLayer = 0;
350 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700351 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700352 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 return;
354 }
355 mDeathRecipient = deathRecipient;
356
357 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
358 mAttrs.type <= LAST_SUB_WINDOW)) {
359 // The multiplier here is to reserve space for multiple
360 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700361 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
363 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700364 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800365 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700366 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900367
368 int children_size = mAttachedWindow.mChildWindows.size();
369 if (children_size == 0) {
370 mAttachedWindow.mChildWindows.add(this);
371 } else {
372 for (int i = 0; i < children_size; i++) {
373 WindowState child = (WindowState)mAttachedWindow.mChildWindows.get(i);
374 if (this.mSubLayer < child.mSubLayer) {
375 mAttachedWindow.mChildWindows.add(i, this);
376 break;
377 } else if (this.mSubLayer > child.mSubLayer) {
378 continue;
379 }
380
381 if (this.mBaseLayer <= child.mBaseLayer) {
382 mAttachedWindow.mChildWindows.add(i, this);
383 break;
384 } else {
385 continue;
386 }
387 }
388 if (children_size == mAttachedWindow.mChildWindows.size()) {
389 mAttachedWindow.mChildWindows.add(this);
390 }
391 }
392
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800393 mLayoutAttached = mAttrs.type !=
394 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
395 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
396 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
397 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
398 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
399 } else {
400 // The multiplier here is to reserve space for multiple
401 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700402 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800403 * WindowManagerService.TYPE_LAYER_MULTIPLIER
404 + WindowManagerService.TYPE_LAYER_OFFSET;
405 mSubLayer = 0;
406 mAttachedWindow = null;
407 mLayoutAttached = false;
408 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
409 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
410 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
411 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
412 }
413
414 WindowState appWin = this;
415 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700416 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800417 }
418 WindowToken appToken = appWin.mToken;
419 while (appToken.appWindowToken == null) {
420 WindowToken parent = mService.mTokenMap.get(appToken.token);
421 if (parent == null || appToken == parent) {
422 break;
423 }
424 appToken = parent;
425 }
426 mRootToken = appToken;
427 mAppToken = appToken.appWindowToken;
428
Craig Mautner322e4032012-07-13 13:35:20 -0700429 mWinAnimator = new WindowStateAnimator(this);
430 mWinAnimator.mAlpha = a.alpha;
431
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800432 mRequestedWidth = 0;
433 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700434 mLastRequestedWidth = 0;
435 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800436 mXOffset = 0;
437 mYOffset = 0;
438 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800439 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700440 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
441 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800442 }
443
444 void attach() {
445 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700446 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800447 + ", list=" + mToken.windows);
448 mSession.windowAddedLocked();
449 }
450
Craig Mautnera2c77052012-03-26 12:14:43 -0700451 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800452 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800453 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800454 }
455
456 @Override
457 public String getOwningPackage() {
458 return mAttrs.packageName;
459 }
460
461 @Override
John Spurlock46646232013-09-30 22:32:42 -0400462 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463 mHaveFrame = true;
464
John Spurlock7045aaa2013-07-16 17:38:54 -0400465 TaskStack stack = mAppToken != null ? getStack() : null;
466 if (stack != null && stack.hasSibling()) {
467 mContainingFrame.set(getStackBounds(stack));
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700468 if (mUnderStatusBar) {
469 mContainingFrame.top = pf.top;
470 }
Craig Mautner967212c2013-04-13 21:10:58 -0700471 } else {
472 mContainingFrame.set(pf);
473 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800474
Craig Mautnereda67292013-04-28 13:50:14 -0700475 mDisplayFrame.set(df);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800476
Craig Mautner967212c2013-04-13 21:10:58 -0700477 final int pw = mContainingFrame.width();
478 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800479
480 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700481 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
482 if (mAttrs.width < 0) {
483 w = pw;
484 } else if (mEnforceSizeCompat) {
485 w = (int)(mAttrs.width * mGlobalScale + .5f);
486 } else {
487 w = mAttrs.width;
488 }
489 if (mAttrs.height < 0) {
490 h = ph;
491 } else if (mEnforceSizeCompat) {
492 h = (int)(mAttrs.height * mGlobalScale + .5f);
493 } else {
494 h = mAttrs.height;
495 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800496 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700497 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
498 w = pw;
499 } else if (mEnforceSizeCompat) {
500 w = (int)(mRequestedWidth * mGlobalScale + .5f);
501 } else {
502 w = mRequestedWidth;
503 }
504 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
505 h = ph;
506 } else if (mEnforceSizeCompat) {
507 h = (int)(mRequestedHeight * mGlobalScale + .5f);
508 } else {
509 h = mRequestedHeight;
510 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800511 }
512
513 if (!mParentFrame.equals(pf)) {
514 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
515 // + " to " + pf);
516 mParentFrame.set(pf);
517 mContentChanged = true;
518 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700519 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
520 mLastRequestedWidth = mRequestedWidth;
521 mLastRequestedHeight = mRequestedHeight;
522 mContentChanged = true;
523 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800524
Craig Mautnereda67292013-04-28 13:50:14 -0700525 mOverscanFrame.set(of);
526 mContentFrame.set(cf);
527 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400528 mDecorFrame.set(dcf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800529
Craig Mautnereda67292013-04-28 13:50:14 -0700530 final int fw = mFrame.width();
531 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800532
533 //System.out.println("In: w=" + w + " h=" + h + " container=" +
534 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
535
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700536 float x, y;
537 if (mEnforceSizeCompat) {
538 x = mAttrs.x * mGlobalScale;
539 y = mAttrs.y * mGlobalScale;
540 } else {
541 x = mAttrs.x;
542 y = mAttrs.y;
543 }
544
Craig Mautner967212c2013-04-13 21:10:58 -0700545 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700546 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700547 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800548
549 //System.out.println("Out: " + mFrame);
550
551 // Now make sure the window fits in the overall display.
Craig Mautnereda67292013-04-28 13:50:14 -0700552 Gravity.applyDisplay(mAttrs.gravity, df, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800553
Craig Mautnera248eee2013-05-07 11:41:27 -0700554 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800555 // final window frame.
Craig Mautnereda67292013-04-28 13:50:14 -0700556 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
557 Math.max(mContentFrame.top, mFrame.top),
558 Math.min(mContentFrame.right, mFrame.right),
559 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800560
Craig Mautnereda67292013-04-28 13:50:14 -0700561 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
562 Math.max(mVisibleFrame.top, mFrame.top),
563 Math.min(mVisibleFrame.right, mFrame.right),
564 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800565
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700566 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
567 Math.max(mOverscanFrame.top - mFrame.top, 0),
568 Math.max(mFrame.right - mOverscanFrame.right, 0),
569 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800570
Craig Mautnereda67292013-04-28 13:50:14 -0700571 mContentInsets.set(mContentFrame.left - mFrame.left,
572 mContentFrame.top - mFrame.top,
573 mFrame.right - mContentFrame.right,
574 mFrame.bottom - mContentFrame.bottom);
575
576 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
577 mVisibleFrame.top - mFrame.top,
578 mFrame.right - mVisibleFrame.right,
579 mFrame.bottom - mVisibleFrame.bottom);
580
581 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400582 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700583 // If there is a size compatibility scale being applied to the
584 // window, we need to apply this to its insets so that they are
585 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700586 mOverscanInsets.scale(mInvGlobalScale);
587 mContentInsets.scale(mInvGlobalScale);
588 mVisibleInsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700589
590 // Also the scaled frame that we report to the app needs to be
591 // adjusted to be in its coordinate space.
592 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400593 }
594
Craig Mautnereda67292013-04-28 13:50:14 -0700595 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautner59c00972012-07-30 12:10:24 -0700596 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
John Spurlockef4adae2013-08-26 17:58:58 -0400597 mService.updateWallpaperOffsetLocked(this,
598 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800599 }
600
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700601 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
602 "Resolving (mRequestedWidth="
603 + mRequestedWidth + ", mRequestedheight="
604 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
605 + "): frame=" + mFrame.toShortString()
606 + " ci=" + mContentInsets.toShortString()
607 + " vi=" + mVisibleInsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800608 }
609
Craig Mautnera2c77052012-03-26 12:14:43 -0700610 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800611 public Rect getFrameLw() {
612 return mFrame;
613 }
614
Craig Mautnera2c77052012-03-26 12:14:43 -0700615 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700616 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800617 return mShownFrame;
618 }
619
Craig Mautnera2c77052012-03-26 12:14:43 -0700620 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800621 public Rect getDisplayFrameLw() {
622 return mDisplayFrame;
623 }
624
Craig Mautnera2c77052012-03-26 12:14:43 -0700625 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800626 public Rect getOverscanFrameLw() {
627 return mOverscanFrame;
628 }
629
630 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800631 public Rect getContentFrameLw() {
632 return mContentFrame;
633 }
634
Craig Mautnera2c77052012-03-26 12:14:43 -0700635 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636 public Rect getVisibleFrameLw() {
637 return mVisibleFrame;
638 }
639
Craig Mautnera2c77052012-03-26 12:14:43 -0700640 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800641 public boolean getGivenInsetsPendingLw() {
642 return mGivenInsetsPending;
643 }
644
Craig Mautnera2c77052012-03-26 12:14:43 -0700645 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800646 public Rect getGivenContentInsetsLw() {
647 return mGivenContentInsets;
648 }
649
Craig Mautnera2c77052012-03-26 12:14:43 -0700650 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651 public Rect getGivenVisibleInsetsLw() {
652 return mGivenVisibleInsets;
653 }
654
Craig Mautnera2c77052012-03-26 12:14:43 -0700655 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800656 public WindowManager.LayoutParams getAttrs() {
657 return mAttrs;
658 }
659
Craig Mautner812d2ca2012-09-27 15:35:34 -0700660 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800661 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
662 int index = -1;
663 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700664 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800665 while (true) {
666 if ((ws.mAttrs.privateFlags
667 & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
668 return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
669 }
670 // If we reached the bottom of the range of windows we are considering,
671 // assume no menu is needed.
672 if (ws == bottom) {
673 return false;
674 }
675 // The current window hasn't specified whether menu key is needed;
676 // look behind it.
677 // First, we may need to determine the starting position.
678 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700679 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800680 }
681 index--;
682 if (index < 0) {
683 return false;
684 }
Craig Mautner59c00972012-07-30 12:10:24 -0700685 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800686 }
687 }
688
Craig Mautner19d59bc2012-09-04 11:15:56 -0700689 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700690 public int getSystemUiVisibility() {
691 return mSystemUiVisibility;
692 }
693
Craig Mautner19d59bc2012-09-04 11:15:56 -0700694 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800695 public int getSurfaceLayer() {
696 return mLayer;
697 }
698
Craig Mautner812d2ca2012-09-27 15:35:34 -0700699 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800700 public IApplicationToken getAppToken() {
701 return mAppToken != null ? mAppToken.appToken : null;
702 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700703
704 public int getDisplayId() {
705 return mDisplayContent.getDisplayId();
706 }
707
Craig Mautnerd9a22882013-03-16 15:00:36 -0700708 TaskStack getStack() {
Craig Mautner05d29032013-05-03 13:40:13 -0700709 AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken;
710 if (wtoken != null) {
711 Task task = mService.mTaskIdToTask.get(wtoken.groupId);
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700712 if (task != null) {
713 return task.mStack;
714 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700715 }
Craig Mautner05d29032013-05-03 13:40:13 -0700716 return mDisplayContent.getHomeStack();
Craig Mautnerd9a22882013-03-16 15:00:36 -0700717 }
718
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700719 Rect getStackBounds() {
John Spurlock7045aaa2013-07-16 17:38:54 -0400720 return getStackBounds(getStack());
721 }
722
723 private Rect getStackBounds(TaskStack stack) {
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700724 if (stack != null) {
725 return stack.mStackBox.mBounds;
726 }
727 return mFrame;
728 }
729
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800730 public long getInputDispatchingTimeoutNanos() {
731 return mAppToken != null
732 ? mAppToken.inputDispatchingTimeoutNanos
733 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
734 }
735
Craig Mautnere8552142012-11-07 13:55:47 -0800736 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800737 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700738 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800739 }
740
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800741 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
742 if (dsdx < .99999f || dsdx > 1.00001f) return false;
743 if (dtdy < .99999f || dtdy > 1.00001f) return false;
744 if (dtdx < -.000001f || dtdx > .000001f) return false;
745 if (dsdy < -.000001f || dsdy > .000001f) return false;
746 return true;
747 }
748
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400749 void prelayout() {
750 if (mEnforceSizeCompat) {
751 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700752 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400753 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700754 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400755 }
756 }
757
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800758 /**
759 * Is this window visible? It is not visible if there is no
760 * surface, or we are in the process of running an exit animation
761 * that will remove the surface, or its app token has been hidden.
762 */
Craig Mautner88400d32012-09-30 12:35:45 -0700763 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800764 public boolean isVisibleLw() {
765 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700766 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800767 && (atoken == null || !atoken.hiddenRequested)
768 && !mExiting && !mDestroying;
769 }
770
771 /**
772 * Like {@link #isVisibleLw}, but also counts a window that is currently
773 * "hidden" behind the keyguard as visible. This allows us to apply
774 * things like window flags that impact the keyguard.
775 * XXX I am starting to think we need to have ANOTHER visibility flag
776 * for this "hidden behind keyguard" state rather than overloading
777 * mPolicyVisibility. Ungh.
778 */
Craig Mautner88400d32012-09-30 12:35:45 -0700779 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800780 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700781 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800782 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700783 return false;
784 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800785 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700786 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -0700787 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700788 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800789 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700790 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
791 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700792 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800793 }
794
795 /**
796 * Is this window visible, ignoring its app token? It is not visible
797 * if there is no surface, or we are in the process of running an exit animation
798 * that will remove the surface.
799 */
800 public boolean isWinVisibleLw() {
801 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700802 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -0700803 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800804 && !mExiting && !mDestroying;
805 }
806
807 /**
808 * The same as isVisible(), but follows the current hidden state of
809 * the associated app token, not the pending requested hidden state.
810 */
811 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700812 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800813 && !mRootToken.hidden && !mExiting && !mDestroying;
814 }
815
816 /**
817 * Can this window possibly be a drag/drop target? The test here is
818 * a combination of the above "visible now" with the check that the
819 * Input Manager uses when discarding windows from input consideration.
820 */
821 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700822 return isVisibleNow() && !mRemoved
823 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800824 }
825
826 /**
827 * Same as isVisible(), but we also count it as visible between the
828 * call to IWindowSession.add() and the first relayout().
829 */
830 boolean isVisibleOrAdding() {
831 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700832 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800833 && mPolicyVisibility && !mAttachedHidden
834 && (atoken == null || !atoken.hiddenRequested)
835 && !mExiting && !mDestroying;
836 }
837
838 /**
839 * Is this window currently on-screen? It is on-screen either if it
840 * is visible or it is currently running an animation before no longer
841 * being visible.
842 */
843 boolean isOnScreen() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700844 if (!mHasSurface || !mPolicyVisibility || mDestroying) {
845 return false;
846 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800847 final AppWindowToken atoken = mAppToken;
848 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700849 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800850 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800851 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700852 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800853 }
854
855 /**
856 * Like isOnScreen(), but we don't return true if the window is part
857 * of a transition that has not yet been started.
858 */
859 boolean isReadyForDisplay() {
860 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800861 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800862 return false;
863 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700864 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800865 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
866 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700867 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -0700868 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800869 }
870
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800871 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700872 * Like isReadyForDisplay(), but ignores any force hiding of the window due
873 * to the keyguard.
874 */
875 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800876 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700877 return false;
878 }
879 final AppWindowToken atoken = mAppToken;
880 if (atoken == null && !mPolicyVisibility) {
881 // If this is not an app window, and the policy has asked to force
882 // hide, then we really do want to hide.
883 return false;
884 }
885 return mHasSurface && !mDestroying
886 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
887 && !mRootToken.hidden)
888 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -0700889 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
890 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700891 }
892
893 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800894 * Like isOnScreen, but returns false if the surface hasn't yet
895 * been drawn.
896 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700897 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800898 public boolean isDisplayedLw() {
899 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700900 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800901 && ((!mAttachedHidden &&
902 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700903 || mWinAnimator.mAnimating
904 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800905 }
906
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700907 /**
Craig Mautnerae446592012-12-06 19:05:05 -0800908 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700909 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700910 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700911 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -0800912 return mWinAnimator.mAnimation != null
913 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700914 }
915
Craig Mautner812d2ca2012-09-27 15:35:34 -0700916 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800917 public boolean isGoneForLayoutLw() {
918 final AppWindowToken atoken = mAppToken;
919 return mViewVisibility == View.GONE
920 || !mRelayoutCalled
921 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -0700922 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800923 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -0700924 || (mExiting && !isAnimatingLw())
925 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800926 }
927
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800928 /**
929 * Returns true if the window has a surface that it has drawn a
930 * complete UI in to.
931 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800932 public boolean isDrawFinishedLw() {
933 return mHasSurface && !mDestroying &&
934 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
935 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
936 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
937 }
938
939 /**
940 * Returns true if the window has a surface that it has drawn a
941 * complete UI in to.
942 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800943 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700944 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -0700945 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
946 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800947 }
948
949 /**
950 * Return true if the window is opaque and fully drawn. This indicates
951 * it may obscure windows behind it.
952 */
953 boolean isOpaqueDrawn() {
954 return (mAttrs.format == PixelFormat.OPAQUE
955 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -0700956 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -0700957 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800958 }
959
960 /**
961 * Return whether this window is wanting to have a translation
962 * animation applied to it for an in-progress move. (Only makes
963 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
964 */
965 boolean shouldAnimateMove() {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700966 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800967 && (mFrame.top != mLastFrame.top
968 || mFrame.left != mLastFrame.left)
Dianne Hackborn1c5383c2013-04-15 15:07:21 -0700969 && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Craig Mautner2fb98b12012-03-20 17:24:00 -0700970 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800971 }
972
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800973 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700974 return mFrame.left <= 0 && mFrame.top <= 0 &&
975 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800976 }
977
Craig Mautner812d2ca2012-09-27 15:35:34 -0700978 boolean isConfigChanged() {
Craig Mautnere8552142012-11-07 13:55:47 -0800979 boolean configChanged = mConfiguration != mService.mCurConfiguration
Craig Mautner812d2ca2012-09-27 15:35:34 -0700980 && (mConfiguration == null
981 || (mConfiguration.diff(mService.mCurConfiguration) != 0));
Craig Mautnere8552142012-11-07 13:55:47 -0800982
983 if (mAttrs.type == TYPE_KEYGUARD) {
984 // Retain configuration changed status until resetConfiguration called.
985 mConfigHasChanged |= configChanged;
986 configChanged = mConfigHasChanged;
987 }
988
989 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -0700990 }
991
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800992 void removeLocked() {
993 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800994
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800995 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700996 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997 mAttachedWindow.mChildWindows.remove(this);
998 }
Craig Mautner96868332012-12-04 14:29:11 -0800999 mWinAnimator.destroyDeferredSurfaceLocked();
1000 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001001 mSession.windowRemovedLocked();
1002 try {
1003 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1004 } catch (RuntimeException e) {
1005 // Ignore if it has already been removed (usually because
1006 // we are doing this as part of processing a death note.)
1007 }
1008 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001009
Craig Mautnere8552142012-11-07 13:55:47 -08001010 void setConfiguration(final Configuration newConfig) {
1011 mConfiguration = newConfig;
1012 mConfigHasChanged = false;
1013 }
1014
Jeff Browncc4f7db2011-08-30 20:34:48 -07001015 void setInputChannel(InputChannel inputChannel) {
1016 if (mInputChannel != null) {
1017 throw new IllegalStateException("Window already has an input channel.");
1018 }
1019
1020 mInputChannel = inputChannel;
1021 mInputWindowHandle.inputChannel = inputChannel;
1022 }
1023
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001024 void disposeInputChannel() {
1025 if (mInputChannel != null) {
1026 mService.mInputManager.unregisterInputChannel(mInputChannel);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001027
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001028 mInputChannel.dispose();
1029 mInputChannel = null;
1030 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001031
1032 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001033 }
1034
1035 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001036 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001037 public void binderDied() {
1038 try {
1039 synchronized(mService.mWindowMap) {
1040 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001041 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001042 if (win != null) {
1043 mService.removeWindowLocked(mSession, win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001044 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001045 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
1046 mService.removeWindowLocked(mSession, WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001047 }
1048 }
1049 } catch (IllegalArgumentException ex) {
1050 // This will happen if the window has already been
1051 // removed.
1052 }
1053 }
1054 }
1055
Craig Mautner58106812012-12-28 12:27:40 -08001056 /**
1057 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001058 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001059 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001060 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001061 && (mViewVisibility == View.VISIBLE)
1062 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1063 }
1064
Craig Mautner749a7bb2012-04-02 13:49:53 -07001065 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001066 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001067 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001068 }
1069
Craig Mautner749a7bb2012-04-02 13:49:53 -07001070 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001071 public boolean showLw(boolean doAnimation) {
1072 return showLw(doAnimation, true);
1073 }
1074
1075 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001076 if (isHiddenFromUserLocked()) {
Craig Mautner88400d32012-09-30 12:35:45 -07001077 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
Craig Mautnera2d7b112012-08-21 15:12:20 -07001078 + this + ", type " + mAttrs.type + ", belonging to " + mOwnerUid);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001079 return false;
1080 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001081 if (!mAppOpVisibility) {
1082 // Being hidden due to app op request.
1083 return false;
1084 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001085 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001086 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001087 return false;
1088 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001089 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001090 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001091 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001092 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001093 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001094 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001095 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001096 // Check for the case where we are currently visible and
1097 // not animating; we do not want to do animation at such a
1098 // point to become visible when we already are.
1099 doAnimation = false;
1100 }
1101 }
1102 mPolicyVisibility = true;
1103 mPolicyVisibilityAfterAnim = true;
1104 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001105 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001106 }
1107 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001108 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001109 }
1110 return true;
1111 }
1112
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001113 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001114 public boolean hideLw(boolean doAnimation) {
1115 return hideLw(doAnimation, true);
1116 }
1117
1118 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1119 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001120 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001121 doAnimation = false;
1122 }
1123 }
1124 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1125 : mPolicyVisibility;
1126 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001127 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001128 return false;
1129 }
1130 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001131 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001132 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001133 doAnimation = false;
1134 }
1135 }
1136 if (doAnimation) {
1137 mPolicyVisibilityAfterAnim = false;
1138 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001139 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001140 mPolicyVisibilityAfterAnim = false;
1141 mPolicyVisibility = false;
1142 // Window is no longer visible -- make sure if we were waiting
1143 // for it to be displayed before enabling the display, that
1144 // we allow the display to be enabled now.
1145 mService.enableScreenIfNeededLocked();
1146 if (mService.mCurrentFocus == this) {
Craig Mautner58458122013-09-14 14:59:50 -07001147 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1148 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001149 mService.mFocusMayChange = true;
1150 }
1151 }
1152 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001153 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001154 }
1155 return true;
1156 }
1157
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001158 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001159 if (mAppOpVisibility != state) {
1160 mAppOpVisibility = state;
1161 if (state) {
1162 // If the policy visibility had last been to hide, then this
1163 // will incorrectly show at this point since we lost that
1164 // information. Not a big deal -- for the windows that have app
1165 // ops modifies they should only be hidden by policy due to the
1166 // lock screen, and the user won't be changing this if locked.
1167 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001168 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001169 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001170 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001171 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001172 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001173 }
1174
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001175 @Override
1176 public boolean isAlive() {
1177 return mClient.asBinder().isBinderAlive();
1178 }
1179
Craig Mautnera987d432012-10-11 14:07:58 -07001180 boolean isClosing() {
1181 return mExiting || (mService.mClosingApps.contains(mAppToken));
1182 }
1183
Craig Mautner69b08182012-09-05 13:07:13 -07001184 @Override
1185 public boolean isDefaultDisplay() {
1186 return mDisplayContent.isDefaultDisplay;
1187 }
1188
Craig Mautner88400d32012-09-30 12:35:45 -07001189 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1190 mShowToOwnerOnly = showToOwnerOnly;
1191 }
1192
Craig Mautner5962b122012-10-05 14:45:52 -07001193 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001194 // Attached windows are evaluated based on the window that they are attached to.
1195 WindowState win = this;
1196 while (win.mAttachedWindow != null) {
1197 win = win.mAttachedWindow;
1198 }
1199 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1200 && win.mAppToken != null && win.mAppToken.showWhenLocked) {
1201 // Save some cycles by not calling getDisplayInfo unless it is an application
1202 // window intended for all users.
1203 final DisplayInfo displayInfo = win.mDisplayContent.getDisplayInfo();
1204 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1205 && win.mFrame.right >= displayInfo.appWidth
1206 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001207 // Is a fullscreen window, like the clock alarm. Show to everyone.
1208 return false;
1209 }
1210 }
1211
Craig Mautner341220f2012-10-16 15:20:09 -07001212 return win.mShowToOwnerOnly
1213 && UserHandle.getUserId(win.mOwnerUid) != mService.mCurrentUserId;
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001214 }
1215
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001216 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1217 outRegion.set(
1218 frame.left + inset.left, frame.top + inset.top,
1219 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001220 }
1221
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001222 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001223 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001224 switch (mTouchableInsets) {
1225 default:
1226 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1227 outRegion.set(frame);
1228 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001229 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001230 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001231 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001232 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001233 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001234 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001235 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1236 final Region givenTouchableRegion = mGivenTouchableRegion;
1237 outRegion.set(givenTouchableRegion);
1238 outRegion.translate(frame.left, frame.top);
1239 break;
1240 }
1241 }
1242 }
1243
Craig Mautner59c00972012-07-30 12:10:24 -07001244 WindowList getWindowList() {
1245 return mDisplayContent.getWindowList();
1246 }
1247
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001248 /**
1249 * Report a focus change. Must be called with no locks held, and consistently
1250 * from the same serialized thread (such as dispatched from a handler).
1251 */
1252 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1253 try {
1254 mClient.windowFocusChanged(focused, inTouchMode);
1255 } catch (RemoteException e) {
1256 }
1257 if (mFocusCallbacks != null) {
1258 final int N = mFocusCallbacks.beginBroadcast();
1259 for (int i=0; i<N; i++) {
1260 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1261 try {
1262 if (focused) {
1263 obs.focusGained(mWindowId.asBinder());
1264 } else {
1265 obs.focusLost(mWindowId.asBinder());
1266 }
1267 } catch (RemoteException e) {
1268 }
1269 }
1270 mFocusCallbacks.finishBroadcast();
1271 }
1272 }
1273
1274 public void registerFocusObserver(IWindowFocusObserver observer) {
1275 synchronized(mService.mWindowMap) {
1276 if (mFocusCallbacks == null) {
1277 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1278 }
1279 mFocusCallbacks.register(observer);
1280 }
1281 }
1282
1283 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1284 synchronized(mService.mWindowMap) {
1285 if (mFocusCallbacks != null) {
1286 mFocusCallbacks.unregister(observer);
1287 }
1288 }
1289 }
1290
1291 public boolean isFocused() {
1292 synchronized(mService.mWindowMap) {
1293 return mService.mCurrentFocus == this;
1294 }
1295 }
1296
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001297 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Craig Mautner59c00972012-07-30 12:10:24 -07001298 pw.print(prefix); pw.print("mDisplayId="); pw.print(mDisplayContent.getDisplayId());
1299 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001300 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001301 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001302 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1303 pw.print(" package="); pw.print(mAttrs.packageName);
1304 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001305 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001306 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1307 pw.print(" h="); pw.print(mRequestedHeight);
1308 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001309 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1310 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1311 pw.print(" h="); pw.println(mLastRequestedHeight);
1312 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001313 if (mAttachedWindow != null || mLayoutAttached) {
1314 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1315 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1316 }
1317 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1318 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1319 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1320 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1321 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1322 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001323 if (dumpAll) {
1324 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1325 pw.print(" mSubLayer="); pw.print(mSubLayer);
1326 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001327 pw.print((mTargetAppToken != null ?
1328 mTargetAppToken.mAppAnimator.animLayerAdjustment
1329 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001330 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1331 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001332 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001333 if (dumpAll) {
1334 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1335 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1336 if (mAppToken != null) {
1337 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1338 }
1339 if (mTargetAppToken != null) {
1340 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1341 }
1342 pw.print(prefix); pw.print("mViewVisibility=0x");
1343 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001344 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1345 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001346 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1347 pw.print(" mSystemUiVisibility=0x");
1348 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001350 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1351 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001352 pw.print(prefix); pw.print("mPolicyVisibility=");
1353 pw.print(mPolicyVisibility);
1354 pw.print(" mPolicyVisibilityAfterAnim=");
1355 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001356 pw.print(" mAppOpVisibility=");
1357 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001358 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1359 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001360 if (!mRelayoutCalled || mLayoutNeeded) {
1361 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1362 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001363 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001364 if (mXOffset != 0 || mYOffset != 0) {
1365 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1366 pw.print(" y="); pw.println(mYOffset);
1367 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001368 if (dumpAll) {
1369 pw.print(prefix); pw.print("mGivenContentInsets=");
1370 mGivenContentInsets.printShortString(pw);
1371 pw.print(" mGivenVisibleInsets=");
1372 mGivenVisibleInsets.printShortString(pw);
1373 pw.println();
1374 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1375 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1376 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001377 Region region = new Region();
1378 getTouchableRegion(region);
1379 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001380 }
1381 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001382 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001383 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001384 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1385 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001386 if (dumpAll) {
1387 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1388 pw.print(" last="); mLastFrame.printShortString(pw);
1389 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001390 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1391 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1392 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001393 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001394 if (mEnforceSizeCompat) {
1395 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001396 pw.println();
1397 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001398 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001399 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001400 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001401 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001402 pw.println();
1403 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1404 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001405 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001406 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001407 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001408 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04001409 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
1410 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001411 pw.print(prefix); pw.print("Cur insets: overscan=");
1412 mOverscanInsets.printShortString(pw);
1413 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001414 pw.print(" visible="); mVisibleInsets.printShortString(pw);
1415 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001416 pw.print(prefix); pw.print("Lst insets: overscan=");
1417 mLastOverscanInsets.printShortString(pw);
1418 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001419 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001420 pw.println();
1421 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001422 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1423 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001424 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1425 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1426 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1427 pw.print(" mDestroying="); pw.print(mDestroying);
1428 pw.print(" mRemoved="); pw.println(mRemoved);
1429 }
1430 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1431 pw.print(prefix); pw.print("mOrientationChanging=");
1432 pw.print(mOrientationChanging);
1433 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1434 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1435 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07001436 if (mLastFreezeDuration != 0) {
1437 pw.print(prefix); pw.print("mLastFreezeDuration=");
1438 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
1439 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001440 if (mHScale != 1 || mVScale != 1) {
1441 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1442 pw.print(" mVScale="); pw.println(mVScale);
1443 }
1444 if (mWallpaperX != -1 || mWallpaperY != -1) {
1445 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1446 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1447 }
1448 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1449 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1450 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1451 }
1452 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001453
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001454 String makeInputChannelName() {
1455 return Integer.toHexString(System.identityHashCode(this))
1456 + " " + mAttrs.getTitle();
1457 }
1458
1459 @Override
1460 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001461 CharSequence title = mAttrs.getTitle();
1462 if (title == null || title.length() <= 0) {
1463 title = mAttrs.packageName;
1464 }
1465 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1466 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001467 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001468 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001469 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001470 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001471 }
1472 return mStringNameCache;
1473 }
satokcef37fb2011-10-24 21:49:38 +09001474}