diff options
| -rw-r--r-- | api/test-current.txt | 9 | ||||
| -rw-r--r-- | core/java/android/view/animation/AnimationUtils.java | 34 |
2 files changed, 41 insertions, 2 deletions
diff --git a/api/test-current.txt b/api/test-current.txt index b02da04bbcd1..eda6296fb39a 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -1047,6 +1047,15 @@ package android.view.accessibility { } +package android.view.animation { + + public class AnimationUtils { + method public static void lockAnimationClock(long); + method public static void unlockAnimationClock(); + } + +} + package android.view.autofill { public final class AutofillId implements android.os.Parcelable { diff --git a/core/java/android/view/animation/AnimationUtils.java b/core/java/android/view/animation/AnimationUtils.java index 990fbdb019d6..29f8442b2b46 100644 --- a/core/java/android/view/animation/AnimationUtils.java +++ b/core/java/android/view/animation/AnimationUtils.java @@ -18,6 +18,7 @@ package android.view.animation; import android.annotation.AnimRes; import android.annotation.InterpolatorRes; +import android.annotation.TestApi; import android.content.Context; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; @@ -58,14 +59,43 @@ public class AnimationUtils { } }; - /** @hide */ + /** + * Locks AnimationUtils{@link #currentAnimationTimeMillis()} to a fixed value for the current + * thread. This is used by {@link android.view.Choreographer} to ensure that all accesses + * during a vsync update are synchronized to the timestamp of the vsync. + * + * It is also exposed to tests to allow for rapid, flake-free headless testing. + * + * Must be followed by a call to {@link #unlockAnimationClock()} to allow time to + * progress. Failing to do this will result in stuck animations, scrolls, and flings. + * + * Note that time is not allowed to "rewind" and must perpetually flow forward. So the + * lock may fail if the time is in the past from a previously returned value, however + * time will be frozen for the duration of the lock. The clock is a thread-local, so + * ensure that {@link #lockAnimationClock(long)}, {@link #unlockAnimationClock()}, and + * {@link #currentAnimationTimeMillis()} are all called on the same thread. + * + * This is also not reference counted in any way. Any call to {@link #unlockAnimationClock()} + * will unlock the clock for everyone on the same thread. It is therefore recommended + * for tests to use their own thread to ensure that there is no collision with any existing + * {@link android.view.Choreographer} instance. + * + * @hide + * */ + @TestApi public static void lockAnimationClock(long vsyncMillis) { AnimationState state = sAnimationState.get(); state.animationClockLocked = true; state.currentVsyncTimeMillis = vsyncMillis; } - /** @hide */ + /** + * Frees the time lock set in place by {@link #lockAnimationClock(long)}. Must be called + * to allow the animation clock to self-update. + * + * @hide + */ + @TestApi public static void unlockAnimationClock() { sAnimationState.get().animationClockLocked = false; } |