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