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