blob: 506fcecfa51b4d858a07ab354892658d4d9fb13b [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
19import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
20import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080021import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080022import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
23import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Craig Mautnere8552142012-11-07 13:55:47 -080024import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080025import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
26
Dianne Hackbornc2293022013-02-06 23:14:49 -080027import android.app.AppOpsManager;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080028import android.os.RemoteCallbackList;
29import android.view.IWindowFocusObserver;
30import android.view.IWindowId;
Jeff Brown4532e612012-04-05 14:27:12 -070031import com.android.server.input.InputWindowHandle;
32
Craig Mautnere7ae2502012-03-26 17:11:19 -070033import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080034import android.content.res.Configuration;
35import android.graphics.Matrix;
36import android.graphics.PixelFormat;
37import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070038import android.graphics.RectF;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080039import android.graphics.Region;
40import android.os.IBinder;
41import android.os.RemoteException;
Craig Mautner9dc52bc2012-08-06 14:15:42 -070042import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080043import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070044import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080045import android.view.Gravity;
46import android.view.IApplicationToken;
47import android.view.IWindow;
48import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049import android.view.View;
50import android.view.ViewTreeObserver;
51import android.view.WindowManager;
52import android.view.WindowManagerPolicy;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080053
54import java.io.PrintWriter;
55import java.util.ArrayList;
56
Craig Mautner59c00972012-07-30 12:10:24 -070057class WindowList extends ArrayList<WindowState> {
58}
59
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060/**
61 * A window in the window manager.
62 */
Craig Mautnere32c3072012-03-12 15:25:35 -070063final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070064 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -080065
Dianne Hackborn5fd21692011-06-07 14:09:47 -070066 static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
67 static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
Dianne Hackborn36991742011-10-11 21:35:26 -070068 static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
Dianne Hackborn5fd21692011-06-07 14:09:47 -070069 static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
70
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
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800269 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270 boolean mRemoved;
271
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800272 /**
273 * Temp for keeping track of windows that have been removed when
274 * rebuilding window list.
275 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276 boolean mRebuilding;
277
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700279 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280 InputChannel mInputChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800281
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 // Used to improve performance of toString()
283 String mStringNameCache;
284 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700285 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286
Craig Mautnera2c77052012-03-26 12:14:43 -0700287 final WindowStateAnimator mWinAnimator;
288
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700289 boolean mHasSurface = false;
290
Craig Mautner59c00972012-07-30 12:10:24 -0700291 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700292
Craig Mautner88400d32012-09-30 12:35:45 -0700293 /** When true this window can be displayed on screens owther than mOwnerUid's */
294 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700295
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800297 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700298 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800299 mService = service;
300 mSession = s;
301 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800302 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700304 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800305 mWindowId = new IWindowId.Stub() {
306 @Override
307 public void registerFocusObserver(IWindowFocusObserver observer) {
308 WindowState.this.registerFocusObserver(observer);
309 }
310 @Override
311 public void unregisterFocusObserver(IWindowFocusObserver observer) {
312 WindowState.this.unregisterFocusObserver(observer);
313 }
314 @Override
315 public boolean isFocused() {
316 return WindowState.this.isFocused();
317 }
318 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800319 mAttrs.copyFrom(a);
320 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700321 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700322 mPolicy = mService.mPolicy;
323 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700325 mSeq = seq;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400326 mEnforceSizeCompat = (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800327 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700328 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700329 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 try {
331 c.asBinder().linkToDeath(deathRecipient, 0);
332 } catch (RemoteException e) {
333 mDeathRecipient = null;
334 mAttachedWindow = null;
335 mLayoutAttached = false;
336 mIsImWindow = false;
337 mIsWallpaper = false;
338 mIsFloatingLayer = false;
339 mBaseLayer = 0;
340 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700341 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700342 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800343 return;
344 }
345 mDeathRecipient = deathRecipient;
346
347 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
348 mAttrs.type <= LAST_SUB_WINDOW)) {
349 // The multiplier here is to reserve space for multiple
350 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700351 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800352 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
353 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700354 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700356 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800357 mAttachedWindow.mChildWindows.add(this);
358 mLayoutAttached = mAttrs.type !=
359 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
360 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
361 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
362 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
363 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
364 } else {
365 // The multiplier here is to reserve space for multiple
366 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700367 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368 * WindowManagerService.TYPE_LAYER_MULTIPLIER
369 + WindowManagerService.TYPE_LAYER_OFFSET;
370 mSubLayer = 0;
371 mAttachedWindow = null;
372 mLayoutAttached = false;
373 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
374 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
375 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
376 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
377 }
378
379 WindowState appWin = this;
380 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700381 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800382 }
383 WindowToken appToken = appWin.mToken;
384 while (appToken.appWindowToken == null) {
385 WindowToken parent = mService.mTokenMap.get(appToken.token);
386 if (parent == null || appToken == parent) {
387 break;
388 }
389 appToken = parent;
390 }
391 mRootToken = appToken;
392 mAppToken = appToken.appWindowToken;
393
Craig Mautner322e4032012-07-13 13:35:20 -0700394 mWinAnimator = new WindowStateAnimator(this);
395 mWinAnimator.mAlpha = a.alpha;
396
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800397 mRequestedWidth = 0;
398 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700399 mLastRequestedWidth = 0;
400 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800401 mXOffset = 0;
402 mYOffset = 0;
403 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800404 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700405 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
406 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800407 }
408
409 void attach() {
410 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700411 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800412 + ", list=" + mToken.windows);
413 mSession.windowAddedLocked();
414 }
415
Craig Mautnera2c77052012-03-26 12:14:43 -0700416 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800417 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800418 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800419 }
420
421 @Override
422 public String getOwningPackage() {
423 return mAttrs.packageName;
424 }
425
426 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800427 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800428 mHaveFrame = true;
429
430 final Rect container = mContainingFrame;
431 container.set(pf);
432
433 final Rect display = mDisplayFrame;
434 display.set(df);
435
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800436 final int pw = container.right - container.left;
437 final int ph = container.bottom - container.top;
438
439 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700440 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
441 if (mAttrs.width < 0) {
442 w = pw;
443 } else if (mEnforceSizeCompat) {
444 w = (int)(mAttrs.width * mGlobalScale + .5f);
445 } else {
446 w = mAttrs.width;
447 }
448 if (mAttrs.height < 0) {
449 h = ph;
450 } else if (mEnforceSizeCompat) {
451 h = (int)(mAttrs.height * mGlobalScale + .5f);
452 } else {
453 h = mAttrs.height;
454 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800455 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700456 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
457 w = pw;
458 } else if (mEnforceSizeCompat) {
459 w = (int)(mRequestedWidth * mGlobalScale + .5f);
460 } else {
461 w = mRequestedWidth;
462 }
463 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
464 h = ph;
465 } else if (mEnforceSizeCompat) {
466 h = (int)(mRequestedHeight * mGlobalScale + .5f);
467 } else {
468 h = mRequestedHeight;
469 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800470 }
471
472 if (!mParentFrame.equals(pf)) {
473 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
474 // + " to " + pf);
475 mParentFrame.set(pf);
476 mContentChanged = true;
477 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700478 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
479 mLastRequestedWidth = mRequestedWidth;
480 mLastRequestedHeight = mRequestedHeight;
481 mContentChanged = true;
482 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800483
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800484 final Rect overscan = mOverscanFrame;
485 overscan.set(of);
486
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800487 final Rect content = mContentFrame;
488 content.set(cf);
489
490 final Rect visible = mVisibleFrame;
491 visible.set(vf);
492
493 final Rect frame = mFrame;
494 final int fw = frame.width();
495 final int fh = frame.height();
496
497 //System.out.println("In: w=" + w + " h=" + h + " container=" +
498 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
499
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700500 float x, y;
501 if (mEnforceSizeCompat) {
502 x = mAttrs.x * mGlobalScale;
503 y = mAttrs.y * mGlobalScale;
504 } else {
505 x = mAttrs.x;
506 y = mAttrs.y;
507 }
508
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800509 Gravity.apply(mAttrs.gravity, w, h, container,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700510 (int) (x + mAttrs.horizontalMargin * pw),
511 (int) (y + mAttrs.verticalMargin * ph), frame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800512
513 //System.out.println("Out: " + mFrame);
514
515 // Now make sure the window fits in the overall display.
516 Gravity.applyDisplay(mAttrs.gravity, df, frame);
517
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800518 // Make sure the overscan, content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519 // final window frame.
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800520 if (overscan.left < frame.left) overscan.left = frame.left;
521 if (overscan.top < frame.top) overscan.top = frame.top;
522 if (overscan.right > frame.right) overscan.right = frame.right;
523 if (overscan.bottom > frame.bottom) overscan.bottom = frame.bottom;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800524 if (content.left < frame.left) content.left = frame.left;
525 if (content.top < frame.top) content.top = frame.top;
526 if (content.right > frame.right) content.right = frame.right;
527 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
528 if (visible.left < frame.left) visible.left = frame.left;
529 if (visible.top < frame.top) visible.top = frame.top;
530 if (visible.right > frame.right) visible.right = frame.right;
531 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
532
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800533 final Rect overscanInsets = mOverscanInsets;
534 overscanInsets.left = overscan.left-frame.left;
535 overscanInsets.top = overscan.top-frame.top;
536 overscanInsets.right = frame.right-overscan.right;
537 overscanInsets.bottom = frame.bottom-overscan.bottom;
538
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800539 final Rect contentInsets = mContentInsets;
540 contentInsets.left = content.left-frame.left;
541 contentInsets.top = content.top-frame.top;
542 contentInsets.right = frame.right-content.right;
543 contentInsets.bottom = frame.bottom-content.bottom;
544
545 final Rect visibleInsets = mVisibleInsets;
546 visibleInsets.left = visible.left-frame.left;
547 visibleInsets.top = visible.top-frame.top;
548 visibleInsets.right = frame.right-visible.right;
549 visibleInsets.bottom = frame.bottom-visible.bottom;
550
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700551 mCompatFrame.set(frame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400552 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700553 // If there is a size compatibility scale being applied to the
554 // window, we need to apply this to its insets so that they are
555 // reported to the app in its coordinate space.
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800556 overscanInsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700557 contentInsets.scale(mInvGlobalScale);
558 visibleInsets.scale(mInvGlobalScale);
559
560 // Also the scaled frame that we report to the app needs to be
561 // adjusted to be in its coordinate space.
562 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400563 }
564
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800565 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
Craig Mautner59c00972012-07-30 12:10:24 -0700566 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
567 mService.updateWallpaperOffsetLocked(this, displayInfo.appWidth, displayInfo.appHeight,
568 false);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800569 }
570
571 if (WindowManagerService.localLOGV) {
572 //if ("com.google.android.youtube".equals(mAttrs.packageName)
573 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700574 Slog.v(TAG, "Resolving (mRequestedWidth="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800575 + mRequestedWidth + ", mRequestedheight="
576 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
577 + "): frame=" + mFrame.toShortString()
578 + " ci=" + contentInsets.toShortString()
579 + " vi=" + visibleInsets.toShortString());
580 //}
581 }
582 }
583
Craig Mautnera2c77052012-03-26 12:14:43 -0700584 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800585 public Rect getFrameLw() {
586 return mFrame;
587 }
588
Craig Mautnera2c77052012-03-26 12:14:43 -0700589 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700590 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800591 return mShownFrame;
592 }
593
Craig Mautnera2c77052012-03-26 12:14:43 -0700594 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800595 public Rect getDisplayFrameLw() {
596 return mDisplayFrame;
597 }
598
Craig Mautnera2c77052012-03-26 12:14:43 -0700599 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800600 public Rect getOverscanFrameLw() {
601 return mOverscanFrame;
602 }
603
604 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800605 public Rect getContentFrameLw() {
606 return mContentFrame;
607 }
608
Craig Mautnera2c77052012-03-26 12:14:43 -0700609 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800610 public Rect getVisibleFrameLw() {
611 return mVisibleFrame;
612 }
613
Craig Mautnera2c77052012-03-26 12:14:43 -0700614 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800615 public boolean getGivenInsetsPendingLw() {
616 return mGivenInsetsPending;
617 }
618
Craig Mautnera2c77052012-03-26 12:14:43 -0700619 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800620 public Rect getGivenContentInsetsLw() {
621 return mGivenContentInsets;
622 }
623
Craig Mautnera2c77052012-03-26 12:14:43 -0700624 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800625 public Rect getGivenVisibleInsetsLw() {
626 return mGivenVisibleInsets;
627 }
628
Craig Mautnera2c77052012-03-26 12:14:43 -0700629 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800630 public WindowManager.LayoutParams getAttrs() {
631 return mAttrs;
632 }
633
Craig Mautner812d2ca2012-09-27 15:35:34 -0700634 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800635 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
636 int index = -1;
637 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700638 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800639 while (true) {
640 if ((ws.mAttrs.privateFlags
641 & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
642 return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
643 }
644 // If we reached the bottom of the range of windows we are considering,
645 // assume no menu is needed.
646 if (ws == bottom) {
647 return false;
648 }
649 // The current window hasn't specified whether menu key is needed;
650 // look behind it.
651 // First, we may need to determine the starting position.
652 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700653 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800654 }
655 index--;
656 if (index < 0) {
657 return false;
658 }
Craig Mautner59c00972012-07-30 12:10:24 -0700659 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800660 }
661 }
662
Craig Mautner19d59bc2012-09-04 11:15:56 -0700663 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700664 public int getSystemUiVisibility() {
665 return mSystemUiVisibility;
666 }
667
Craig Mautner19d59bc2012-09-04 11:15:56 -0700668 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800669 public int getSurfaceLayer() {
670 return mLayer;
671 }
672
Craig Mautner812d2ca2012-09-27 15:35:34 -0700673 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800674 public IApplicationToken getAppToken() {
675 return mAppToken != null ? mAppToken.appToken : null;
676 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700677
678 public int getDisplayId() {
679 return mDisplayContent.getDisplayId();
680 }
681
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800682 public long getInputDispatchingTimeoutNanos() {
683 return mAppToken != null
684 ? mAppToken.inputDispatchingTimeoutNanos
685 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
686 }
687
Craig Mautnere8552142012-11-07 13:55:47 -0800688 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800689 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700690 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800691 }
692
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800693 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
694 if (dsdx < .99999f || dsdx > 1.00001f) return false;
695 if (dtdy < .99999f || dtdy > 1.00001f) return false;
696 if (dtdx < -.000001f || dtdx > .000001f) return false;
697 if (dsdy < -.000001f || dsdy > .000001f) return false;
698 return true;
699 }
700
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400701 void prelayout() {
702 if (mEnforceSizeCompat) {
703 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700704 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400705 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700706 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400707 }
708 }
709
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800710 /**
711 * Is this window visible? It is not visible if there is no
712 * surface, or we are in the process of running an exit animation
713 * that will remove the surface, or its app token has been hidden.
714 */
Craig Mautner88400d32012-09-30 12:35:45 -0700715 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800716 public boolean isVisibleLw() {
717 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700718 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800719 && (atoken == null || !atoken.hiddenRequested)
720 && !mExiting && !mDestroying;
721 }
722
723 /**
724 * Like {@link #isVisibleLw}, but also counts a window that is currently
725 * "hidden" behind the keyguard as visible. This allows us to apply
726 * things like window flags that impact the keyguard.
727 * XXX I am starting to think we need to have ANOTHER visibility flag
728 * for this "hidden behind keyguard" state rather than overloading
729 * mPolicyVisibility. Ungh.
730 */
Craig Mautner88400d32012-09-30 12:35:45 -0700731 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800732 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700733 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800734 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700735 return false;
736 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800737 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700738 final boolean animating = atoken != null
Craig Mautner59431632012-04-04 11:56:44 -0700739 ? (atoken.mAppAnimator.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700740 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800741 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700742 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
743 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700744 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800745 }
746
747 /**
748 * Is this window visible, ignoring its app token? It is not visible
749 * if there is no surface, or we are in the process of running an exit animation
750 * that will remove the surface.
751 */
752 public boolean isWinVisibleLw() {
753 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700754 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -0700755 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800756 && !mExiting && !mDestroying;
757 }
758
759 /**
760 * The same as isVisible(), but follows the current hidden state of
761 * the associated app token, not the pending requested hidden state.
762 */
763 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700764 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800765 && !mRootToken.hidden && !mExiting && !mDestroying;
766 }
767
768 /**
769 * Can this window possibly be a drag/drop target? The test here is
770 * a combination of the above "visible now" with the check that the
771 * Input Manager uses when discarding windows from input consideration.
772 */
773 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700774 return isVisibleNow() && !mRemoved
775 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800776 }
777
778 /**
779 * Same as isVisible(), but we also count it as visible between the
780 * call to IWindowSession.add() and the first relayout().
781 */
782 boolean isVisibleOrAdding() {
783 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700784 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800785 && mPolicyVisibility && !mAttachedHidden
786 && (atoken == null || !atoken.hiddenRequested)
787 && !mExiting && !mDestroying;
788 }
789
790 /**
791 * Is this window currently on-screen? It is on-screen either if it
792 * is visible or it is currently running an animation before no longer
793 * being visible.
794 */
795 boolean isOnScreen() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700796 if (!mHasSurface || !mPolicyVisibility || mDestroying) {
797 return false;
798 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800799 final AppWindowToken atoken = mAppToken;
800 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700801 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800802 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800803 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700804 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800805 }
806
807 /**
808 * Like isOnScreen(), but we don't return true if the window is part
809 * of a transition that has not yet been started.
810 */
811 boolean isReadyForDisplay() {
812 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -0800813 mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800814 return false;
815 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700816 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800817 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
818 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700819 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -0700820 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800821 }
822
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800823 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700824 * Like isReadyForDisplay(), but ignores any force hiding of the window due
825 * to the keyguard.
826 */
827 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800828 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700829 return false;
830 }
831 final AppWindowToken atoken = mAppToken;
832 if (atoken == null && !mPolicyVisibility) {
833 // If this is not an app window, and the policy has asked to force
834 // hide, then we really do want to hide.
835 return false;
836 }
837 return mHasSurface && !mDestroying
838 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
839 && !mRootToken.hidden)
840 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -0700841 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
842 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -0700843 }
844
845 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800846 * Like isOnScreen, but returns false if the surface hasn't yet
847 * been drawn.
848 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700849 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800850 public boolean isDisplayedLw() {
851 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700852 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800853 && ((!mAttachedHidden &&
854 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700855 || mWinAnimator.mAnimating
856 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800857 }
858
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700859 /**
Craig Mautnerae446592012-12-06 19:05:05 -0800860 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700861 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -0700862 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700863 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -0800864 return mWinAnimator.mAnimation != null
865 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700866 }
867
Craig Mautner812d2ca2012-09-27 15:35:34 -0700868 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800869 public boolean isGoneForLayoutLw() {
870 final AppWindowToken atoken = mAppToken;
871 return mViewVisibility == View.GONE
872 || !mRelayoutCalled
873 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -0700874 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800875 || mAttachedHidden
876 || mExiting || mDestroying;
877 }
878
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800879 /**
880 * Returns true if the window has a surface that it has drawn a
881 * complete UI in to.
882 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -0800883 public boolean isDrawFinishedLw() {
884 return mHasSurface && !mDestroying &&
885 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
886 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
887 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
888 }
889
890 /**
891 * Returns true if the window has a surface that it has drawn a
892 * complete UI in to.
893 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800894 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700895 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -0700896 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
897 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800898 }
899
900 /**
901 * Return true if the window is opaque and fully drawn. This indicates
902 * it may obscure windows behind it.
903 */
904 boolean isOpaqueDrawn() {
905 return (mAttrs.format == PixelFormat.OPAQUE
906 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -0700907 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -0700908 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800909 }
910
911 /**
912 * Return whether this window is wanting to have a translation
913 * animation applied to it for an in-progress move. (Only makes
914 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
915 */
916 boolean shouldAnimateMove() {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700917 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800918 && (mFrame.top != mLastFrame.top
919 || mFrame.left != mLastFrame.left)
Craig Mautner2fb98b12012-03-20 17:24:00 -0700920 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800921 }
922
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800923 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700924 return mFrame.left <= 0 && mFrame.top <= 0 &&
925 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800926 }
927
Craig Mautner812d2ca2012-09-27 15:35:34 -0700928 boolean isConfigChanged() {
Craig Mautnere8552142012-11-07 13:55:47 -0800929 boolean configChanged = mConfiguration != mService.mCurConfiguration
Craig Mautner812d2ca2012-09-27 15:35:34 -0700930 && (mConfiguration == null
931 || (mConfiguration.diff(mService.mCurConfiguration) != 0));
Craig Mautnere8552142012-11-07 13:55:47 -0800932
933 if (mAttrs.type == TYPE_KEYGUARD) {
934 // Retain configuration changed status until resetConfiguration called.
935 mConfigHasChanged |= configChanged;
936 configChanged = mConfigHasChanged;
937 }
938
939 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -0700940 }
941
942 boolean isConfigDiff(int mask) {
943 return mConfiguration != mService.mCurConfiguration
944 && mConfiguration != null
945 && (mConfiguration.diff(mService.mCurConfiguration) & mask) != 0;
946 }
947
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800948 void removeLocked() {
949 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800950
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800951 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700952 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800953 mAttachedWindow.mChildWindows.remove(this);
954 }
Craig Mautner96868332012-12-04 14:29:11 -0800955 mWinAnimator.destroyDeferredSurfaceLocked();
956 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800957 mSession.windowRemovedLocked();
958 try {
959 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
960 } catch (RuntimeException e) {
961 // Ignore if it has already been removed (usually because
962 // we are doing this as part of processing a death note.)
963 }
964 }
Jeff Browncc4f7db2011-08-30 20:34:48 -0700965
Craig Mautnere8552142012-11-07 13:55:47 -0800966 void setConfiguration(final Configuration newConfig) {
967 mConfiguration = newConfig;
968 mConfigHasChanged = false;
969 }
970
Jeff Browncc4f7db2011-08-30 20:34:48 -0700971 void setInputChannel(InputChannel inputChannel) {
972 if (mInputChannel != null) {
973 throw new IllegalStateException("Window already has an input channel.");
974 }
975
976 mInputChannel = inputChannel;
977 mInputWindowHandle.inputChannel = inputChannel;
978 }
979
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800980 void disposeInputChannel() {
981 if (mInputChannel != null) {
982 mService.mInputManager.unregisterInputChannel(mInputChannel);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800983
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800984 mInputChannel.dispose();
985 mInputChannel = null;
986 }
Jeff Browncc4f7db2011-08-30 20:34:48 -0700987
988 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800989 }
990
991 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -0800992 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800993 public void binderDied() {
994 try {
995 synchronized(mService.mWindowMap) {
996 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -0700997 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800998 if (win != null) {
999 mService.removeWindowLocked(mSession, win);
Craig Mautnera99764e2013-03-06 10:22:16 -08001000 } else if (WindowState.this.mHasSurface) {
1001 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
1002 mService.removeWindowLocked(mSession, WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001003 }
1004 }
1005 } catch (IllegalArgumentException ex) {
1006 // This will happen if the window has already been
1007 // removed.
1008 }
1009 }
1010 }
1011
Craig Mautner58106812012-12-28 12:27:40 -08001012 /**
1013 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001014 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001015 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001016 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001017 && (mViewVisibility == View.VISIBLE)
1018 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1019 }
1020
Craig Mautner749a7bb2012-04-02 13:49:53 -07001021 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001022 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001023 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001024 }
1025
Craig Mautner749a7bb2012-04-02 13:49:53 -07001026 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001027 public boolean showLw(boolean doAnimation) {
1028 return showLw(doAnimation, true);
1029 }
1030
1031 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001032 if (isHiddenFromUserLocked()) {
Craig Mautner88400d32012-09-30 12:35:45 -07001033 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
Craig Mautnera2d7b112012-08-21 15:12:20 -07001034 + this + ", type " + mAttrs.type + ", belonging to " + mOwnerUid);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001035 return false;
1036 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001037 if (!mAppOpVisibility) {
1038 // Being hidden due to app op request.
1039 return false;
1040 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001041 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001042 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001043 return false;
1044 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001045 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001046 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001047 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001048 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001049 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001050 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001051 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001052 // Check for the case where we are currently visible and
1053 // not animating; we do not want to do animation at such a
1054 // point to become visible when we already are.
1055 doAnimation = false;
1056 }
1057 }
1058 mPolicyVisibility = true;
1059 mPolicyVisibilityAfterAnim = true;
1060 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001061 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001062 }
1063 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001064 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001065 }
1066 return true;
1067 }
1068
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001069 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001070 public boolean hideLw(boolean doAnimation) {
1071 return hideLw(doAnimation, true);
1072 }
1073
1074 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1075 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001076 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001077 doAnimation = false;
1078 }
1079 }
1080 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1081 : mPolicyVisibility;
1082 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001083 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001084 return false;
1085 }
1086 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001087 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001088 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001089 doAnimation = false;
1090 }
1091 }
1092 if (doAnimation) {
1093 mPolicyVisibilityAfterAnim = false;
1094 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001095 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001096 mPolicyVisibilityAfterAnim = false;
1097 mPolicyVisibility = false;
1098 // Window is no longer visible -- make sure if we were waiting
1099 // for it to be displayed before enabling the display, that
1100 // we allow the display to be enabled now.
1101 mService.enableScreenIfNeededLocked();
1102 if (mService.mCurrentFocus == this) {
1103 mService.mFocusMayChange = true;
1104 }
1105 }
1106 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001107 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001108 }
1109 return true;
1110 }
1111
Craig Mautner2ad92072013-02-25 16:19:24 -08001112 public boolean setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001113 if (mAppOpVisibility != state) {
1114 mAppOpVisibility = state;
1115 if (state) {
1116 // If the policy visibility had last been to hide, then this
1117 // will incorrectly show at this point since we lost that
1118 // information. Not a big deal -- for the windows that have app
1119 // ops modifies they should only be hidden by policy due to the
1120 // lock screen, and the user won't be changing this if locked.
1121 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautner2ad92072013-02-25 16:19:24 -08001122 showLw(true, false);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001123 } else {
Craig Mautner2ad92072013-02-25 16:19:24 -08001124 hideLw(true, false);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001125 }
Craig Mautner2ad92072013-02-25 16:19:24 -08001126 return true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001127 }
Craig Mautner2ad92072013-02-25 16:19:24 -08001128 return false;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001129 }
1130
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001131 @Override
1132 public boolean isAlive() {
1133 return mClient.asBinder().isBinderAlive();
1134 }
1135
Craig Mautnera987d432012-10-11 14:07:58 -07001136 boolean isClosing() {
1137 return mExiting || (mService.mClosingApps.contains(mAppToken));
1138 }
1139
Craig Mautner69b08182012-09-05 13:07:13 -07001140 @Override
1141 public boolean isDefaultDisplay() {
1142 return mDisplayContent.isDefaultDisplay;
1143 }
1144
Craig Mautner88400d32012-09-30 12:35:45 -07001145 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1146 mShowToOwnerOnly = showToOwnerOnly;
1147 }
1148
Craig Mautner5962b122012-10-05 14:45:52 -07001149 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001150 // Attached windows are evaluated based on the window that they are attached to.
1151 WindowState win = this;
1152 while (win.mAttachedWindow != null) {
1153 win = win.mAttachedWindow;
1154 }
1155 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1156 && win.mAppToken != null && win.mAppToken.showWhenLocked) {
1157 // Save some cycles by not calling getDisplayInfo unless it is an application
1158 // window intended for all users.
1159 final DisplayInfo displayInfo = win.mDisplayContent.getDisplayInfo();
1160 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1161 && win.mFrame.right >= displayInfo.appWidth
1162 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001163 // Is a fullscreen window, like the clock alarm. Show to everyone.
1164 return false;
1165 }
1166 }
1167
Craig Mautner341220f2012-10-16 15:20:09 -07001168 return win.mShowToOwnerOnly
1169 && UserHandle.getUserId(win.mOwnerUid) != mService.mCurrentUserId;
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001170 }
1171
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001172 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1173 outRegion.set(
1174 frame.left + inset.left, frame.top + inset.top,
1175 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001176 }
1177
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001178 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001179 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001180 switch (mTouchableInsets) {
1181 default:
1182 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1183 outRegion.set(frame);
1184 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001185 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001186 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001187 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001188 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001189 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001190 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001191 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1192 final Region givenTouchableRegion = mGivenTouchableRegion;
1193 outRegion.set(givenTouchableRegion);
1194 outRegion.translate(frame.left, frame.top);
1195 break;
1196 }
1197 }
1198 }
1199
Craig Mautner59c00972012-07-30 12:10:24 -07001200 WindowList getWindowList() {
1201 return mDisplayContent.getWindowList();
1202 }
1203
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001204 /**
1205 * Report a focus change. Must be called with no locks held, and consistently
1206 * from the same serialized thread (such as dispatched from a handler).
1207 */
1208 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1209 try {
1210 mClient.windowFocusChanged(focused, inTouchMode);
1211 } catch (RemoteException e) {
1212 }
1213 if (mFocusCallbacks != null) {
1214 final int N = mFocusCallbacks.beginBroadcast();
1215 for (int i=0; i<N; i++) {
1216 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1217 try {
1218 if (focused) {
1219 obs.focusGained(mWindowId.asBinder());
1220 } else {
1221 obs.focusLost(mWindowId.asBinder());
1222 }
1223 } catch (RemoteException e) {
1224 }
1225 }
1226 mFocusCallbacks.finishBroadcast();
1227 }
1228 }
1229
1230 public void registerFocusObserver(IWindowFocusObserver observer) {
1231 synchronized(mService.mWindowMap) {
1232 if (mFocusCallbacks == null) {
1233 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1234 }
1235 mFocusCallbacks.register(observer);
1236 }
1237 }
1238
1239 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1240 synchronized(mService.mWindowMap) {
1241 if (mFocusCallbacks != null) {
1242 mFocusCallbacks.unregister(observer);
1243 }
1244 }
1245 }
1246
1247 public boolean isFocused() {
1248 synchronized(mService.mWindowMap) {
1249 return mService.mCurrentFocus == this;
1250 }
1251 }
1252
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001253 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Craig Mautner59c00972012-07-30 12:10:24 -07001254 pw.print(prefix); pw.print("mDisplayId="); pw.print(mDisplayContent.getDisplayId());
1255 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001256 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001257 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001258 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1259 pw.print(" package="); pw.print(mAttrs.packageName);
1260 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001261 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001262 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1263 pw.print(" h="); pw.print(mRequestedHeight);
1264 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001265 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1266 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1267 pw.print(" h="); pw.println(mLastRequestedHeight);
1268 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001269 if (mAttachedWindow != null || mLayoutAttached) {
1270 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1271 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1272 }
1273 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1274 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1275 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1276 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1277 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1278 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001279 if (dumpAll) {
1280 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1281 pw.print(" mSubLayer="); pw.print(mSubLayer);
1282 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001283 pw.print((mTargetAppToken != null ?
1284 mTargetAppToken.mAppAnimator.animLayerAdjustment
1285 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001286 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1287 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001288 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001289 if (dumpAll) {
1290 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1291 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1292 if (mAppToken != null) {
1293 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1294 }
1295 if (mTargetAppToken != null) {
1296 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1297 }
1298 pw.print(prefix); pw.print("mViewVisibility=0x");
1299 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001300 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1301 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001302 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1303 pw.print(" mSystemUiVisibility=0x");
1304 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001305 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001306 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1307 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001308 pw.print(prefix); pw.print("mPolicyVisibility=");
1309 pw.print(mPolicyVisibility);
1310 pw.print(" mPolicyVisibilityAfterAnim=");
1311 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001312 pw.print(" mAppOpVisibility=");
1313 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001314 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1315 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08001316 if (!mRelayoutCalled || mLayoutNeeded) {
1317 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
1318 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001319 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001320 if (mXOffset != 0 || mYOffset != 0) {
1321 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1322 pw.print(" y="); pw.println(mYOffset);
1323 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001324 if (dumpAll) {
1325 pw.print(prefix); pw.print("mGivenContentInsets=");
1326 mGivenContentInsets.printShortString(pw);
1327 pw.print(" mGivenVisibleInsets=");
1328 mGivenVisibleInsets.printShortString(pw);
1329 pw.println();
1330 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1331 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1332 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001333 Region region = new Region();
1334 getTouchableRegion(region);
1335 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001336 }
1337 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001338 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001339 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Craig Mautner178af592012-09-17 10:37:29 -07001340 pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
1341 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001342 if (dumpAll) {
1343 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1344 pw.print(" last="); mLastFrame.printShortString(pw);
1345 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001346 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1347 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1348 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001349 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001350 if (mEnforceSizeCompat) {
1351 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001352 pw.println();
1353 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001354 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001355 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001356 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001357 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001358 pw.println();
1359 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
1360 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001361 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001362 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001363 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001364 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001365 pw.print(prefix); pw.print("Cur insets: overscan=");
1366 mOverscanInsets.printShortString(pw);
1367 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001368 pw.print(" visible="); mVisibleInsets.printShortString(pw);
1369 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001370 pw.print(prefix); pw.print("Lst insets: overscan=");
1371 mLastOverscanInsets.printShortString(pw);
1372 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001373 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001374 pw.println();
1375 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07001376 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
1377 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001378 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1379 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1380 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1381 pw.print(" mDestroying="); pw.print(mDestroying);
1382 pw.print(" mRemoved="); pw.println(mRemoved);
1383 }
1384 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1385 pw.print(prefix); pw.print("mOrientationChanging=");
1386 pw.print(mOrientationChanging);
1387 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1388 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1389 }
1390 if (mHScale != 1 || mVScale != 1) {
1391 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1392 pw.print(" mVScale="); pw.println(mVScale);
1393 }
1394 if (mWallpaperX != -1 || mWallpaperY != -1) {
1395 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1396 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1397 }
1398 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1399 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1400 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1401 }
1402 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001403
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001404 String makeInputChannelName() {
1405 return Integer.toHexString(System.identityHashCode(this))
1406 + " " + mAttrs.getTitle();
1407 }
1408
1409 @Override
1410 public String toString() {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001411 CharSequence title = mAttrs.getTitle();
1412 if (title == null || title.length() <= 0) {
1413 title = mAttrs.packageName;
1414 }
1415 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
1416 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07001417 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001418 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07001419 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07001420 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001421 }
1422 return mStringNameCache;
1423 }
satokcef37fb2011-10-24 21:49:38 +09001424}