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