blob: 75bda4155295e9a933c1e745e28c994cfb72beb0 [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;
22import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
23import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
24import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
25import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
26
27import com.android.server.wm.WindowManagerService.H;
28
29import 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;
42import android.view.Surface;
43import android.view.View;
44import android.view.ViewTreeObserver;
45import android.view.WindowManager;
46import android.view.WindowManagerPolicy;
47import android.view.WindowManager.LayoutParams;
48import android.view.animation.Animation;
49import android.view.animation.Transformation;
50
51import java.io.PrintWriter;
52import java.util.ArrayList;
53
54/**
55 * A window in the window manager.
56 */
57final class WindowState implements WindowManagerPolicy.WindowState {
Dianne Hackborn5fd21692011-06-07 14:09:47 -070058 static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
59 static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
Dianne Hackborn36991742011-10-11 21:35:26 -070060 static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
Dianne Hackborn5fd21692011-06-07 14:09:47 -070061 static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
62
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063 final WindowManagerService mService;
64 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;
87 Surface mSurface;
Dianne Hackborn6d05fd32011-11-19 14:36:15 -080088 Surface mPendingDestroySurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080089 boolean mReportDestroySurface;
90 boolean mSurfacePendingDestroy;
91 boolean mAttachedHidden; // is our parent window hidden?
92 boolean mLastHidden; // was this window last hidden?
93 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Dianne Hackbornffb3d932011-05-17 17:44:51 -070094
95 /**
96 * The window size that was requested by the application. These are in
97 * the application's coordinate space (without compatibility scale applied).
98 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099 int mRequestedWidth;
100 int mRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700101
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800102 int mLayer;
103 int mAnimLayer;
104 int mLastLayer;
105 boolean mHaveFrame;
106 boolean mObscured;
107 boolean mTurnOnScreen;
108
109 int mLayoutSeq = -1;
110
111 Configuration mConfiguration = null;
112
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700113 /**
114 * Actual frame shown on-screen (may be modified by animation). These
115 * are in the screen's coordinate space (WITH the compatibility scale
116 * applied).
117 */
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700118 final RectF mShownFrame = new RectF();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800119
120 /**
121 * Set when we have changed the size of the surface, to know that
122 * we must tell them application to resize (and thus redraw itself).
123 */
124 boolean mSurfaceResized;
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800125
126 /**
127 * Set if the client has asked that the destroy of its surface be delayed
128 * until it explicitly says it is okay.
129 */
130 boolean mSurfaceDestroyDeferred;
131
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700133 * Insets that determine the actually visible area. These are in the application's
134 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135 */
136 final Rect mVisibleInsets = new Rect();
137 final Rect mLastVisibleInsets = new Rect();
138 boolean mVisibleInsetsChanged;
139
140 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700141 * Insets that are covered by system windows. These are in the application's
142 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 */
144 final Rect mContentInsets = new Rect();
145 final Rect mLastContentInsets = new Rect();
146 boolean mContentInsetsChanged;
147
148 /**
149 * Set to true if we are waiting for this window to receive its
150 * given internal insets before laying out other windows based on it.
151 */
152 boolean mGivenInsetsPending;
153
154 /**
155 * These are the content insets that were given during layout for
156 * this window, to be applied to windows behind it.
157 */
158 final Rect mGivenContentInsets = new Rect();
159
160 /**
161 * These are the visible insets that were given during layout for
162 * this window, to be applied to windows behind it.
163 */
164 final Rect mGivenVisibleInsets = new Rect();
165
166 /**
167 * This is the given touchable area relative to the window frame, or null if none.
168 */
169 final Region mGivenTouchableRegion = new Region();
170
171 /**
172 * Flag indicating whether the touchable region should be adjusted by
173 * the visible insets; if false the area outside the visible insets is
174 * NOT touchable, so we must use those to adjust the frame during hit
175 * tests.
176 */
177 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
178
179 // Current transformation being applied.
180 boolean mHaveMatrix;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400181 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700182 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
184 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
185 float mHScale=1, mVScale=1;
186 float mLastHScale=1, mLastVScale=1;
187 final Matrix mTmpMatrix = new Matrix();
188
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700189 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 final Rect mFrame = new Rect();
191 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700192 // Frame that is scaled to the application's coordinate space when in
193 // screen size compatibility mode.
194 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195
196 final Rect mContainingFrame = new Rect();
197 final Rect mDisplayFrame = new Rect();
198 final Rect mContentFrame = new Rect();
199 final Rect mParentFrame = new Rect();
200 final Rect mVisibleFrame = new Rect();
201
202 boolean mContentChanged;
203
204 float mShownAlpha = 1;
205 float mAlpha = 1;
206 float mLastAlpha = 1;
207
208 // Set to true if, when the window gets displayed, it should perform
209 // an enter animation.
210 boolean mEnterAnimationPending;
211
212 // Currently running animation.
213 boolean mAnimating;
214 boolean mLocalAnimating;
215 Animation mAnimation;
216 boolean mAnimationIsEntrance;
217 boolean mHasTransformation;
218 boolean mHasLocalTransformation;
219 final Transformation mTransformation = new Transformation();
220
221 // If a window showing a wallpaper: the requested offset for the
222 // wallpaper; if a wallpaper window: the currently applied offset.
223 float mWallpaperX = -1;
224 float mWallpaperY = -1;
225
226 // If a window showing a wallpaper: what fraction of the offset
227 // range corresponds to a full virtual screen.
228 float mWallpaperXStep = -1;
229 float mWallpaperYStep = -1;
230
231 // Wallpaper windows: pixels offset based on above variables.
232 int mXOffset;
233 int mYOffset;
234
235 // This is set after IWindowSession.relayout() has been called at
236 // least once for the window. It allows us to detect the situation
237 // where we don't yet have a surface, but should have one soon, so
238 // we can give the window focus before waiting for the relayout.
239 boolean mRelayoutCalled;
240
241 // This is set after the Surface has been created but before the
242 // window has been drawn. During this time the surface is hidden.
243 boolean mDrawPending;
244
245 // This is set after the window has finished drawing for the first
246 // time but before its surface is shown. The surface will be
247 // displayed when the next layout is run.
248 boolean mCommitDrawPending;
249
250 // This is set during the time after the window's drawing has been
251 // committed, and before its surface is actually shown. It is used
252 // to delay showing the surface until all windows in a token are ready
253 // to be shown.
254 boolean mReadyToShow;
255
256 // Set when the window has been shown in the screen the first time.
257 boolean mHasDrawn;
258
259 // Currently running an exit animation?
260 boolean mExiting;
261
262 // Currently on the mDestroySurface list?
263 boolean mDestroying;
264
265 // Completely remove from window manager after exit animation?
266 boolean mRemoveOnExit;
267
268 // Set when the orientation is changing and this window has not yet
269 // been updated for the new orientation.
270 boolean mOrientationChanging;
271
272 // Is this window now (or just being) removed?
273 boolean mRemoved;
274
275 // Temp for keeping track of windows that have been removed when
276 // rebuilding window list.
277 boolean mRebuilding;
278
279 // For debugging, this is the last information given to the surface flinger.
280 boolean mSurfaceShown;
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700281 float mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 int mSurfaceLayer;
283 float mSurfaceAlpha;
284
285 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700286 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 InputChannel mInputChannel;
288
289 // Used to improve performance of toString()
290 String mStringNameCache;
291 CharSequence mLastTitle;
292 boolean mWasPaused;
293
294 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700295 WindowState attachedWindow, int seq, WindowManager.LayoutParams a,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 int viewVisibility) {
297 mService = service;
298 mSession = s;
299 mClient = c;
300 mToken = token;
301 mAttrs.copyFrom(a);
302 mViewVisibility = viewVisibility;
303 DeathRecipient deathRecipient = new DeathRecipient();
304 mAlpha = a.alpha;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700305 mSeq = seq;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400306 mEnforceSizeCompat = (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800307 if (WindowManagerService.localLOGV) Slog.v(
308 WindowManagerService.TAG, "Window " + this + " client=" + c.asBinder()
309 + " token=" + token + " (" + mAttrs.token + ")");
310 try {
311 c.asBinder().linkToDeath(deathRecipient, 0);
312 } catch (RemoteException e) {
313 mDeathRecipient = null;
314 mAttachedWindow = null;
315 mLayoutAttached = false;
316 mIsImWindow = false;
317 mIsWallpaper = false;
318 mIsFloatingLayer = false;
319 mBaseLayer = 0;
320 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700321 mInputWindowHandle = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322 return;
323 }
324 mDeathRecipient = deathRecipient;
325
326 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
327 mAttrs.type <= LAST_SUB_WINDOW)) {
328 // The multiplier here is to reserve space for multiple
329 // windows in the same type layer.
330 mBaseLayer = mService.mPolicy.windowTypeToLayerLw(
331 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
332 + WindowManagerService.TYPE_LAYER_OFFSET;
333 mSubLayer = mService.mPolicy.subWindowTypeToLayerLw(a.type);
334 mAttachedWindow = attachedWindow;
335 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(WindowManagerService.TAG, "Adding " + this + " to " + mAttachedWindow);
336 mAttachedWindow.mChildWindows.add(this);
337 mLayoutAttached = mAttrs.type !=
338 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
339 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
340 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
341 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
342 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
343 } else {
344 // The multiplier here is to reserve space for multiple
345 // windows in the same type layer.
346 mBaseLayer = mService.mPolicy.windowTypeToLayerLw(a.type)
347 * WindowManagerService.TYPE_LAYER_MULTIPLIER
348 + WindowManagerService.TYPE_LAYER_OFFSET;
349 mSubLayer = 0;
350 mAttachedWindow = null;
351 mLayoutAttached = false;
352 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
353 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
354 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
355 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
356 }
357
358 WindowState appWin = this;
359 while (appWin.mAttachedWindow != null) {
360 appWin = mAttachedWindow;
361 }
362 WindowToken appToken = appWin.mToken;
363 while (appToken.appWindowToken == null) {
364 WindowToken parent = mService.mTokenMap.get(appToken.token);
365 if (parent == null || appToken == parent) {
366 break;
367 }
368 appToken = parent;
369 }
370 mRootToken = appToken;
371 mAppToken = appToken.appWindowToken;
372
373 mSurface = null;
374 mRequestedWidth = 0;
375 mRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800376 mXOffset = 0;
377 mYOffset = 0;
378 mLayer = 0;
379 mAnimLayer = 0;
380 mLastLayer = 0;
381 mInputWindowHandle = new InputWindowHandle(
382 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
383 }
384
385 void attach() {
386 if (WindowManagerService.localLOGV) Slog.v(
387 WindowManagerService.TAG, "Attaching " + this + " token=" + mToken
388 + ", list=" + mToken.windows);
389 mSession.windowAddedLocked();
390 }
391
392 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
393 mHaveFrame = true;
394
395 final Rect container = mContainingFrame;
396 container.set(pf);
397
398 final Rect display = mDisplayFrame;
399 display.set(df);
400
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800401 final int pw = container.right - container.left;
402 final int ph = container.bottom - container.top;
403
404 int w,h;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700405 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
406 if (mAttrs.width < 0) {
407 w = pw;
408 } else if (mEnforceSizeCompat) {
409 w = (int)(mAttrs.width * mGlobalScale + .5f);
410 } else {
411 w = mAttrs.width;
412 }
413 if (mAttrs.height < 0) {
414 h = ph;
415 } else if (mEnforceSizeCompat) {
416 h = (int)(mAttrs.height * mGlobalScale + .5f);
417 } else {
418 h = mAttrs.height;
419 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800420 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700421 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
422 w = pw;
423 } else if (mEnforceSizeCompat) {
424 w = (int)(mRequestedWidth * mGlobalScale + .5f);
425 } else {
426 w = mRequestedWidth;
427 }
428 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
429 h = ph;
430 } else if (mEnforceSizeCompat) {
431 h = (int)(mRequestedHeight * mGlobalScale + .5f);
432 } else {
433 h = mRequestedHeight;
434 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800435 }
436
437 if (!mParentFrame.equals(pf)) {
438 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
439 // + " to " + pf);
440 mParentFrame.set(pf);
441 mContentChanged = true;
442 }
443
444 final Rect content = mContentFrame;
445 content.set(cf);
446
447 final Rect visible = mVisibleFrame;
448 visible.set(vf);
449
450 final Rect frame = mFrame;
451 final int fw = frame.width();
452 final int fh = frame.height();
453
454 //System.out.println("In: w=" + w + " h=" + h + " container=" +
455 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
456
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700457 float x, y;
458 if (mEnforceSizeCompat) {
459 x = mAttrs.x * mGlobalScale;
460 y = mAttrs.y * mGlobalScale;
461 } else {
462 x = mAttrs.x;
463 y = mAttrs.y;
464 }
465
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800466 Gravity.apply(mAttrs.gravity, w, h, container,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700467 (int) (x + mAttrs.horizontalMargin * pw),
468 (int) (y + mAttrs.verticalMargin * ph), frame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469
470 //System.out.println("Out: " + mFrame);
471
472 // Now make sure the window fits in the overall display.
473 Gravity.applyDisplay(mAttrs.gravity, df, frame);
474
475 // Make sure the content and visible frames are inside of the
476 // final window frame.
477 if (content.left < frame.left) content.left = frame.left;
478 if (content.top < frame.top) content.top = frame.top;
479 if (content.right > frame.right) content.right = frame.right;
480 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
481 if (visible.left < frame.left) visible.left = frame.left;
482 if (visible.top < frame.top) visible.top = frame.top;
483 if (visible.right > frame.right) visible.right = frame.right;
484 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
485
486 final Rect contentInsets = mContentInsets;
487 contentInsets.left = content.left-frame.left;
488 contentInsets.top = content.top-frame.top;
489 contentInsets.right = frame.right-content.right;
490 contentInsets.bottom = frame.bottom-content.bottom;
491
492 final Rect visibleInsets = mVisibleInsets;
493 visibleInsets.left = visible.left-frame.left;
494 visibleInsets.top = visible.top-frame.top;
495 visibleInsets.right = frame.right-visible.right;
496 visibleInsets.bottom = frame.bottom-visible.bottom;
497
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700498 mCompatFrame.set(frame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400499 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700500 // If there is a size compatibility scale being applied to the
501 // window, we need to apply this to its insets so that they are
502 // reported to the app in its coordinate space.
503 contentInsets.scale(mInvGlobalScale);
504 visibleInsets.scale(mInvGlobalScale);
505
506 // Also the scaled frame that we report to the app needs to be
507 // adjusted to be in its coordinate space.
508 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400509 }
510
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800511 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
Jeff Brownbc68a592011-07-25 12:58:12 -0700512 mService.updateWallpaperOffsetLocked(this,
513 mService.mAppDisplayWidth, mService.mAppDisplayHeight, false);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800514 }
515
516 if (WindowManagerService.localLOGV) {
517 //if ("com.google.android.youtube".equals(mAttrs.packageName)
518 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
519 Slog.v(WindowManagerService.TAG, "Resolving (mRequestedWidth="
520 + mRequestedWidth + ", mRequestedheight="
521 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
522 + "): frame=" + mFrame.toShortString()
523 + " ci=" + contentInsets.toShortString()
524 + " vi=" + visibleInsets.toShortString());
525 //}
526 }
527 }
528
529 public Rect getFrameLw() {
530 return mFrame;
531 }
532
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700533 public RectF getShownFrameLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800534 return mShownFrame;
535 }
536
537 public Rect getDisplayFrameLw() {
538 return mDisplayFrame;
539 }
540
541 public Rect getContentFrameLw() {
542 return mContentFrame;
543 }
544
545 public Rect getVisibleFrameLw() {
546 return mVisibleFrame;
547 }
548
549 public boolean getGivenInsetsPendingLw() {
550 return mGivenInsetsPending;
551 }
552
553 public Rect getGivenContentInsetsLw() {
554 return mGivenContentInsets;
555 }
556
557 public Rect getGivenVisibleInsetsLw() {
558 return mGivenVisibleInsets;
559 }
560
561 public WindowManager.LayoutParams getAttrs() {
562 return mAttrs;
563 }
564
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800565 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
566 int index = -1;
567 WindowState ws = this;
568 while (true) {
569 if ((ws.mAttrs.privateFlags
570 & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
571 return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
572 }
573 // If we reached the bottom of the range of windows we are considering,
574 // assume no menu is needed.
575 if (ws == bottom) {
576 return false;
577 }
578 // The current window hasn't specified whether menu key is needed;
579 // look behind it.
580 // First, we may need to determine the starting position.
581 if (index < 0) {
582 index = mService.mWindows.indexOf(ws);
583 }
584 index--;
585 if (index < 0) {
586 return false;
587 }
588 ws = mService.mWindows.get(index);
589 }
590 }
591
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700592 public int getSystemUiVisibility() {
593 return mSystemUiVisibility;
594 }
595
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800596 public int getSurfaceLayer() {
597 return mLayer;
598 }
599
600 public IApplicationToken getAppToken() {
601 return mAppToken != null ? mAppToken.appToken : null;
602 }
603
604 public long getInputDispatchingTimeoutNanos() {
605 return mAppToken != null
606 ? mAppToken.inputDispatchingTimeoutNanos
607 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
608 }
609
610 public boolean hasAppShownWindows() {
611 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
612 }
613
614 public void setAnimation(Animation anim) {
615 if (WindowManagerService.localLOGV) Slog.v(
616 WindowManagerService.TAG, "Setting animation in " + this + ": " + anim);
617 mAnimating = false;
618 mLocalAnimating = false;
619 mAnimation = anim;
620 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
621 mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
622 }
623
624 public void clearAnimation() {
625 if (mAnimation != null) {
626 mAnimating = true;
627 mLocalAnimating = false;
628 mAnimation.cancel();
629 mAnimation = null;
630 }
631 }
632
satokcef37fb2011-10-24 21:49:38 +0900633 // TODO: Fix and call finishExit() instead of cancelExitAnimationForNextAnimationLocked()
634 // for avoiding the code duplication.
635 void cancelExitAnimationForNextAnimationLocked() {
636 if (!mExiting) return;
637 if (mAnimation != null) {
638 mAnimation.cancel();
639 mAnimation = null;
640 destroySurfaceLocked();
641 }
642 mExiting = false;
643 }
644
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800645 Surface createSurfaceLocked() {
646 if (mSurface == null) {
647 mReportDestroySurface = false;
648 mSurfacePendingDestroy = false;
Dianne Hackborne02c88a2011-10-28 13:58:15 -0700649 if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(WindowManagerService.TAG,
650 "createSurface " + this + ": DRAW NOW PENDING");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651 mDrawPending = true;
652 mCommitDrawPending = false;
653 mReadyToShow = false;
654 if (mAppToken != null) {
655 mAppToken.allDrawn = false;
656 }
657
Dianne Hackborn3ec891a2011-10-25 13:58:30 -0700658 mService.makeWindowFreezingScreenIfNeededLocked(this);
659
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800660 int flags = 0;
661
662 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
663 flags |= Surface.SECURE;
664 }
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700665 if (DEBUG_VISIBILITY) Slog.v(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800666 WindowManagerService.TAG, "Creating surface in session "
667 + mSession.mSurfaceSession + " window " + this
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700668 + " w=" + mCompatFrame.width()
669 + " h=" + mCompatFrame.height() + " format="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800670 + mAttrs.format + " flags=" + flags);
671
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700672 int w = mCompatFrame.width();
673 int h = mCompatFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800674 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
675 // for a scaled surface, we always want the requested
676 // size.
677 w = mRequestedWidth;
678 h = mRequestedHeight;
679 }
680
681 // Something is wrong and SurfaceFlinger will not like this,
682 // try to revert to sane values
683 if (w <= 0) w = 1;
684 if (h <= 0) h = 1;
685
686 mSurfaceShown = false;
687 mSurfaceLayer = 0;
688 mSurfaceAlpha = 1;
689 mSurfaceX = 0;
690 mSurfaceY = 0;
691 mSurfaceW = w;
692 mSurfaceH = h;
693 try {
694 final boolean isHwAccelerated = (mAttrs.flags &
695 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
696 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
Romain Guy4941dea2011-09-26 16:08:14 -0700697 if (!PixelFormat.formatHasAlpha(mAttrs.format)) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800698 flags |= Surface.OPAQUE;
699 }
700 mSurface = new Surface(
701 mSession.mSurfaceSession, mSession.mPid,
702 mAttrs.getTitle().toString(),
703 0, w, h, format, flags);
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700704 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
705 " CREATE SURFACE "
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800706 + mSurface + " IN SESSION "
707 + mSession.mSurfaceSession
708 + ": pid=" + mSession.mPid + " format="
709 + mAttrs.format + " flags=0x"
710 + Integer.toHexString(flags)
711 + " / " + this);
712 } catch (Surface.OutOfResourcesException e) {
713 Slog.w(WindowManagerService.TAG, "OutOfResourcesException creating surface");
Dianne Hackborn64825172011-03-02 21:32:58 -0800714 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800715 return null;
716 } catch (Exception e) {
717 Slog.e(WindowManagerService.TAG, "Exception creating surface", e);
718 return null;
719 }
720
721 if (WindowManagerService.localLOGV) Slog.v(
722 WindowManagerService.TAG, "Got surface: " + mSurface
723 + ", set left=" + mFrame.left + " top=" + mFrame.top
724 + ", animLayer=" + mAnimLayer);
Dianne Hackborn36991742011-10-11 21:35:26 -0700725 if (SHOW_LIGHT_TRANSACTIONS) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800726 Slog.i(WindowManagerService.TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700727 WindowManagerService.logSurface(this, "CREATE pos=(" + mFrame.left
728 + "," + mFrame.top + ") (" +
729 mCompatFrame.width() + "x" + mCompatFrame.height() + "), layer=" +
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800730 mAnimLayer + " HIDE", null);
731 }
732 Surface.openTransaction();
733 try {
734 try {
735 mSurfaceX = mFrame.left + mXOffset;
736 mSurfaceY = mFrame.top + mYOffset;
737 mSurface.setPosition(mSurfaceX, mSurfaceY);
738 mSurfaceLayer = mAnimLayer;
739 mSurface.setLayer(mAnimLayer);
740 mSurfaceShown = false;
741 mSurface.hide();
742 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700743 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(this, "DITHER", null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800744 mSurface.setFlags(Surface.SURFACE_DITHER,
745 Surface.SURFACE_DITHER);
746 }
747 } catch (RuntimeException e) {
748 Slog.w(WindowManagerService.TAG, "Error creating surface in " + w, e);
Dianne Hackborn64825172011-03-02 21:32:58 -0800749 mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800750 }
751 mLastHidden = true;
752 } finally {
753 Surface.closeTransaction();
Dianne Hackborn36991742011-10-11 21:35:26 -0700754 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
755 "<<< CLOSE TRANSACTION createSurfaceLocked");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800756 }
757 if (WindowManagerService.localLOGV) Slog.v(
758 WindowManagerService.TAG, "Created surface " + this);
759 }
760 return mSurface;
761 }
762
763 void destroySurfaceLocked() {
764 if (mAppToken != null && this == mAppToken.startingWindow) {
765 mAppToken.startingDisplayed = false;
766 }
767
768 if (mSurface != null) {
769 mDrawPending = false;
770 mCommitDrawPending = false;
771 mReadyToShow = false;
772
773 int i = mChildWindows.size();
774 while (i > 0) {
775 i--;
776 WindowState c = mChildWindows.get(i);
777 c.mAttachedHidden = true;
778 }
779
780 if (mReportDestroySurface) {
781 mReportDestroySurface = false;
782 mSurfacePendingDestroy = true;
783 try {
784 mClient.dispatchGetNewSurface();
785 // We'll really destroy on the next time around.
786 return;
787 } catch (RemoteException e) {
788 }
789 }
790
791 try {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700792 if (DEBUG_VISIBILITY) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800793 RuntimeException e = null;
794 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
795 e = new RuntimeException();
796 e.fillInStackTrace();
797 }
798 Slog.w(WindowManagerService.TAG, "Window " + this + " destroying surface "
799 + mSurface + ", session " + mSession, e);
800 }
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800801 if (mSurfaceDestroyDeferred) {
802 if (mSurface != null && mPendingDestroySurface != mSurface) {
803 if (mPendingDestroySurface != null) {
804 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
805 RuntimeException e = null;
806 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
807 e = new RuntimeException();
808 e.fillInStackTrace();
809 }
810 WindowManagerService.logSurface(this, "DESTROY PENDING", e);
811 }
812 mPendingDestroySurface.destroy();
813 }
814 mPendingDestroySurface = mSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800815 }
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800816 } else {
817 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
818 RuntimeException e = null;
819 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
820 e = new RuntimeException();
821 e.fillInStackTrace();
822 }
823 WindowManagerService.logSurface(this, "DESTROY", e);
824 }
825 mSurface.destroy();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800826 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800827 } catch (RuntimeException e) {
828 Slog.w(WindowManagerService.TAG, "Exception thrown when destroying Window " + this
829 + " surface " + mSurface + " session " + mSession
830 + ": " + e.toString());
831 }
832
833 mSurfaceShown = false;
834 mSurface = null;
835 }
836 }
837
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800838 void destroyDeferredSurfaceLocked() {
839 try {
840 if (mPendingDestroySurface != null) {
841 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
842 RuntimeException e = null;
843 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
844 e = new RuntimeException();
845 e.fillInStackTrace();
846 }
847 mService.logSurface(this, "DESTROY PENDING", e);
848 }
849 mPendingDestroySurface.destroy();
850 }
851 } catch (RuntimeException e) {
852 Slog.w(WindowManagerService.TAG, "Exception thrown when destroying Window "
853 + this + " surface " + mPendingDestroySurface
854 + " session " + mSession + ": " + e.toString());
855 }
856 mSurfaceDestroyDeferred = false;
857 mPendingDestroySurface = null;
858 }
859
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800860 boolean finishDrawingLocked() {
861 if (mDrawPending) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700862 if (SHOW_TRANSACTIONS || WindowManagerService.DEBUG_ORIENTATION) Slog.v(
Dianne Hackborn3ec891a2011-10-25 13:58:30 -0700863 WindowManagerService.TAG, "finishDrawingLocked: " + this + " in " + mSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800864 mCommitDrawPending = true;
865 mDrawPending = false;
866 return true;
867 }
868 return false;
869 }
870
871 // This must be called while inside a transaction.
872 boolean commitFinishDrawingLocked(long currentTime) {
873 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
874 if (!mCommitDrawPending) {
875 return false;
876 }
877 mCommitDrawPending = false;
878 mReadyToShow = true;
879 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
880 final AppWindowToken atoken = mAppToken;
881 if (atoken == null || atoken.allDrawn || starting) {
882 performShowLocked();
883 }
884 return true;
885 }
886
887 // This must be called while inside a transaction.
888 boolean performShowLocked() {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700889 if (DEBUG_VISIBILITY) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800890 RuntimeException e = null;
891 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
892 e = new RuntimeException();
893 e.fillInStackTrace();
894 }
895 Slog.v(WindowManagerService.TAG, "performShow on " + this
896 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
897 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
898 }
899 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700900 if (SHOW_TRANSACTIONS || WindowManagerService.DEBUG_ORIENTATION) WindowManagerService.logSurface(this,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800901 "SHOW (performShowLocked)", null);
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700902 if (DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "Showing " + this
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800903 + " during animation: policyVis=" + mPolicyVisibility
904 + " attHidden=" + mAttachedHidden
905 + " tok.hiddenRequested="
906 + (mAppToken != null ? mAppToken.hiddenRequested : false)
907 + " tok.hidden="
908 + (mAppToken != null ? mAppToken.hidden : false)
909 + " animating=" + mAnimating
910 + " tok animating="
911 + (mAppToken != null ? mAppToken.animating : false));
912 if (!mService.showSurfaceRobustlyLocked(this)) {
913 return false;
914 }
915 mLastAlpha = -1;
916 mHasDrawn = true;
917 mLastHidden = false;
918 mReadyToShow = false;
919 mService.enableScreenIfNeededLocked();
920
921 mService.applyEnterAnimationLocked(this);
922
923 int i = mChildWindows.size();
924 while (i > 0) {
925 i--;
926 WindowState c = mChildWindows.get(i);
927 if (c.mAttachedHidden) {
928 c.mAttachedHidden = false;
929 if (c.mSurface != null) {
930 c.performShowLocked();
931 // It hadn't been shown, which means layout not
932 // performed on it, so now we want to make sure to
933 // do a layout. If called from within the transaction
934 // loop, this will cause it to restart with a new
935 // layout.
936 mService.mLayoutNeeded = true;
937 }
938 }
939 }
940
941 if (mAttrs.type != TYPE_APPLICATION_STARTING
942 && mAppToken != null) {
943 mAppToken.firstWindowDrawn = true;
944
945 if (mAppToken.startingData != null) {
946 if (WindowManagerService.DEBUG_STARTING_WINDOW || WindowManagerService.DEBUG_ANIM) Slog.v(WindowManagerService.TAG,
947 "Finish starting " + mToken
948 + ": first real window is shown, no animation");
949 // If this initial window is animating, stop it -- we
950 // will do an animation to reveal it from behind the
951 // starting window, so there is no need for it to also
952 // be doing its own stuff.
953 if (mAnimation != null) {
954 mAnimation.cancel();
955 mAnimation = null;
956 // Make sure we clean up the animation.
957 mAnimating = true;
958 }
959 mService.mFinishedStarting.add(mAppToken);
960 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
961 }
962 mAppToken.updateReportedVisibilityLocked();
963 }
964 }
965 return true;
966 }
967
968 // This must be called while inside a transaction. Returns true if
969 // there is more animation to run.
970 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700971 if (!mService.mDisplayFrozen && mService.mPolicy.isScreenOnFully()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800972 // We will run animations as long as the display isn't frozen.
973
974 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
975 mHasTransformation = true;
976 mHasLocalTransformation = true;
977 if (!mLocalAnimating) {
978 if (WindowManagerService.DEBUG_ANIM) Slog.v(
979 WindowManagerService.TAG, "Starting animation in " + this +
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700980 " @ " + currentTime + ": ww=" + mFrame.width() +
981 " wh=" + mFrame.height() +
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800982 " dw=" + dw + " dh=" + dh + " scale=" + mService.mWindowAnimationScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700983 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800984 mAnimation.setStartTime(currentTime);
985 mLocalAnimating = true;
986 mAnimating = true;
987 }
988 mTransformation.clear();
989 final boolean more = mAnimation.getTransformation(
990 currentTime, mTransformation);
991 if (WindowManagerService.DEBUG_ANIM) Slog.v(
992 WindowManagerService.TAG, "Stepped animation in " + this +
993 ": more=" + more + ", xform=" + mTransformation);
994 if (more) {
995 // we're not done!
996 return true;
997 }
998 if (WindowManagerService.DEBUG_ANIM) Slog.v(
999 WindowManagerService.TAG, "Finished animation in " + this +
1000 " @ " + currentTime);
1001
1002 if (mAnimation != null) {
1003 mAnimation.cancel();
1004 mAnimation = null;
1005 }
1006 //WindowManagerService.this.dump();
1007 }
1008 mHasLocalTransformation = false;
1009 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
1010 && mAppToken.animation != null) {
1011 // When our app token is animating, we kind-of pretend like
1012 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
1013 // part of this check means that we will only do this if
1014 // our window is not currently exiting, or it is not
1015 // locally animating itself. The idea being that one that
1016 // is exiting and doing a local animation should be removed
1017 // once that animation is done.
1018 mAnimating = true;
1019 mHasTransformation = true;
1020 mTransformation.clear();
1021 return false;
1022 } else if (mHasTransformation) {
1023 // Little trick to get through the path below to act like
1024 // we have finished an animation.
1025 mAnimating = true;
1026 } else if (isAnimating()) {
1027 mAnimating = true;
1028 }
1029 } else if (mAnimation != null) {
1030 // If the display is frozen, and there is a pending animation,
1031 // clear it and make sure we run the cleanup code.
1032 mAnimating = true;
1033 mLocalAnimating = true;
1034 mAnimation.cancel();
1035 mAnimation = null;
1036 }
1037
1038 if (!mAnimating && !mLocalAnimating) {
1039 return false;
1040 }
1041
1042 if (WindowManagerService.DEBUG_ANIM) Slog.v(
1043 WindowManagerService.TAG, "Animation done in " + this + ": exiting=" + mExiting
1044 + ", reportedVisible="
1045 + (mAppToken != null ? mAppToken.reportedVisible : false));
1046
1047 mAnimating = false;
1048 mLocalAnimating = false;
1049 if (mAnimation != null) {
1050 mAnimation.cancel();
1051 mAnimation = null;
1052 }
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001053 if (mService.mWindowDetachedWallpaper == this) {
1054 mService.mWindowDetachedWallpaper = null;
1055 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001056 mAnimLayer = mLayer;
1057 if (mIsImWindow) {
1058 mAnimLayer += mService.mInputMethodAnimLayerAdjustment;
1059 } else if (mIsWallpaper) {
1060 mAnimLayer += mService.mWallpaperAnimLayerAdjustment;
1061 }
1062 if (WindowManagerService.DEBUG_LAYERS) Slog.v(WindowManagerService.TAG, "Stepping win " + this
1063 + " anim layer: " + mAnimLayer);
1064 mHasTransformation = false;
1065 mHasLocalTransformation = false;
1066 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001067 if (DEBUG_VISIBILITY) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001068 Slog.v(WindowManagerService.TAG, "Policy visibility changing after anim in " + this + ": "
1069 + mPolicyVisibilityAfterAnim);
1070 }
1071 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Dianne Hackbornf8098702011-09-13 13:26:38 -07001072 mService.mLayoutNeeded = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001073 if (!mPolicyVisibility) {
1074 if (mService.mCurrentFocus == this) {
1075 mService.mFocusMayChange = true;
1076 }
1077 // Window is no longer visible -- make sure if we were waiting
1078 // for it to be displayed before enabling the display, that
1079 // we allow the display to be enabled now.
1080 mService.enableScreenIfNeededLocked();
1081 }
1082 }
1083 mTransformation.clear();
1084 if (mHasDrawn
1085 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1086 && mAppToken != null
1087 && mAppToken.firstWindowDrawn
1088 && mAppToken.startingData != null) {
1089 if (WindowManagerService.DEBUG_STARTING_WINDOW) Slog.v(WindowManagerService.TAG, "Finish starting "
1090 + mToken + ": first real window done animating");
1091 mService.mFinishedStarting.add(mAppToken);
1092 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
1093 }
1094
1095 finishExit();
1096
1097 if (mAppToken != null) {
1098 mAppToken.updateReportedVisibilityLocked();
1099 }
1100
1101 return false;
1102 }
1103
1104 void finishExit() {
1105 if (WindowManagerService.DEBUG_ANIM) Slog.v(
1106 WindowManagerService.TAG, "finishExit in " + this
1107 + ": exiting=" + mExiting
1108 + " remove=" + mRemoveOnExit
1109 + " windowAnimating=" + isWindowAnimating());
1110
1111 final int N = mChildWindows.size();
1112 for (int i=0; i<N; i++) {
1113 mChildWindows.get(i).finishExit();
1114 }
1115
1116 if (!mExiting) {
1117 return;
1118 }
1119
1120 if (isWindowAnimating()) {
1121 return;
1122 }
1123
1124 if (WindowManagerService.localLOGV) Slog.v(
1125 WindowManagerService.TAG, "Exit animation finished in " + this
1126 + ": remove=" + mRemoveOnExit);
1127 if (mSurface != null) {
1128 mService.mDestroySurface.add(this);
1129 mDestroying = true;
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001130 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001131 mSurfaceShown = false;
1132 try {
1133 mSurface.hide();
1134 } catch (RuntimeException e) {
1135 Slog.w(WindowManagerService.TAG, "Error hiding surface in " + this, e);
1136 }
1137 mLastHidden = true;
1138 }
1139 mExiting = false;
1140 if (mRemoveOnExit) {
1141 mService.mPendingRemove.add(this);
1142 mRemoveOnExit = false;
1143 }
1144 }
1145
1146 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1147 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1148 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1149 if (dtdx < -.000001f || dtdx > .000001f) return false;
1150 if (dsdy < -.000001f || dsdy > .000001f) return false;
1151 return true;
1152 }
1153
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001154 void prelayout() {
1155 if (mEnforceSizeCompat) {
1156 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001157 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001158 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001159 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001160 }
1161 }
1162
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001163 void computeShownFrameLocked() {
1164 final boolean selfTransformation = mHasLocalTransformation;
1165 Transformation attachedTransformation =
1166 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
1167 ? mAttachedWindow.mTransformation : null;
1168 Transformation appTransformation =
1169 (mAppToken != null && mAppToken.hasTransformation)
1170 ? mAppToken.transformation : null;
1171
1172 // Wallpapers are animated based on the "real" window they
1173 // are currently targeting.
1174 if (mAttrs.type == TYPE_WALLPAPER && mService.mLowerWallpaperTarget == null
1175 && mService.mWallpaperTarget != null) {
1176 if (mService.mWallpaperTarget.mHasLocalTransformation &&
1177 mService.mWallpaperTarget.mAnimation != null &&
1178 !mService.mWallpaperTarget.mAnimation.getDetachWallpaper()) {
1179 attachedTransformation = mService.mWallpaperTarget.mTransformation;
1180 if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
1181 Slog.v(WindowManagerService.TAG, "WP target attached xform: " + attachedTransformation);
1182 }
1183 }
1184 if (mService.mWallpaperTarget.mAppToken != null &&
1185 mService.mWallpaperTarget.mAppToken.hasTransformation &&
1186 mService.mWallpaperTarget.mAppToken.animation != null &&
1187 !mService.mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
1188 appTransformation = mService.mWallpaperTarget.mAppToken.transformation;
1189 if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
1190 Slog.v(WindowManagerService.TAG, "WP target app xform: " + appTransformation);
1191 }
1192 }
1193 }
1194
1195 final boolean screenAnimation = mService.mScreenRotationAnimation != null
1196 && mService.mScreenRotationAnimation.isAnimating();
1197 if (selfTransformation || attachedTransformation != null
1198 || appTransformation != null || screenAnimation) {
1199 // cache often used attributes locally
1200 final Rect frame = mFrame;
1201 final float tmpFloats[] = mService.mTmpFloats;
1202 final Matrix tmpMatrix = mTmpMatrix;
1203
1204 // Compute the desired transformation.
Dianne Hackborn73db0d82011-09-16 01:09:40 -07001205 if (screenAnimation) {
1206 // If we are doing a screen animation, the global rotation
1207 // applied to windows can result in windows that are carefully
1208 // aligned with each other to slightly separate, allowing you
1209 // to see what is behind them. An unsightly mess. This...
1210 // thing... magically makes it call good: scale each window
1211 // slightly (two pixels larger in each dimension, from the
1212 // window's center).
1213 final float w = frame.width();
1214 final float h = frame.height();
Mathias Agopian526f0a02011-10-18 20:19:59 -07001215 if (w>=1 && h>=1) {
1216 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
1217 } else {
1218 tmpMatrix.reset();
1219 }
Dianne Hackborn73db0d82011-09-16 01:09:40 -07001220 } else {
1221 tmpMatrix.reset();
1222 }
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001223 tmpMatrix.postScale(mGlobalScale, mGlobalScale);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001224 if (selfTransformation) {
1225 tmpMatrix.postConcat(mTransformation.getMatrix());
1226 }
1227 tmpMatrix.postTranslate(frame.left + mXOffset, frame.top + mYOffset);
1228 if (attachedTransformation != null) {
1229 tmpMatrix.postConcat(attachedTransformation.getMatrix());
1230 }
1231 if (appTransformation != null) {
1232 tmpMatrix.postConcat(appTransformation.getMatrix());
1233 }
1234 if (screenAnimation) {
1235 tmpMatrix.postConcat(
1236 mService.mScreenRotationAnimation.getEnterTransformation().getMatrix());
1237 }
1238
1239 // "convert" it into SurfaceFlinger's format
1240 // (a 2x2 matrix + an offset)
1241 // Here we must not transform the position of the surface
1242 // since it is already included in the transformation.
1243 //Slog.i(TAG, "Transform: " + matrix);
1244
1245 mHaveMatrix = true;
1246 tmpMatrix.getValues(tmpFloats);
1247 mDsDx = tmpFloats[Matrix.MSCALE_X];
1248 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1249 mDsDy = tmpFloats[Matrix.MSKEW_X];
1250 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornd040edb2011-08-31 12:47:58 -07001251 float x = tmpFloats[Matrix.MTRANS_X];
1252 float y = tmpFloats[Matrix.MTRANS_Y];
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001253 int w = frame.width();
1254 int h = frame.height();
1255 mShownFrame.set(x, y, x+w, y+h);
1256
1257 // Now set the alpha... but because our current hardware
1258 // can't do alpha transformation on a non-opaque surface,
1259 // turn it off if we are running an animation that is also
1260 // transforming since it is more important to have that
1261 // animation be smooth.
1262 mShownAlpha = mAlpha;
1263 if (!mService.mLimitedAlphaCompositing
1264 || (!PixelFormat.formatHasAlpha(mAttrs.format)
1265 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
1266 && x == frame.left && y == frame.top))) {
1267 //Slog.i(TAG, "Applying alpha transform");
1268 if (selfTransformation) {
1269 mShownAlpha *= mTransformation.getAlpha();
1270 }
1271 if (attachedTransformation != null) {
1272 mShownAlpha *= attachedTransformation.getAlpha();
1273 }
1274 if (appTransformation != null) {
1275 mShownAlpha *= appTransformation.getAlpha();
1276 }
1277 if (screenAnimation) {
1278 mShownAlpha *=
1279 mService.mScreenRotationAnimation.getEnterTransformation().getAlpha();
1280 }
1281 } else {
1282 //Slog.i(TAG, "Not applying alpha transform");
1283 }
1284
1285 if (WindowManagerService.localLOGV) Slog.v(
1286 WindowManagerService.TAG, "Continuing animation in " + this +
1287 ": " + mShownFrame +
1288 ", alpha=" + mTransformation.getAlpha());
1289 return;
1290 }
1291
1292 mShownFrame.set(mFrame);
1293 if (mXOffset != 0 || mYOffset != 0) {
1294 mShownFrame.offset(mXOffset, mYOffset);
1295 }
1296 mShownAlpha = mAlpha;
1297 mHaveMatrix = false;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001298 mDsDx = mGlobalScale;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001299 mDtDx = 0;
1300 mDsDy = 0;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001301 mDtDy = mGlobalScale;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001302 }
1303
1304 /**
1305 * Is this window visible? It is not visible if there is no
1306 * surface, or we are in the process of running an exit animation
1307 * that will remove the surface, or its app token has been hidden.
1308 */
1309 public boolean isVisibleLw() {
1310 final AppWindowToken atoken = mAppToken;
1311 return mSurface != null && mPolicyVisibility && !mAttachedHidden
1312 && (atoken == null || !atoken.hiddenRequested)
1313 && !mExiting && !mDestroying;
1314 }
1315
1316 /**
1317 * Like {@link #isVisibleLw}, but also counts a window that is currently
1318 * "hidden" behind the keyguard as visible. This allows us to apply
1319 * things like window flags that impact the keyguard.
1320 * XXX I am starting to think we need to have ANOTHER visibility flag
1321 * for this "hidden behind keyguard" state rather than overloading
1322 * mPolicyVisibility. Ungh.
1323 */
1324 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001325 if (mRootToken.waitingToShow &&
1326 mService.mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
1327 return false;
1328 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001329 final AppWindowToken atoken = mAppToken;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001330 final boolean animating = atoken != null
1331 ? (atoken.animation != null) : false;
1332 return mSurface != null && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001333 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001334 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1335 && !mRootToken.hidden)
1336 || mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001337 }
1338
1339 /**
1340 * Is this window visible, ignoring its app token? It is not visible
1341 * if there is no surface, or we are in the process of running an exit animation
1342 * that will remove the surface.
1343 */
1344 public boolean isWinVisibleLw() {
1345 final AppWindowToken atoken = mAppToken;
1346 return mSurface != null && mPolicyVisibility && !mAttachedHidden
1347 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
1348 && !mExiting && !mDestroying;
1349 }
1350
1351 /**
1352 * The same as isVisible(), but follows the current hidden state of
1353 * the associated app token, not the pending requested hidden state.
1354 */
1355 boolean isVisibleNow() {
1356 return mSurface != null && mPolicyVisibility && !mAttachedHidden
1357 && !mRootToken.hidden && !mExiting && !mDestroying;
1358 }
1359
1360 /**
1361 * Can this window possibly be a drag/drop target? The test here is
1362 * a combination of the above "visible now" with the check that the
1363 * Input Manager uses when discarding windows from input consideration.
1364 */
1365 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001366 return isVisibleNow() && !mRemoved
1367 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001368 }
1369
1370 /**
1371 * Same as isVisible(), but we also count it as visible between the
1372 * call to IWindowSession.add() and the first relayout().
1373 */
1374 boolean isVisibleOrAdding() {
1375 final AppWindowToken atoken = mAppToken;
1376 return ((mSurface != null && !mReportDestroySurface)
1377 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
1378 && mPolicyVisibility && !mAttachedHidden
1379 && (atoken == null || !atoken.hiddenRequested)
1380 && !mExiting && !mDestroying;
1381 }
1382
1383 /**
1384 * Is this window currently on-screen? It is on-screen either if it
1385 * is visible or it is currently running an animation before no longer
1386 * being visible.
1387 */
1388 boolean isOnScreen() {
1389 final AppWindowToken atoken = mAppToken;
1390 if (atoken != null) {
1391 return mSurface != null && mPolicyVisibility && !mDestroying
1392 && ((!mAttachedHidden && !atoken.hiddenRequested)
1393 || mAnimation != null || atoken.animation != null);
1394 } else {
1395 return mSurface != null && mPolicyVisibility && !mDestroying
1396 && (!mAttachedHidden || mAnimation != null);
1397 }
1398 }
1399
1400 /**
1401 * Like isOnScreen(), but we don't return true if the window is part
1402 * of a transition that has not yet been started.
1403 */
1404 boolean isReadyForDisplay() {
1405 if (mRootToken.waitingToShow &&
1406 mService.mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
1407 return false;
1408 }
1409 final AppWindowToken atoken = mAppToken;
1410 final boolean animating = atoken != null
1411 ? (atoken.animation != null) : false;
1412 return mSurface != null && mPolicyVisibility && !mDestroying
1413 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1414 && !mRootToken.hidden)
1415 || mAnimation != null || animating);
1416 }
1417
1418 /** Is the window or its container currently animating? */
1419 boolean isAnimating() {
1420 final WindowState attached = mAttachedWindow;
1421 final AppWindowToken atoken = mAppToken;
1422 return mAnimation != null
1423 || (attached != null && attached.mAnimation != null)
1424 || (atoken != null &&
1425 (atoken.animation != null
1426 || atoken.inPendingTransaction));
1427 }
1428
1429 /** Is this window currently animating? */
1430 boolean isWindowAnimating() {
1431 return mAnimation != null;
1432 }
1433
1434 /**
1435 * Like isOnScreen, but returns false if the surface hasn't yet
1436 * been drawn.
1437 */
1438 public boolean isDisplayedLw() {
1439 final AppWindowToken atoken = mAppToken;
1440 return mSurface != null && mPolicyVisibility && !mDestroying
1441 && !mDrawPending && !mCommitDrawPending
1442 && ((!mAttachedHidden &&
1443 (atoken == null || !atoken.hiddenRequested))
1444 || mAnimating);
1445 }
1446
1447 /**
1448 * Returns true if the window has a surface that it has drawn a
1449 * complete UI in to.
1450 */
1451 public boolean isDrawnLw() {
1452 final AppWindowToken atoken = mAppToken;
1453 return mSurface != null && !mDestroying
1454 && !mDrawPending && !mCommitDrawPending;
1455 }
1456
1457 /**
1458 * Return true if the window is opaque and fully drawn. This indicates
1459 * it may obscure windows behind it.
1460 */
1461 boolean isOpaqueDrawn() {
1462 return (mAttrs.format == PixelFormat.OPAQUE
1463 || mAttrs.type == TYPE_WALLPAPER)
1464 && mSurface != null && mAnimation == null
1465 && (mAppToken == null || mAppToken.animation == null)
1466 && !mDrawPending && !mCommitDrawPending;
1467 }
1468
1469 /**
1470 * Return whether this window is wanting to have a translation
1471 * animation applied to it for an in-progress move. (Only makes
1472 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1473 */
1474 boolean shouldAnimateMove() {
1475 return mContentChanged && !mExiting && !mLastHidden && !mService.mDisplayFrozen
1476 && (mFrame.top != mLastFrame.top
1477 || mFrame.left != mLastFrame.left)
1478 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001479 && mService.mPolicy.isScreenOnFully();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001480 }
1481
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001482 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001483 return mFrame.left <= 0 && mFrame.top <= 0 &&
1484 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001485 }
1486
1487 void removeLocked() {
1488 disposeInputChannel();
1489
1490 if (mAttachedWindow != null) {
1491 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(WindowManagerService.TAG, "Removing " + this + " from " + mAttachedWindow);
1492 mAttachedWindow.mChildWindows.remove(this);
1493 }
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001494 destroyDeferredSurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001495 destroySurfaceLocked();
1496 mSession.windowRemovedLocked();
1497 try {
1498 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1499 } catch (RuntimeException e) {
1500 // Ignore if it has already been removed (usually because
1501 // we are doing this as part of processing a death note.)
1502 }
1503 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001504
1505 void setInputChannel(InputChannel inputChannel) {
1506 if (mInputChannel != null) {
1507 throw new IllegalStateException("Window already has an input channel.");
1508 }
1509
1510 mInputChannel = inputChannel;
1511 mInputWindowHandle.inputChannel = inputChannel;
1512 }
1513
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001514 void disposeInputChannel() {
1515 if (mInputChannel != null) {
1516 mService.mInputManager.unregisterInputChannel(mInputChannel);
1517
1518 mInputChannel.dispose();
1519 mInputChannel = null;
1520 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001521
1522 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001523 }
1524
1525 private class DeathRecipient implements IBinder.DeathRecipient {
1526 public void binderDied() {
1527 try {
1528 synchronized(mService.mWindowMap) {
1529 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
1530 Slog.i(WindowManagerService.TAG, "WIN DEATH: " + win);
1531 if (win != null) {
1532 mService.removeWindowLocked(mSession, win);
1533 }
1534 }
1535 } catch (IllegalArgumentException ex) {
1536 // This will happen if the window has already been
1537 // removed.
1538 }
1539 }
1540 }
1541
1542 /** Returns true if this window desires key events. */
1543 public final boolean canReceiveKeys() {
1544 return isVisibleOrAdding()
1545 && (mViewVisibility == View.VISIBLE)
1546 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1547 }
1548
1549 public boolean hasDrawnLw() {
1550 return mHasDrawn;
1551 }
1552
1553 public boolean showLw(boolean doAnimation) {
1554 return showLw(doAnimation, true);
1555 }
1556
1557 boolean showLw(boolean doAnimation, boolean requestAnim) {
1558 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
1559 return false;
1560 }
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001561 if (DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001562 if (doAnimation) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001563 if (DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "doAnimation: mPolicyVisibility="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001564 + mPolicyVisibility + " mAnimation=" + mAnimation);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001565 if (mService.mDisplayFrozen || !mService.mPolicy.isScreenOnFully()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001566 doAnimation = false;
1567 } else if (mPolicyVisibility && mAnimation == null) {
1568 // Check for the case where we are currently visible and
1569 // not animating; we do not want to do animation at such a
1570 // point to become visible when we already are.
1571 doAnimation = false;
1572 }
1573 }
1574 mPolicyVisibility = true;
1575 mPolicyVisibilityAfterAnim = true;
1576 if (doAnimation) {
1577 mService.applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
1578 }
1579 if (requestAnim) {
1580 mService.requestAnimationLocked(0);
1581 }
1582 return true;
1583 }
1584
1585 public boolean hideLw(boolean doAnimation) {
1586 return hideLw(doAnimation, true);
1587 }
1588
1589 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1590 if (doAnimation) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001591 if (mService.mDisplayFrozen || !mService.mPolicy.isScreenOnFully()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001592 doAnimation = false;
1593 }
1594 }
1595 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1596 : mPolicyVisibility;
1597 if (!current) {
1598 return false;
1599 }
1600 if (doAnimation) {
1601 mService.applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
1602 if (mAnimation == null) {
1603 doAnimation = false;
1604 }
1605 }
1606 if (doAnimation) {
1607 mPolicyVisibilityAfterAnim = false;
1608 } else {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001609 if (DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001610 mPolicyVisibilityAfterAnim = false;
1611 mPolicyVisibility = false;
1612 // Window is no longer visible -- make sure if we were waiting
1613 // for it to be displayed before enabling the display, that
1614 // we allow the display to be enabled now.
1615 mService.enableScreenIfNeededLocked();
1616 if (mService.mCurrentFocus == this) {
1617 mService.mFocusMayChange = true;
1618 }
1619 }
1620 if (requestAnim) {
1621 mService.requestAnimationLocked(0);
1622 }
1623 return true;
1624 }
1625
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001626 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1627 outRegion.set(
1628 frame.left + inset.left, frame.top + inset.top,
1629 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001630 }
1631
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001632 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001633 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001634 switch (mTouchableInsets) {
1635 default:
1636 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1637 outRegion.set(frame);
1638 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001639 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001640 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001641 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001642 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001643 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001644 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001645 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1646 final Region givenTouchableRegion = mGivenTouchableRegion;
1647 outRegion.set(givenTouchableRegion);
1648 outRegion.translate(frame.left, frame.top);
1649 break;
1650 }
1651 }
1652 }
1653
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001654 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001655 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
1656 pw.print(" mClient="); pw.println(mClient.asBinder());
1657 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001658 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1659 pw.print(" h="); pw.print(mRequestedHeight);
1660 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001661 if (mAttachedWindow != null || mLayoutAttached) {
1662 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1663 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1664 }
1665 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1666 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1667 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1668 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1669 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1670 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001671 if (dumpAll) {
1672 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1673 pw.print(" mSubLayer="); pw.print(mSubLayer);
1674 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
1675 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
1676 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
1677 pw.print("="); pw.print(mAnimLayer);
1678 pw.print(" mLastLayer="); pw.println(mLastLayer);
1679 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001680 if (mSurface != null) {
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001681 if (dumpAll) {
1682 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
1683 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001684 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
1685 pw.print(" layer="); pw.print(mSurfaceLayer);
1686 pw.print(" alpha="); pw.print(mSurfaceAlpha);
1687 pw.print(" rect=("); pw.print(mSurfaceX);
1688 pw.print(","); pw.print(mSurfaceY);
1689 pw.print(") "); pw.print(mSurfaceW);
1690 pw.print(" x "); pw.println(mSurfaceH);
1691 }
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001692 if (mPendingDestroySurface != null) {
1693 pw.print(prefix); pw.print("mPendingDestroySurface=");
1694 pw.println(mPendingDestroySurface);
1695 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001696 if (dumpAll) {
1697 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1698 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1699 if (mAppToken != null) {
1700 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
1701 }
1702 if (mTargetAppToken != null) {
1703 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1704 }
1705 pw.print(prefix); pw.print("mViewVisibility=0x");
1706 pw.print(Integer.toHexString(mViewVisibility));
1707 pw.print(" mLastHidden="); pw.print(mLastHidden);
1708 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1709 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001710 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1711 pw.print(" mSystemUiVisibility=0x");
1712 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001713 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001714 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
1715 pw.print(prefix); pw.print("mPolicyVisibility=");
1716 pw.print(mPolicyVisibility);
1717 pw.print(" mPolicyVisibilityAfterAnim=");
1718 pw.print(mPolicyVisibilityAfterAnim);
1719 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1720 }
1721 if (!mRelayoutCalled) {
1722 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
1723 }
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001724 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1725 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1726 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1727 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001728 if (mXOffset != 0 || mYOffset != 0) {
1729 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
1730 pw.print(" y="); pw.println(mYOffset);
1731 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001732 if (dumpAll) {
1733 pw.print(prefix); pw.print("mGivenContentInsets=");
1734 mGivenContentInsets.printShortString(pw);
1735 pw.print(" mGivenVisibleInsets=");
1736 mGivenVisibleInsets.printShortString(pw);
1737 pw.println();
1738 if (mTouchableInsets != 0 || mGivenInsetsPending) {
1739 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
1740 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
1741 }
1742 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001743 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001744 pw.print(prefix); pw.print("mShownFrame=");
Dianne Hackbornb961cd22011-06-21 12:13:37 -07001745 mShownFrame.printShortString(pw); pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001746 if (dumpAll) {
1747 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
1748 pw.print(" last="); mLastFrame.printShortString(pw);
1749 pw.println();
1750 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001751 if (mEnforceSizeCompat) {
1752 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001753 pw.println();
1754 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001755 if (dumpAll) {
1756 pw.print(prefix); pw.print("mContainingFrame=");
1757 mContainingFrame.printShortString(pw);
1758 pw.print(" mParentFrame=");
1759 mParentFrame.printShortString(pw);
1760 pw.print(" mDisplayFrame=");
1761 mDisplayFrame.printShortString(pw);
1762 pw.println();
1763 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
1764 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
1765 pw.println();
1766 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
1767 pw.print(" last="); mLastContentInsets.printShortString(pw);
1768 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
1769 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
1770 pw.println();
1771 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001772 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1773 || mAnimation != null) {
1774 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1775 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1776 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
1777 pw.print(" mAnimation="); pw.println(mAnimation);
1778 }
1779 if (mHasTransformation || mHasLocalTransformation) {
1780 pw.print(prefix); pw.print("XForm: has=");
1781 pw.print(mHasTransformation);
1782 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1783 pw.print(" "); mTransformation.printShortString(pw);
1784 pw.println();
1785 }
1786 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1787 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1788 pw.print(" mAlpha="); pw.print(mAlpha);
1789 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1790 }
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001791 if (mHaveMatrix || mGlobalScale != 1) {
1792 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mGlobalScale);
1793 pw.print(" mDsDx="); pw.print(mDsDx);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001794 pw.print(" mDtDx="); pw.print(mDtDx);
1795 pw.print(" mDsDy="); pw.print(mDsDy);
1796 pw.print(" mDtDy="); pw.println(mDtDy);
1797 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001798 if (dumpAll) {
1799 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
1800 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
1801 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
1802 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
1803 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001804 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
1805 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
1806 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
1807 pw.print(" mDestroying="); pw.print(mDestroying);
1808 pw.print(" mRemoved="); pw.println(mRemoved);
1809 }
1810 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
1811 pw.print(prefix); pw.print("mOrientationChanging=");
1812 pw.print(mOrientationChanging);
1813 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
1814 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
1815 }
1816 if (mHScale != 1 || mVScale != 1) {
1817 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
1818 pw.print(" mVScale="); pw.println(mVScale);
1819 }
1820 if (mWallpaperX != -1 || mWallpaperY != -1) {
1821 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
1822 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
1823 }
1824 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
1825 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
1826 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
1827 }
1828 }
1829
1830 String makeInputChannelName() {
1831 return Integer.toHexString(System.identityHashCode(this))
1832 + " " + mAttrs.getTitle();
1833 }
1834
1835 @Override
1836 public String toString() {
1837 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
1838 || mWasPaused != mToken.paused) {
1839 mLastTitle = mAttrs.getTitle();
1840 mWasPaused = mToken.paused;
1841 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
1842 + " " + mLastTitle + " paused=" + mWasPaused + "}";
1843 }
1844 return mStringNameCache;
1845 }
satokcef37fb2011-10-24 21:49:38 +09001846}