blob: dda6b100a7919c090760e3622a6067008507a8d0 [file] [log] [blame]
Craig Mautner764983d2012-03-22 11:37:36 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2
3package com.android.server.wm;
4
5import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Craig Mautnerf12100e2012-06-25 11:13:24 -07006import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Craig Mautner764983d2012-03-22 11:37:36 -07007
Craig Mautnera608b882012-03-30 13:03:49 -07008import static com.android.server.wm.WindowManagerService.LayoutFields.SET_UPDATE_ROTATION;
9import static com.android.server.wm.WindowManagerService.LayoutFields.SET_WALLPAPER_MAY_CHANGE;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070010import static com.android.server.wm.WindowManagerService.LayoutFields.SET_FORCE_HIDING_CHANGED;
Craig Mautner2639da52012-07-09 09:39:06 -070011import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070012
Craig Mautner711f90a2012-07-03 18:43:52 -070013import static com.android.server.wm.WindowManagerService.H.UPDATE_ANIM_PARAMETERS;
Craig Mautnera608b882012-03-30 13:03:49 -070014
Craig Mautner764983d2012-03-22 11:37:36 -070015import android.content.Context;
16import android.os.SystemClock;
17import android.util.Log;
18import android.util.Slog;
19import android.view.Surface;
Craig Mautner764983d2012-03-22 11:37:36 -070020import android.view.WindowManagerPolicy;
21import android.view.animation.Animation;
Craig Mautner764983d2012-03-22 11:37:36 -070022
23import com.android.internal.policy.impl.PhoneWindowManager;
Craig Mautner711f90a2012-07-03 18:43:52 -070024import com.android.server.wm.WindowManagerService.LayoutToAnimatorParams;
Craig Mautner764983d2012-03-22 11:37:36 -070025
Craig Mautnere7ae2502012-03-26 17:11:19 -070026import java.io.PrintWriter;
Dianne Hackborn0c2acff2012-04-12 15:17:07 -070027import java.util.ArrayList;
Craig Mautnere7ae2502012-03-26 17:11:19 -070028
Craig Mautner764983d2012-03-22 11:37:36 -070029/**
Craig Mautner764983d2012-03-22 11:37:36 -070030 * Singleton class that carries out the animations and Surface operations in a separate task
31 * on behalf of WindowManagerService.
32 */
33public class WindowAnimator {
Craig Mautnerbb1449b2012-03-23 16:11:14 -070034 private static final String TAG = "WindowAnimator";
Craig Mautner764983d2012-03-22 11:37:36 -070035
36 final WindowManagerService mService;
37 final Context mContext;
38 final WindowManagerPolicy mPolicy;
39
Craig Mautner7358fbf2012-04-12 21:06:33 -070040 ArrayList<WindowStateAnimator> mWinAnimators = new ArrayList<WindowStateAnimator>();
Craig Mautnerbec53f72012-04-05 11:49:05 -070041
Craig Mautner764983d2012-03-22 11:37:36 -070042 boolean mAnimating;
Craig Mautner01cd0e72012-06-18 10:19:11 -070043
Craig Mautner1caa3992012-06-22 09:46:48 -070044 final Runnable mAnimationRunnable;
45
Craig Mautner764983d2012-03-22 11:37:36 -070046 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. */
Craig Mautner6fbda632012-07-03 09:26:39 -070061 private int mAnimTransactionSequence;
Craig Mautner764983d2012-03-22 11:37:36 -070062
63 /** The one and only screen rotation if one is happening */
64 ScreenRotationAnimation mScreenRotationAnimation = null;
65
Craig Mautnere7ae2502012-03-26 17:11:19 -070066 // 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
Craig Mautner01cd0e72012-06-18 10:19:11 -070069 // seen. If multiple windows satisfy this, use the lowest window.
Craig Mautnere7ae2502012-03-26 17:11:19 -070070 WindowState mWindowDetachedWallpaper = null;
Craig Mautner01cd0e72012-06-18 10:19:11 -070071
Craig Mautnere7ae2502012-03-26 17:11:19 -070072 DimSurface mWindowAnimationBackgroundSurface = null;
73
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070074 WindowStateAnimator mUniverseBackground = null;
75 int mAboveUniverseLayer = 0;
76
Craig Mautnera608b882012-03-30 13:03:49 -070077 int mBulkUpdateParams = 0;
78
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070079 DimAnimator mDimAnimator = null;
80 DimAnimator.Parameters mDimParams = null;
81
Craig Mautner4d7349b2012-04-20 14:52:47 -070082 static final int WALLPAPER_ACTION_PENDING = 1;
83 int mPendingActions;
84
Craig Mautner1caa3992012-06-22 09:46:48 -070085 WindowState mWallpaperTarget = null;
Craig Mautner918b53b2012-07-09 14:15:54 -070086 AppWindowAnimator mWpAppAnimator = null;
87 WindowState mLowerWallpaperTarget = null;
88 WindowState mUpperWallpaperTarget = null;
Craig Mautner1caa3992012-06-22 09:46:48 -070089
Craig Mautner918b53b2012-07-09 14:15:54 -070090 ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
91
92 /** Parameters being passed from this into mService. */
93 static class AnimatorToLayoutParams {
94 boolean mUpdateQueued;
95 int mBulkUpdateParams;
96 int mPendingLayoutChanges;
97 WindowState mWindowDetachedWallpaper;
98 }
99 /** Do not modify unless holding mService.mWindowMap or this and mAnimToLayout in that order */
Craig Mautner711f90a2012-07-03 18:43:52 -0700100 final AnimatorToLayoutParams mAnimToLayout = new AnimatorToLayoutParams();
101
Craig Mautner918b53b2012-07-09 14:15:54 -0700102 WindowAnimator(final WindowManagerService service) {
Craig Mautner764983d2012-03-22 11:37:36 -0700103 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700104 mContext = service.mContext;
105 mPolicy = service.mPolicy;
Craig Mautner1caa3992012-06-22 09:46:48 -0700106
107 mAnimationRunnable = new Runnable() {
108 @Override
109 public void run() {
110 // TODO(cmautner): When full isolation is achieved for animation, the first lock
111 // goes away and only the WindowAnimator.this remains.
112 synchronized(mService.mWindowMap) {
113 synchronized(WindowAnimator.this) {
114 copyLayoutToAnimParamsLocked();
115 animateLocked();
116 }
117 }
118 }
119 };
Craig Mautner9e809442012-06-22 17:13:04 -0700120
121 mWindowAnimationBackgroundSurface = new DimSurface(mService.mFxSession);
Craig Mautnera76fdb72012-07-03 19:03:02 -0700122 mDimAnimator = new DimAnimator(mService.mFxSession);
Craig Mautner1caa3992012-06-22 09:46:48 -0700123 }
124
Craig Mautner711f90a2012-07-03 18:43:52 -0700125 /** Locked on mAnimToLayout */
126 void updateAnimToLayoutLocked() {
127 final AnimatorToLayoutParams animToLayout = mAnimToLayout;
128 synchronized (animToLayout) {
129 animToLayout.mBulkUpdateParams = mBulkUpdateParams;
130 animToLayout.mPendingLayoutChanges = mPendingLayoutChanges;
131 animToLayout.mWindowDetachedWallpaper = mWindowDetachedWallpaper;
132
133 if (!animToLayout.mUpdateQueued) {
134 animToLayout.mUpdateQueued = true;
135 mService.mH.sendMessage(mService.mH.obtainMessage(UPDATE_ANIM_PARAMETERS));
136 }
137 }
138 }
139
Craig Mautner1caa3992012-06-22 09:46:48 -0700140 /** Copy all WindowManagerService params into local params here. Locked on 'this'. */
141 private void copyLayoutToAnimParamsLocked() {
Craig Mautner711f90a2012-07-03 18:43:52 -0700142 final LayoutToAnimatorParams layoutToAnim = mService.mLayoutToAnim;
Craig Mautner1caa3992012-06-22 09:46:48 -0700143 synchronized(layoutToAnim) {
144 layoutToAnim.mAnimationScheduled = false;
145
Craig Mautner918b53b2012-07-09 14:15:54 -0700146 if ((layoutToAnim.mChanges & LayoutToAnimatorParams.WALLPAPER_TOKENS_CHANGED) != 0) {
147 layoutToAnim.mChanges &= ~LayoutToAnimatorParams.WALLPAPER_TOKENS_CHANGED;
148 mWallpaperTokens = new ArrayList<WindowToken>(layoutToAnim.mWallpaperTokens);
149 }
150
Craig Mautner1caa3992012-06-22 09:46:48 -0700151 mWinAnimators = new ArrayList<WindowStateAnimator>(layoutToAnim.mWinAnimators);
152 mWallpaperTarget = layoutToAnim.mWallpaperTarget;
Craig Mautner918b53b2012-07-09 14:15:54 -0700153 mWpAppAnimator = mWallpaperTarget == null
154 ? null : mWallpaperTarget.mAppToken == null
155 ? null : mWallpaperTarget.mAppToken.mAppAnimator;
156 mLowerWallpaperTarget = layoutToAnim.mLowerWallpaperTarget;
157 mUpperWallpaperTarget = layoutToAnim.mUpperWallpaperTarget;
Craig Mautnera76fdb72012-07-03 19:03:02 -0700158
159 // Set the new DimAnimator params.
160 DimAnimator.Parameters dimParams = layoutToAnim.mDimParams;
161 if (dimParams == null) {
162 mDimParams = dimParams;
163 } else {
164 final WindowStateAnimator newWinAnimator = dimParams.mDimWinAnimator;
165
166 // Only set dim params on the highest dimmed layer.
167 final WindowStateAnimator existingDimWinAnimator = mDimParams == null
168 ? null : mDimParams.mDimWinAnimator;
169 // Don't turn on for an unshown surface, or for any layer but the highest dimmed one.
170 if (newWinAnimator.mSurfaceShown &&
171 (existingDimWinAnimator == null || !existingDimWinAnimator.mSurfaceShown
172 || existingDimWinAnimator.mAnimLayer < newWinAnimator.mAnimLayer)) {
173 mDimParams = dimParams;
174 }
175 }
Craig Mautner1caa3992012-06-22 09:46:48 -0700176 }
177 }
178
Craig Mautnerb9836b92012-06-11 11:40:09 -0700179 void hideWallpapersLocked(final WindowState w) {
Craig Mautner918b53b2012-07-09 14:15:54 -0700180 if ((mWallpaperTarget == w && mLowerWallpaperTarget == null) || mWallpaperTarget == null) {
181 final int numTokens = mWallpaperTokens.size();
182 for (int i = numTokens - 1; i >= 0; i--) {
183 final WindowToken token = mWallpaperTokens.get(i);
184 final int numWindows = token.windows.size();
185 for (int j = numWindows - 1; j >= 0; j--) {
186 final WindowState wallpaper = token.windows.get(j);
Craig Mautnerb9836b92012-06-11 11:40:09 -0700187 final WindowStateAnimator winAnimator = wallpaper.mWinAnimator;
188 if (!winAnimator.mLastHidden) {
189 winAnimator.hide();
Craig Mautner507a2ee2012-06-13 08:39:38 -0700190 mService.dispatchWallpaperVisibility(wallpaper, false);
Craig Mautnerb9836b92012-06-11 11:40:09 -0700191 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
192 }
193 }
194 token.hidden = true;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700195 }
Craig Mautner0afddcb2012-05-08 15:38:00 -0700196 }
197 }
198
Craig Mautner764983d2012-03-22 11:37:36 -0700199 private void updateWindowsAppsAndRotationAnimationsLocked() {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700200 final ArrayList<AppWindowToken> appTokens = mService.mAnimatingAppTokens;
Craig Mautner764983d2012-03-22 11:37:36 -0700201 int i;
Craig Mautneref25d7a2012-05-15 23:01:47 -0700202 final int NAT = appTokens.size();
Craig Mautner764983d2012-03-22 11:37:36 -0700203 for (i=0; i<NAT; i++) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700204 final AppWindowAnimator appAnimator = appTokens.get(i).mAppAnimator;
Craig Mautner59431632012-04-04 11:56:44 -0700205 final boolean wasAnimating = appAnimator.animation != null
Craig Mautnerfbf378c2012-04-23 17:24:21 -0700206 && appAnimator.animation != AppWindowAnimator.sDummyAnimation;
Craig Mautner59431632012-04-04 11:56:44 -0700207 if (appAnimator.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) {
Craig Mautner764983d2012-03-22 11:37:36 -0700208 mAnimating = true;
Craig Mautnerbb1449b2012-03-23 16:11:14 -0700209 } else if (wasAnimating) {
210 // stopped animating, do one more pass through the layout
211 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700212 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
Craig Mautner59431632012-04-04 11:56:44 -0700213 mService.debugLayoutRepeats("appToken " + appAnimator.mAppToken + " done",
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700214 mPendingLayoutChanges);
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700215 }
Craig Mautner83339b42012-05-01 22:13:23 -0700216 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
217 "updateWindowsApps...: done animating " + appAnimator.mAppToken);
Craig Mautnerbb1449b2012-03-23 16:11:14 -0700218 }
219 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700220
Craig Mautnerbb1449b2012-03-23 16:11:14 -0700221 final int NEAT = mService.mExitingAppTokens.size();
222 for (i=0; i<NEAT; i++) {
Craig Mautnere4d8a5d2012-04-05 13:10:37 -0700223 final AppWindowAnimator appAnimator = mService.mExitingAppTokens.get(i).mAppAnimator;
Craig Mautner59431632012-04-04 11:56:44 -0700224 final boolean wasAnimating = appAnimator.animation != null
Craig Mautnerfbf378c2012-04-23 17:24:21 -0700225 && appAnimator.animation != AppWindowAnimator.sDummyAnimation;
Craig Mautner59431632012-04-04 11:56:44 -0700226 if (appAnimator.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) {
Craig Mautnerbb1449b2012-03-23 16:11:14 -0700227 mAnimating = true;
228 } else if (wasAnimating) {
229 // stopped animating, do one more pass through the layout
230 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700231 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
Craig Mautner83339b42012-05-01 22:13:23 -0700232 mService.debugLayoutRepeats("exiting appToken " + appAnimator.mAppToken
Craig Mautner59431632012-04-04 11:56:44 -0700233 + " done", mPendingLayoutChanges);
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700234 }
Craig Mautner83339b42012-05-01 22:13:23 -0700235 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
236 "updateWindowsApps...: done animating exiting " + appAnimator.mAppToken);
Craig Mautner764983d2012-03-22 11:37:36 -0700237 }
238 }
239
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700240 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
Craig Mautner764983d2012-03-22 11:37:36 -0700241 if (mScreenRotationAnimation.stepAnimationLocked(mCurrentTime)) {
Craig Mautner764983d2012-03-22 11:37:36 -0700242 mAnimating = true;
243 } else {
Craig Mautnera608b882012-03-30 13:03:49 -0700244 mBulkUpdateParams |= SET_UPDATE_ROTATION;
Craig Mautner764983d2012-03-22 11:37:36 -0700245 mScreenRotationAnimation.kill();
246 mScreenRotationAnimation = null;
247 }
248 }
249 }
250
Craig Mautner078ea0a2012-06-25 11:04:29 -0700251 private void updateWindowsLocked() {
Craig Mautner6fbda632012-07-03 09:26:39 -0700252 ++mAnimTransactionSequence;
Craig Mautner764983d2012-03-22 11:37:36 -0700253
Dianne Hackborn0c2acff2012-04-12 15:17:07 -0700254 ArrayList<WindowStateAnimator> unForceHiding = null;
255 boolean wallpaperInUnForceHiding = false;
256
Craig Mautner078ea0a2012-06-25 11:04:29 -0700257 boolean forceHiding = false;
Craig Mautner01cd0e72012-06-18 10:19:11 -0700258 for (int i = mWinAnimators.size() - 1; i >= 0; i--) {
259 WindowStateAnimator winAnimator = mWinAnimators.get(i);
260 WindowState win = winAnimator.mWin;
Craig Mautnerbec53f72012-04-05 11:49:05 -0700261 final int flags = winAnimator.mAttrFlags;
Craig Mautner764983d2012-03-22 11:37:36 -0700262
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700263 if (winAnimator.mSurface != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700264 final boolean wasAnimating = winAnimator.mWasAnimating;
265 final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime);
Craig Mautner764983d2012-03-22 11:37:36 -0700266
267 if (WindowManagerService.DEBUG_WALLPAPER) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700268 Slog.v(TAG, win + ": wasAnimating=" + wasAnimating +
Craig Mautner764983d2012-03-22 11:37:36 -0700269 ", nowAnimating=" + nowAnimating);
270 }
271
Craig Mautner918b53b2012-07-09 14:15:54 -0700272 if (wasAnimating && !winAnimator.mAnimating && mWallpaperTarget == win) {
Craig Mautnera608b882012-03-30 13:03:49 -0700273 mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
Craig Mautner764983d2012-03-22 11:37:36 -0700274 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700275 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700276 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2",
277 mPendingLayoutChanges);
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700278 }
Craig Mautner764983d2012-03-22 11:37:36 -0700279 }
280
Craig Mautnerbec53f72012-04-05 11:49:05 -0700281 if (mPolicy.doesForceHide(win, win.mAttrs)) {
Craig Mautner764983d2012-03-22 11:37:36 -0700282 if (!wasAnimating && nowAnimating) {
Craig Mautner83339b42012-05-01 22:13:23 -0700283 if (WindowManagerService.DEBUG_ANIM ||
284 WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
285 "Animation started that could impact force hide: " + win);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700286 mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED;
Craig Mautner764983d2012-03-22 11:37:36 -0700287 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700288 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700289 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 3",
290 mPendingLayoutChanges);
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700291 }
Craig Mautner764983d2012-03-22 11:37:36 -0700292 mService.mFocusMayChange = true;
Dianne Hackbornac920872012-05-22 11:49:49 -0700293 }
Craig Mautnerf12100e2012-06-25 11:13:24 -0700294 if (win.isReadyForDisplay() && winAnimator.mAnimationIsEntrance) {
Craig Mautner078ea0a2012-06-25 11:04:29 -0700295 forceHiding = true;
Craig Mautner764983d2012-03-22 11:37:36 -0700296 }
Dianne Hackbornac920872012-05-22 11:49:49 -0700297 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
Craig Mautner078ea0a2012-06-25 11:04:29 -0700298 "Force hide " + forceHiding
Dianne Hackbornac920872012-05-22 11:49:49 -0700299 + " hasSurface=" + win.mHasSurface
300 + " policyVis=" + win.mPolicyVisibility
301 + " destroying=" + win.mDestroying
302 + " attHidden=" + win.mAttachedHidden
303 + " vis=" + win.mViewVisibility
304 + " hidden=" + win.mRootToken.hidden
305 + " anim=" + win.mWinAnimator.mAnimation);
Craig Mautnerbec53f72012-04-05 11:49:05 -0700306 } else if (mPolicy.canBeForceHidden(win, win.mAttrs)) {
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700307 final boolean changed;
Craig Mautner078ea0a2012-06-25 11:04:29 -0700308 if (forceHiding && (!winAnimator.isAnimating()
Craig Mautnerf12100e2012-06-25 11:13:24 -0700309 || (winAnimator.mAttrFlags & FLAG_SHOW_WHEN_LOCKED) == 0)) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700310 changed = win.hideLw(false, false);
Craig Mautner764983d2012-03-22 11:37:36 -0700311 if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
Craig Mautnerbec53f72012-04-05 11:49:05 -0700312 "Now policy hidden: " + win);
Craig Mautner764983d2012-03-22 11:37:36 -0700313 } else {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700314 changed = win.showLw(false, false);
Craig Mautner764983d2012-03-22 11:37:36 -0700315 if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
Craig Mautnerbec53f72012-04-05 11:49:05 -0700316 "Now policy shown: " + win);
Craig Mautner764983d2012-03-22 11:37:36 -0700317 if (changed) {
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700318 if ((mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0
Craig Mautnerbec53f72012-04-05 11:49:05 -0700319 && win.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn0c2acff2012-04-12 15:17:07 -0700320 if (unForceHiding == null) {
321 unForceHiding = new ArrayList<WindowStateAnimator>();
322 }
323 unForceHiding.add(winAnimator);
Craig Mautner01cd0e72012-06-18 10:19:11 -0700324 if ((flags & FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn0c2acff2012-04-12 15:17:07 -0700325 wallpaperInUnForceHiding = true;
Craig Mautner764983d2012-03-22 11:37:36 -0700326 }
327 }
Craig Mautnerbec53f72012-04-05 11:49:05 -0700328 if (mCurrentFocus == null || mCurrentFocus.mLayer < win.mLayer) {
Craig Mautner764983d2012-03-22 11:37:36 -0700329 // We are showing on to of the current
330 // focus, so re-evaluate focus to make
331 // sure it is correct.
332 mService.mFocusMayChange = true;
333 }
334 }
335 }
Craig Mautner01cd0e72012-06-18 10:19:11 -0700336 if (changed && (flags & FLAG_SHOW_WALLPAPER) != 0) {
Craig Mautnera608b882012-03-30 13:03:49 -0700337 mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
Craig Mautner764983d2012-03-22 11:37:36 -0700338 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700339 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700340 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 4",
341 mPendingLayoutChanges);
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700342 }
Craig Mautner764983d2012-03-22 11:37:36 -0700343 }
344 }
345 }
346
Craig Mautnerbec53f72012-04-05 11:49:05 -0700347 final AppWindowToken atoken = win.mAppToken;
Craig Mautner6fbda632012-07-03 09:26:39 -0700348 if (winAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW) {
349 if (atoken == null || atoken.allDrawn) {
350 if (winAnimator.performShowLocked()) {
351 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
352 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
353 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5",
354 mPendingLayoutChanges);
Craig Mautner764983d2012-03-22 11:37:36 -0700355 }
356 }
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700357 }
Craig Mautner764983d2012-03-22 11:37:36 -0700358 }
Craig Mautner59431632012-04-04 11:56:44 -0700359 final AppWindowAnimator appAnimator =
360 atoken == null ? null : atoken.mAppAnimator;
361 if (appAnimator != null && appAnimator.thumbnail != null) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700362 if (appAnimator.thumbnailTransactionSeq != mAnimTransactionSequence) {
363 appAnimator.thumbnailTransactionSeq = mAnimTransactionSequence;
Craig Mautner59431632012-04-04 11:56:44 -0700364 appAnimator.thumbnailLayer = 0;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700365 }
Craig Mautner59431632012-04-04 11:56:44 -0700366 if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
367 appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700368 }
369 }
Craig Mautner764983d2012-03-22 11:37:36 -0700370 } // end forall windows
Dianne Hackborn0c2acff2012-04-12 15:17:07 -0700371
Craig Mautner078ea0a2012-06-25 11:04:29 -0700372 // If we have windows that are being show due to them no longer
373 // being force-hidden, apply the appropriate animation to them.
374 if (unForceHiding != null) {
375 for (int i=unForceHiding.size()-1; i>=0; i--) {
376 Animation a = mPolicy.createForceHideEnterAnimation(wallpaperInUnForceHiding);
377 if (a != null) {
378 final WindowStateAnimator winAnimator = unForceHiding.get(i);
379 winAnimator.setAnimation(a);
380 winAnimator.mAnimationIsEntrance = true;
381 }
382 }
383 }
384 }
385
386 private void updateWallpaperLocked() {
387 WindowStateAnimator windowAnimationBackground = null;
388 int windowAnimationBackgroundColor = 0;
389 WindowState detachedWallpaper = null;
390
391 for (int i = mWinAnimators.size() - 1; i >= 0; i--) {
392 WindowStateAnimator winAnimator = mWinAnimators.get(i);
393 if (winAnimator.mSurface == null) {
394 continue;
395 }
396
397 final int flags = winAnimator.mAttrFlags;
398 final WindowState win = winAnimator.mWin;
399
400 // If this window is animating, make a note that we have
401 // an animating window and take care of a request to run
402 // a detached wallpaper animation.
403 if (winAnimator.mAnimating) {
404 if (winAnimator.mAnimation != null) {
405 if ((flags & FLAG_SHOW_WALLPAPER) != 0
406 && winAnimator.mAnimation.getDetachWallpaper()) {
407 detachedWallpaper = win;
408 }
409 final int backgroundColor = winAnimator.mAnimation.getBackgroundColor();
410 if (backgroundColor != 0) {
411 if (windowAnimationBackground == null || (winAnimator.mAnimLayer <
412 windowAnimationBackground.mAnimLayer)) {
413 windowAnimationBackground = winAnimator;
414 windowAnimationBackgroundColor = backgroundColor;
415 }
416 }
417 }
418 mAnimating = true;
419 }
420
421 // If this window's app token is running a detached wallpaper
422 // animation, make a note so we can ensure the wallpaper is
423 // displayed behind it.
424 final AppWindowAnimator appAnimator =
425 win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
426 if (appAnimator != null && appAnimator.animation != null
427 && appAnimator.animating) {
428 if ((flags & FLAG_SHOW_WALLPAPER) != 0
429 && appAnimator.animation.getDetachWallpaper()) {
430 detachedWallpaper = win;
431 }
432
433 final int backgroundColor = appAnimator.animation.getBackgroundColor();
434 if (backgroundColor != 0) {
435 if (windowAnimationBackground == null || (winAnimator.mAnimLayer <
436 windowAnimationBackground.mAnimLayer)) {
437 windowAnimationBackground = winAnimator;
438 windowAnimationBackgroundColor = backgroundColor;
439 }
440 }
441 }
442 } // end forall windows
443
Craig Mautner9e809442012-06-22 17:13:04 -0700444 if (mWindowDetachedWallpaper != detachedWallpaper) {
445 if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG,
446 "Detached wallpaper changed from " + mWindowDetachedWallpaper
447 + " to " + detachedWallpaper);
448 mWindowDetachedWallpaper = detachedWallpaper;
449 mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
450 }
451
452 if (windowAnimationBackgroundColor != 0) {
453 // If the window that wants black is the current wallpaper
454 // target, then the black goes *below* the wallpaper so we
455 // don't cause the wallpaper to suddenly disappear.
456 int animLayer = windowAnimationBackground.mAnimLayer;
457 WindowState win = windowAnimationBackground.mWin;
Craig Mautner918b53b2012-07-09 14:15:54 -0700458 if (windowAnimationBackground != null && mWallpaperTarget == win
459 || mLowerWallpaperTarget == win || mUpperWallpaperTarget == win) {
Craig Mautner9e809442012-06-22 17:13:04 -0700460 final int N = mWinAnimators.size();
461 for (int i = 0; i < N; i++) {
462 WindowStateAnimator winAnimator = mWinAnimators.get(i);
Craig Mautner918b53b2012-07-09 14:15:54 -0700463 if (winAnimator.mIsWallpaper) {
Craig Mautner9e809442012-06-22 17:13:04 -0700464 animLayer = winAnimator.mAnimLayer;
465 break;
466 }
467 }
468 }
469
Craig Mautner078ea0a2012-06-25 11:04:29 -0700470 mWindowAnimationBackgroundSurface.show(mDw, mDh,
Craig Mautner9e809442012-06-22 17:13:04 -0700471 animLayer - WindowManagerService.LAYER_OFFSET_DIM,
472 windowAnimationBackgroundColor);
473 } else {
474 mWindowAnimationBackgroundSurface.hide();
475 }
Craig Mautner764983d2012-03-22 11:37:36 -0700476 }
477
478 private void testTokenMayBeDrawnLocked() {
479 // See if any windows have been drawn, so they (and others
480 // associated with them) can now be shown.
Craig Mautneref25d7a2012-05-15 23:01:47 -0700481 final ArrayList<AppWindowToken> appTokens = mService.mAnimatingAppTokens;
482 final int NT = appTokens.size();
Craig Mautner764983d2012-03-22 11:37:36 -0700483 for (int i=0; i<NT; i++) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700484 AppWindowToken wtoken = appTokens.get(i);
Craig Mautner6fbda632012-07-03 09:26:39 -0700485 final boolean allDrawn = wtoken.allDrawn;
486 if (allDrawn != wtoken.mAppAnimator.allDrawn) {
487 wtoken.mAppAnimator.allDrawn = allDrawn;
488 if (allDrawn) {
489 // The token has now changed state to having all
490 // windows shown... what to do, what to do?
491 if (wtoken.mAppAnimator.freezingScreen) {
492 wtoken.mAppAnimator.showAllWindowsLocked();
493 mService.unsetAppFreezingScreenLocked(wtoken, false, true);
494 if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(TAG,
495 "Setting mOrientationChangeComplete=true because wtoken "
496 + wtoken + " numInteresting=" + wtoken.numInterestingWindows
497 + " numDrawn=" + wtoken.numDrawnWindows);
498 // This will set mOrientationChangeComplete and cause a pass through layout.
499 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
500 } else {
501 mPendingLayoutChanges |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
502 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
503 mService.debugLayoutRepeats("testTokenMayBeDrawnLocked",
504 mPendingLayoutChanges);
505 }
Craig Mautner764983d2012-03-22 11:37:36 -0700506
Craig Mautner6fbda632012-07-03 09:26:39 -0700507 // We can now show all of the drawn windows!
508 if (!mService.mOpeningApps.contains(wtoken)) {
509 mAnimating |= wtoken.mAppAnimator.showAllWindowsLocked();
510 }
Craig Mautner764983d2012-03-22 11:37:36 -0700511 }
512 }
513 }
514 }
515 }
516
517 private void performAnimationsLocked() {
Craig Mautner078ea0a2012-06-25 11:04:29 -0700518 updateWindowsLocked();
519 updateWallpaperLocked();
Craig Mautner764983d2012-03-22 11:37:36 -0700520
Craig Mautner4d7349b2012-04-20 14:52:47 -0700521 if ((mPendingLayoutChanges & WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
522 mPendingActions |= WALLPAPER_ACTION_PENDING;
523 }
Craig Mautner764983d2012-03-22 11:37:36 -0700524
Craig Mautner6fbda632012-07-03 09:26:39 -0700525 testTokenMayBeDrawnLocked();
Craig Mautner764983d2012-03-22 11:37:36 -0700526 }
527
Craig Mautner1caa3992012-06-22 09:46:48 -0700528 // TODO(cmautner): Change the following comment when no longer locked on mWindowMap */
529 /** Locked on mService.mWindowMap and this. */
530 private void animateLocked() {
Craig Mautnerbb1449b2012-03-23 16:11:14 -0700531 mPendingLayoutChanges = 0;
Craig Mautner764983d2012-03-22 11:37:36 -0700532 mCurrentTime = SystemClock.uptimeMillis();
Craig Mautner2639da52012-07-09 09:39:06 -0700533 mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE;
Chet Haase198e5642012-05-10 09:55:15 -0700534 boolean wasAnimating = mAnimating;
Craig Mautner7d8df392012-04-06 15:26:23 -0700535 mAnimating = false;
536 if (WindowManagerService.DEBUG_WINDOW_TRACE) {
537 Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime);
538 }
Craig Mautner764983d2012-03-22 11:37:36 -0700539
540 // Update animations of all applications, including those
541 // associated with exiting/removed apps
542 Surface.openTransaction();
543
544 try {
545 updateWindowsAppsAndRotationAnimationsLocked();
546 performAnimationsLocked();
547
548 // THIRD LOOP: Update the surfaces of all windows.
549
550 if (mScreenRotationAnimation != null) {
551 mScreenRotationAnimation.updateSurfaces();
552 }
553
Craig Mautner7358fbf2012-04-12 21:06:33 -0700554 final int N = mWinAnimators.size();
555 for (int i = 0; i < N; i++) {
Craig Mautner0fa77c12012-06-11 15:57:19 -0700556 mWinAnimators.get(i).prepareSurfaceLocked(true);
Craig Mautner764983d2012-03-22 11:37:36 -0700557 }
558
Craig Mautner6af9b922012-04-05 19:25:51 -0700559 if (mDimParams != null) {
560 mDimAnimator.updateParameters(mContext.getResources(), mDimParams, mCurrentTime);
561 }
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700562 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Craig Mautnerf8d4fbb2012-04-11 09:25:53 -0700563 mAnimating |= mDimAnimator.updateSurface(isDimming(), mCurrentTime,
Craig Mautner6af9b922012-04-05 19:25:51 -0700564 !mService.okToDisplay());
Craig Mautner764983d2012-03-22 11:37:36 -0700565 }
566
567 if (mService.mBlackFrame != null) {
568 if (mScreenRotationAnimation != null) {
569 mService.mBlackFrame.setMatrix(
570 mScreenRotationAnimation.getEnterTransformation().getMatrix());
571 } else {
572 mService.mBlackFrame.clearMatrix();
573 }
574 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700575
576 if (mService.mWatermark != null) {
577 mService.mWatermark.drawIfNeeded();
578 }
Craig Mautner764983d2012-03-22 11:37:36 -0700579 } catch (RuntimeException e) {
580 Log.wtf(TAG, "Unhandled exception in Window Manager", e);
581 } finally {
582 Surface.closeTransaction();
583 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700584
Craig Mautner01cd0e72012-06-18 10:19:11 -0700585 if (mBulkUpdateParams != 0 || mPendingLayoutChanges != 0) {
Craig Mautner711f90a2012-07-03 18:43:52 -0700586 updateAnimToLayoutLocked();
Craig Mautner01cd0e72012-06-18 10:19:11 -0700587 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700588
589 if (mAnimating) {
Craig Mautner711f90a2012-07-03 18:43:52 -0700590 synchronized (mService.mLayoutToAnim) {
591 mService.scheduleAnimationLocked();
Craig Mautner1caa3992012-06-22 09:46:48 -0700592 }
Chet Haase198e5642012-05-10 09:55:15 -0700593 } else if (wasAnimating) {
594 mService.requestTraversalLocked();
Craig Mautner7d8df392012-04-06 15:26:23 -0700595 }
596 if (WindowManagerService.DEBUG_WINDOW_TRACE) {
597 Slog.i(TAG, "!!! animate: exit mAnimating=" + mAnimating
598 + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams)
599 + " mPendingLayoutChanges=" + Integer.toHexString(mPendingLayoutChanges));
600 }
Craig Mautner764983d2012-03-22 11:37:36 -0700601 }
602
603 WindowState mCurrentFocus;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700604 void setCurrentFocus(final WindowState currentFocus) {
Craig Mautner764983d2012-03-22 11:37:36 -0700605 mCurrentFocus = currentFocus;
606 }
607
608 void setDisplayDimensions(final int curWidth, final int curHeight,
609 final int appWidth, final int appHeight) {
610 mDw = curWidth;
611 mDh = curHeight;
612 mInnerDw = appWidth;
613 mInnerDh = appHeight;
614 }
615
Craig Mautnerf8d4fbb2012-04-11 09:25:53 -0700616 boolean isDimming() {
617 return mDimParams != null;
618 }
619
Craig Mautneracafd192012-05-10 10:41:02 -0700620 boolean isDimming(final WindowStateAnimator winAnimator) {
621 return mDimParams != null && mDimParams.mDimWinAnimator == winAnimator;
622 }
623
Craig Mautnere7ae2502012-03-26 17:11:19 -0700624 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700625 if (dumpAll) {
626 if (mWindowDetachedWallpaper != null) {
627 pw.print(prefix); pw.print("mWindowDetachedWallpaper=");
628 pw.println(mWindowDetachedWallpaper);
629 }
630 pw.print(prefix); pw.print("mAnimTransactionSequence=");
631 pw.println(mAnimTransactionSequence);
632 if (mWindowAnimationBackgroundSurface != null) {
633 pw.print(prefix); pw.print("mWindowAnimationBackgroundSurface:");
634 mWindowAnimationBackgroundSurface.printTo(prefix + " ", pw);
635 }
636 if (mDimAnimator != null) {
637 pw.print(prefix); pw.print("mDimAnimator:");
638 mDimAnimator.printTo(prefix + " ", pw);
639 } else {
640 pw.print(prefix); pw.print("no DimAnimator ");
641 }
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700642 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700643 }
Craig Mautnerbec53f72012-04-05 11:49:05 -0700644
645 static class SetAnimationParams {
646 final WindowStateAnimator mWinAnimator;
647 final Animation mAnimation;
648 final int mAnimDw;
649 final int mAnimDh;
650 public SetAnimationParams(final WindowStateAnimator winAnimator,
651 final Animation animation, final int animDw, final int animDh) {
652 mWinAnimator = winAnimator;
653 mAnimation = animation;
654 mAnimDw = animDw;
655 mAnimDh = animDh;
656 }
657 }
Craig Mautner4d7349b2012-04-20 14:52:47 -0700658
659 synchronized void clearPendingActions() {
660 mPendingActions = 0;
661 }
Craig Mautner764983d2012-03-22 11:37:36 -0700662}