blob: d65b947f597bc03bec77a3f87018164cca6358b6 [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;
24import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
25
Jeff Brown4532e612012-04-05 14:27:12 -070026import com.android.server.input.InputWindowHandle;
27
Craig Mautnere7ae2502012-03-26 17:11:19 -070028import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080029import android.content.res.Configuration;
30import android.graphics.Matrix;
31import android.graphics.PixelFormat;
32import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070033import android.graphics.RectF;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080034import android.graphics.Region;
35import android.os.IBinder;
36import android.os.RemoteException;
37import android.util.Slog;
38import android.view.Gravity;
39import android.view.IApplicationToken;
40import android.view.IWindow;
41import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042import android.view.View;
43import android.view.ViewTreeObserver;
44import android.view.WindowManager;
45import android.view.WindowManagerPolicy;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080046
47import java.io.PrintWriter;
48import java.util.ArrayList;
49
50/**
51 * A window in the window manager.
52 */
Craig Mautnere32c3072012-03-12 15:25:35 -070053final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070054 static final String TAG = "WindowState";
55
Dianne Hackborn5fd21692011-06-07 14:09:47 -070056 static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
57 static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
Dianne Hackborn36991742011-10-11 21:35:26 -070058 static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
Dianne Hackborn5fd21692011-06-07 14:09:47 -070059 static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
60
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -070062 final WindowManagerPolicy mPolicy;
63 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064 final Session mSession;
65 final IWindow mClient;
66 WindowToken mToken;
67 WindowToken mRootToken;
68 AppWindowToken mAppToken;
69 AppWindowToken mTargetAppToken;
70 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
71 final DeathRecipient mDeathRecipient;
72 final WindowState mAttachedWindow;
73 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
74 final int mBaseLayer;
75 final int mSubLayer;
76 final boolean mLayoutAttached;
77 final boolean mIsImWindow;
78 final boolean mIsWallpaper;
79 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -070080 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -070081 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080082 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -070083 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080084 boolean mPolicyVisibility = true;
85 boolean mPolicyVisibilityAfterAnim = true;
86 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080087 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080088 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Dianne Hackbornffb3d932011-05-17 17:44:51 -070089
90 /**
91 * The window size that was requested by the application. These are in
92 * the application's coordinate space (without compatibility scale applied).
93 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080094 int mRequestedWidth;
95 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -070096 int mLastRequestedWidth;
97 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -070098
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100 boolean mHaveFrame;
101 boolean mObscured;
102 boolean mTurnOnScreen;
103
104 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700105
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 Configuration mConfiguration = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700107
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700108 /**
109 * Actual frame shown on-screen (may be modified by animation). These
110 * are in the screen's coordinate space (WITH the compatibility scale
111 * applied).
112 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700113 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114
115 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700116 * Insets that determine the actually visible area. These are in the application's
117 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800118 */
119 final Rect mVisibleInsets = new Rect();
120 final Rect mLastVisibleInsets = new Rect();
121 boolean mVisibleInsetsChanged;
122
123 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700124 * Insets that are covered by system windows. These are in the application's
125 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 */
127 final Rect mContentInsets = new Rect();
128 final Rect mLastContentInsets = new Rect();
129 boolean mContentInsetsChanged;
130
131 /**
132 * Set to true if we are waiting for this window to receive its
133 * given internal insets before laying out other windows based on it.
134 */
135 boolean mGivenInsetsPending;
136
137 /**
138 * These are the content insets that were given during layout for
139 * this window, to be applied to windows behind it.
140 */
141 final Rect mGivenContentInsets = new Rect();
142
143 /**
144 * These are the visible insets that were given during layout for
145 * this window, to be applied to windows behind it.
146 */
147 final Rect mGivenVisibleInsets = new Rect();
148
149 /**
150 * This is the given touchable area relative to the window frame, or null if none.
151 */
152 final Region mGivenTouchableRegion = new Region();
153
154 /**
155 * Flag indicating whether the touchable region should be adjusted by
156 * the visible insets; if false the area outside the visible insets is
157 * NOT touchable, so we must use those to adjust the frame during hit
158 * tests.
159 */
160 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
161
162 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400163 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700164 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 float mHScale=1, mVScale=1;
166 float mLastHScale=1, mLastVScale=1;
167 final Matrix mTmpMatrix = new Matrix();
168
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700169 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 final Rect mFrame = new Rect();
171 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700172 // Frame that is scaled to the application's coordinate space when in
173 // screen size compatibility mode.
174 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175
176 final Rect mContainingFrame = new Rect();
177 final Rect mDisplayFrame = new Rect();
178 final Rect mContentFrame = new Rect();
179 final Rect mParentFrame = new Rect();
180 final Rect mVisibleFrame = new Rect();
181
182 boolean mContentChanged;
183
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 // If a window showing a wallpaper: the requested offset for the
185 // wallpaper; if a wallpaper window: the currently applied offset.
186 float mWallpaperX = -1;
187 float mWallpaperY = -1;
188
189 // If a window showing a wallpaper: what fraction of the offset
190 // range corresponds to a full virtual screen.
191 float mWallpaperXStep = -1;
192 float mWallpaperYStep = -1;
193
194 // Wallpaper windows: pixels offset based on above variables.
195 int mXOffset;
196 int mYOffset;
197
198 // This is set after IWindowSession.relayout() has been called at
199 // least once for the window. It allows us to detect the situation
200 // where we don't yet have a surface, but should have one soon, so
201 // we can give the window focus before waiting for the relayout.
202 boolean mRelayoutCalled;
203
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800204 // If the application has called relayout() with changes that can
205 // impact its window's size, we need to perform a layout pass on it
206 // even if it is not currently visible for layout. This is set
207 // when in that case until the layout is done.
208 boolean mLayoutNeeded;
209
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800210 // Currently running an exit animation?
211 boolean mExiting;
212
213 // Currently on the mDestroySurface list?
214 boolean mDestroying;
215
216 // Completely remove from window manager after exit animation?
217 boolean mRemoveOnExit;
218
219 // Set when the orientation is changing and this window has not yet
220 // been updated for the new orientation.
221 boolean mOrientationChanging;
222
223 // Is this window now (or just being) removed?
224 boolean mRemoved;
225
226 // Temp for keeping track of windows that have been removed when
227 // rebuilding window list.
228 boolean mRebuilding;
229
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700231 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 InputChannel mInputChannel;
233
234 // Used to improve performance of toString()
235 String mStringNameCache;
236 CharSequence mLastTitle;
237 boolean mWasPaused;
238
Craig Mautnera2c77052012-03-26 12:14:43 -0700239 final WindowStateAnimator mWinAnimator;
240
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700241 boolean mHasSurface = false;
242
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700244 WindowState attachedWindow, int seq, WindowManager.LayoutParams a,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 int viewVisibility) {
246 mService = service;
247 mSession = s;
248 mClient = c;
249 mToken = token;
250 mAttrs.copyFrom(a);
251 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700252 mPolicy = mService.mPolicy;
253 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700255 mSeq = seq;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400256 mEnforceSizeCompat = (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700258 TAG, "Window " + this + " client=" + c.asBinder()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259 + " token=" + token + " (" + mAttrs.token + ")");
260 try {
261 c.asBinder().linkToDeath(deathRecipient, 0);
262 } catch (RemoteException e) {
263 mDeathRecipient = null;
264 mAttachedWindow = null;
265 mLayoutAttached = false;
266 mIsImWindow = false;
267 mIsWallpaper = false;
268 mIsFloatingLayer = false;
269 mBaseLayer = 0;
270 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700271 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700272 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800273 return;
274 }
275 mDeathRecipient = deathRecipient;
276
277 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
278 mAttrs.type <= LAST_SUB_WINDOW)) {
279 // The multiplier here is to reserve space for multiple
280 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700281 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
283 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700284 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 mAttachedWindow = attachedWindow;
Craig Mautnerd87946b2012-03-29 18:00:19 -0700286 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 mAttachedWindow.mChildWindows.add(this);
288 mLayoutAttached = mAttrs.type !=
289 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
290 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
291 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
292 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
293 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
294 } else {
295 // The multiplier here is to reserve space for multiple
296 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700297 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298 * WindowManagerService.TYPE_LAYER_MULTIPLIER
299 + WindowManagerService.TYPE_LAYER_OFFSET;
300 mSubLayer = 0;
301 mAttachedWindow = null;
302 mLayoutAttached = false;
303 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
304 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
305 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
306 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
307 }
308
Craig Mautnera2c77052012-03-26 12:14:43 -0700309 mWinAnimator = new WindowStateAnimator(service, this, mAttachedWindow);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700310 mWinAnimator.mAlpha = a.alpha;
Craig Mautnera2c77052012-03-26 12:14:43 -0700311
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312 WindowState appWin = this;
313 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700314 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315 }
316 WindowToken appToken = appWin.mToken;
317 while (appToken.appWindowToken == null) {
318 WindowToken parent = mService.mTokenMap.get(appToken.token);
319 if (parent == null || appToken == parent) {
320 break;
321 }
322 appToken = parent;
323 }
324 mRootToken = appToken;
325 mAppToken = appToken.appWindowToken;
326
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800327 mRequestedWidth = 0;
328 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700329 mLastRequestedWidth = 0;
330 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 mXOffset = 0;
332 mYOffset = 0;
333 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 mInputWindowHandle = new InputWindowHandle(
335 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
336 }
337
338 void attach() {
339 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700340 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800341 + ", list=" + mToken.windows);
342 mSession.windowAddedLocked();
343 }
344
Craig Mautnera2c77052012-03-26 12:14:43 -0700345 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800346 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
347 mHaveFrame = true;
348
349 final Rect container = mContainingFrame;
350 container.set(pf);
351
352 final Rect display = mDisplayFrame;
353 display.set(df);
354
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355 final int pw = container.right - container.left;
356 final int ph = container.bottom - container.top;
357
358 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700359 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
360 if (mAttrs.width < 0) {
361 w = pw;
362 } else if (mEnforceSizeCompat) {
363 w = (int)(mAttrs.width * mGlobalScale + .5f);
364 } else {
365 w = mAttrs.width;
366 }
367 if (mAttrs.height < 0) {
368 h = ph;
369 } else if (mEnforceSizeCompat) {
370 h = (int)(mAttrs.height * mGlobalScale + .5f);
371 } else {
372 h = mAttrs.height;
373 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800374 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700375 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
376 w = pw;
377 } else if (mEnforceSizeCompat) {
378 w = (int)(mRequestedWidth * mGlobalScale + .5f);
379 } else {
380 w = mRequestedWidth;
381 }
382 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
383 h = ph;
384 } else if (mEnforceSizeCompat) {
385 h = (int)(mRequestedHeight * mGlobalScale + .5f);
386 } else {
387 h = mRequestedHeight;
388 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800389 }
390
391 if (!mParentFrame.equals(pf)) {
392 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
393 // + " to " + pf);
394 mParentFrame.set(pf);
395 mContentChanged = true;
396 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700397 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
398 mLastRequestedWidth = mRequestedWidth;
399 mLastRequestedHeight = mRequestedHeight;
400 mContentChanged = true;
401 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402
403 final Rect content = mContentFrame;
404 content.set(cf);
405
406 final Rect visible = mVisibleFrame;
407 visible.set(vf);
408
409 final Rect frame = mFrame;
410 final int fw = frame.width();
411 final int fh = frame.height();
412
413 //System.out.println("In: w=" + w + " h=" + h + " container=" +
414 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
415
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700416 float x, y;
417 if (mEnforceSizeCompat) {
418 x = mAttrs.x * mGlobalScale;
419 y = mAttrs.y * mGlobalScale;
420 } else {
421 x = mAttrs.x;
422 y = mAttrs.y;
423 }
424
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800425 Gravity.apply(mAttrs.gravity, w, h, container,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700426 (int) (x + mAttrs.horizontalMargin * pw),
427 (int) (y + mAttrs.verticalMargin * ph), frame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800428
429 //System.out.println("Out: " + mFrame);
430
431 // Now make sure the window fits in the overall display.
432 Gravity.applyDisplay(mAttrs.gravity, df, frame);
433
434 // Make sure the content and visible frames are inside of the
435 // final window frame.
436 if (content.left < frame.left) content.left = frame.left;
437 if (content.top < frame.top) content.top = frame.top;
438 if (content.right > frame.right) content.right = frame.right;
439 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
440 if (visible.left < frame.left) visible.left = frame.left;
441 if (visible.top < frame.top) visible.top = frame.top;
442 if (visible.right > frame.right) visible.right = frame.right;
443 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
444
445 final Rect contentInsets = mContentInsets;
446 contentInsets.left = content.left-frame.left;
447 contentInsets.top = content.top-frame.top;
448 contentInsets.right = frame.right-content.right;
449 contentInsets.bottom = frame.bottom-content.bottom;
450
451 final Rect visibleInsets = mVisibleInsets;
452 visibleInsets.left = visible.left-frame.left;
453 visibleInsets.top = visible.top-frame.top;
454 visibleInsets.right = frame.right-visible.right;
455 visibleInsets.bottom = frame.bottom-visible.bottom;
456
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700457 mCompatFrame.set(frame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400458 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700459 // If there is a size compatibility scale being applied to the
460 // window, we need to apply this to its insets so that they are
461 // reported to the app in its coordinate space.
462 contentInsets.scale(mInvGlobalScale);
463 visibleInsets.scale(mInvGlobalScale);
464
465 // Also the scaled frame that we report to the app needs to be
466 // adjusted to be in its coordinate space.
467 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400468 }
469
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800470 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
Jeff Brownbc68a592011-07-25 12:58:12 -0700471 mService.updateWallpaperOffsetLocked(this,
472 mService.mAppDisplayWidth, mService.mAppDisplayHeight, false);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473 }
474
475 if (WindowManagerService.localLOGV) {
476 //if ("com.google.android.youtube".equals(mAttrs.packageName)
477 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700478 Slog.v(TAG, "Resolving (mRequestedWidth="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800479 + mRequestedWidth + ", mRequestedheight="
480 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
481 + "): frame=" + mFrame.toShortString()
482 + " ci=" + contentInsets.toShortString()
483 + " vi=" + visibleInsets.toShortString());
484 //}
485 }
486 }
487
Craig Mautnera2c77052012-03-26 12:14:43 -0700488 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 public Rect getFrameLw() {
490 return mFrame;
491 }
492
Craig Mautnera2c77052012-03-26 12:14:43 -0700493 @Override
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700494 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800495 return mShownFrame;
496 }
497
Craig Mautnera2c77052012-03-26 12:14:43 -0700498 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800499 public Rect getDisplayFrameLw() {
500 return mDisplayFrame;
501 }
502
Craig Mautnera2c77052012-03-26 12:14:43 -0700503 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800504 public Rect getContentFrameLw() {
505 return mContentFrame;
506 }
507
Craig Mautnera2c77052012-03-26 12:14:43 -0700508 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800509 public Rect getVisibleFrameLw() {
510 return mVisibleFrame;
511 }
512
Craig Mautnera2c77052012-03-26 12:14:43 -0700513 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800514 public boolean getGivenInsetsPendingLw() {
515 return mGivenInsetsPending;
516 }
517
Craig Mautnera2c77052012-03-26 12:14:43 -0700518 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519 public Rect getGivenContentInsetsLw() {
520 return mGivenContentInsets;
521 }
522
Craig Mautnera2c77052012-03-26 12:14:43 -0700523 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800524 public Rect getGivenVisibleInsetsLw() {
525 return mGivenVisibleInsets;
526 }
527
Craig Mautnera2c77052012-03-26 12:14:43 -0700528 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800529 public WindowManager.LayoutParams getAttrs() {
530 return mAttrs;
531 }
532
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800533 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
534 int index = -1;
535 WindowState ws = this;
536 while (true) {
537 if ((ws.mAttrs.privateFlags
538 & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
539 return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
540 }
541 // If we reached the bottom of the range of windows we are considering,
542 // assume no menu is needed.
543 if (ws == bottom) {
544 return false;
545 }
546 // The current window hasn't specified whether menu key is needed;
547 // look behind it.
548 // First, we may need to determine the starting position.
549 if (index < 0) {
550 index = mService.mWindows.indexOf(ws);
551 }
552 index--;
553 if (index < 0) {
554 return false;
555 }
556 ws = mService.mWindows.get(index);
557 }
558 }
559
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700560 public int getSystemUiVisibility() {
561 return mSystemUiVisibility;
562 }
563
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800564 public int getSurfaceLayer() {
565 return mLayer;
566 }
567
568 public IApplicationToken getAppToken() {
569 return mAppToken != null ? mAppToken.appToken : null;
570 }
571
572 public long getInputDispatchingTimeoutNanos() {
573 return mAppToken != null
574 ? mAppToken.inputDispatchingTimeoutNanos
575 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
576 }
577
578 public boolean hasAppShownWindows() {
579 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
580 }
581
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800582 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
583 if (dsdx < .99999f || dsdx > 1.00001f) return false;
584 if (dtdy < .99999f || dtdy > 1.00001f) return false;
585 if (dtdx < -.000001f || dtdx > .000001f) return false;
586 if (dsdy < -.000001f || dsdy > .000001f) return false;
587 return true;
588 }
589
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400590 void prelayout() {
591 if (mEnforceSizeCompat) {
592 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700593 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400594 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700595 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400596 }
597 }
598
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800599 /**
600 * Is this window visible? It is not visible if there is no
601 * surface, or we are in the process of running an exit animation
602 * that will remove the surface, or its app token has been hidden.
603 */
604 public boolean isVisibleLw() {
605 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700606 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800607 && (atoken == null || !atoken.hiddenRequested)
608 && !mExiting && !mDestroying;
609 }
610
611 /**
612 * Like {@link #isVisibleLw}, but also counts a window that is currently
613 * "hidden" behind the keyguard as visible. This allows us to apply
614 * things like window flags that impact the keyguard.
615 * XXX I am starting to think we need to have ANOTHER visibility flag
616 * for this "hidden behind keyguard" state rather than overloading
617 * mPolicyVisibility. Ungh.
618 */
619 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700620 if (mRootToken.waitingToShow &&
621 mService.mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
622 return false;
623 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800624 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700625 final boolean animating = atoken != null
626 ? (atoken.animation != null) : false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700627 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800628 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700629 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
630 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700631 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800632 }
633
634 /**
635 * Is this window visible, ignoring its app token? It is not visible
636 * if there is no surface, or we are in the process of running an exit animation
637 * that will remove the surface.
638 */
639 public boolean isWinVisibleLw() {
640 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700641 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
643 && !mExiting && !mDestroying;
644 }
645
646 /**
647 * The same as isVisible(), but follows the current hidden state of
648 * the associated app token, not the pending requested hidden state.
649 */
650 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700651 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800652 && !mRootToken.hidden && !mExiting && !mDestroying;
653 }
654
655 /**
656 * Can this window possibly be a drag/drop target? The test here is
657 * a combination of the above "visible now" with the check that the
658 * Input Manager uses when discarding windows from input consideration.
659 */
660 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700661 return isVisibleNow() && !mRemoved
662 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800663 }
664
665 /**
666 * Same as isVisible(), but we also count it as visible between the
667 * call to IWindowSession.add() and the first relayout().
668 */
669 boolean isVisibleOrAdding() {
670 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700671 return ((mHasSurface && !mWinAnimator.mReportDestroySurface)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
673 && mPolicyVisibility && !mAttachedHidden
674 && (atoken == null || !atoken.hiddenRequested)
675 && !mExiting && !mDestroying;
676 }
677
678 /**
679 * Is this window currently on-screen? It is on-screen either if it
680 * is visible or it is currently running an animation before no longer
681 * being visible.
682 */
683 boolean isOnScreen() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700684 if (!mHasSurface || !mPolicyVisibility || mDestroying) {
685 return false;
686 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800687 final AppWindowToken atoken = mAppToken;
688 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700689 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnera2c77052012-03-26 12:14:43 -0700690 || mWinAnimator.mAnimation != null || atoken.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800691 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700692 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800693 }
694
695 /**
696 * Like isOnScreen(), but we don't return true if the window is part
697 * of a transition that has not yet been started.
698 */
699 boolean isReadyForDisplay() {
700 if (mRootToken.waitingToShow &&
701 mService.mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
702 return false;
703 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700704 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800705 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
706 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -0700707 || mWinAnimator.mAnimation != null
Craig Mautnerad3a9bb2012-03-09 11:31:06 -0800708 || ((mAppToken != null) && (mAppToken.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800709 }
710
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800711 /**
712 * Like isOnScreen, but returns false if the surface hasn't yet
713 * been drawn.
714 */
715 public boolean isDisplayedLw() {
716 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700717 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800718 && ((!mAttachedHidden &&
719 (atoken == null || !atoken.hiddenRequested))
Craig Mautnera2c77052012-03-26 12:14:43 -0700720 || mWinAnimator.mAnimating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800721 }
722
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800723 public boolean isGoneForLayoutLw() {
724 final AppWindowToken atoken = mAppToken;
725 return mViewVisibility == View.GONE
726 || !mRelayoutCalled
727 || (atoken == null && mRootToken.hidden)
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800728 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -0800729 || mAttachedHidden
730 || mExiting || mDestroying;
731 }
732
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800733 /**
734 * Returns true if the window has a surface that it has drawn a
735 * complete UI in to.
736 */
737 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700738 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -0700739 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
740 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800741 }
742
743 /**
744 * Return true if the window is opaque and fully drawn. This indicates
745 * it may obscure windows behind it.
746 */
747 boolean isOpaqueDrawn() {
748 return (mAttrs.format == PixelFormat.OPAQUE
749 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -0700750 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700751 && (mAppToken == null || mAppToken.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800752 }
753
754 /**
755 * Return whether this window is wanting to have a translation
756 * animation applied to it for an in-progress move. (Only makes
757 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
758 */
759 boolean shouldAnimateMove() {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700760 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800761 && (mFrame.top != mLastFrame.top
762 || mFrame.left != mLastFrame.left)
Craig Mautner2fb98b12012-03-20 17:24:00 -0700763 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800764 }
765
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800766 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700767 return mFrame.left <= 0 && mFrame.top <= 0 &&
768 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800769 }
770
771 void removeLocked() {
772 disposeInputChannel();
773
774 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700775 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800776 mAttachedWindow.mChildWindows.remove(this);
777 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700778 mWinAnimator.destroyDeferredSurfaceLocked();
779 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800780 mSession.windowRemovedLocked();
781 try {
782 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
783 } catch (RuntimeException e) {
784 // Ignore if it has already been removed (usually because
785 // we are doing this as part of processing a death note.)
786 }
787 }
Jeff Browncc4f7db2011-08-30 20:34:48 -0700788
789 void setInputChannel(InputChannel inputChannel) {
790 if (mInputChannel != null) {
791 throw new IllegalStateException("Window already has an input channel.");
792 }
793
794 mInputChannel = inputChannel;
795 mInputWindowHandle.inputChannel = inputChannel;
796 }
797
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800798 void disposeInputChannel() {
799 if (mInputChannel != null) {
800 mService.mInputManager.unregisterInputChannel(mInputChannel);
801
802 mInputChannel.dispose();
803 mInputChannel = null;
804 }
Jeff Browncc4f7db2011-08-30 20:34:48 -0700805
806 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800807 }
808
809 private class DeathRecipient implements IBinder.DeathRecipient {
810 public void binderDied() {
811 try {
812 synchronized(mService.mWindowMap) {
813 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -0700814 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800815 if (win != null) {
816 mService.removeWindowLocked(mSession, win);
817 }
818 }
819 } catch (IllegalArgumentException ex) {
820 // This will happen if the window has already been
821 // removed.
822 }
823 }
824 }
825
826 /** Returns true if this window desires key events. */
827 public final boolean canReceiveKeys() {
828 return isVisibleOrAdding()
829 && (mViewVisibility == View.VISIBLE)
830 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
831 }
832
Craig Mautner749a7bb2012-04-02 13:49:53 -0700833 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800834 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700835 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800836 }
837
Craig Mautner749a7bb2012-04-02 13:49:53 -0700838 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800839 public boolean showLw(boolean doAnimation) {
840 return showLw(doAnimation, true);
841 }
842
843 boolean showLw(boolean doAnimation, boolean requestAnim) {
844 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -0700845 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800846 return false;
847 }
Craig Mautnerd87946b2012-03-29 18:00:19 -0700848 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800849 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700850 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -0700851 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -0700852 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800853 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700854 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800855 // Check for the case where we are currently visible and
856 // not animating; we do not want to do animation at such a
857 // point to become visible when we already are.
858 doAnimation = false;
859 }
860 }
861 mPolicyVisibility = true;
862 mPolicyVisibilityAfterAnim = true;
863 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700864 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800865 }
866 if (requestAnim) {
Jeff Brown4a06c802012-02-15 15:06:01 -0800867 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800868 }
869 return true;
870 }
871
872 public boolean hideLw(boolean doAnimation) {
873 return hideLw(doAnimation, true);
874 }
875
876 boolean hideLw(boolean doAnimation, boolean requestAnim) {
877 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -0700878 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800879 doAnimation = false;
880 }
881 }
882 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
883 : mPolicyVisibility;
884 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -0700885 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800886 return false;
887 }
888 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700889 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -0700890 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800891 doAnimation = false;
892 }
893 }
894 if (doAnimation) {
895 mPolicyVisibilityAfterAnim = false;
896 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700897 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800898 mPolicyVisibilityAfterAnim = false;
899 mPolicyVisibility = false;
900 // Window is no longer visible -- make sure if we were waiting
901 // for it to be displayed before enabling the display, that
902 // we allow the display to be enabled now.
903 mService.enableScreenIfNeededLocked();
904 if (mService.mCurrentFocus == this) {
905 mService.mFocusMayChange = true;
906 }
907 }
908 if (requestAnim) {
Jeff Brown4a06c802012-02-15 15:06:01 -0800909 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800910 }
911 return true;
912 }
913
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700914 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
915 outRegion.set(
916 frame.left + inset.left, frame.top + inset.top,
917 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400918 }
919
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800920 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700921 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800922 switch (mTouchableInsets) {
923 default:
924 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
925 outRegion.set(frame);
926 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400927 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700928 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800929 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400930 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700931 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800932 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800933 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
934 final Region givenTouchableRegion = mGivenTouchableRegion;
935 outRegion.set(givenTouchableRegion);
936 outRegion.translate(frame.left, frame.top);
937 break;
938 }
939 }
940 }
941
Dianne Hackborna44abeb2011-08-08 19:24:01 -0700942 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800943 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
944 pw.print(" mClient="); pw.println(mClient.asBinder());
945 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -0700946 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
947 pw.print(" h="); pw.print(mRequestedHeight);
948 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -0700949 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
950 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
951 pw.print(" h="); pw.println(mLastRequestedHeight);
952 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800953 if (mAttachedWindow != null || mLayoutAttached) {
954 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
955 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
956 }
957 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
958 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
959 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
960 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
961 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
962 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -0700963 if (dumpAll) {
964 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
965 pw.print(" mSubLayer="); pw.print(mSubLayer);
966 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
967 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
968 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700969 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
970 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800971 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -0700972 if (dumpAll) {
973 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
974 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
975 if (mAppToken != null) {
976 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
977 }
978 if (mTargetAppToken != null) {
979 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
980 }
981 pw.print(prefix); pw.print("mViewVisibility=0x");
982 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -0700983 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
984 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700985 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
986 pw.print(" mSystemUiVisibility=0x");
987 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800988 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800989 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
990 pw.print(prefix); pw.print("mPolicyVisibility=");
991 pw.print(mPolicyVisibility);
992 pw.print(" mPolicyVisibilityAfterAnim=");
993 pw.print(mPolicyVisibilityAfterAnim);
994 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
995 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800996 if (!mRelayoutCalled || mLayoutNeeded) {
997 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
998 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800999 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001000 if (mXOffset != 0 || mYOffset != 0) {
1001 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1002 pw.print(" y="); pw.println(mYOffset);
1003 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001004 if (dumpAll) {
1005 pw.print(prefix); pw.print("mGivenContentInsets=");
1006 mGivenContentInsets.printShortString(pw);
1007 pw.print(" mGivenVisibleInsets=");
1008 mGivenVisibleInsets.printShortString(pw);
1009 pw.println();
1010 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1011 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1012 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
1013 }
1014 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001015 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001016 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
1017 pw.print(" mShownFrame="); mShownFrame.printShortString(pw); pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001018 if (dumpAll) {
1019 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1020 pw.print(" last="); mLastFrame.printShortString(pw);
1021 pw.println();
1022 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001023 if (mEnforceSizeCompat) {
1024 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001025 pw.println();
1026 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001027 if (dumpAll) {
1028 pw.print(prefix); pw.print("mContainingFrame=");
1029 mContainingFrame.printShortString(pw);
1030 pw.print(" mParentFrame=");
1031 mParentFrame.printShortString(pw);
1032 pw.print(" mDisplayFrame=");
1033 mDisplayFrame.printShortString(pw);
1034 pw.println();
1035 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
1036 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
1037 pw.println();
1038 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
1039 pw.print(" last="); mLastContentInsets.printShortString(pw);
1040 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
1041 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
1042 pw.println();
1043 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001044 mWinAnimator.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001045 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1046 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1047 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1048 pw.print(" mDestroying="); pw.print(mDestroying);
1049 pw.print(" mRemoved="); pw.println(mRemoved);
1050 }
1051 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1052 pw.print(prefix); pw.print("mOrientationChanging=");
1053 pw.print(mOrientationChanging);
1054 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1055 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1056 }
1057 if (mHScale != 1 || mVScale != 1) {
1058 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1059 pw.print(" mVScale="); pw.println(mVScale);
1060 }
1061 if (mWallpaperX != -1 || mWallpaperY != -1) {
1062 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1063 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1064 }
1065 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1066 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1067 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1068 }
1069 }
1070
1071 String makeInputChannelName() {
1072 return Integer.toHexString(System.identityHashCode(this))
1073 + " " + mAttrs.getTitle();
1074 }
1075
1076 @Override
1077 public String toString() {
1078 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
1079 || mWasPaused != mToken.paused) {
1080 mLastTitle = mAttrs.getTitle();
1081 mWasPaused = mToken.paused;
1082 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
1083 + " " + mLastTitle + " paused=" + mWasPaused + "}";
1084 }
1085 return mStringNameCache;
1086 }
satokcef37fb2011-10-24 21:49:38 +09001087}