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