Fix race condition in BoundsAnimationController

- The SfVsyncFrameCallbackProvider needs to be initialized with the
  associated handler thread's Choreographer instance.

Bug: 111465953
Test: Take a systrace and ensure the animation is running on the right
      thread

Change-Id: Ia70b09d391fd2d154e00d081cfcf0d2354e51db2
(cherry picked from commit 3749a052c9)
This commit is contained in:
Winson Chung
2018-07-16 12:42:37 -07:00
parent e85115fdb7
commit f8a96ddcb8
2 changed files with 9 additions and 1 deletions

View File

@@ -31,11 +31,13 @@ import android.os.IBinder;
import android.os.Debug;
import android.util.ArrayMap;
import android.util.Slog;
import android.view.Choreographer;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -112,6 +114,7 @@ public class BoundsAnimationController {
private final Interpolator mFastOutSlowInInterpolator;
private boolean mFinishAnimationAfterTransition = false;
private final AnimationHandler mAnimationHandler;
private Choreographer mChoreographer;
private static final int WAIT_FOR_DRAW_TIMEOUT_MS = 3000;
@@ -123,6 +126,12 @@ public class BoundsAnimationController {
mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
com.android.internal.R.interpolator.fast_out_slow_in);
mAnimationHandler = animationHandler;
if (animationHandler != null) {
// If an animation handler is provided, then ensure that it runs on the sf vsync tick
handler.runWithScissors(() -> mChoreographer = Choreographer.getSfInstance(),
0 /* timeout */);
animationHandler.setProvider(new SfVsyncFrameCallbackProvider(mChoreographer));
}
}
@VisibleForTesting

View File

@@ -1005,7 +1005,6 @@ public class WindowManagerService extends IWindowManager.Stub
mAppTransition.registerListenerLocked(mActivityManagerAppTransitionNotifier);
final AnimationHandler animationHandler = new AnimationHandler();
animationHandler.setProvider(new SfVsyncFrameCallbackProvider());
mBoundsAnimationController = new BoundsAnimationController(context, mAppTransition,
AnimationThread.getHandler(), animationHandler);