1 /* 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 17 package com.android.server.wm; 18 19 import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY; 20 import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT; 21 22 import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; 23 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; 24 import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; 25 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; 26 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; 27 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; 28 import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD; 29 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; 30 31 import android.app.AppOpsManager; 32 import android.os.RemoteCallbackList; 33 import android.util.TimeUtils; 34 import android.view.IWindowFocusObserver; 35 import android.view.IWindowId; 36 import com.android.server.input.InputWindowHandle; 37 38 import android.content.Context; 39 import android.content.res.Configuration; 40 import android.graphics.Matrix; 41 import android.graphics.PixelFormat; 42 import android.graphics.Rect; 43 import android.graphics.RectF; 44 import android.graphics.Region; 45 import android.os.IBinder; 46 import android.os.RemoteException; 47 import android.os.UserHandle; 48 import android.util.Slog; 49 import android.view.DisplayInfo; 50 import android.view.Gravity; 51 import android.view.IApplicationToken; 52 import android.view.IWindow; 53 import android.view.InputChannel; 54 import android.view.View; 55 import android.view.ViewTreeObserver; 56 import android.view.WindowManager; 57 import android.view.WindowManagerPolicy; 58 59 import java.io.PrintWriter; 60 import java.util.ArrayList; 61 62 class WindowList extends ArrayList<WindowState> { 63 } 64 65 /** 66 * A window in the window manager. 67 */ 68 final class WindowState implements WindowManagerPolicy.WindowState { 69 static final String TAG = "WindowState"; 70 71 final WindowManagerService mService; 72 final WindowManagerPolicy mPolicy; 73 final Context mContext; 74 final Session mSession; 75 final IWindow mClient; 76 final int mAppOp; 77 // UserId and appId of the owner. Don't display windows of non-current user. 78 final int mOwnerUid; 79 final IWindowId mWindowId; 80 WindowToken mToken; 81 WindowToken mRootToken; 82 AppWindowToken mAppToken; 83 AppWindowToken mTargetAppToken; 84 85 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever 86 // modified they will need to be locked. 87 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); 88 final DeathRecipient mDeathRecipient; 89 final WindowState mAttachedWindow; 90 final WindowList mChildWindows = new WindowList(); 91 final int mBaseLayer; 92 final int mSubLayer; 93 final boolean mLayoutAttached; 94 final boolean mIsImWindow; 95 final boolean mIsWallpaper; 96 final boolean mIsFloatingLayer; 97 int mSeq; 98 boolean mEnforceSizeCompat; 99 int mViewVisibility; 100 int mSystemUiVisibility; 101 boolean mPolicyVisibility = true; 102 boolean mPolicyVisibilityAfterAnim = true; 103 boolean mAppOpVisibility = true; 104 boolean mAppFreezing; 105 boolean mAttachedHidden; // is our parent window hidden? 106 boolean mWallpaperVisible; // for wallpaper, what was last vis report? 107 108 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks; 109 110 /** 111 * The window size that was requested by the application. These are in 112 * the application's coordinate space (without compatibility scale applied). 113 */ 114 int mRequestedWidth; 115 int mRequestedHeight; 116 int mLastRequestedWidth; 117 int mLastRequestedHeight; 118 119 int mLayer; 120 boolean mHaveFrame; 121 boolean mObscured; 122 boolean mTurnOnScreen; 123 124 int mLayoutSeq = -1; 125 126 Configuration mConfiguration = null; 127 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned. 128 // Used only on {@link #TYPE_KEYGUARD}. 129 private boolean mConfigHasChanged; 130 131 /** 132 * Actual frame shown on-screen (may be modified by animation). These 133 * are in the screen's coordinate space (WITH the compatibility scale 134 * applied). 135 */ 136 final RectF mShownFrame = new RectF(); 137 138 /** 139 * Insets that determine the actually visible area. These are in the application's 140 * coordinate space (without compatibility scale applied). 141 */ 142 final Rect mVisibleInsets = new Rect(); 143 final Rect mLastVisibleInsets = new Rect(); 144 boolean mVisibleInsetsChanged; 145 146 /** 147 * Insets that are covered by system windows (such as the status bar) and 148 * transient docking windows (such as the IME). These are in the application's 149 * coordinate space (without compatibility scale applied). 150 */ 151 final Rect mContentInsets = new Rect(); 152 final Rect mLastContentInsets = new Rect(); 153 boolean mContentInsetsChanged; 154 155 /** 156 * Insets that determine the area covered by the display overscan region. These are in the 157 * application's coordinate space (without compatibility scale applied). 158 */ 159 final Rect mOverscanInsets = new Rect(); 160 final Rect mLastOverscanInsets = new Rect(); 161 boolean mOverscanInsetsChanged; 162 163 /** 164 * Set to true if we are waiting for this window to receive its 165 * given internal insets before laying out other windows based on it. 166 */ 167 boolean mGivenInsetsPending; 168 169 /** 170 * These are the content insets that were given during layout for 171 * this window, to be applied to windows behind it. 172 */ 173 final Rect mGivenContentInsets = new Rect(); 174 175 /** 176 * These are the visible insets that were given during layout for 177 * this window, to be applied to windows behind it. 178 */ 179 final Rect mGivenVisibleInsets = new Rect(); 180 181 /** 182 * This is the given touchable area relative to the window frame, or null if none. 183 */ 184 final Region mGivenTouchableRegion = new Region(); 185 186 /** 187 * Flag indicating whether the touchable region should be adjusted by 188 * the visible insets; if false the area outside the visible insets is 189 * NOT touchable, so we must use those to adjust the frame during hit 190 * tests. 191 */ 192 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; 193 194 /** 195 * This is rectangle of the window's surface that is not covered by 196 * system decorations. 197 */ 198 final Rect mSystemDecorRect = new Rect(); 199 final Rect mLastSystemDecorRect = new Rect(); 200 201 // Current transformation being applied. 202 float mGlobalScale=1; 203 float mInvGlobalScale=1; 204 float mHScale=1, mVScale=1; 205 float mLastHScale=1, mLastVScale=1; 206 final Matrix mTmpMatrix = new Matrix(); 207 208 // "Real" frame that the application sees, in display coordinate space. 209 final Rect mFrame = new Rect(); 210 final Rect mLastFrame = new Rect(); 211 // Frame that is scaled to the application's coordinate space when in 212 // screen size compatibility mode. 213 final Rect mCompatFrame = new Rect(); 214 215 final Rect mContainingFrame = new Rect(); 216 final Rect mDisplayFrame = new Rect(); 217 final Rect mOverscanFrame = new Rect(); 218 final Rect mContentFrame = new Rect(); 219 final Rect mParentFrame = new Rect(); 220 final Rect mVisibleFrame = new Rect(); 221 final Rect mDecorFrame = new Rect(); 222 223 boolean mContentChanged; 224 225 // If a window showing a wallpaper: the requested offset for the 226 // wallpaper; if a wallpaper window: the currently applied offset. 227 float mWallpaperX = -1; 228 float mWallpaperY = -1; 229 230 // If a window showing a wallpaper: what fraction of the offset 231 // range corresponds to a full virtual screen. 232 float mWallpaperXStep = -1; 233 float mWallpaperYStep = -1; 234 235 // Wallpaper windows: pixels offset based on above variables. 236 int mXOffset; 237 int mYOffset; 238 239 /** 240 * This is set after IWindowSession.relayout() has been called at 241 * least once for the window. It allows us to detect the situation 242 * where we don't yet have a surface, but should have one soon, so 243 * we can give the window focus before waiting for the relayout. 244 */ 245 boolean mRelayoutCalled; 246 247 /** 248 * If the application has called relayout() with changes that can 249 * impact its window's size, we need to perform a layout pass on it 250 * even if it is not currently visible for layout. This is set 251 * when in that case until the layout is done. 252 */ 253 boolean mLayoutNeeded; 254 255 /** Currently running an exit animation? */ 256 boolean mExiting; 257 258 /** Currently on the mDestroySurface list? */ 259 boolean mDestroying; 260 261 /** Completely remove from window manager after exit animation? */ 262 boolean mRemoveOnExit; 263 264 /** 265 * Set when the orientation is changing and this window has not yet 266 * been updated for the new orientation. 267 */ 268 boolean mOrientationChanging; 269 270 /** 271 * How long we last kept the screen frozen. 272 */ 273 int mLastFreezeDuration; 274 275 /** Is this window now (or just being) removed? */ 276 boolean mRemoved; 277 278 /** 279 * Temp for keeping track of windows that have been removed when 280 * rebuilding window list. 281 */ 282 boolean mRebuilding; 283 284 // Input channel and input window handle used by the input dispatcher. 285 final InputWindowHandle mInputWindowHandle; 286 InputChannel mInputChannel; 287 288 // Used to improve performance of toString() 289 String mStringNameCache; 290 CharSequence mLastTitle; 291 boolean mWasExiting; 292 293 final WindowStateAnimator mWinAnimator; 294 295 boolean mHasSurface = false; 296 297 DisplayContent mDisplayContent; 298 299 /** When true this window can be displayed on screens owther than mOwnerUid's */ 300 private boolean mShowToOwnerOnly; 301 302 /** When true this window is at the top of the screen and should be layed out to extend under 303 * the status bar */ 304 boolean mUnderStatusBar = true; 305 306 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, 307 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a, 308 int viewVisibility, final DisplayContent displayContent) { 309 mService = service; 310 mSession = s; 311 mClient = c; 312 mAppOp = appOp; 313 mToken = token; 314 mOwnerUid = s.mUid; 315 mWindowId = new IWindowId.Stub() { 316 @Override 317 public void registerFocusObserver(IWindowFocusObserver observer) { 318 WindowState.this.registerFocusObserver(observer); 319 } 320 @Override 321 public void unregisterFocusObserver(IWindowFocusObserver observer) { 322 WindowState.this.unregisterFocusObserver(observer); 323 } 324 @Override 325 public boolean isFocused() { 326 return WindowState.this.isFocused(); 327 } 328 }; 329 mAttrs.copyFrom(a); 330 mViewVisibility = viewVisibility; 331 mDisplayContent = displayContent; 332 mPolicy = mService.mPolicy; 333 mContext = mService.mContext; 334 DeathRecipient deathRecipient = new DeathRecipient(); 335 mSeq = seq; 336 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0; 337 if (WindowManagerService.localLOGV) Slog.v( 338 TAG, "Window " + this + " client=" + c.asBinder() 339 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a); 340 try { 341 c.asBinder().linkToDeath(deathRecipient, 0); 342 } catch (RemoteException e) { 343 mDeathRecipient = null; 344 mAttachedWindow = null; 345 mLayoutAttached = false; 346 mIsImWindow = false; 347 mIsWallpaper = false; 348 mIsFloatingLayer = false; 349 mBaseLayer = 0; 350 mSubLayer = 0; 351 mInputWindowHandle = null; 352 mWinAnimator = null; 353 return; 354 } 355 mDeathRecipient = deathRecipient; 356 357 if ((mAttrs.type >= FIRST_SUB_WINDOW && 358 mAttrs.type <= LAST_SUB_WINDOW)) { 359 // The multiplier here is to reserve space for multiple 360 // windows in the same type layer. 361 mBaseLayer = mPolicy.windowTypeToLayerLw( 362 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER 363 + WindowManagerService.TYPE_LAYER_OFFSET; 364 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); 365 mAttachedWindow = attachedWindow; 366 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow); 367 368 int children_size = mAttachedWindow.mChildWindows.size(); 369 if (children_size == 0) { 370 mAttachedWindow.mChildWindows.add(this); 371 } else { 372 for (int i = 0; i < children_size; i++) { 373 WindowState child = (WindowState)mAttachedWindow.mChildWindows.get(i); 374 if (this.mSubLayer < child.mSubLayer) { 375 mAttachedWindow.mChildWindows.add(i, this); 376 break; 377 } else if (this.mSubLayer > child.mSubLayer) { 378 continue; 379 } 380 381 if (this.mBaseLayer <= child.mBaseLayer) { 382 mAttachedWindow.mChildWindows.add(i, this); 383 break; 384 } else { 385 continue; 386 } 387 } 388 if (children_size == mAttachedWindow.mChildWindows.size()) { 389 mAttachedWindow.mChildWindows.add(this); 390 } 391 } 392 393 mLayoutAttached = mAttrs.type != 394 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; 395 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD 396 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; 397 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; 398 mIsFloatingLayer = mIsImWindow || mIsWallpaper; 399 } else { 400 // The multiplier here is to reserve space for multiple 401 // windows in the same type layer. 402 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) 403 * WindowManagerService.TYPE_LAYER_MULTIPLIER 404 + WindowManagerService.TYPE_LAYER_OFFSET; 405 mSubLayer = 0; 406 mAttachedWindow = null; 407 mLayoutAttached = false; 408 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD 409 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; 410 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; 411 mIsFloatingLayer = mIsImWindow || mIsWallpaper; 412 } 413 414 WindowState appWin = this; 415 while (appWin.mAttachedWindow != null) { 416 appWin = appWin.mAttachedWindow; 417 } 418 WindowToken appToken = appWin.mToken; 419 while (appToken.appWindowToken == null) { 420 WindowToken parent = mService.mTokenMap.get(appToken.token); 421 if (parent == null || appToken == parent) { 422 break; 423 } 424 appToken = parent; 425 } 426 mRootToken = appToken; 427 mAppToken = appToken.appWindowToken; 428 429 mWinAnimator = new WindowStateAnimator(this); 430 mWinAnimator.mAlpha = a.alpha; 431 432 mRequestedWidth = 0; 433 mRequestedHeight = 0; 434 mLastRequestedWidth = 0; 435 mLastRequestedHeight = 0; 436 mXOffset = 0; 437 mYOffset = 0; 438 mLayer = 0; 439 mInputWindowHandle = new InputWindowHandle( 440 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, 441 displayContent.getDisplayId()); 442 } 443 444 void attach() { 445 if (WindowManagerService.localLOGV) Slog.v( 446 TAG, "Attaching " + this + " token=" + mToken 447 + ", list=" + mToken.windows); 448 mSession.windowAddedLocked(); 449 } 450 451 @Override 452 public int getOwningUid() { 453 return mOwnerUid; 454 } 455 456 @Override 457 public String getOwningPackage() { 458 return mAttrs.packageName; 459 } 460 461 @Override 462 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf) { 463 mHaveFrame = true; 464 465 TaskStack stack = mAppToken != null ? getStack() : null; 466 if (stack != null && stack.hasSibling()) { 467 mContainingFrame.set(getStackBounds(stack)); 468 if (mUnderStatusBar) { 469 mContainingFrame.top = pf.top; 470 } 471 } else { 472 mContainingFrame.set(pf); 473 } 474 475 mDisplayFrame.set(df); 476 477 final int pw = mContainingFrame.width(); 478 final int ph = mContainingFrame.height(); 479 480 int w,h; 481 if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) { 482 if (mAttrs.width < 0) { 483 w = pw; 484 } else if (mEnforceSizeCompat) { 485 w = (int)(mAttrs.width * mGlobalScale + .5f); 486 } else { 487 w = mAttrs.width; 488 } 489 if (mAttrs.height < 0) { 490 h = ph; 491 } else if (mEnforceSizeCompat) { 492 h = (int)(mAttrs.height * mGlobalScale + .5f); 493 } else { 494 h = mAttrs.height; 495 } 496 } else { 497 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) { 498 w = pw; 499 } else if (mEnforceSizeCompat) { 500 w = (int)(mRequestedWidth * mGlobalScale + .5f); 501 } else { 502 w = mRequestedWidth; 503 } 504 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) { 505 h = ph; 506 } else if (mEnforceSizeCompat) { 507 h = (int)(mRequestedHeight * mGlobalScale + .5f); 508 } else { 509 h = mRequestedHeight; 510 } 511 } 512 513 if (!mParentFrame.equals(pf)) { 514 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame 515 // + " to " + pf); 516 mParentFrame.set(pf); 517 mContentChanged = true; 518 } 519 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { 520 mLastRequestedWidth = mRequestedWidth; 521 mLastRequestedHeight = mRequestedHeight; 522 mContentChanged = true; 523 } 524 525 mOverscanFrame.set(of); 526 mContentFrame.set(cf); 527 mVisibleFrame.set(vf); 528 mDecorFrame.set(dcf); 529 530 final int fw = mFrame.width(); 531 final int fh = mFrame.height(); 532 533 //System.out.println("In: w=" + w + " h=" + h + " container=" + 534 // container + " x=" + mAttrs.x + " y=" + mAttrs.y); 535 536 float x, y; 537 if (mEnforceSizeCompat) { 538 x = mAttrs.x * mGlobalScale; 539 y = mAttrs.y * mGlobalScale; 540 } else { 541 x = mAttrs.x; 542 y = mAttrs.y; 543 } 544 545 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame, 546 (int) (x + mAttrs.horizontalMargin * pw), 547 (int) (y + mAttrs.verticalMargin * ph), mFrame); 548 549 //System.out.println("Out: " + mFrame); 550 551 // Now make sure the window fits in the overall display. 552 Gravity.applyDisplay(mAttrs.gravity, df, mFrame); 553 554 // Make sure the content and visible frames are inside of the 555 // final window frame. 556 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left), 557 Math.max(mContentFrame.top, mFrame.top), 558 Math.min(mContentFrame.right, mFrame.right), 559 Math.min(mContentFrame.bottom, mFrame.bottom)); 560 561 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left), 562 Math.max(mVisibleFrame.top, mFrame.top), 563 Math.min(mVisibleFrame.right, mFrame.right), 564 Math.min(mVisibleFrame.bottom, mFrame.bottom)); 565 566 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0), 567 Math.max(mOverscanFrame.top - mFrame.top, 0), 568 Math.max(mFrame.right - mOverscanFrame.right, 0), 569 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0)); 570 571 mContentInsets.set(mContentFrame.left - mFrame.left, 572 mContentFrame.top - mFrame.top, 573 mFrame.right - mContentFrame.right, 574 mFrame.bottom - mContentFrame.bottom); 575 576 mVisibleInsets.set(mVisibleFrame.left - mFrame.left, 577 mVisibleFrame.top - mFrame.top, 578 mFrame.right - mVisibleFrame.right, 579 mFrame.bottom - mVisibleFrame.bottom); 580 581 mCompatFrame.set(mFrame); 582 if (mEnforceSizeCompat) { 583 // If there is a size compatibility scale being applied to the 584 // window, we need to apply this to its insets so that they are 585 // reported to the app in its coordinate space. 586 mOverscanInsets.scale(mInvGlobalScale); 587 mContentInsets.scale(mInvGlobalScale); 588 mVisibleInsets.scale(mInvGlobalScale); 589 590 // Also the scaled frame that we report to the app needs to be 591 // adjusted to be in its coordinate space. 592 mCompatFrame.scale(mInvGlobalScale); 593 } 594 595 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) { 596 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo(); 597 mService.updateWallpaperOffsetLocked(this, 598 displayInfo.logicalWidth, displayInfo.logicalHeight, false); 599 } 600 601 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG, 602 "Resolving (mRequestedWidth=" 603 + mRequestedWidth + ", mRequestedheight=" 604 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph 605 + "): frame=" + mFrame.toShortString() 606 + " ci=" + mContentInsets.toShortString() 607 + " vi=" + mVisibleInsets.toShortString()); 608 } 609 610 @Override 611 public Rect getFrameLw() { 612 return mFrame; 613 } 614 615 @Override 616 public RectF getShownFrameLw() { 617 return mShownFrame; 618 } 619 620 @Override 621 public Rect getDisplayFrameLw() { 622 return mDisplayFrame; 623 } 624 625 @Override 626 public Rect getOverscanFrameLw() { 627 return mOverscanFrame; 628 } 629 630 @Override 631 public Rect getContentFrameLw() { 632 return mContentFrame; 633 } 634 635 @Override 636 public Rect getVisibleFrameLw() { 637 return mVisibleFrame; 638 } 639 640 @Override 641 public boolean getGivenInsetsPendingLw() { 642 return mGivenInsetsPending; 643 } 644 645 @Override 646 public Rect getGivenContentInsetsLw() { 647 return mGivenContentInsets; 648 } 649 650 @Override 651 public Rect getGivenVisibleInsetsLw() { 652 return mGivenVisibleInsets; 653 } 654 655 @Override 656 public WindowManager.LayoutParams getAttrs() { 657 return mAttrs; 658 } 659 660 @Override 661 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) { 662 int index = -1; 663 WindowState ws = this; 664 WindowList windows = getWindowList(); 665 while (true) { 666 if ((ws.mAttrs.privateFlags 667 & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) { 668 return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0; 669 } 670 // If we reached the bottom of the range of windows we are considering, 671 // assume no menu is needed. 672 if (ws == bottom) { 673 return false; 674 } 675 // The current window hasn't specified whether menu key is needed; 676 // look behind it. 677 // First, we may need to determine the starting position. 678 if (index < 0) { 679 index = windows.indexOf(ws); 680 } 681 index--; 682 if (index < 0) { 683 return false; 684 } 685 ws = windows.get(index); 686 } 687 } 688 689 @Override 690 public int getSystemUiVisibility() { 691 return mSystemUiVisibility; 692 } 693 694 @Override 695 public int getSurfaceLayer() { 696 return mLayer; 697 } 698 699 @Override 700 public IApplicationToken getAppToken() { 701 return mAppToken != null ? mAppToken.appToken : null; 702 } 703 704 public int getDisplayId() { 705 return mDisplayContent.getDisplayId(); 706 } 707 708 TaskStack getStack() { 709 AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken; 710 if (wtoken != null) { 711 Task task = mService.mTaskIdToTask.get(wtoken.groupId); 712 if (task != null) { 713 return task.mStack; 714 } 715 } 716 return mDisplayContent.getHomeStack(); 717 } 718 719 Rect getStackBounds() { 720 return getStackBounds(getStack()); 721 } 722 723 private Rect getStackBounds(TaskStack stack) { 724 if (stack != null) { 725 return stack.mStackBox.mBounds; 726 } 727 return mFrame; 728 } 729 730 public long getInputDispatchingTimeoutNanos() { 731 return mAppToken != null 732 ? mAppToken.inputDispatchingTimeoutNanos 733 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; 734 } 735 736 @Override 737 public boolean hasAppShownWindows() { 738 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed); 739 } 740 741 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { 742 if (dsdx < .99999f || dsdx > 1.00001f) return false; 743 if (dtdy < .99999f || dtdy > 1.00001f) return false; 744 if (dtdx < -.000001f || dtdx > .000001f) return false; 745 if (dsdy < -.000001f || dsdy > .000001f) return false; 746 return true; 747 } 748 749 void prelayout() { 750 if (mEnforceSizeCompat) { 751 mGlobalScale = mService.mCompatibleScreenScale; 752 mInvGlobalScale = 1/mGlobalScale; 753 } else { 754 mGlobalScale = mInvGlobalScale = 1; 755 } 756 } 757 758 /** 759 * Is this window visible? It is not visible if there is no 760 * surface, or we are in the process of running an exit animation 761 * that will remove the surface, or its app token has been hidden. 762 */ 763 @Override 764 public boolean isVisibleLw() { 765 final AppWindowToken atoken = mAppToken; 766 return mHasSurface && mPolicyVisibility && !mAttachedHidden 767 && (atoken == null || !atoken.hiddenRequested) 768 && !mExiting && !mDestroying; 769 } 770 771 /** 772 * Like {@link #isVisibleLw}, but also counts a window that is currently 773 * "hidden" behind the keyguard as visible. This allows us to apply 774 * things like window flags that impact the keyguard. 775 * XXX I am starting to think we need to have ANOTHER visibility flag 776 * for this "hidden behind keyguard" state rather than overloading 777 * mPolicyVisibility. Ungh. 778 */ 779 @Override 780 public boolean isVisibleOrBehindKeyguardLw() { 781 if (mRootToken.waitingToShow && 782 mService.mAppTransition.isTransitionSet()) { 783 return false; 784 } 785 final AppWindowToken atoken = mAppToken; 786 final boolean animating = atoken != null 787 ? (atoken.mAppAnimator.animation != null) : false; 788 return mHasSurface && !mDestroying && !mExiting 789 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) 790 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE 791 && !mRootToken.hidden) 792 || mWinAnimator.mAnimation != null || animating); 793 } 794 795 /** 796 * Is this window visible, ignoring its app token? It is not visible 797 * if there is no surface, or we are in the process of running an exit animation 798 * that will remove the surface. 799 */ 800 public boolean isWinVisibleLw() { 801 final AppWindowToken atoken = mAppToken; 802 return mHasSurface && mPolicyVisibility && !mAttachedHidden 803 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating) 804 && !mExiting && !mDestroying; 805 } 806 807 /** 808 * The same as isVisible(), but follows the current hidden state of 809 * the associated app token, not the pending requested hidden state. 810 */ 811 boolean isVisibleNow() { 812 return mHasSurface && mPolicyVisibility && !mAttachedHidden 813 && !mRootToken.hidden && !mExiting && !mDestroying; 814 } 815 816 /** 817 * Can this window possibly be a drag/drop target? The test here is 818 * a combination of the above "visible now" with the check that the 819 * Input Manager uses when discarding windows from input consideration. 820 */ 821 boolean isPotentialDragTarget() { 822 return isVisibleNow() && !mRemoved 823 && mInputChannel != null && mInputWindowHandle != null; 824 } 825 826 /** 827 * Same as isVisible(), but we also count it as visible between the 828 * call to IWindowSession.add() and the first relayout(). 829 */ 830 boolean isVisibleOrAdding() { 831 final AppWindowToken atoken = mAppToken; 832 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) 833 && mPolicyVisibility && !mAttachedHidden 834 && (atoken == null || !atoken.hiddenRequested) 835 && !mExiting && !mDestroying; 836 } 837 838 /** 839 * Is this window currently on-screen? It is on-screen either if it 840 * is visible or it is currently running an animation before no longer 841 * being visible. 842 */ 843 boolean isOnScreen() { 844 if (!mHasSurface || !mPolicyVisibility || mDestroying) { 845 return false; 846 } 847 final AppWindowToken atoken = mAppToken; 848 if (atoken != null) { 849 return ((!mAttachedHidden && !atoken.hiddenRequested) 850 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null); 851 } 852 return !mAttachedHidden || mWinAnimator.mAnimation != null; 853 } 854 855 /** 856 * Like isOnScreen(), but we don't return true if the window is part 857 * of a transition that has not yet been started. 858 */ 859 boolean isReadyForDisplay() { 860 if (mRootToken.waitingToShow && 861 mService.mAppTransition.isTransitionSet()) { 862 return false; 863 } 864 return mHasSurface && mPolicyVisibility && !mDestroying 865 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE 866 && !mRootToken.hidden) 867 || mWinAnimator.mAnimation != null 868 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null))); 869 } 870 871 /** 872 * Like isReadyForDisplay(), but ignores any force hiding of the window due 873 * to the keyguard. 874 */ 875 boolean isReadyForDisplayIgnoringKeyguard() { 876 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) { 877 return false; 878 } 879 final AppWindowToken atoken = mAppToken; 880 if (atoken == null && !mPolicyVisibility) { 881 // If this is not an app window, and the policy has asked to force 882 // hide, then we really do want to hide. 883 return false; 884 } 885 return mHasSurface && !mDestroying 886 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE 887 && !mRootToken.hidden) 888 || mWinAnimator.mAnimation != null 889 || ((atoken != null) && (atoken.mAppAnimator.animation != null) 890 && !mWinAnimator.isDummyAnimation())); 891 } 892 893 /** 894 * Like isOnScreen, but returns false if the surface hasn't yet 895 * been drawn. 896 */ 897 @Override 898 public boolean isDisplayedLw() { 899 final AppWindowToken atoken = mAppToken; 900 return isDrawnLw() && mPolicyVisibility 901 && ((!mAttachedHidden && 902 (atoken == null || !atoken.hiddenRequested)) 903 || mWinAnimator.mAnimating 904 || (atoken != null && atoken.mAppAnimator.animation != null)); 905 } 906 907 /** 908 * Return true if this window or its app token is currently animating. 909 */ 910 @Override 911 public boolean isAnimatingLw() { 912 return mWinAnimator.mAnimation != null 913 || (mAppToken != null && mAppToken.mAppAnimator.animation != null); 914 } 915 916 @Override 917 public boolean isGoneForLayoutLw() { 918 final AppWindowToken atoken = mAppToken; 919 return mViewVisibility == View.GONE 920 || !mRelayoutCalled 921 || (atoken == null && mRootToken.hidden) 922 || (atoken != null && (atoken.hiddenRequested || atoken.hidden)) 923 || mAttachedHidden 924 || (mExiting && !isAnimatingLw()) 925 || mDestroying; 926 } 927 928 /** 929 * Returns true if the window has a surface that it has drawn a 930 * complete UI in to. 931 */ 932 public boolean isDrawFinishedLw() { 933 return mHasSurface && !mDestroying && 934 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING 935 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW 936 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN); 937 } 938 939 /** 940 * Returns true if the window has a surface that it has drawn a 941 * complete UI in to. 942 */ 943 public boolean isDrawnLw() { 944 return mHasSurface && !mDestroying && 945 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW 946 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN); 947 } 948 949 /** 950 * Return true if the window is opaque and fully drawn. This indicates 951 * it may obscure windows behind it. 952 */ 953 boolean isOpaqueDrawn() { 954 return (mAttrs.format == PixelFormat.OPAQUE 955 || mAttrs.type == TYPE_WALLPAPER) 956 && isDrawnLw() && mWinAnimator.mAnimation == null 957 && (mAppToken == null || mAppToken.mAppAnimator.animation == null); 958 } 959 960 /** 961 * Return whether this window is wanting to have a translation 962 * animation applied to it for an in-progress move. (Only makes 963 * sense to call from performLayoutAndPlaceSurfacesLockedInner().) 964 */ 965 boolean shouldAnimateMove() { 966 return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay() 967 && (mFrame.top != mLastFrame.top 968 || mFrame.left != mLastFrame.left) 969 && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0 970 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove()); 971 } 972 973 boolean isFullscreen(int screenWidth, int screenHeight) { 974 return mFrame.left <= 0 && mFrame.top <= 0 && 975 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; 976 } 977 978 boolean isConfigChanged() { 979 boolean configChanged = mConfiguration != mService.mCurConfiguration 980 && (mConfiguration == null 981 || (mConfiguration.diff(mService.mCurConfiguration) != 0)); 982 983 if (mAttrs.type == TYPE_KEYGUARD) { 984 // Retain configuration changed status until resetConfiguration called. 985 mConfigHasChanged |= configChanged; 986 configChanged = mConfigHasChanged; 987 } 988 989 return configChanged; 990 } 991 992 void removeLocked() { 993 disposeInputChannel(); 994 995 if (mAttachedWindow != null) { 996 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow); 997 mAttachedWindow.mChildWindows.remove(this); 998 } 999 mWinAnimator.destroyDeferredSurfaceLocked(); 1000 mWinAnimator.destroySurfaceLocked(); 1001 mSession.windowRemovedLocked(); 1002 try { 1003 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); 1004 } catch (RuntimeException e) { 1005 // Ignore if it has already been removed (usually because 1006 // we are doing this as part of processing a death note.) 1007 } 1008 } 1009 1010 void setConfiguration(final Configuration newConfig) { 1011 mConfiguration = newConfig; 1012 mConfigHasChanged = false; 1013 } 1014 1015 void setInputChannel(InputChannel inputChannel) { 1016 if (mInputChannel != null) { 1017 throw new IllegalStateException("Window already has an input channel."); 1018 } 1019 1020 mInputChannel = inputChannel; 1021 mInputWindowHandle.inputChannel = inputChannel; 1022 } 1023 1024 void disposeInputChannel() { 1025 if (mInputChannel != null) { 1026 mService.mInputManager.unregisterInputChannel(mInputChannel); 1027 1028 mInputChannel.dispose(); 1029 mInputChannel = null; 1030 } 1031 1032 mInputWindowHandle.inputChannel = null; 1033 } 1034 1035 private class DeathRecipient implements IBinder.DeathRecipient { 1036 @Override 1037 public void binderDied() { 1038 try { 1039 synchronized(mService.mWindowMap) { 1040 WindowState win = mService.windowForClientLocked(mSession, mClient, false); 1041 Slog.i(TAG, "WIN DEATH: " + win); 1042 if (win != null) { 1043 mService.removeWindowLocked(mSession, win); 1044 } else if (mHasSurface) { 1045 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid."); 1046 mService.removeWindowLocked(mSession, WindowState.this); 1047 } 1048 } 1049 } catch (IllegalArgumentException ex) { 1050 // This will happen if the window has already been 1051 // removed. 1052 } 1053 } 1054 } 1055 1056 /** 1057 * @return true if this window desires key events. 1058 */ 1059 public final boolean canReceiveKeys() { 1060 return isVisibleOrAdding() 1061 && (mViewVisibility == View.VISIBLE) 1062 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); 1063 } 1064 1065 @Override 1066 public boolean hasDrawnLw() { 1067 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN; 1068 } 1069 1070 @Override 1071 public boolean showLw(boolean doAnimation) { 1072 return showLw(doAnimation, true); 1073 } 1074 1075 boolean showLw(boolean doAnimation, boolean requestAnim) { 1076 if (isHiddenFromUserLocked()) { 1077 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display " 1078 + this + ", type " + mAttrs.type + ", belonging to " + mOwnerUid); 1079 return false; 1080 } 1081 if (!mAppOpVisibility) { 1082 // Being hidden due to app op request. 1083 return false; 1084 } 1085 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { 1086 // Already showing. 1087 return false; 1088 } 1089 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); 1090 if (doAnimation) { 1091 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" 1092 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation); 1093 if (!mService.okToDisplay()) { 1094 doAnimation = false; 1095 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) { 1096 // Check for the case where we are currently visible and 1097 // not animating; we do not want to do animation at such a 1098 // point to become visible when we already are. 1099 doAnimation = false; 1100 } 1101 } 1102 mPolicyVisibility = true; 1103 mPolicyVisibilityAfterAnim = true; 1104 if (doAnimation) { 1105 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true); 1106 } 1107 if (requestAnim) { 1108 mService.scheduleAnimationLocked(); 1109 } 1110 return true; 1111 } 1112 1113 @Override 1114 public boolean hideLw(boolean doAnimation) { 1115 return hideLw(doAnimation, true); 1116 } 1117 1118 boolean hideLw(boolean doAnimation, boolean requestAnim) { 1119 if (doAnimation) { 1120 if (!mService.okToDisplay()) { 1121 doAnimation = false; 1122 } 1123 } 1124 boolean current = doAnimation ? mPolicyVisibilityAfterAnim 1125 : mPolicyVisibility; 1126 if (!current) { 1127 // Already hiding. 1128 return false; 1129 } 1130 if (doAnimation) { 1131 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false); 1132 if (mWinAnimator.mAnimation == null) { 1133 doAnimation = false; 1134 } 1135 } 1136 if (doAnimation) { 1137 mPolicyVisibilityAfterAnim = false; 1138 } else { 1139 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); 1140 mPolicyVisibilityAfterAnim = false; 1141 mPolicyVisibility = false; 1142 // Window is no longer visible -- make sure if we were waiting 1143 // for it to be displayed before enabling the display, that 1144 // we allow the display to be enabled now. 1145 mService.enableScreenIfNeededLocked(); 1146 if (mService.mCurrentFocus == this) { 1147 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG, 1148 "WindowState.hideLw: setting mFocusMayChange true"); 1149 mService.mFocusMayChange = true; 1150 } 1151 } 1152 if (requestAnim) { 1153 mService.scheduleAnimationLocked(); 1154 } 1155 return true; 1156 } 1157 1158 public void setAppOpVisibilityLw(boolean state) { 1159 if (mAppOpVisibility != state) { 1160 mAppOpVisibility = state; 1161 if (state) { 1162 // If the policy visibility had last been to hide, then this 1163 // will incorrectly show at this point since we lost that 1164 // information. Not a big deal -- for the windows that have app 1165 // ops modifies they should only be hidden by policy due to the 1166 // lock screen, and the user won't be changing this if locked. 1167 // Plus it will quickly be fixed the next time we do a layout. 1168 showLw(true, true); 1169 } else { 1170 hideLw(true, true); 1171 } 1172 } 1173 } 1174 1175 @Override 1176 public boolean isAlive() { 1177 return mClient.asBinder().isBinderAlive(); 1178 } 1179 1180 boolean isClosing() { 1181 return mExiting || (mService.mClosingApps.contains(mAppToken)); 1182 } 1183 1184 @Override 1185 public boolean isDefaultDisplay() { 1186 return mDisplayContent.isDefaultDisplay; 1187 } 1188 1189 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) { 1190 mShowToOwnerOnly = showToOwnerOnly; 1191 } 1192 1193 boolean isHiddenFromUserLocked() { 1194 // Attached windows are evaluated based on the window that they are attached to. 1195 WindowState win = this; 1196 while (win.mAttachedWindow != null) { 1197 win = win.mAttachedWindow; 1198 } 1199 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW 1200 && win.mAppToken != null && win.mAppToken.showWhenLocked) { 1201 // Save some cycles by not calling getDisplayInfo unless it is an application 1202 // window intended for all users. 1203 final DisplayInfo displayInfo = win.mDisplayContent.getDisplayInfo(); 1204 if (win.mFrame.left <= 0 && win.mFrame.top <= 0 1205 && win.mFrame.right >= displayInfo.appWidth 1206 && win.mFrame.bottom >= displayInfo.appHeight) { 1207 // Is a fullscreen window, like the clock alarm. Show to everyone. 1208 return false; 1209 } 1210 } 1211 1212 return win.mShowToOwnerOnly 1213 && UserHandle.getUserId(win.mOwnerUid) != mService.mCurrentUserId; 1214 } 1215 1216 private static void applyInsets(Region outRegion, Rect frame, Rect inset) { 1217 outRegion.set( 1218 frame.left + inset.left, frame.top + inset.top, 1219 frame.right - inset.right, frame.bottom - inset.bottom); 1220 } 1221 1222 public void getTouchableRegion(Region outRegion) { 1223 final Rect frame = mFrame; 1224 switch (mTouchableInsets) { 1225 default: 1226 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: 1227 outRegion.set(frame); 1228 break; 1229 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: 1230 applyInsets(outRegion, frame, mGivenContentInsets); 1231 break; 1232 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: 1233 applyInsets(outRegion, frame, mGivenVisibleInsets); 1234 break; 1235 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: { 1236 final Region givenTouchableRegion = mGivenTouchableRegion; 1237 outRegion.set(givenTouchableRegion); 1238 outRegion.translate(frame.left, frame.top); 1239 break; 1240 } 1241 } 1242 } 1243 1244 WindowList getWindowList() { 1245 return mDisplayContent.getWindowList(); 1246 } 1247 1248 /** 1249 * Report a focus change. Must be called with no locks held, and consistently 1250 * from the same serialized thread (such as dispatched from a handler). 1251 */ 1252 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) { 1253 try { 1254 mClient.windowFocusChanged(focused, inTouchMode); 1255 } catch (RemoteException e) { 1256 } 1257 if (mFocusCallbacks != null) { 1258 final int N = mFocusCallbacks.beginBroadcast(); 1259 for (int i=0; i<N; i++) { 1260 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i); 1261 try { 1262 if (focused) { 1263 obs.focusGained(mWindowId.asBinder()); 1264 } else { 1265 obs.focusLost(mWindowId.asBinder()); 1266 } 1267 } catch (RemoteException e) { 1268 } 1269 } 1270 mFocusCallbacks.finishBroadcast(); 1271 } 1272 } 1273 1274 public void registerFocusObserver(IWindowFocusObserver observer) { 1275 synchronized(mService.mWindowMap) { 1276 if (mFocusCallbacks == null) { 1277 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>(); 1278 } 1279 mFocusCallbacks.register(observer); 1280 } 1281 } 1282 1283 public void unregisterFocusObserver(IWindowFocusObserver observer) { 1284 synchronized(mService.mWindowMap) { 1285 if (mFocusCallbacks != null) { 1286 mFocusCallbacks.unregister(observer); 1287 } 1288 } 1289 } 1290 1291 public boolean isFocused() { 1292 synchronized(mService.mWindowMap) { 1293 return mService.mCurrentFocus == this; 1294 } 1295 } 1296 1297 void dump(PrintWriter pw, String prefix, boolean dumpAll) { 1298 pw.print(prefix); pw.print("mDisplayId="); pw.print(mDisplayContent.getDisplayId()); 1299 pw.print(" mSession="); pw.print(mSession); 1300 pw.print(" mClient="); pw.println(mClient.asBinder()); 1301 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid); 1302 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly); 1303 pw.print(" package="); pw.print(mAttrs.packageName); 1304 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp)); 1305 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); 1306 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); 1307 pw.print(" h="); pw.print(mRequestedHeight); 1308 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); 1309 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { 1310 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth); 1311 pw.print(" h="); pw.println(mLastRequestedHeight); 1312 } 1313 if (mAttachedWindow != null || mLayoutAttached) { 1314 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); 1315 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); 1316 } 1317 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { 1318 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); 1319 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); 1320 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); 1321 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); 1322 } 1323 if (dumpAll) { 1324 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); 1325 pw.print(" mSubLayer="); pw.print(mSubLayer); 1326 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); 1327 pw.print((mTargetAppToken != null ? 1328 mTargetAppToken.mAppAnimator.animLayerAdjustment 1329 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0))); 1330 pw.print("="); pw.print(mWinAnimator.mAnimLayer); 1331 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer); 1332 } 1333 if (dumpAll) { 1334 pw.print(prefix); pw.print("mToken="); pw.println(mToken); 1335 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); 1336 if (mAppToken != null) { 1337 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); 1338 } 1339 if (mTargetAppToken != null) { 1340 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); 1341 } 1342 pw.print(prefix); pw.print("mViewVisibility=0x"); 1343 pw.print(Integer.toHexString(mViewVisibility)); 1344 pw.print(" mHaveFrame="); pw.print(mHaveFrame); 1345 pw.print(" mObscured="); pw.println(mObscured); 1346 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq); 1347 pw.print(" mSystemUiVisibility=0x"); 1348 pw.println(Integer.toHexString(mSystemUiVisibility)); 1349 } 1350 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility 1351 || mAttachedHidden) { 1352 pw.print(prefix); pw.print("mPolicyVisibility="); 1353 pw.print(mPolicyVisibility); 1354 pw.print(" mPolicyVisibilityAfterAnim="); 1355 pw.print(mPolicyVisibilityAfterAnim); 1356 pw.print(" mAppOpVisibility="); 1357 pw.print(mAppOpVisibility); 1358 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); 1359 } 1360 if (!mRelayoutCalled || mLayoutNeeded) { 1361 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled); 1362 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded); 1363 } 1364 if (mXOffset != 0 || mYOffset != 0) { 1365 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); 1366 pw.print(" y="); pw.println(mYOffset); 1367 } 1368 if (dumpAll) { 1369 pw.print(prefix); pw.print("mGivenContentInsets="); 1370 mGivenContentInsets.printShortString(pw); 1371 pw.print(" mGivenVisibleInsets="); 1372 mGivenVisibleInsets.printShortString(pw); 1373 pw.println(); 1374 if (mTouchableInsets != 0 || mGivenInsetsPending) { 1375 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); 1376 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); 1377 Region region = new Region(); 1378 getTouchableRegion(region); 1379 pw.print(prefix); pw.print("touchable region="); pw.println(region); 1380 } 1381 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); 1382 } 1383 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface); 1384 pw.print(" mShownFrame="); mShownFrame.printShortString(pw); 1385 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay()); 1386 if (dumpAll) { 1387 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); 1388 pw.print(" last="); mLastFrame.printShortString(pw); 1389 pw.println(); 1390 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw); 1391 pw.print(" last="); mLastSystemDecorRect.printShortString(pw); 1392 pw.println(); 1393 } 1394 if (mEnforceSizeCompat) { 1395 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw); 1396 pw.println(); 1397 } 1398 if (dumpAll) { 1399 pw.print(prefix); pw.print("Frames: containing="); 1400 mContainingFrame.printShortString(pw); 1401 pw.print(" parent="); mParentFrame.printShortString(pw); 1402 pw.println(); 1403 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw); 1404 pw.print(" overscan="); mOverscanFrame.printShortString(pw); 1405 pw.println(); 1406 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw); 1407 pw.print(" visible="); mVisibleFrame.printShortString(pw); 1408 pw.println(); 1409 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw); 1410 pw.println(); 1411 pw.print(prefix); pw.print("Cur insets: overscan="); 1412 mOverscanInsets.printShortString(pw); 1413 pw.print(" content="); mContentInsets.printShortString(pw); 1414 pw.print(" visible="); mVisibleInsets.printShortString(pw); 1415 pw.println(); 1416 pw.print(prefix); pw.print("Lst insets: overscan="); 1417 mLastOverscanInsets.printShortString(pw); 1418 pw.print(" content="); mLastContentInsets.printShortString(pw); 1419 pw.print(" visible="); mLastVisibleInsets.printShortString(pw); 1420 pw.println(); 1421 } 1422 pw.print(prefix); pw.print(mWinAnimator); pw.println(":"); 1423 mWinAnimator.dump(pw, prefix + " ", dumpAll); 1424 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { 1425 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); 1426 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); 1427 pw.print(" mDestroying="); pw.print(mDestroying); 1428 pw.print(" mRemoved="); pw.println(mRemoved); 1429 } 1430 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { 1431 pw.print(prefix); pw.print("mOrientationChanging="); 1432 pw.print(mOrientationChanging); 1433 pw.print(" mAppFreezing="); pw.print(mAppFreezing); 1434 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); 1435 } 1436 if (mLastFreezeDuration != 0) { 1437 pw.print(prefix); pw.print("mLastFreezeDuration="); 1438 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println(); 1439 } 1440 if (mHScale != 1 || mVScale != 1) { 1441 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); 1442 pw.print(" mVScale="); pw.println(mVScale); 1443 } 1444 if (mWallpaperX != -1 || mWallpaperY != -1) { 1445 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); 1446 pw.print(" mWallpaperY="); pw.println(mWallpaperY); 1447 } 1448 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { 1449 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); 1450 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); 1451 } 1452 } 1453 1454 String makeInputChannelName() { 1455 return Integer.toHexString(System.identityHashCode(this)) 1456 + " " + mAttrs.getTitle(); 1457 } 1458 1459 @Override 1460 public String toString() { 1461 CharSequence title = mAttrs.getTitle(); 1462 if (title == null || title.length() <= 0) { 1463 title = mAttrs.packageName; 1464 } 1465 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) { 1466 mLastTitle = title; 1467 mWasExiting = mExiting; 1468 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) 1469 + " u" + UserHandle.getUserId(mSession.mUid) 1470 + " " + mLastTitle + (mExiting ? " EXITING}" : "}"); 1471 } 1472 return mStringNameCache; 1473 } 1474 } 1475