Home | History | Annotate | Download | only in wm
      1 // Copyright 2012 Google Inc. All Rights Reserved.
      2 
      3 package com.android.server.wm;
      4 
      5 import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
      6 import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
      7 
      8 import static com.android.server.wm.WindowManagerService.LayoutFields.SET_UPDATE_ROTATION;
      9 import static com.android.server.wm.WindowManagerService.LayoutFields.SET_WALLPAPER_MAY_CHANGE;
     10 import static com.android.server.wm.WindowManagerService.LayoutFields.SET_FORCE_HIDING_CHANGED;
     11 
     12 import static com.android.server.wm.WindowManagerService.H.SET_DIM_PARAMETERS;
     13 
     14 import android.content.Context;
     15 import android.os.SystemClock;
     16 import android.util.Log;
     17 import android.util.Slog;
     18 import android.view.Surface;
     19 import android.view.WindowManager;
     20 import android.view.WindowManagerPolicy;
     21 import android.view.animation.Animation;
     22 
     23 import com.android.internal.policy.impl.PhoneWindowManager;
     24 
     25 import java.io.PrintWriter;
     26 import java.util.ArrayList;
     27 
     28 /**
     29  * Singleton class that carries out the animations and Surface operations in a separate task
     30  * on behalf of WindowManagerService.
     31  */
     32 public class WindowAnimator {
     33     private static final String TAG = "WindowAnimator";
     34 
     35     // mForceHiding states.
     36     private static final int KEYGUARD_NOT_SHOWN     = 0;
     37     private static final int KEYGUARD_ANIMATING_IN  = 1;
     38     private static final int KEYGUARD_SHOWN         = 2;
     39     private static final int KEYGUARD_ANIMATING_OUT = 3;
     40     int mForceHiding;
     41 
     42     final WindowManagerService mService;
     43     final Context mContext;
     44     final WindowManagerPolicy mPolicy;
     45 
     46     ArrayList<WindowStateAnimator> mWinAnimators = new ArrayList<WindowStateAnimator>();
     47 
     48     boolean mAnimating;
     49     WindowState mWindowAnimationBackground;
     50     int mWindowAnimationBackgroundColor;
     51     int mAdjResult;
     52 
     53     int mPendingLayoutChanges;
     54 
     55     /** Overall window dimensions */
     56     int mDw, mDh;
     57 
     58     /** Interior window dimensions */
     59     int mInnerDw, mInnerDh;
     60 
     61     /** Time of current animation step. Reset on each iteration */
     62     long mCurrentTime;
     63 
     64     /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this
     65      * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */
     66     private int mAnimTransactionSequence;
     67 
     68     /** The one and only screen rotation if one is happening */
     69     ScreenRotationAnimation mScreenRotationAnimation = null;
     70 
     71     // Window currently running an animation that has requested it be detached
     72     // from the wallpaper.  This means we need to ensure the wallpaper is
     73     // visible behind it in case it animates in a way that would allow it to be
     74     // seen.
     75     WindowState mWindowDetachedWallpaper = null;
     76     WindowState mDetachedWallpaper = null;
     77     DimSurface mWindowAnimationBackgroundSurface = null;
     78 
     79     int mBulkUpdateParams = 0;
     80 
     81     DimAnimator mDimAnimator = null;
     82     DimAnimator.Parameters mDimParams = null;
     83 
     84     static final int WALLPAPER_ACTION_PENDING = 1;
     85     int mPendingActions;
     86 
     87     WindowAnimator(final WindowManagerService service, final Context context,
     88             final WindowManagerPolicy policy) {
     89         mService = service;
     90         mContext = context;
     91         mPolicy = policy;
     92     }
     93 
     94     void hideWallpapersLocked(final WindowState w) {
     95         if ((mService.mWallpaperTarget == w && mService.mLowerWallpaperTarget == null)
     96                 || mService.mWallpaperTarget == null) {
     97             for (final WindowToken token : mService.mWallpaperTokens) {
     98                 for (final WindowState wallpaper : token.windows) {
     99                     final WindowStateAnimator winAnimator = wallpaper.mWinAnimator;
    100                     if (!winAnimator.mLastHidden) {
    101                         winAnimator.hide();
    102                         mService.dispatchWallpaperVisibility(wallpaper, false);
    103                         mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
    104                     }
    105                 }
    106                 token.hidden = true;
    107             }
    108         }
    109     }
    110 
    111     private void testWallpaperAndBackgroundLocked() {
    112         if (mWindowDetachedWallpaper != mDetachedWallpaper) {
    113             if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG,
    114                     "Detached wallpaper changed from " + mWindowDetachedWallpaper
    115                     + " to " + mDetachedWallpaper);
    116             mWindowDetachedWallpaper = mDetachedWallpaper;
    117             mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
    118         }
    119 
    120         if (mWindowAnimationBackgroundColor != 0) {
    121             // If the window that wants black is the current wallpaper
    122             // target, then the black goes *below* the wallpaper so we
    123             // don't cause the wallpaper to suddenly disappear.
    124             WindowState target = mWindowAnimationBackground;
    125             if (mService.mWallpaperTarget == target
    126                     || mService.mLowerWallpaperTarget == target
    127                     || mService.mUpperWallpaperTarget == target) {
    128                 final int N = mService.mWindows.size();
    129                 for (int i = 0; i < N; i++) {
    130                     WindowState w = mService.mWindows.get(i);
    131                     if (w.mIsWallpaper) {
    132                         target = w;
    133                         break;
    134                     }
    135                 }
    136             }
    137             if (mWindowAnimationBackgroundSurface == null) {
    138                 mWindowAnimationBackgroundSurface = new DimSurface(mService.mFxSession);
    139             }
    140             final int dw = mDw;
    141             final int dh = mDh;
    142             mWindowAnimationBackgroundSurface.show(dw, dh,
    143                     target.mWinAnimator.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM,
    144                     mWindowAnimationBackgroundColor);
    145         } else if (mWindowAnimationBackgroundSurface != null) {
    146             mWindowAnimationBackgroundSurface.hide();
    147         }
    148     }
    149 
    150     private void updateWindowsAppsAndRotationAnimationsLocked() {
    151         final ArrayList<AppWindowToken> appTokens = mService.mAnimatingAppTokens;
    152         int i;
    153         final int NAT = appTokens.size();
    154         for (i=0; i<NAT; i++) {
    155             final AppWindowAnimator appAnimator = appTokens.get(i).mAppAnimator;
    156             final boolean wasAnimating = appAnimator.animation != null
    157                     && appAnimator.animation != AppWindowAnimator.sDummyAnimation;
    158             if (appAnimator.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) {
    159                 mAnimating = true;
    160             } else if (wasAnimating) {
    161                 // stopped animating, do one more pass through the layout
    162                 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
    163                 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
    164                     mService.debugLayoutRepeats("appToken " + appAnimator.mAppToken + " done",
    165                         mPendingLayoutChanges);
    166                 }
    167                 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
    168                         "updateWindowsApps...: done animating " + appAnimator.mAppToken);
    169             }
    170         }
    171 
    172         final int NEAT = mService.mExitingAppTokens.size();
    173         for (i=0; i<NEAT; i++) {
    174             final AppWindowAnimator appAnimator = mService.mExitingAppTokens.get(i).mAppAnimator;
    175             final boolean wasAnimating = appAnimator.animation != null
    176                     && appAnimator.animation != AppWindowAnimator.sDummyAnimation;
    177             if (appAnimator.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) {
    178                 mAnimating = true;
    179             } else if (wasAnimating) {
    180                 // stopped animating, do one more pass through the layout
    181                 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
    182                 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
    183                     mService.debugLayoutRepeats("exiting appToken " + appAnimator.mAppToken
    184                         + " done", mPendingLayoutChanges);
    185                 }
    186                 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
    187                         "updateWindowsApps...: done animating exiting " + appAnimator.mAppToken);
    188             }
    189         }
    190 
    191         if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
    192             if (mScreenRotationAnimation.stepAnimationLocked(mCurrentTime)) {
    193                 mAnimating = true;
    194             } else {
    195                 mBulkUpdateParams |= SET_UPDATE_ROTATION;
    196                 mScreenRotationAnimation.kill();
    197                 mScreenRotationAnimation = null;
    198             }
    199         }
    200     }
    201 
    202     private void updateWindowsAndWallpaperLocked() {
    203         ++mAnimTransactionSequence;
    204 
    205         ArrayList<WindowStateAnimator> unForceHiding = null;
    206         boolean wallpaperInUnForceHiding = false;
    207 
    208         for (int i = mService.mWindows.size() - 1; i >= 0; i--) {
    209             WindowState win = mService.mWindows.get(i);
    210             WindowStateAnimator winAnimator = win.mWinAnimator;
    211             final int flags = winAnimator.mAttrFlags;
    212 
    213             if (winAnimator.mSurface != null) {
    214                 final boolean wasAnimating = winAnimator.mWasAnimating;
    215                 final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime);
    216 
    217                 if (WindowManagerService.DEBUG_WALLPAPER) {
    218                     Slog.v(TAG, win + ": wasAnimating=" + wasAnimating +
    219                             ", nowAnimating=" + nowAnimating);
    220                 }
    221 
    222                 // If this window is animating, make a note that we have
    223                 // an animating window and take care of a request to run
    224                 // a detached wallpaper animation.
    225                 if (nowAnimating) {
    226                     if (winAnimator.mAnimation != null) {
    227                         if ((flags & FLAG_SHOW_WALLPAPER) != 0
    228                                 && winAnimator.mAnimation.getDetachWallpaper()) {
    229                             mDetachedWallpaper = win;
    230                         }
    231                         final int backgroundColor = winAnimator.mAnimation.getBackgroundColor();
    232                         if (backgroundColor != 0) {
    233                             if (mWindowAnimationBackground == null
    234                                     || (winAnimator.mAnimLayer <
    235                                             mWindowAnimationBackground.mWinAnimator.mAnimLayer)) {
    236                                 mWindowAnimationBackground = win;
    237                                 mWindowAnimationBackgroundColor = backgroundColor;
    238                             }
    239                         }
    240                     }
    241                     mAnimating = true;
    242                 }
    243 
    244                 // If this window's app token is running a detached wallpaper
    245                 // animation, make a note so we can ensure the wallpaper is
    246                 // displayed behind it.
    247                 final AppWindowAnimator appAnimator =
    248                         win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
    249                 if (appAnimator != null && appAnimator.animation != null
    250                         && appAnimator.animating) {
    251                     if ((flags & FLAG_SHOW_WALLPAPER) != 0
    252                             && appAnimator.animation.getDetachWallpaper()) {
    253                         mDetachedWallpaper = win;
    254                     }
    255                     final int backgroundColor = appAnimator.animation.getBackgroundColor();
    256                     if (backgroundColor != 0) {
    257                         if (mWindowAnimationBackground == null
    258                                 || (winAnimator.mAnimLayer <
    259                                         mWindowAnimationBackground.mWinAnimator.mAnimLayer)) {
    260                             mWindowAnimationBackground = win;
    261                             mWindowAnimationBackgroundColor = backgroundColor;
    262                         }
    263                     }
    264                 }
    265 
    266                 if (wasAnimating && !winAnimator.mAnimating && mService.mWallpaperTarget == win) {
    267                     mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
    268                     mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
    269                     if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
    270                         mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2",
    271                             mPendingLayoutChanges);
    272                     }
    273                 }
    274 
    275                 if (mPolicy.doesForceHide(win, win.mAttrs)) {
    276                     if (!wasAnimating && nowAnimating) {
    277                         if (WindowManagerService.DEBUG_ANIM ||
    278                                 WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
    279                                 "Animation started that could impact force hide: " + win);
    280                         mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED;
    281                         mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
    282                         if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
    283                             mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 3",
    284                                 mPendingLayoutChanges);
    285                         }
    286                         mService.mFocusMayChange = true;
    287                     }
    288                     if (win.isReadyForDisplay()) {
    289                         if (nowAnimating) {
    290                             if (winAnimator.mAnimationIsEntrance) {
    291                                 mForceHiding = KEYGUARD_ANIMATING_IN;
    292                             } else {
    293                                 mForceHiding = KEYGUARD_ANIMATING_OUT;
    294                             }
    295                         } else {
    296                             mForceHiding = KEYGUARD_SHOWN;
    297                         }
    298                     }
    299                     if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
    300                             "Force hide " + mForceHiding
    301                             + " hasSurface=" + win.mHasSurface
    302                             + " policyVis=" + win.mPolicyVisibility
    303                             + " destroying=" + win.mDestroying
    304                             + " attHidden=" + win.mAttachedHidden
    305                             + " vis=" + win.mViewVisibility
    306                             + " hidden=" + win.mRootToken.hidden
    307                             + " anim=" + win.mWinAnimator.mAnimation);
    308                 } else if (mPolicy.canBeForceHidden(win, win.mAttrs)) {
    309                     final boolean hideWhenLocked =
    310                             (winAnimator.mAttrFlags & FLAG_SHOW_WHEN_LOCKED) == 0;
    311                     final boolean changed;
    312                     if (((mForceHiding == KEYGUARD_ANIMATING_IN)
    313                                 && (!winAnimator.isAnimating() || hideWhenLocked))
    314                             || ((mForceHiding == KEYGUARD_SHOWN) && hideWhenLocked)) {
    315                         changed = win.hideLw(false, false);
    316                         if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
    317                                 "Now policy hidden: " + win);
    318                     } else {
    319                         changed = win.showLw(false, false);
    320                         if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
    321                                 "Now policy shown: " + win);
    322                         if (changed) {
    323                             if ((mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0
    324                                     && win.isVisibleNow() /*w.isReadyForDisplay()*/) {
    325                                 if (unForceHiding == null) {
    326                                     unForceHiding = new ArrayList<WindowStateAnimator>();
    327                                 }
    328                                 unForceHiding.add(winAnimator);
    329                                 if ((win.mAttrs.flags&WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
    330                                     wallpaperInUnForceHiding = true;
    331                                 }
    332                             }
    333                             if (mCurrentFocus == null || mCurrentFocus.mLayer < win.mLayer) {
    334                                 // We are showing on to of the current
    335                                 // focus, so re-evaluate focus to make
    336                                 // sure it is correct.
    337                                 mService.mFocusMayChange = true;
    338                             }
    339                         }
    340                     }
    341                     if (changed && (flags & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
    342                         mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
    343                         mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
    344                         if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
    345                             mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 4",
    346                                 mPendingLayoutChanges);
    347                         }
    348                     }
    349                 }
    350             }
    351 
    352             final AppWindowToken atoken = win.mAppToken;
    353             if (winAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW) {
    354                 if (atoken == null || atoken.allDrawn) {
    355                     if (winAnimator.performShowLocked()) {
    356                         mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
    357                         if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
    358                             mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5",
    359                                 mPendingLayoutChanges);
    360                         }
    361                     }
    362                 }
    363             }
    364             final AppWindowAnimator appAnimator =
    365                     atoken == null ? null : atoken.mAppAnimator;
    366             if (appAnimator != null && appAnimator.thumbnail != null) {
    367                 if (appAnimator.thumbnailTransactionSeq != mAnimTransactionSequence) {
    368                     appAnimator.thumbnailTransactionSeq = mAnimTransactionSequence;
    369                     appAnimator.thumbnailLayer = 0;
    370                 }
    371                 if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
    372                     appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
    373                 }
    374             }
    375         } // end forall windows
    376 
    377         // If we have windows that are being show due to them no longer
    378         // being force-hidden, apply the appropriate animation to them.
    379         if (unForceHiding != null) {
    380             for (int i=unForceHiding.size()-1; i>=0; i--) {
    381                 Animation a = mPolicy.createForceHideEnterAnimation(wallpaperInUnForceHiding);
    382                 if (a != null) {
    383                     final WindowStateAnimator winAnimator = unForceHiding.get(i);
    384                     winAnimator.setAnimation(a);
    385                     winAnimator.mAnimationIsEntrance = true;
    386                 }
    387             }
    388         }
    389     }
    390 
    391     private void testTokenMayBeDrawnLocked() {
    392         // See if any windows have been drawn, so they (and others
    393         // associated with them) can now be shown.
    394         final ArrayList<AppWindowToken> appTokens = mService.mAnimatingAppTokens;
    395         final int NT = appTokens.size();
    396         for (int i=0; i<NT; i++) {
    397             AppWindowToken wtoken = appTokens.get(i);
    398             final boolean allDrawn = wtoken.allDrawn;
    399             if (allDrawn != wtoken.mAppAnimator.allDrawn) {
    400                 wtoken.mAppAnimator.allDrawn = allDrawn;
    401                 if (allDrawn) {
    402                     // The token has now changed state to having all
    403                     // windows shown...  what to do, what to do?
    404                     if (wtoken.mAppAnimator.freezingScreen) {
    405                         wtoken.mAppAnimator.showAllWindowsLocked();
    406                         mService.unsetAppFreezingScreenLocked(wtoken, false, true);
    407                         if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(TAG,
    408                                 "Setting mOrientationChangeComplete=true because wtoken "
    409                                 + wtoken + " numInteresting=" + wtoken.numInterestingWindows
    410                                 + " numDrawn=" + wtoken.numDrawnWindows);
    411                         // This will set mOrientationChangeComplete and cause a pass through layout.
    412                         mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
    413                     } else {
    414                         mPendingLayoutChanges |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
    415                         if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
    416                             mService.debugLayoutRepeats("testTokenMayBeDrawnLocked",
    417                                 mPendingLayoutChanges);
    418                         }
    419 
    420                         // We can now show all of the drawn windows!
    421                         if (!mService.mOpeningApps.contains(wtoken)) {
    422                             mAnimating |= wtoken.mAppAnimator.showAllWindowsLocked();
    423                         }
    424                     }
    425                 }
    426             }
    427         }
    428     }
    429 
    430     private void performAnimationsLocked() {
    431         mForceHiding = KEYGUARD_NOT_SHOWN;
    432         mDetachedWallpaper = null;
    433         mWindowAnimationBackground = null;
    434         mWindowAnimationBackgroundColor = 0;
    435 
    436         updateWindowsAndWallpaperLocked();
    437         if ((mPendingLayoutChanges & WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
    438             mPendingActions |= WALLPAPER_ACTION_PENDING;
    439         }
    440 
    441         testTokenMayBeDrawnLocked();
    442     }
    443 
    444     synchronized void animate() {
    445         mPendingLayoutChanges = 0;
    446         mCurrentTime = SystemClock.uptimeMillis();
    447         mBulkUpdateParams = 0;
    448         boolean wasAnimating = mAnimating;
    449         mAnimating = false;
    450         if (WindowManagerService.DEBUG_WINDOW_TRACE) {
    451             Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime);
    452         }
    453 
    454         // Update animations of all applications, including those
    455         // associated with exiting/removed apps
    456         Surface.openTransaction();
    457 
    458         try {
    459             updateWindowsAppsAndRotationAnimationsLocked();
    460             performAnimationsLocked();
    461             testWallpaperAndBackgroundLocked();
    462 
    463             // THIRD LOOP: Update the surfaces of all windows.
    464 
    465             if (mScreenRotationAnimation != null) {
    466                 mScreenRotationAnimation.updateSurfaces();
    467             }
    468 
    469             final int N = mWinAnimators.size();
    470             for (int i = 0; i < N; i++) {
    471                 mWinAnimators.get(i).prepareSurfaceLocked(true);
    472             }
    473 
    474             if (mDimParams != null) {
    475                 mDimAnimator.updateParameters(mContext.getResources(), mDimParams, mCurrentTime);
    476             }
    477             if (mDimAnimator != null && mDimAnimator.mDimShown) {
    478                 mAnimating |= mDimAnimator.updateSurface(isDimming(), mCurrentTime,
    479                         !mService.okToDisplay());
    480             }
    481 
    482             if (mService.mBlackFrame != null) {
    483                 if (mScreenRotationAnimation != null) {
    484                     mService.mBlackFrame.setMatrix(
    485                             mScreenRotationAnimation.getEnterTransformation().getMatrix());
    486                 } else {
    487                     mService.mBlackFrame.clearMatrix();
    488                 }
    489             }
    490 
    491             if (mService.mWatermark != null) {
    492                 mService.mWatermark.drawIfNeeded();
    493             }
    494         } catch (RuntimeException e) {
    495             Log.wtf(TAG, "Unhandled exception in Window Manager", e);
    496         } finally {
    497             Surface.closeTransaction();
    498         }
    499 
    500         mService.bulkSetParameters(mBulkUpdateParams, mPendingLayoutChanges);
    501 
    502         if (mAnimating) {
    503             mService.scheduleAnimationLocked();
    504         } else if (wasAnimating) {
    505             mService.requestTraversalLocked();
    506         }
    507         if (WindowManagerService.DEBUG_WINDOW_TRACE) {
    508             Slog.i(TAG, "!!! animate: exit mAnimating=" + mAnimating
    509                 + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams)
    510                 + " mPendingLayoutChanges=" + Integer.toHexString(mPendingLayoutChanges));
    511         }
    512     }
    513 
    514     WindowState mCurrentFocus;
    515     void setCurrentFocus(final WindowState currentFocus) {
    516         mCurrentFocus = currentFocus;
    517     }
    518 
    519     void setDisplayDimensions(final int curWidth, final int curHeight,
    520                         final int appWidth, final int appHeight) {
    521         mDw = curWidth;
    522         mDh = curHeight;
    523         mInnerDw = appWidth;
    524         mInnerDh = appHeight;
    525     }
    526 
    527     void startDimming(final WindowStateAnimator winAnimator, final float target,
    528                       final int width, final int height) {
    529         if (mDimAnimator == null) {
    530             mDimAnimator = new DimAnimator(mService.mFxSession);
    531         }
    532         // Only set dim params on the highest dimmed layer.
    533         final WindowStateAnimator dimWinAnimator = mDimParams == null
    534                 ? null : mDimParams.mDimWinAnimator;
    535         // Don't turn on for an unshown surface, or for any layer but the highest dimmed one.
    536         if (winAnimator.mSurfaceShown &&
    537                 (dimWinAnimator == null || !dimWinAnimator.mSurfaceShown
    538                 || dimWinAnimator.mAnimLayer < winAnimator.mAnimLayer)) {
    539             mService.mH.sendMessage(mService.mH.obtainMessage(SET_DIM_PARAMETERS,
    540                     new DimAnimator.Parameters(winAnimator, width, height, target)));
    541         }
    542     }
    543 
    544     // TODO(cmautner): Move into Handler
    545     void stopDimming() {
    546         mService.mH.sendMessage(mService.mH.obtainMessage(SET_DIM_PARAMETERS, null));
    547     }
    548 
    549     boolean isDimming() {
    550         return mDimParams != null;
    551     }
    552 
    553     boolean isDimming(final WindowStateAnimator winAnimator) {
    554         return mDimParams != null && mDimParams.mDimWinAnimator == winAnimator;
    555     }
    556 
    557     public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
    558         if (dumpAll) {
    559             if (mWindowDetachedWallpaper != null) {
    560                 pw.print(prefix); pw.print("mWindowDetachedWallpaper=");
    561                         pw.println(mWindowDetachedWallpaper);
    562             }
    563             pw.print(prefix); pw.print("mAnimTransactionSequence=");
    564                     pw.println(mAnimTransactionSequence);
    565             if (mWindowAnimationBackgroundSurface != null) {
    566                 pw.print(prefix); pw.print("mWindowAnimationBackgroundSurface:");
    567                         mWindowAnimationBackgroundSurface.printTo(prefix + "  ", pw);
    568             }
    569             if (mDimAnimator != null) {
    570                 pw.print(prefix); pw.print("mDimAnimator:");
    571                 mDimAnimator.printTo(prefix + "  ", pw);
    572             } else {
    573                 pw.print(prefix); pw.print("no DimAnimator ");
    574             }
    575         }
    576     }
    577 
    578     static class SetAnimationParams {
    579         final WindowStateAnimator mWinAnimator;
    580         final Animation mAnimation;
    581         final int mAnimDw;
    582         final int mAnimDh;
    583         public SetAnimationParams(final WindowStateAnimator winAnimator,
    584                                   final Animation animation, final int animDw, final int animDh) {
    585             mWinAnimator = winAnimator;
    586             mAnimation = animation;
    587             mAnimDw = animDw;
    588             mAnimDh = animDh;
    589         }
    590     }
    591 
    592     synchronized void clearPendingActions() {
    593         mPendingActions = 0;
    594     }
    595 }
    596