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