WindowAnimator.java revision b180d7707ffc2671caf494f2110b8942cedb5521
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 win.getStack().setAnimationBackground(winAnimator, color); 458 } 459 } 460 mAnimating = true; 461 } 462 463 // If this window's app token is running a detached wallpaper 464 // animation, make a note so we can ensure the wallpaper is 465 // displayed behind it. 466 final AppWindowAnimator appAnimator = winAnimator.mAppAnimator; 467 if (appAnimator != null && appAnimator.animation != null 468 && appAnimator.animating) { 469 if ((flags & FLAG_SHOW_WALLPAPER) != 0 470 && appAnimator.animation.getDetachWallpaper()) { 471 detachedWallpaper = win; 472 } 473 474 final int color = appAnimator.animation.getBackgroundColor(); 475 if (color != 0) { 476 win.getStack().setAnimationBackground(winAnimator, color); 477 } 478 } 479 } // end forall windows 480 481 if (mWindowDetachedWallpaper != detachedWallpaper) { 482 if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG, 483 "Detached wallpaper changed from " + mWindowDetachedWallpaper 484 + " to " + detachedWallpaper); 485 mWindowDetachedWallpaper = detachedWallpaper; 486 mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; 487 } 488 } 489 490 /** See if any windows have been drawn, so they (and others associated with them) can now be 491 * shown. */ 492 private void testTokenMayBeDrawnLocked(int displayId) { 493 // See if any windows have been drawn, so they (and others 494 // associated with them) can now be shown. 495 final ArrayList<Task> tasks = mService.getDisplayContentLocked(displayId).getTasks(); 496 final int numTasks = tasks.size(); 497 for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { 498 final AppTokenList tokens = tasks.get(taskNdx).mAppTokens; 499 final int numTokens = tokens.size(); 500 for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) { 501 final AppWindowToken wtoken = tokens.get(tokenNdx); 502 AppWindowAnimator appAnimator = wtoken.mAppAnimator; 503 final boolean allDrawn = wtoken.allDrawn; 504 if (allDrawn != appAnimator.allDrawn) { 505 appAnimator.allDrawn = allDrawn; 506 if (allDrawn) { 507 // The token has now changed state to having all 508 // windows shown... what to do, what to do? 509 if (appAnimator.freezingScreen) { 510 appAnimator.showAllWindowsLocked(); 511 mService.unsetAppFreezingScreenLocked(wtoken, false, true); 512 if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(TAG, 513 "Setting mOrientationChangeComplete=true because wtoken " 514 + wtoken + " numInteresting=" + wtoken.numInterestingWindows 515 + " numDrawn=" + wtoken.numDrawnWindows); 516 // This will set mOrientationChangeComplete and cause a pass through layout. 517 setAppLayoutChanges(appAnimator, 518 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER, 519 "testTokenMayBeDrawnLocked: freezingScreen"); 520 } else { 521 setAppLayoutChanges(appAnimator, 522 WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM, 523 "testTokenMayBeDrawnLocked"); 524 525 // We can now show all of the drawn windows! 526 if (!mService.mOpeningApps.contains(wtoken)) { 527 mAnimating |= appAnimator.showAllWindowsLocked(); 528 } 529 } 530 } 531 } 532 } 533 } 534 } 535 536 537 /** Locked on mService.mWindowMap. */ 538 private void animateLocked() { 539 if (!mInitialized) { 540 return; 541 } 542 543 mCurrentTime = SystemClock.uptimeMillis(); 544 mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE; 545 boolean wasAnimating = mAnimating; 546 mAnimating = false; 547 if (WindowManagerService.DEBUG_WINDOW_TRACE) { 548 Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime); 549 } 550 551 if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i( 552 TAG, ">>> OPEN TRANSACTION animateLocked"); 553 SurfaceControl.openTransaction(); 554 SurfaceControl.setAnimationTransaction(); 555 try { 556 final int numDisplays = mDisplayContentsAnimators.size(); 557 for (int i = 0; i < numDisplays; i++) { 558 final int displayId = mDisplayContentsAnimators.keyAt(i); 559 updateAppWindowsLocked(displayId); 560 DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i); 561 562 final ScreenRotationAnimation screenRotationAnimation = 563 displayAnimator.mScreenRotationAnimation; 564 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) { 565 if (screenRotationAnimation.stepAnimationLocked(mCurrentTime)) { 566 mAnimating = true; 567 } else { 568 mBulkUpdateParams |= SET_UPDATE_ROTATION; 569 screenRotationAnimation.kill(); 570 displayAnimator.mScreenRotationAnimation = null; 571 572 //TODO (multidisplay): Accessibility supported only for the default display. 573 if (mService.mAccessibilityController != null 574 && displayId == Display.DEFAULT_DISPLAY) { 575 // We just finished rotation animation which means we did not 576 // anounce the rotation and waited for it to end, announce now. 577 mService.mAccessibilityController.onRotationChangedLocked( 578 mService.getDefaultDisplayContentLocked(), mService.mRotation); 579 } 580 } 581 } 582 583 // Update animations of all applications, including those 584 // associated with exiting/removed apps 585 updateWindowsLocked(displayId); 586 updateWallpaperLocked(displayId); 587 588 final WindowList windows = mService.getWindowListLocked(displayId); 589 final int N = windows.size(); 590 for (int j = 0; j < N; j++) { 591 windows.get(j).mWinAnimator.prepareSurfaceLocked(true); 592 } 593 } 594 595 for (int i = 0; i < numDisplays; i++) { 596 final int displayId = mDisplayContentsAnimators.keyAt(i); 597 598 testTokenMayBeDrawnLocked(displayId); 599 600 final ScreenRotationAnimation screenRotationAnimation = 601 mDisplayContentsAnimators.valueAt(i).mScreenRotationAnimation; 602 if (screenRotationAnimation != null) { 603 screenRotationAnimation.updateSurfacesInTransaction(); 604 } 605 606 mAnimating |= mService.getDisplayContentLocked(displayId).animateDimLayers(); 607 608 //TODO (multidisplay): Magnification is supported only for the default display. 609 if (mService.mAccessibilityController != null 610 && displayId == Display.DEFAULT_DISPLAY) { 611 mService.mAccessibilityController.drawMagnifiedRegionBorderIfNeededLocked(); 612 } 613 } 614 615 if (mAnimating) { 616 mService.scheduleAnimationLocked(); 617 } 618 619 mService.setFocusedStackLayer(); 620 621 if (mService.mWatermark != null) { 622 mService.mWatermark.drawIfNeeded(); 623 } 624 } catch (RuntimeException e) { 625 Log.wtf(TAG, "Unhandled exception in Window Manager", e); 626 } finally { 627 SurfaceControl.closeTransaction(); 628 if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i( 629 TAG, "<<< CLOSE TRANSACTION animateLocked"); 630 } 631 632 boolean hasPendingLayoutChanges = false; 633 final int numDisplays = mService.mDisplayContents.size(); 634 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { 635 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx); 636 final int pendingChanges = getPendingLayoutChanges(displayContent.getDisplayId()); 637 if ((pendingChanges & WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { 638 mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING; 639 } 640 if (pendingChanges != 0) { 641 hasPendingLayoutChanges = true; 642 } 643 } 644 645 boolean doRequest = false; 646 if (mBulkUpdateParams != 0) { 647 doRequest = mService.copyAnimToLayoutParamsLocked(); 648 } 649 650 if (hasPendingLayoutChanges || doRequest) { 651 mService.requestTraversalLocked(); 652 } 653 654 if (!mAnimating && wasAnimating) { 655 mService.requestTraversalLocked(); 656 } 657 if (WindowManagerService.DEBUG_WINDOW_TRACE) { 658 Slog.i(TAG, "!!! animate: exit mAnimating=" + mAnimating 659 + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams) 660 + " mPendingLayoutChanges(DEFAULT_DISPLAY)=" 661 + Integer.toHexString(getPendingLayoutChanges(Display.DEFAULT_DISPLAY))); 662 } 663 } 664 665 static String bulkUpdateParamsToString(int bulkUpdateParams) { 666 StringBuilder builder = new StringBuilder(128); 667 if ((bulkUpdateParams & LayoutFields.SET_UPDATE_ROTATION) != 0) { 668 builder.append(" UPDATE_ROTATION"); 669 } 670 if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_MAY_CHANGE) != 0) { 671 builder.append(" WALLPAPER_MAY_CHANGE"); 672 } 673 if ((bulkUpdateParams & LayoutFields.SET_FORCE_HIDING_CHANGED) != 0) { 674 builder.append(" FORCE_HIDING_CHANGED"); 675 } 676 if ((bulkUpdateParams & LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE) != 0) { 677 builder.append(" ORIENTATION_CHANGE_COMPLETE"); 678 } 679 if ((bulkUpdateParams & LayoutFields.SET_TURN_ON_SCREEN) != 0) { 680 builder.append(" TURN_ON_SCREEN"); 681 } 682 return builder.toString(); 683 } 684 685 public void dumpLocked(PrintWriter pw, String prefix, boolean dumpAll) { 686 final String subPrefix = " " + prefix; 687 final String subSubPrefix = " " + subPrefix; 688 689 for (int i = 0; i < mDisplayContentsAnimators.size(); i++) { 690 pw.print(prefix); pw.print("DisplayContentsAnimator #"); 691 pw.print(mDisplayContentsAnimators.keyAt(i)); 692 pw.println(":"); 693 DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i); 694 final WindowList windows = 695 mService.getWindowListLocked(mDisplayContentsAnimators.keyAt(i)); 696 final int N = windows.size(); 697 for (int j = 0; j < N; j++) { 698 WindowStateAnimator wanim = windows.get(j).mWinAnimator; 699 pw.print(subPrefix); pw.print("Window #"); pw.print(j); 700 pw.print(": "); pw.println(wanim); 701 } 702 if (displayAnimator.mScreenRotationAnimation != null) { 703 pw.print(subPrefix); pw.println("mScreenRotationAnimation:"); 704 displayAnimator.mScreenRotationAnimation.printTo(subSubPrefix, pw); 705 } else if (dumpAll) { 706 pw.print(subPrefix); pw.println("no ScreenRotationAnimation "); 707 } 708 } 709 710 pw.println(); 711 712 if (dumpAll) { 713 pw.print(prefix); pw.print("mAnimTransactionSequence="); 714 pw.print(mAnimTransactionSequence); 715 pw.print(" mForceHiding="); pw.println(forceHidingToString()); 716 pw.print(prefix); pw.print("mCurrentTime="); 717 pw.println(TimeUtils.formatUptime(mCurrentTime)); 718 } 719 if (mBulkUpdateParams != 0) { 720 pw.print(prefix); pw.print("mBulkUpdateParams=0x"); 721 pw.print(Integer.toHexString(mBulkUpdateParams)); 722 pw.println(bulkUpdateParamsToString(mBulkUpdateParams)); 723 } 724 if (mWindowDetachedWallpaper != null) { 725 pw.print(prefix); pw.print("mWindowDetachedWallpaper="); 726 pw.println(mWindowDetachedWallpaper); 727 } 728 if (mUniverseBackground != null) { 729 pw.print(prefix); pw.print("mUniverseBackground="); pw.print(mUniverseBackground); 730 pw.print(" mAboveUniverseLayer="); pw.println(mAboveUniverseLayer); 731 } 732 } 733 734 int getPendingLayoutChanges(final int displayId) { 735 if (displayId < 0) { 736 return 0; 737 } 738 return mService.getDisplayContentLocked(displayId).pendingLayoutChanges; 739 } 740 741 void setPendingLayoutChanges(final int displayId, final int changes) { 742 if (displayId >= 0) { 743 mService.getDisplayContentLocked(displayId).pendingLayoutChanges |= changes; 744 } 745 } 746 747 void setAppLayoutChanges(final AppWindowAnimator appAnimator, final int changes, String s) { 748 // Used to track which displays layout changes have been done. 749 SparseIntArray displays = new SparseIntArray(2); 750 WindowList windows = appAnimator.mAppToken.allAppWindows; 751 for (int i = windows.size() - 1; i >= 0; i--) { 752 final int displayId = windows.get(i).getDisplayId(); 753 if (displayId >= 0 && displays.indexOfKey(displayId) < 0) { 754 setPendingLayoutChanges(displayId, changes); 755 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { 756 mService.debugLayoutRepeats(s, getPendingLayoutChanges(displayId)); 757 } 758 // Keep from processing this display again. 759 displays.put(displayId, changes); 760 } 761 } 762 } 763 764 private DisplayContentsAnimator getDisplayContentsAnimatorLocked(int displayId) { 765 DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId); 766 if (displayAnimator == null) { 767 displayAnimator = new DisplayContentsAnimator(); 768 mDisplayContentsAnimators.put(displayId, displayAnimator); 769 } 770 return displayAnimator; 771 } 772 773 void setScreenRotationAnimationLocked(int displayId, ScreenRotationAnimation animation) { 774 if (displayId >= 0) { 775 getDisplayContentsAnimatorLocked(displayId).mScreenRotationAnimation = animation; 776 } 777 } 778 779 ScreenRotationAnimation getScreenRotationAnimationLocked(int displayId) { 780 if (displayId < 0) { 781 return null; 782 } 783 return getDisplayContentsAnimatorLocked(displayId).mScreenRotationAnimation; 784 } 785 786 private class DisplayContentsAnimator { 787 ScreenRotationAnimation mScreenRotationAnimation = null; 788 } 789} 790