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