blob: d56e2254d724f36ffc15dfb80dc98b63604e2d75 [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();
221
222 boolean mContentChanged;
223
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 // If a window showing a wallpaper: the requested offset for the
225 // wallpaper; if a wallpaper window: the currently applied offset.
226 float mWallpaperX = -1;
227 float mWallpaperY = -1;
228
229 // If a window showing a wallpaper: what fraction of the offset
230 // range corresponds to a full virtual screen.
231 float mWallpaperXStep = -1;
232 float mWallpaperYStep = -1;
233
234 // Wallpaper windows: pixels offset based on above variables.
235 int mXOffset;
236 int mYOffset;
237
Craig Mautner2268e7e2012-12-13 15:40:00 -0800238 /**
239 * This is set after IWindowSession.relayout() has been called at
240 * least once for the window. It allows us to detect the situation
241 * where we don't yet have a surface, but should have one soon, so
242 * we can give the window focus before waiting for the relayout.
243 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 boolean mRelayoutCalled;
245
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800246 /**
247 * If the application has called relayout() with changes that can
248 * impact its window's size, we need to perform a layout pass on it
249 * even if it is not currently visible for layout. This is set
250 * when in that case until the layout is done.
251 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800252 boolean mLayoutNeeded;
253
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800254 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 boolean mExiting;
256
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800257 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800258 boolean mDestroying;
259
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800260 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 boolean mRemoveOnExit;
262
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800263 /**
264 * Set when the orientation is changing and this window has not yet
265 * been updated for the new orientation.
266 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267 boolean mOrientationChanging;
268
Dianne Hackborna57c6952013-03-29 14:46:40 -0700269 /**
270 * How long we last kept the screen frozen.
271 */
272 int mLastFreezeDuration;
273
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800274 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 boolean mRemoved;
276
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800277 /**
278 * Temp for keeping track of windows that have been removed when
279 * rebuilding window list.
280 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 boolean mRebuilding;
282
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800283 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700284 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800286
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 // Used to improve performance of toString()
288 String mStringNameCache;
289 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700290 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291
Craig Mautnera2c77052012-03-26 12:14:43 -0700292 final WindowStateAnimator mWinAnimator;
293
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700294 boolean mHasSurface = false;
295
Craig Mautner59c00972012-07-30 12:10:24 -0700296 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700297
Craig Mautner88400d32012-09-30 12:35:45 -0700298 /** When true this window can be displayed on screens owther than mOwnerUid's */
299 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700300
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700301 /** When true this window is at the top of the screen and should be layed out to extend under
302 * the status bar */
303 boolean mUnderStatusBar = true;
304
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800306 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700307 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308 mService = service;
309 mSession = s;
310 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800311 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700313 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800314 mWindowId = new IWindowId.Stub() {
315 @Override
316 public void registerFocusObserver(IWindowFocusObserver observer) {
317 WindowState.this.registerFocusObserver(observer);
318 }
319 @Override
320 public void unregisterFocusObserver(IWindowFocusObserver observer) {
321 WindowState.this.unregisterFocusObserver(observer);
322 }
323 @Override
324 public boolean isFocused() {
325 return WindowState.this.isFocused();
326 }
327 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800328 mAttrs.copyFrom(a);
329 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700330 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700331 mPolicy = mService.mPolicy;
332 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800333 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700334 mSeq = seq;
Adam Lesinski6a591f52013-10-01 18:11:17 -0700335 mEnforceSizeCompat = (mAttrs.flags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700337 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700338 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339 try {
340 c.asBinder().linkToDeath(deathRecipient, 0);
341 } catch (RemoteException e) {
342 mDeathRecipient = null;
343 mAttachedWindow = null;
344 mLayoutAttached = false;
345 mIsImWindow = false;
346 mIsWallpaper = false;
347 mIsFloatingLayer = false;
348 mBaseLayer = 0;
349 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700350 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700351 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800352 return;
353 }
354 mDeathRecipient = deathRecipient;
355
356 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
357 mAttrs.type <= LAST_SUB_WINDOW)) {
358 // The multiplier here is to reserve space for multiple
359 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700360 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800361 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
362 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700363 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800364 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700365 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900366
367 int children_size = mAttachedWindow.mChildWindows.size();
368 if (children_size == 0) {
369 mAttachedWindow.mChildWindows.add(this);
370 } else {
371 for (int i = 0; i < children_size; i++) {
372 WindowState child = (WindowState)mAttachedWindow.mChildWindows.get(i);
373 if (this.mSubLayer < child.mSubLayer) {
374 mAttachedWindow.mChildWindows.add(i, this);
375 break;
376 } else if (this.mSubLayer > child.mSubLayer) {
377 continue;
378 }
379
380 if (this.mBaseLayer <= child.mBaseLayer) {
381 mAttachedWindow.mChildWindows.add(i, this);
382 break;
383 } else {
384 continue;
385 }
386 }
387 if (children_size == mAttachedWindow.mChildWindows.size()) {
388 mAttachedWindow.mChildWindows.add(this);
389 }
390 }
391
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392 mLayoutAttached = mAttrs.type !=
393 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
394 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
395 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
396 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
397 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
398 } else {
399 // The multiplier here is to reserve space for multiple
400 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700401 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402 * WindowManagerService.TYPE_LAYER_MULTIPLIER
403 + WindowManagerService.TYPE_LAYER_OFFSET;
404 mSubLayer = 0;
405 mAttachedWindow = null;
406 mLayoutAttached = false;
407 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
408 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
409 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
410 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
411 }
412
413 WindowState appWin = this;
414 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700415 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800416 }
417 WindowToken appToken = appWin.mToken;
418 while (appToken.appWindowToken == null) {
419 WindowToken parent = mService.mTokenMap.get(appToken.token);
420 if (parent == null || appToken == parent) {
421 break;
422 }
423 appToken = parent;
424 }
425 mRootToken = appToken;
426 mAppToken = appToken.appWindowToken;
427
Craig Mautner322e4032012-07-13 13:35:20 -0700428 mWinAnimator = new WindowStateAnimator(this);
429 mWinAnimator.mAlpha = a.alpha;
430
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800431 mRequestedWidth = 0;
432 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700433 mLastRequestedWidth = 0;
434 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800435 mXOffset = 0;
436 mYOffset = 0;
437 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800438 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700439 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
440 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800441 }
442
443 void attach() {
444 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700445 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800446 + ", list=" + mToken.windows);
447 mSession.windowAddedLocked();
448 }
449
Craig Mautnera2c77052012-03-26 12:14:43 -0700450 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800451 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800452 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800453 }
454
455 @Override
456 public String getOwningPackage() {
457 return mAttrs.packageName;
458 }
459
460 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800461 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800462 mHaveFrame = true;
463
John Spurlock7045aaa2013-07-16 17:38:54 -0400464 TaskStack stack = mAppToken != null ? getStack() : null;
465 if (stack != null && stack.hasSibling()) {
466 mContainingFrame.set(getStackBounds(stack));
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700467 if (mUnderStatusBar) {
468 mContainingFrame.top = pf.top;
469 }
Craig Mautner967212c2013-04-13 21:10:58 -0700470 } else {
471 mContainingFrame.set(pf);
472 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473
Craig Mautnereda67292013-04-28 13:50:14 -0700474 mDisplayFrame.set(df);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800475
Craig Mautner967212c2013-04-13 21:10:58 -0700476 final int pw = mContainingFrame.width();
477 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800478
479 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700480 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
481 if (mAttrs.width < 0) {
482 w = pw;
483 } else if (mEnforceSizeCompat) {
484 w = (int)(mAttrs.width * mGlobalScale + .5f);
485 } else {
486 w = mAttrs.width;
487 }
488 if (mAttrs.height < 0) {
489 h = ph;
490 } else if (mEnforceSizeCompat) {
491 h = (int)(mAttrs.height * mGlobalScale + .5f);
492 } else {
493 h = mAttrs.height;
494 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800495 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700496 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
497 w = pw;
498 } else if (mEnforceSizeCompat) {
499 w = (int)(mRequestedWidth * mGlobalScale + .5f);
500 } else {
501 w = mRequestedWidth;
502 }
503 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
504 h = ph;
505 } else if (mEnforceSizeCompat) {
506 h = (int)(mRequestedHeight * mGlobalScale + .5f);
507 } else {
508 h = mRequestedHeight;
509 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800510 }
511
512 if (!mParentFrame.equals(pf)) {
513 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
514 // + " to " + pf);
515 mParentFrame.set(pf);
516 mContentChanged = true;
517 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700518 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
519 mLastRequestedWidth = mRequestedWidth;
520 mLastRequestedHeight = mRequestedHeight;
521 mContentChanged = true;
522 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800523
Craig Mautnereda67292013-04-28 13:50:14 -0700524 mOverscanFrame.set(of);
525 mContentFrame.set(cf);
526 mVisibleFrame.set(vf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800527
Craig Mautnereda67292013-04-28 13:50:14 -0700528 final int fw = mFrame.width();
529 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800530
531 //System.out.println("In: w=" + w + " h=" + h + " container=" +
532 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
533
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700534 float x, y;
535 if (mEnforceSizeCompat) {
536 x = mAttrs.x * mGlobalScale;
537 y = mAttrs.y * mGlobalScale;
538 } else {
539 x = mAttrs.x;
540 y = mAttrs.y;
541 }
542
Craig Mautner967212c2013-04-13 21:10:58 -0700543 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700544 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700545 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546
547 //System.out.println("Out: " + mFrame);
548
549 // Now make sure the window fits in the overall display.
Craig Mautnereda67292013-04-28 13:50:14 -0700550 Gravity.applyDisplay(mAttrs.gravity, df, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800551
Craig Mautnera248eee2013-05-07 11:41:27 -0700552 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800553 // final window frame.
Craig Mautnereda67292013-04-28 13:50:14 -0700554 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
555 Math.max(mContentFrame.top, mFrame.top),
556 Math.min(mContentFrame.right, mFrame.right),
557 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800558
Craig Mautnereda67292013-04-28 13:50:14 -0700559 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
560 Math.max(mVisibleFrame.top, mFrame.top),
561 Math.min(mVisibleFrame.right, mFrame.right),
562 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800563
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700564 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
565 Math.max(mOverscanFrame.top - mFrame.top, 0),
566 Math.max(mFrame.right - mOverscanFrame.right, 0),
567 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800568
Craig Mautnereda67292013-04-28 13:50:14 -0700569 mContentInsets.set(mContentFrame.left - mFrame.left,
570 mContentFrame.top - mFrame.top,
571 mFrame.right - mContentFrame.right,
572 mFrame.bottom - mContentFrame.bottom);
573
574 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
575 mVisibleFrame.top - mFrame.top,
576 mFrame.right - mVisibleFrame.right,
577 mFrame.bottom - mVisibleFrame.bottom);
578
579 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400580 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700581 // If there is a size compatibility scale being applied to the
582 // window, we need to apply this to its insets so that they are
583 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700584 mOverscanInsets.scale(mInvGlobalScale);
585 mContentInsets.scale(mInvGlobalScale);
586 mVisibleInsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700587
588 // Also the scaled frame that we report to the app needs to be
589 // adjusted to be in its coordinate space.
590 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400591 }
592
Craig Mautnereda67292013-04-28 13:50:14 -0700593 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautner59c00972012-07-30 12:10:24 -0700594 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
John Spurlockef4adae2013-08-26 17:58:58 -0400595 mService.updateWallpaperOffsetLocked(this,
596 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800597 }
598
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700599 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
600 "Resolving (mRequestedWidth="
601 + mRequestedWidth + ", mRequestedheight="
602 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
603 + "): frame=" + mFrame.toShortString()
604 + " ci=" + mContentInsets.toShortString()
605 + " vi=" + mVisibleInsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800606 }
607
Craig Mautnera2c77052012-03-26 12:14:43 -0700608 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800609 public Rect getFrameLw() {
610 return mFrame;
611 }
612
Craig Mautnera2c77052012-03-26 12:14:43 -0700613 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700614 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800615 return mShownFrame;
616 }
617
Craig Mautnera2c77052012-03-26 12:14:43 -0700618 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800619 public Rect getDisplayFrameLw() {
620 return mDisplayFrame;
621 }
622
Craig Mautnera2c77052012-03-26 12:14:43 -0700623 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800624 public Rect getOverscanFrameLw() {
625 return mOverscanFrame;
626 }
627
628 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800629 public Rect getContentFrameLw() {
630 return mContentFrame;
631 }
632
Craig Mautnera2c77052012-03-26 12:14:43 -0700633 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800634 public Rect getVisibleFrameLw() {
635 return mVisibleFrame;
636 }
637
Craig Mautnera2c77052012-03-26 12:14:43 -0700638 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800639 public boolean getGivenInsetsPendingLw() {
640 return mGivenInsetsPending;
641 }
642
Craig Mautnera2c77052012-03-26 12:14:43 -0700643 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800644 public Rect getGivenContentInsetsLw() {
645 return mGivenContentInsets;
646 }
647
Craig Mautnera2c77052012-03-26 12:14:43 -0700648 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800649 public Rect getGivenVisibleInsetsLw() {
650 return mGivenVisibleInsets;
651 }
652
Craig Mautnera2c77052012-03-26 12:14:43 -0700653 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800654 public WindowManager.LayoutParams getAttrs() {
655 return mAttrs;
656 }
657
Craig Mautner812d2ca2012-09-27 15:35:34 -0700658 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800659 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
660 int index = -1;
661 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700662 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800663 while (true) {
664 if ((ws.mAttrs.privateFlags
665 & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
666 return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
667 }
668 // If we reached the bottom of the range of windows we are considering,
669 // assume no menu is needed.
670 if (ws == bottom) {
671 return false;
672 }
673 // The current window hasn't specified whether menu key is needed;
674 // look behind it.
675 // First, we may need to determine the starting position.
676 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700677 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800678 }
679 index--;
680 if (index < 0) {
681 return false;
682 }
Craig Mautner59c00972012-07-30 12:10:24 -0700683 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800684 }
685 }
686
Craig Mautner19d59bc2012-09-04 11:15:56 -0700687 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700688 public int getSystemUiVisibility() {
689 return mSystemUiVisibility;
690 }
691
Craig Mautner19d59bc2012-09-04 11:15:56 -0700692 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800693 public int getSurfaceLayer() {
694 return mLayer;
695 }
696
Craig Mautner812d2ca2012-09-27 15:35:34 -0700697 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800698 public IApplicationToken getAppToken() {
699 return mAppToken != null ? mAppToken.appToken : null;
700 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700701
702 public int getDisplayId() {
703 return mDisplayContent.getDisplayId();
704 }
705
Craig Mautnerd9a22882013-03-16 15:00:36 -0700706 TaskStack getStack() {
Craig Mautner05d29032013-05-03 13:40:13 -0700707 AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken;
708 if (wtoken != null) {
709 Task task = mService.mTaskIdToTask.get(wtoken.groupId);
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700710 if (task != null) {
711 return task.mStack;
712 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700713 }
Craig Mautner05d29032013-05-03 13:40:13 -0700714 return mDisplayContent.getHomeStack();
Craig Mautnerd9a22882013-03-16 15:00:36 -0700715 }
716
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700717 Rect getStackBounds() {
John Spurlock7045aaa2013-07-16 17:38:54 -0400718 return getStackBounds(getStack());
719 }
720
721 private Rect getStackBounds(TaskStack stack) {
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700722 if (stack != null) {
723 return stack.mStackBox.mBounds;
724 }
725 return mFrame;
726 }
727
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800728 public long getInputDispatchingTimeoutNanos() {
729 return mAppToken != null
730 ? mAppToken.inputDispatchingTimeoutNanos
731 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
732 }
733
Craig Mautnere8552142012-11-07 13:55:47 -0800734 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800735 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700736 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800737 }
738
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800739 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
740 if (dsdx < .99999f || dsdx > 1.00001f) return false;
741 if (dtdy < .99999f || dtdy > 1.00001f) return false;
742 if (dtdx < -.000001f || dtdx > .000001f) return false;
743 if (dsdy < -.000001f || dsdy > .000001f) return false;
744 return true;
745 }
746
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400747 void prelayout() {
748 if (mEnforceSizeCompat) {
749 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700750 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400751 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700752 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400753 }
754 }
755
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800756 /**
757 * Is this window visible? It is not visible if there is no
758 * surface, or we are in the process of running an exit animation
759 * that will remove the surface, or its app token has been hidden.
760 */
Craig Mautner88400d32012-09-30 12:35:45 -0700761 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800762 public boolean isVisibleLw() {
763 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700764 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800765 && (atoken == null || !atoken.hiddenRequested)
766 && !mExiting && !mDestroying;
767 }
768
769 /**
770 * Like {@link #isVisibleLw}, but also counts a window that is currently
771 * "hidden" behind the keyguard as visible. This allows us to apply
772 * things like window flags that impact the keyguard.
773 * XXX I am starting to think we need to have ANOTHER visibility flag
774 * for this "hidden behind keyguard" state rather than overloading
775 * mPolicyVisibility. Ungh.
776 */
Craig Mautner88400d32012-09-30 12:35:45 -0700777 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800778 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700779 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800780 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700781 return false;
782 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800783 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700784 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -0700785 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700786 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800787 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700788 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
789 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700790 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800791 }
792
793 /**
794 * Is this window visible, ignoring its app token? It is not visible
795 * if there is no surface, or we are in the process of running an exit animation
796 * that will remove the surface.
797 */
798 public boolean isWinVisibleLw() {
799 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700800 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -0700801 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800802 && !mExiting && !mDestroying;
803 }
804
805 /**
806 * The same as isVisible(), but follows the current hidden state of
807 * the associated app token, not the pending requested hidden state.
808 */
809 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700810 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800811 && !mRootToken.hidden && !mExiting && !mDestroying;
812 }
813
814 /**
815 * Can this window possibly be a drag/drop target? The test here is
816 * a combination of the above "visible now" with the check that the
817 * Input Manager uses when discarding windows from input consideration.
818 */
819 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700820 return isVisibleNow() && !mRemoved
821 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800822 }
823
824 /**
825 * Same as isVisible(), but we also count it as visible between the
826 * call to IWindowSession.add() and the first relayout().
827 */
828 boolean isVisibleOrAdding() {
829 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700830 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800831 && mPolicyVisibility && !mAttachedHidden
832 && (atoken == null || !atoken.hiddenRequested)
833 && !mExiting && !mDestroying;
834 }
835
836 /**
837 * Is this window currently on-screen? It is on-screen either if it
838 * is visible or it is currently running an animation before no longer
839 * being visible.
840 */
841 boolean isOnScreen() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700842 if (!mHasSurface || !mPolicyVisibility || mDestroying) {
843 return false;
844 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800845 final AppWindowToken atoken = mAppToken;
846 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700847 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800848 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800849 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700850 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800851 }
852
853 /**
854 * Like isOnScreen(), but we don't return true if the window is part
855 * of a transition that has not yet been started.
856 */
857 boolean isReadyForDisplay() {
858 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800859 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800860 return false;
861 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700862 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800863 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
864 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700865 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -0700866 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800867 }
868
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800869 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700870 * Like isReadyForDisplay(), but ignores any force hiding of the window due
871 * to the keyguard.
872 */
873 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800874 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700875 return false;
876 }
877 final AppWindowToken atoken = mAppToken;
878 if (atoken == null && !mPolicyVisibility) {
879 // If this is not an app window, and the policy has asked to force
880 // hide, then we really do want to hide.
881 return false;
882 }
883 return mHasSurface && !mDestroying
884 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
885 && !mRootToken.hidden)
886 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -0700887 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
888 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700889 }
890
891 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800892 * Like isOnScreen, but returns false if the surface hasn't yet
893 * been drawn.
894 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700895 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800896 public boolean isDisplayedLw() {
897 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700898 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800899 && ((!mAttachedHidden &&
900 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700901 || mWinAnimator.mAnimating
902 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800903 }
904
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700905 /**
Craig Mautnerae446592012-12-06 19:05:05 -0800906 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700907 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700908 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700909 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -0800910 return mWinAnimator.mAnimation != null
911 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700912 }
913
Craig Mautner812d2ca2012-09-27 15:35:34 -0700914 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800915 public boolean isGoneForLayoutLw() {
916 final AppWindowToken atoken = mAppToken;
917 return mViewVisibility == View.GONE
918 || !mRelayoutCalled
919 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -0700920 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800921 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -0700922 || (mExiting && !isAnimatingLw())
923 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800924 }
925
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800926 /**
927 * Returns true if the window has a surface that it has drawn a
928 * complete UI in to.
929 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800930 public boolean isDrawFinishedLw() {
931 return mHasSurface && !mDestroying &&
932 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
933 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
934 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
935 }
936
937 /**
938 * Returns true if the window has a surface that it has drawn a
939 * complete UI in to.
940 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800941 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700942 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -0700943 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
944 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800945 }
946
947 /**
948 * Return true if the window is opaque and fully drawn. This indicates
949 * it may obscure windows behind it.
950 */
951 boolean isOpaqueDrawn() {
952 return (mAttrs.format == PixelFormat.OPAQUE
953 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -0700954 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -0700955 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800956 }
957
958 /**
959 * Return whether this window is wanting to have a translation
960 * animation applied to it for an in-progress move. (Only makes
961 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
962 */
963 boolean shouldAnimateMove() {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700964 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800965 && (mFrame.top != mLastFrame.top
966 || mFrame.left != mLastFrame.left)
Dianne Hackborn1c5383c2013-04-15 15:07:21 -0700967 && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
Craig Mautner2fb98b12012-03-20 17:24:00 -0700968 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800969 }
970
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800971 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700972 return mFrame.left <= 0 && mFrame.top <= 0 &&
973 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800974 }
975
Craig Mautner812d2ca2012-09-27 15:35:34 -0700976 boolean isConfigChanged() {
Craig Mautnere8552142012-11-07 13:55:47 -0800977 boolean configChanged = mConfiguration != mService.mCurConfiguration
Craig Mautner812d2ca2012-09-27 15:35:34 -0700978 && (mConfiguration == null
979 || (mConfiguration.diff(mService.mCurConfiguration) != 0));
Craig Mautnere8552142012-11-07 13:55:47 -0800980
981 if (mAttrs.type == TYPE_KEYGUARD) {
982 // Retain configuration changed status until resetConfiguration called.
983 mConfigHasChanged |= configChanged;
984 configChanged = mConfigHasChanged;
985 }
986
987 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -0700988 }
989
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800990 void removeLocked() {
991 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800992
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800993 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700994 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800995 mAttachedWindow.mChildWindows.remove(this);
996 }
Craig Mautner96868332012-12-04 14:29:11 -0800997 mWinAnimator.destroyDeferredSurfaceLocked();
998 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800999 mSession.windowRemovedLocked();
1000 try {
1001 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1002 } catch (RuntimeException e) {
1003 // Ignore if it has already been removed (usually because
1004 // we are doing this as part of processing a death note.)
1005 }
1006 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001007
Craig Mautnere8552142012-11-07 13:55:47 -08001008 void setConfiguration(final Configuration newConfig) {
1009 mConfiguration = newConfig;
1010 mConfigHasChanged = false;
1011 }
1012
Jeff Browncc4f7db2011-08-30 20:34:48 -07001013 void setInputChannel(InputChannel inputChannel) {
1014 if (mInputChannel != null) {
1015 throw new IllegalStateException("Window already has an input channel.");
1016 }
1017
1018 mInputChannel = inputChannel;
1019 mInputWindowHandle.inputChannel = inputChannel;
1020 }
1021
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001022 void disposeInputChannel() {
1023 if (mInputChannel != null) {
1024 mService.mInputManager.unregisterInputChannel(mInputChannel);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001025
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001026 mInputChannel.dispose();
1027 mInputChannel = null;
1028 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001029
1030 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001031 }
1032
1033 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001034 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001035 public void binderDied() {
1036 try {
1037 synchronized(mService.mWindowMap) {
1038 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001039 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001040 if (win != null) {
1041 mService.removeWindowLocked(mSession, win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001042 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001043 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
1044 mService.removeWindowLocked(mSession, WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001045 }
1046 }
1047 } catch (IllegalArgumentException ex) {
1048 // This will happen if the window has already been
1049 // removed.
1050 }
1051 }
1052 }
1053
Craig Mautner58106812012-12-28 12:27:40 -08001054 /**
1055 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001056 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001057 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001058 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001059 && (mViewVisibility == View.VISIBLE)
1060 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1061 }
1062
Craig Mautner749a7bb2012-04-02 13:49:53 -07001063 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001064 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001065 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001066 }
1067
Craig Mautner749a7bb2012-04-02 13:49:53 -07001068 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001069 public boolean showLw(boolean doAnimation) {
1070 return showLw(doAnimation, true);
1071 }
1072
1073 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001074 if (isHiddenFromUserLocked()) {
Craig Mautner88400d32012-09-30 12:35:45 -07001075 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
Craig Mautnera2d7b112012-08-21 15:12:20 -07001076 + this + ", type " + mAttrs.type + ", belonging to " + mOwnerUid);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001077 return false;
1078 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001079 if (!mAppOpVisibility) {
1080 // Being hidden due to app op request.
1081 return false;
1082 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001083 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001084 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001085 return false;
1086 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001087 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001088 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001089 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001090 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001091 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001092 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001093 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001094 // Check for the case where we are currently visible and
1095 // not animating; we do not want to do animation at such a
1096 // point to become visible when we already are.
1097 doAnimation = false;
1098 }
1099 }
1100 mPolicyVisibility = true;
1101 mPolicyVisibilityAfterAnim = true;
1102 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001103 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001104 }
1105 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001106 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001107 }
1108 return true;
1109 }
1110
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001111 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001112 public boolean hideLw(boolean doAnimation) {
1113 return hideLw(doAnimation, true);
1114 }
1115
1116 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1117 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001118 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001119 doAnimation = false;
1120 }
1121 }
1122 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1123 : mPolicyVisibility;
1124 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001125 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001126 return false;
1127 }
1128 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001129 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001130 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001131 doAnimation = false;
1132 }
1133 }
1134 if (doAnimation) {
1135 mPolicyVisibilityAfterAnim = false;
1136 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001137 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001138 mPolicyVisibilityAfterAnim = false;
1139 mPolicyVisibility = false;
1140 // Window is no longer visible -- make sure if we were waiting
1141 // for it to be displayed before enabling the display, that
1142 // we allow the display to be enabled now.
1143 mService.enableScreenIfNeededLocked();
1144 if (mService.mCurrentFocus == this) {
Craig Mautner58458122013-09-14 14:59:50 -07001145 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1146 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001147 mService.mFocusMayChange = true;
1148 }
1149 }
1150 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001151 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001152 }
1153 return true;
1154 }
1155
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001156 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001157 if (mAppOpVisibility != state) {
1158 mAppOpVisibility = state;
1159 if (state) {
1160 // If the policy visibility had last been to hide, then this
1161 // will incorrectly show at this point since we lost that
1162 // information. Not a big deal -- for the windows that have app
1163 // ops modifies they should only be hidden by policy due to the
1164 // lock screen, and the user won't be changing this if locked.
1165 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001166 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001167 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001168 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001169 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001170 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001171 }
1172
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001173 @Override
1174 public boolean isAlive() {
1175 return mClient.asBinder().isBinderAlive();
1176 }
1177
Craig Mautnera987d432012-10-11 14:07:58 -07001178 boolean isClosing() {
1179 return mExiting || (mService.mClosingApps.contains(mAppToken));
1180 }
1181
Craig Mautner69b08182012-09-05 13:07:13 -07001182 @Override
1183 public boolean isDefaultDisplay() {
1184 return mDisplayContent.isDefaultDisplay;
1185 }
1186
Craig Mautner88400d32012-09-30 12:35:45 -07001187 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1188 mShowToOwnerOnly = showToOwnerOnly;
1189 }
1190
Craig Mautner5962b122012-10-05 14:45:52 -07001191 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001192 // Attached windows are evaluated based on the window that they are attached to.
1193 WindowState win = this;
1194 while (win.mAttachedWindow != null) {
1195 win = win.mAttachedWindow;
1196 }
1197 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1198 && win.mAppToken != null && win.mAppToken.showWhenLocked) {
1199 // Save some cycles by not calling getDisplayInfo unless it is an application
1200 // window intended for all users.
1201 final DisplayInfo displayInfo = win.mDisplayContent.getDisplayInfo();
1202 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1203 && win.mFrame.right >= displayInfo.appWidth
1204 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001205 // Is a fullscreen window, like the clock alarm. Show to everyone.
1206 return false;
1207 }
1208 }
1209
Craig Mautner341220f2012-10-16 15:20:09 -07001210 return win.mShowToOwnerOnly
1211 && UserHandle.getUserId(win.mOwnerUid) != mService.mCurrentUserId;
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001212 }
1213
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001214 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1215 outRegion.set(
1216 frame.left + inset.left, frame.top + inset.top,
1217 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001218 }
1219
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001220 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001221 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001222 switch (mTouchableInsets) {
1223 default:
1224 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1225 outRegion.set(frame);
1226 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001227 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001228 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001229 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001230 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001231 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001232 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001233 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1234 final Region givenTouchableRegion = mGivenTouchableRegion;
1235 outRegion.set(givenTouchableRegion);
1236 outRegion.translate(frame.left, frame.top);
1237 break;
1238 }
1239 }
1240 }
1241
Craig Mautner59c00972012-07-30 12:10:24 -07001242 WindowList getWindowList() {
1243 return mDisplayContent.getWindowList();
1244 }
1245
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001246 /**
1247 * Report a focus change. Must be called with no locks held, and consistently
1248 * from the same serialized thread (such as dispatched from a handler).
1249 */
1250 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1251 try {
1252 mClient.windowFocusChanged(focused, inTouchMode);
1253 } catch (RemoteException e) {
1254 }
1255 if (mFocusCallbacks != null) {
1256 final int N = mFocusCallbacks.beginBroadcast();
1257 for (int i=0; i<N; i++) {
1258 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1259 try {
1260 if (focused) {
1261 obs.focusGained(mWindowId.asBinder());
1262 } else {
1263 obs.focusLost(mWindowId.asBinder());
1264 }
1265 } catch (RemoteException e) {
1266 }
1267 }
1268 mFocusCallbacks.finishBroadcast();
1269 }
1270 }
1271
1272 public void registerFocusObserver(IWindowFocusObserver observer) {
1273 synchronized(mService.mWindowMap) {
1274 if (mFocusCallbacks == null) {
1275 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1276 }
1277 mFocusCallbacks.register(observer);
1278 }
1279 }
1280
1281 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1282 synchronized(mService.mWindowMap) {
1283 if (mFocusCallbacks != null) {
1284 mFocusCallbacks.unregister(observer);
1285 }
1286 }
1287 }
1288
1289 public boolean isFocused() {
1290 synchronized(mService.mWindowMap) {
1291 return mService.mCurrentFocus == this;
1292 }
1293 }
1294
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001295 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Craig Mautner59c00972012-07-30 12:10:24 -07001296 pw.print(prefix); pw.print("mDisplayId="); pw.print(mDisplayContent.getDisplayId());
1297 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001298 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001299 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001300 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1301 pw.print(" package="); pw.print(mAttrs.packageName);
1302 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001303 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001304 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1305 pw.print(" h="); pw.print(mRequestedHeight);
1306 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001307 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1308 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1309 pw.print(" h="); pw.println(mLastRequestedHeight);
1310 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001311 if (mAttachedWindow != null || mLayoutAttached) {
1312 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1313 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1314 }
1315 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1316 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1317 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1318 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1319 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1320 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001321 if (dumpAll) {
1322 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1323 pw.print(" mSubLayer="); pw.print(mSubLayer);
1324 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001325 pw.print((mTargetAppToken != null ?
1326 mTargetAppToken.mAppAnimator.animLayerAdjustment
1327 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001328 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1329 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001330 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001331 if (dumpAll) {
1332 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1333 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1334 if (mAppToken != null) {
1335 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1336 }
1337 if (mTargetAppToken != null) {
1338 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1339 }
1340 pw.print(prefix); pw.print("mViewVisibility=0x");
1341 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001342 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1343 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001344 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1345 pw.print(" mSystemUiVisibility=0x");
1346 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001347 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001348 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1349 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001350 pw.print(prefix); pw.print("mPolicyVisibility=");
1351 pw.print(mPolicyVisibility);
1352 pw.print(" mPolicyVisibilityAfterAnim=");
1353 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001354 pw.print(" mAppOpVisibility=");
1355 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001356 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1357 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001358 if (!mRelayoutCalled || mLayoutNeeded) {
1359 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1360 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001361 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001362 if (mXOffset != 0 || mYOffset != 0) {
1363 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1364 pw.print(" y="); pw.println(mYOffset);
1365 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001366 if (dumpAll) {
1367 pw.print(prefix); pw.print("mGivenContentInsets=");
1368 mGivenContentInsets.printShortString(pw);
1369 pw.print(" mGivenVisibleInsets=");
1370 mGivenVisibleInsets.printShortString(pw);
1371 pw.println();
1372 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1373 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1374 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001375 Region region = new Region();
1376 getTouchableRegion(region);
1377 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001378 }
1379 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001380 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001381 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001382 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1383 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001384 if (dumpAll) {
1385 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1386 pw.print(" last="); mLastFrame.printShortString(pw);
1387 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001388 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1389 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1390 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001391 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001392 if (mEnforceSizeCompat) {
1393 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001394 pw.println();
1395 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001396 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001397 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001398 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001399 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001400 pw.println();
1401 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1402 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001403 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001404 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001405 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001406 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001407 pw.print(prefix); pw.print("Cur insets: overscan=");
1408 mOverscanInsets.printShortString(pw);
1409 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001410 pw.print(" visible="); mVisibleInsets.printShortString(pw);
1411 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001412 pw.print(prefix); pw.print("Lst insets: overscan=");
1413 mLastOverscanInsets.printShortString(pw);
1414 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001415 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001416 pw.println();
1417 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001418 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1419 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001420 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1421 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1422 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1423 pw.print(" mDestroying="); pw.print(mDestroying);
1424 pw.print(" mRemoved="); pw.println(mRemoved);
1425 }
1426 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1427 pw.print(prefix); pw.print("mOrientationChanging=");
1428 pw.print(mOrientationChanging);
1429 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1430 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1431 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07001432 if (mLastFreezeDuration != 0) {
1433 pw.print(prefix); pw.print("mLastFreezeDuration=");
1434 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
1435 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001436 if (mHScale != 1 || mVScale != 1) {
1437 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1438 pw.print(" mVScale="); pw.println(mVScale);
1439 }
1440 if (mWallpaperX != -1 || mWallpaperY != -1) {
1441 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1442 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1443 }
1444 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1445 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1446 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1447 }
1448 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001449
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001450 String makeInputChannelName() {
1451 return Integer.toHexString(System.identityHashCode(this))
1452 + " " + mAttrs.getTitle();
1453 }
1454
1455 @Override
1456 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001457 CharSequence title = mAttrs.getTitle();
1458 if (title == null || title.length() <= 0) {
1459 title = mAttrs.packageName;
1460 }
1461 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1462 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001463 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001464 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001465 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001466 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001467 }
1468 return mStringNameCache;
1469 }
satokcef37fb2011-10-24 21:49:38 +09001470}