WindowAnimator.java revision 41a7b7911eb7f1253c9037e70a6ffca9c535898d
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.server.wm; 18 19import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; 20import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; 21 22import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; 23import static com.android.server.wm.WindowManagerService.LayoutFields.SET_UPDATE_ROTATION; 24import static com.android.server.wm.WindowManagerService.LayoutFields.SET_WALLPAPER_MAY_CHANGE; 25import static com.android.server.wm.WindowManagerService.LayoutFields.SET_FORCE_HIDING_CHANGED; 26import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE; 27import static com.android.server.wm.WindowManagerService.LayoutFields.SET_WALLPAPER_ACTION_PENDING; 28 29import android.content.Context; 30import android.os.Debug; 31import android.os.SystemClock; 32import android.util.Log; 33import android.util.Slog; 34import android.util.SparseArray; 35import android.util.SparseIntArray; 36import android.util.TimeUtils; 37import android.view.Display; 38import android.view.SurfaceControl; 39import android.view.WindowManagerPolicy; 40import android.view.animation.AlphaAnimation; 41import android.view.animation.Animation; 42 43import com.android.server.wm.WindowManagerService.LayoutFields; 44 45import java.io.PrintWriter; 46import java.util.ArrayList; 47 48/** 49 * Singleton class that carries out the animations and Surface operations in a separate task 50 * on behalf of WindowManagerService. 51 */ 52public class WindowAnimator { 53 private static final String TAG = "WindowAnimator"; 54 55 /** How long to give statusbar to clear the private keyguard flag when animating out */ 56 private static final long KEYGUARD_ANIM_TIMEOUT_MS = 1000; 57 58 final WindowManagerService mService; 59 final Context mContext; 60 final WindowManagerPolicy mPolicy; 61 62 boolean mAnimating; 63 64 final Runnable mAnimationRunnable; 65 66 /** Time of current animation step. Reset on each iteration */ 67 long mCurrentTime; 68 69 /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this 70 * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */ 71 private int mAnimTransactionSequence; 72 73 /** Window currently running an animation that has requested it be detached 74 * from the wallpaper. This means we need to ensure the wallpaper is 75 * visible behind it in case it animates in a way that would allow it to be 76 * seen. If multiple windows satisfy this, use the lowest window. */ 77 WindowState mWindowDetachedWallpaper = null; 78 79 WindowStateAnimator mUniverseBackground = null; 80 int mAboveUniverseLayer = 0; 81 82 int mBulkUpdateParams = 0; 83 Object mLastWindowFreezeSource; 84 85 SparseArray<DisplayContentsAnimator> mDisplayContentsAnimators = 86 new SparseArray<DisplayContentsAnimator>(2); 87 88 boolean mInitialized = false; 89 90 boolean mKeyguardGoingAway; 91 boolean mKeyguardGoingAwayToNotificationShade; 92 boolean mKeyguardGoingAwayDisableWindowAnimations; 93 94 // forceHiding states. 95 static final int KEYGUARD_NOT_SHOWN = 0; 96 static final int KEYGUARD_ANIMATING_IN = 1; 97 static final int KEYGUARD_SHOWN = 2; 98 static final int KEYGUARD_ANIMATING_OUT = 3; 99 int mForceHiding = KEYGUARD_NOT_SHOWN; 100 101 private String forceHidingToString() { 102 switch (mForceHiding) { 103 case KEYGUARD_NOT_SHOWN: return "KEYGUARD_NOT_SHOWN"; 104 case KEYGUARD_ANIMATING_IN: return "KEYGUARD_ANIMATING_IN"; 105 case KEYGUARD_SHOWN: return "KEYGUARD_SHOWN"; 106 case KEYGUARD_ANIMATING_OUT:return "KEYGUARD_ANIMATING_OUT"; 107 default: return "KEYGUARD STATE UNKNOWN " + mForceHiding; 108 } 109 } 110 111 WindowAnimator(final WindowManagerService service) { 112 mService = service; 113 mContext = service.mContext; 114 mPolicy = service.mPolicy; 115 116 mAnimationRunnable = new Runnable() { 117 @Override 118 public void run() { 119 synchronized (mService.mWindowMap) { 120 mService.mAnimationScheduled = false; 121 animateLocked(); 122 } 123 } 124 }; 125 } 126 127 void addDisplayLocked(final int displayId) { 128 // Create the DisplayContentsAnimator object by retrieving it. 129 getDisplayContentsAnimatorLocked(displayId); 130 if (displayId == Display.DEFAULT_DISPLAY) { 131 mInitialized = true; 132 } 133 } 134 135 void removeDisplayLocked(final int displayId) { 136 final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId); 137 if (displayAnimator != null) { 138 if (displayAnimator.mScreenRotationAnimation != null) { 139 displayAnimator.mScreenRotationAnimation.kill(); 140 displayAnimator.mScreenRotationAnimation = null; 141 } 142 } 143 144 mDisplayContentsAnimators.delete(displayId); 145 } 146 147 void hideWallpapersLocked(final WindowState w) { 148 final WindowState wallpaperTarget = mService.mWallpaperTarget; 149 final WindowState lowerWallpaperTarget = mService.mLowerWallpaperTarget; 150 final ArrayList<WindowToken> wallpaperTokens = mService.mWallpaperTokens; 151 152 if ((wallpaperTarget == w && lowerWallpaperTarget == null) || wallpaperTarget == null) { 153 final int numTokens = wallpaperTokens.size(); 154 for (int i = numTokens - 1; i >= 0; i--) { 155 final WindowToken token = wallpaperTokens.get(i); 156 final int numWindows = token.windows.size(); 157 for (int j = numWindows - 1; j >= 0; j--) { 158 final WindowState wallpaper = token.windows.get(j); 159 final WindowStateAnimator winAnimator = wallpaper.mWinAnimator; 160 if (!winAnimator.mLastHidden) { 161 winAnimator.hide(); 162 mService.dispatchWallpaperVisibility(wallpaper, false); 163 setPendingLayoutChanges(Display.DEFAULT_DISPLAY, 164 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER); 165 } 166 } 167 if (WindowManagerService.DEBUG_WALLPAPER_LIGHT && !token.hidden) Slog.d(TAG, 168 "Hiding wallpaper " + token + " from " + w 169 + " target=" + wallpaperTarget + " lower=" + lowerWallpaperTarget 170 + "\n" + Debug.getCallers(5, " ")); 171 token.hidden = true; 172 } 173 } 174 } 175 176 private void updateAppWindowsLocked(int displayId) { 177 ArrayList<TaskStack> stacks = mService.getDisplayContentLocked(displayId).getStacks(); 178 for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { 179 final TaskStack stack = stacks.get(stackNdx); 180 final ArrayList<Task> tasks = stack.getTasks(); 181 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { 182 final AppTokenList tokens = tasks.get(taskNdx).mAppTokens; 183 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) { 184 final AppWindowAnimator appAnimator = tokens.get(tokenNdx).mAppAnimator; 185 final boolean wasAnimating = appAnimator.animation != null 186 && appAnimator.animation != AppWindowAnimator.sDummyAnimation; 187 if (appAnimator.stepAnimationLocked(mCurrentTime)) { 188 mAnimating = true; 189 } else if (wasAnimating) { 190 // stopped animating, do one more pass through the layout 191 setAppLayoutChanges(appAnimator, 192 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER, 193 "appToken " + appAnimator.mAppToken + " done"); 194 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG, 195 "updateWindowsApps...: done animating " + appAnimator.mAppToken); 196 } 197 } 198 } 199 200 final AppTokenList exitingAppTokens = stack.mExitingAppTokens; 201 final int NEAT = exitingAppTokens.size(); 202 for (int i = 0; i < NEAT; i++) { 203 final AppWindowAnimator appAnimator = exitingAppTokens.get(i).mAppAnimator; 204 final boolean wasAnimating = appAnimator.animation != null 205 && appAnimator.animation != AppWindowAnimator.sDummyAnimation; 206 if (appAnimator.stepAnimationLocked(mCurrentTime)) { 207 mAnimating = true; 208 } else if (wasAnimating) { 209 // stopped animating, do one more pass through the layout 210 setAppLayoutChanges(appAnimator, WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER, 211 "exiting appToken " + appAnimator.mAppToken + " done"); 212 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG, 213 "updateWindowsApps...: done animating exiting " + appAnimator.mAppToken); 214 } 215 } 216 } 217 } 218 219 private void updateWindowsLocked(final int displayId) { 220 ++mAnimTransactionSequence; 221 222 final WindowList windows = mService.getWindowListLocked(displayId); 223 ArrayList<WindowStateAnimator> unForceHiding = null; 224 boolean wallpaperInUnForceHiding = false; 225 WindowState wallpaper = null; 226 227 if (mKeyguardGoingAway) { 228 for (int i = windows.size() - 1; i >= 0; i--) { 229 WindowState win = windows.get(i); 230 if (!mPolicy.isKeyguardHostWindow(win.mAttrs)) { 231 continue; 232 } 233 final WindowStateAnimator winAnimator = win.mWinAnimator; 234 if ((win.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { 235 if (!winAnimator.mAnimating) { 236 // Create a new animation to delay until keyguard is gone on its own. 237 winAnimator.mAnimation = new AlphaAnimation(1.0f, 1.0f); 238 winAnimator.mAnimation.setDuration(KEYGUARD_ANIM_TIMEOUT_MS); 239 winAnimator.mAnimationIsEntrance = false; 240 } 241 } else { 242 mKeyguardGoingAway = false; 243 winAnimator.clearAnimation(); 244 } 245 break; 246 } 247 } 248 249 mForceHiding = KEYGUARD_NOT_SHOWN; 250 251 final WindowState imeTarget = mService.mInputMethodTarget; 252 final boolean showImeOverKeyguard = imeTarget != null && imeTarget.isVisibleNow() && 253 (imeTarget.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0; 254 255 for (int i = windows.size() - 1; i >= 0; i--) { 256 WindowState win = windows.get(i); 257 WindowStateAnimator winAnimator = win.mWinAnimator; 258 final int flags = win.mAttrs.flags; 259 260 if (winAnimator.mSurfaceControl != null) { 261 final boolean wasAnimating = winAnimator.mWasAnimating; 262 final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime); 263 264 if (WindowManagerService.DEBUG_WALLPAPER) { 265 Slog.v(TAG, win + ": wasAnimating=" + wasAnimating + 266 ", nowAnimating=" + nowAnimating); 267 } 268 269 if (wasAnimating && !winAnimator.mAnimating && mService.mWallpaperTarget == win) { 270 mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; 271 setPendingLayoutChanges(Display.DEFAULT_DISPLAY, 272 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER); 273 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { 274 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2", 275 getPendingLayoutChanges(Display.DEFAULT_DISPLAY)); 276 } 277 } 278 279 if (mPolicy.isForceHiding(win.mAttrs)) { 280 if (!wasAnimating && nowAnimating) { 281 if (WindowManagerService.DEBUG_ANIM || 282 WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, 283 "Animation started that could impact force hide: " + win); 284 mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED; 285 setPendingLayoutChanges(displayId, 286 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER); 287 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { 288 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 3", 289 getPendingLayoutChanges(displayId)); 290 } 291 mService.mFocusMayChange = true; 292 } else if (mKeyguardGoingAway && !nowAnimating) { 293 // Timeout!! 294 Slog.e(TAG, "Timeout waiting for animation to startup"); 295 mPolicy.startKeyguardExitAnimation(0, 0); 296 mKeyguardGoingAway = false; 297 } 298 if (win.isReadyForDisplay()) { 299 if (nowAnimating) { 300 if (winAnimator.mAnimationIsEntrance) { 301 mForceHiding = KEYGUARD_ANIMATING_IN; 302 } else { 303 mForceHiding = KEYGUARD_ANIMATING_OUT; 304 } 305 } else { 306 mForceHiding = win.isDrawnLw() ? KEYGUARD_SHOWN : KEYGUARD_NOT_SHOWN; 307 } 308 } 309 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, 310 "Force hide " + forceHidingToString() 311 + " hasSurface=" + win.mHasSurface 312 + " policyVis=" + win.mPolicyVisibility 313 + " destroying=" + win.mDestroying 314 + " attHidden=" + win.mAttachedHidden 315 + " vis=" + win.mViewVisibility 316 + " hidden=" + win.mRootToken.hidden 317 + " anim=" + win.mWinAnimator.mAnimation); 318 } else if (mPolicy.canBeForceHidden(win, win.mAttrs)) { 319 final boolean hideWhenLocked = (flags & FLAG_SHOW_WHEN_LOCKED) == 0 && 320 !(win.mIsImWindow && showImeOverKeyguard); 321 final boolean changed; 322 if (((mForceHiding == KEYGUARD_ANIMATING_IN) 323 && (!winAnimator.isAnimating() || hideWhenLocked)) 324 || ((mForceHiding == KEYGUARD_SHOWN) && hideWhenLocked)) { 325 changed = win.hideLw(false, false); 326 if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG, 327 "Now policy hidden: " + win); 328 } else { 329 changed = win.showLw(false, false); 330 if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG, 331 "Now policy shown: " + win); 332 if (changed) { 333 if ((mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0 334 && win.isVisibleNow() /*w.isReadyForDisplay()*/) { 335 if (unForceHiding == null) { 336 unForceHiding = new ArrayList<WindowStateAnimator>(); 337 } 338 unForceHiding.add(winAnimator); 339 if ((flags & FLAG_SHOW_WALLPAPER) != 0) { 340 wallpaperInUnForceHiding = true; 341 } 342 } 343 final WindowState currentFocus = mService.mCurrentFocus; 344 if (currentFocus == null || currentFocus.mLayer < win.mLayer) { 345 // We are showing on to of the current 346 // focus, so re-evaluate focus to make 347 // sure it is correct. 348 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.v(TAG, 349 "updateWindowsLocked: setting mFocusMayChange true"); 350 mService.mFocusMayChange = true; 351 } 352 } 353 } 354 if (changed && (flags & FLAG_SHOW_WALLPAPER) != 0) { 355 mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; 356 setPendingLayoutChanges(Display.DEFAULT_DISPLAY, 357 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER); 358 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { 359 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 4", 360 getPendingLayoutChanges(Display.DEFAULT_DISPLAY)); 361 } 362 } 363 } 364 } 365 366 final AppWindowToken atoken = win.mAppToken; 367 if (winAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW) { 368 if (atoken == null || atoken.allDrawn) { 369 if (winAnimator.performShowLocked()) { 370 setPendingLayoutChanges(displayId, 371 WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM); 372 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { 373 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5", 374 getPendingLayoutChanges(displayId)); 375 } 376 } 377 } 378 } 379 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator; 380 if (appAnimator != null && appAnimator.thumbnail != null) { 381 if (appAnimator.thumbnailTransactionSeq != mAnimTransactionSequence) { 382 appAnimator.thumbnailTransactionSeq = mAnimTransactionSequence; 383 appAnimator.thumbnailLayer = 0; 384 } 385 if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) { 386 appAnimator.thumbnailLayer = winAnimator.mAnimLayer; 387 } 388 } 389 if (win.mIsWallpaper) { 390 wallpaper = win; 391 } 392 } // end forall windows 393 394 // If we have windows that are being show due to them no longer 395 // being force-hidden, apply the appropriate animation to them. 396 if (unForceHiding != null) { 397 boolean startKeyguardExit = true; 398 for (int i=unForceHiding.size()-1; i>=0; i--) { 399 Animation a = null; 400 if (!mKeyguardGoingAwayDisableWindowAnimations) { 401 a = mPolicy.createForceHideEnterAnimation(wallpaperInUnForceHiding, 402 mKeyguardGoingAwayToNotificationShade); 403 } 404 if (a != null) { 405 final WindowStateAnimator winAnimator = unForceHiding.get(i); 406 winAnimator.setAnimation(a); 407 winAnimator.keyguardGoingAwayAnimation = true; 408 if (startKeyguardExit && mKeyguardGoingAway) { 409 // Do one time only. 410 mPolicy.startKeyguardExitAnimation(mCurrentTime + a.getStartOffset(), 411 a.getDuration()); 412 mKeyguardGoingAway = false; 413 startKeyguardExit = false; 414 } 415 } 416 } 417 418 // Wallpaper is going away in un-force-hide motion, animate it as well. 419 if (!wallpaperInUnForceHiding && wallpaper != null 420 && !mKeyguardGoingAwayDisableWindowAnimations) { 421 Animation a = mPolicy.createForceHideWallpaperExitAnimation( 422 mKeyguardGoingAwayToNotificationShade); 423 if (a != null) { 424 WindowStateAnimator animator = wallpaper.mWinAnimator; 425 animator.setAnimation(a); 426 } 427 } 428 } 429 } 430 431 private void updateWallpaperLocked(int displayId) { 432 mService.getDisplayContentLocked(displayId).resetAnimationBackgroundAnimator(); 433 434 final WindowList windows = mService.getWindowListLocked(displayId); 435 WindowState detachedWallpaper = null; 436 437 for (int i = windows.size() - 1; i >= 0; i--) { 438 final WindowState win = windows.get(i); 439 WindowStateAnimator winAnimator = win.mWinAnimator; 440 if (winAnimator.mSurfaceControl == null) { 441 continue; 442 } 443 444 final int flags = win.mAttrs.flags; 445 446 // If this window is animating, make a note that we have 447 // an animating window and take care of a request to run 448 // a detached wallpaper animation. 449 if (winAnimator.mAnimating) { 450 if (winAnimator.mAnimation != null) { 451 if ((flags & FLAG_SHOW_WALLPAPER) != 0 452 && winAnimator.mAnimation.getDetachWallpaper()) { 453 detachedWallpaper = win; 454 } 455 final int color = winAnimator.mAnimation.getBackgroundColor(); 456 if (color != 0) { 457 final TaskStack stack = win.getStack(); 458 if (stack != null) { 459 stack.setAnimationBackground(winAnimator, color); 460 } 461 } 462 } 463 mAnimating = true; 464 } 465 466 // If this window's app token is running a detached wallpaper 467 // animation, make a note so we can ensure the wallpaper is 468 // displayed behind it. 469 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator; 470 if (appAnimator != null && appAnimator.animation != null 471 && appAnimator.animating) { 472 if ((flags & FLAG_SHOW_WALLPAPER) != 0 473 && appAnimator.animation.getDetachWallpaper()) { 474 detachedWallpaper = win; 475 } 476 477 final int color = appAnimator.animation.getBackgroundColor(); 478 if (color != 0) { 479 final TaskStack stack = win.getStack(); 480 if (stack != null) { 481 stack.setAnimationBackground(winAnimator, color); 482 } 483 } 484 } 485 } // end forall windows 486 487 if (mWindowDetachedWallpaper != detachedWallpaper) { 488 if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG, 489 "Detached wallpaper changed from " + mWindowDetachedWallpaper 490 + " to " + detachedWallpaper); 491 mWindowDetachedWallpaper = detachedWallpaper; 492 mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; 493 } 494 } 495 496 /** See if any windows have been drawn, so they (and others associated with them) can now be 497 * shown. */ 498 private void testTokenMayBeDrawnLocked(int displayId) { 499 // See if any windows have been drawn, so they (and others 500 // associated with them) can now be shown. 501 final ArrayList<Task> tasks = mService.getDisplayContentLocked(displayId).getTasks(); 502 final int numTasks = tasks.size(); 503 for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { 504 final AppTokenList tokens = tasks.get(taskNdx).mAppTokens; 505 final int numTokens = tokens.size(); 506 for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) { 507 final AppWindowToken wtoken = tokens.get(tokenNdx); 508 AppWindowAnimator appAnimator = wtoken.mAppAnimator; 509 final boolean allDrawn = wtoken.allDrawn; 510 if (allDrawn != appAnimator.allDrawn) { 511 appAnimator.allDrawn = allDrawn; 512 if (allDrawn) { 513 // The token has now changed state to having all 514 // windows shown... what to do, what to do? 515 if (appAnimator.freezingScreen) { 516 appAnimator.showAllWindowsLocked(); 517 mService.unsetAppFreezingScreenLocked(wtoken, false, true); 518 if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(TAG, 519 "Setting mOrientationChangeComplete=true because wtoken " 520 + wtoken + " numInteresting=" + wtoken.numInterestingWindows 521 + " numDrawn=" + wtoken.numDrawnWindows); 522 // This will set mOrientationChangeComplete and cause a pass through layout. 523 setAppLayoutChanges(appAnimator, 524 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER, 525 "testTokenMayBeDrawnLocked: freezingScreen"); 526 } else { 527 setAppLayoutChanges(appAnimator, 528 WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM, 529 "testTokenMayBeDrawnLocked"); 530 531 // We can now show all of the drawn windows! 532 if (!mService.mOpeningApps.contains(wtoken)) { 533 mAnimating |= appAnimator.showAllWindowsLocked(); 534 } 535 } 536 } 537 } 538 } 539 } 540 } 541 542 543 /** Locked on mService.mWindowMap. */ 544 private void animateLocked() { 545 if (!mInitialized) { 546 return; 547 } 548 549 mCurrentTime = SystemClock.uptimeMillis(); 550 mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE; 551 boolean wasAnimating = mAnimating; 552 mAnimating = false; 553 if (WindowManagerService.DEBUG_WINDOW_TRACE) { 554 Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime); 555 } 556 557 if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i( 558 TAG, ">>> OPEN TRANSACTION animateLocked"); 559 SurfaceControl.openTransaction(); 560 SurfaceControl.setAnimationTransaction(); 561 try { 562 final int numDisplays = mDisplayContentsAnimators.size(); 563 for (int i = 0; i < numDisplays; i++) { 564 final int displayId = mDisplayContentsAnimators.keyAt(i); 565 updateAppWindowsLocked(displayId); 566 DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i); 567 568 final ScreenRotationAnimation screenRotationAnimation = 569 displayAnimator.mScreenRotationAnimation; 570 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) { 571 if (screenRotationAnimation.stepAnimationLocked(mCurrentTime)) { 572 mAnimating = true; 573 } else { 574 mBulkUpdateParams |= SET_UPDATE_ROTATION; 575 screenRotationAnimation.kill(); 576 displayAnimator.mScreenRotationAnimation = null; 577 } 578 } 579 580 // Update animations of all applications, including those 581 // associated with exiting/removed apps 582 updateWindowsLocked(displayId); 583 updateWallpaperLocked(displayId); 584 585 final WindowList windows = mService.getWindowListLocked(displayId); 586 final int N = windows.size(); 587 for (int j = 0; j < N; j++) { 588 windows.get(j).mWinAnimator.prepareSurfaceLocked(true); 589 } 590 } 591 592 for (int i = 0; i < numDisplays; i++) { 593 final int displayId = mDisplayContentsAnimators.keyAt(i); 594 595 testTokenMayBeDrawnLocked(displayId); 596 597 final ScreenRotationAnimation screenRotationAnimation = 598 mDisplayContentsAnimators.valueAt(i).mScreenRotationAnimation; 599 if (screenRotationAnimation != null) { 600 screenRotationAnimation.updateSurfacesInTransaction(); 601 } 602 603 mAnimating |= mService.getDisplayContentLocked(displayId).animateDimLayers(); 604 605 //TODO (multidisplay): Magnification is supported only for the default display. 606 if (mService.mAccessibilityController != null 607 && displayId == Display.DEFAULT_DISPLAY) { 608 mService.mAccessibilityController.drawMagnifiedRegionBorderIfNeededLocked(); 609 } 610 } 611 612 if (mAnimating) { 613 mService.scheduleAnimationLocked(); 614 } 615 616 mService.setFocusedStackLayer(); 617 618 if (mService.mWatermark != null) { 619 mService.mWatermark.drawIfNeeded(); 620 } 621 } catch (RuntimeException e) { 622 Log.wtf(TAG, "Unhandled exception in Window Manager", e); 623 } finally { 624 SurfaceControl.closeTransaction(); 625 if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i( 626 TAG, "<<< CLOSE TRANSACTION animateLocked"); 627 } 628 629 boolean hasPendingLayoutChanges = false; 630 final int numDisplays = mService.mDisplayContents.size(); 631 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { 632 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx); 633 final int pendingChanges = getPendingLayoutChanges(displayContent.getDisplayId()); 634 if ((pendingChanges & WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { 635 mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING; 636 } 637 if (pendingChanges != 0) { 638 hasPendingLayoutChanges = true; 639 } 640 } 641 642 boolean doRequest = false; 643 if (mBulkUpdateParams != 0) { 644 doRequest = mService.copyAnimToLayoutParamsLocked(); 645 } 646 647 if (hasPendingLayoutChanges || doRequest) { 648 mService.requestTraversalLocked(); 649 } 650 651 if (!mAnimating && wasAnimating) { 652 mService.requestTraversalLocked(); 653 } 654 if (WindowManagerService.DEBUG_WINDOW_TRACE) { 655 Slog.i(TAG, "!!! animate: exit mAnimating=" + mAnimating 656 + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams) 657 + " mPendingLayoutChanges(DEFAULT_DISPLAY)=" 658 + Integer.toHexString(getPendingLayoutChanges(Display.DEFAULT_DISPLAY))); 659 } 660 } 661 662 static String bulkUpdateParamsToString(int bulkUpdateParams) { 663 StringBuilder builder = new StringBuilder(128); 664 if ((bulkUpdateParams & LayoutFields.SET_UPDATE_ROTATION) != 0) { 665 builder.append(" UPDATE_ROTATION"); 666 } 667 if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_MAY_CHANGE) != 0) { 668 builder.append(" WALLPAPER_MAY_CHANGE"); 669 } 670 if ((bulkUpdateParams & LayoutFields.SET_FORCE_HIDING_CHANGED) != 0) { 671 builder.append(" FORCE_HIDING_CHANGED"); 672 } 673 if ((bulkUpdateParams & LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE) != 0) { 674 builder.append(" ORIENTATION_CHANGE_COMPLETE"); 675 } 676 if ((bulkUpdateParams & LayoutFields.SET_TURN_ON_SCREEN) != 0) { 677 builder.append(" TURN_ON_SCREEN"); 678 } 679 return builder.toString(); 680 } 681 682 public void dumpLocked(PrintWriter pw, String prefix, boolean dumpAll) { 683 final String subPrefix = " " + prefix; 684 final String subSubPrefix = " " + subPrefix; 685 686 for (int i = 0; i < mDisplayContentsAnimators.size(); i++) { 687 pw.print(prefix); pw.print("DisplayContentsAnimator #"); 688 pw.print(mDisplayContentsAnimators.keyAt(i)); 689 pw.println(":"); 690 DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i); 691 final WindowList windows = 692 mService.getWindowListLocked(mDisplayContentsAnimators.keyAt(i)); 693 final int N = windows.size(); 694 for (int j = 0; j < N; j++) { 695 WindowStateAnimator wanim = windows.get(j).mWinAnimator; 696 pw.print(subPrefix); pw.print("Window #"); pw.print(j); 697 pw.print(": "); pw.println(wanim); 698 } 699 if (displayAnimator.mScreenRotationAnimation != null) { 700 pw.print(subPrefix); pw.println("mScreenRotationAnimation:"); 701 displayAnimator.mScreenRotationAnimation.printTo(subSubPrefix, pw); 702 } else if (dumpAll) { 703 pw.print(subPrefix); pw.println("no ScreenRotationAnimation "); 704 } 705 } 706 707 pw.println(); 708 709 if (dumpAll) { 710 pw.print(prefix); pw.print("mAnimTransactionSequence="); 711 pw.print(mAnimTransactionSequence); 712 pw.print(" mForceHiding="); pw.println(forceHidingToString()); 713 pw.print(prefix); pw.print("mCurrentTime="); 714 pw.println(TimeUtils.formatUptime(mCurrentTime)); 715 } 716 if (mBulkUpdateParams != 0) { 717 pw.print(prefix); pw.print("mBulkUpdateParams=0x"); 718 pw.print(Integer.toHexString(mBulkUpdateParams)); 719 pw.println(bulkUpdateParamsToString(mBulkUpdateParams)); 720 } 721 if (mWindowDetachedWallpaper != null) { 722 pw.print(prefix); pw.print("mWindowDetachedWallpaper="); 723 pw.println(mWindowDetachedWallpaper); 724 } 725 if (mUniverseBackground != null) { 726 pw.print(prefix); pw.print("mUniverseBackground="); pw.print(mUniverseBackground); 727 pw.print(" mAboveUniverseLayer="); pw.println(mAboveUniverseLayer); 728 } 729 } 730 731 int getPendingLayoutChanges(final int displayId) { 732 if (displayId < 0) { 733 return 0; 734 } 735 return mService.getDisplayContentLocked(displayId).pendingLayoutChanges; 736 } 737 738 void setPendingLayoutChanges(final int displayId, final int changes) { 739 if (displayId >= 0) { 740 mService.getDisplayContentLocked(displayId).pendingLayoutChanges |= changes; 741 } 742 } 743 744 void setAppLayoutChanges(final AppWindowAnimator appAnimator, final int changes, String s) { 745 // Used to track which displays layout changes have been done. 746 SparseIntArray displays = new SparseIntArray(2); 747 WindowList windows = appAnimator.mAppToken.allAppWindows; 748 for (int i = windows.size() - 1; i >= 0; i--) { 749 final int displayId = windows.get(i).getDisplayId(); 750 if (displayId >= 0 && displays.indexOfKey(displayId) < 0) { 751 setPendingLayoutChanges(displayId, changes); 752 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { 753 mService.debugLayoutRepeats(s, getPendingLayoutChanges(displayId)); 754 } 755 // Keep from processing this display again. 756 displays.put(displayId, changes); 757 } 758 } 759 } 760 761 private DisplayContentsAnimator getDisplayContentsAnimatorLocked(int displayId) { 762 DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId); 763 if (displayAnimator == null) { 764 displayAnimator = new DisplayContentsAnimator(); 765 mDisplayContentsAnimators.put(displayId, displayAnimator); 766 } 767 return displayAnimator; 768 } 769 770 void setScreenRotationAnimationLocked(int displayId, ScreenRotationAnimation animation) { 771 if (displayId >= 0) { 772 getDisplayContentsAnimatorLocked(displayId).mScreenRotationAnimation = animation; 773 } 774 } 775 776 ScreenRotationAnimation getScreenRotationAnimationLocked(int displayId) { 777 if (displayId < 0) { 778 return null; 779 } 780 return getDisplayContentsAnimatorLocked(displayId).mScreenRotationAnimation; 781 } 782 783 private class DisplayContentsAnimator { 784 ScreenRotationAnimation mScreenRotationAnimation = null; 785 } 786} 787