summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShane <shanewong@google.com>2024-01-09 00:25:45 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-01-11 01:36:59 +0000
commit467b57b2ee1818039eb3f65e0d76a973d0626dbe (patch)
tree10921915d38cec2408188d87d7b6af14c70d46fa
parente5d19e56178ca78490fd948c8a28ff243f116bbd (diff)
downloadbase-467b57b2ee1818039eb3f65e0d76a973d0626dbe.tar.gz
Add old lockAnimationClock(long) back
Add old lockAnimationClock(long) back because of a CTS tests failure issue. Might be related to Trunk Stable, The CL is created to resolve the inconsistency between git_main/git_24Q1-release and aosp/android14-tests-dev. For more details, see - https://buganizer.corp.google.com/issues/307888459#comment57 Bug: 307888459 Test: atest AnimationUtilsTest / ChoreographerTest (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:36bef4019e597d4dd169bfadea3f5c7974ee6c5d) Merged-In: Ie7a1f898651d2da040ffaa3f6a0c833b2a8ca2e0 Change-Id: Ie7a1f898651d2da040ffaa3f6a0c833b2a8ca2e0
-rw-r--r--core/api/test-current.txt1
-rw-r--r--core/java/android/view/animation/AnimationUtils.java34
2 files changed, 35 insertions, 0 deletions
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index a3cd3dc87db3..30bd5f65a070 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -3672,6 +3672,7 @@ package android.view.animation {
public class AnimationUtils {
method @FlaggedApi("android.view.flags.expected_presentation_time_read_only") public static void lockAnimationClock(long, long);
+ method public static void lockAnimationClock(long);
method public static void unlockAnimationClock();
}
diff --git a/core/java/android/view/animation/AnimationUtils.java b/core/java/android/view/animation/AnimationUtils.java
index b3359b711989..c1f42d25d0de 100644
--- a/core/java/android/view/animation/AnimationUtils.java
+++ b/core/java/android/view/animation/AnimationUtils.java
@@ -124,6 +124,40 @@ public class AnimationUtils {
}
/**
+ * 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.
+ *
+ * Have to add the method back because of b/307888459.
+ * Remove this method once the lockAnimationClock(long, long) change
+ * is landed to aosp/android14-tests-dev branch.
+ *
+ * @hide
+ */
+ @TestApi
+ public static void lockAnimationClock(long vsyncMillis) {
+ AnimationState state = sAnimationState.get();
+ state.animationClockLocked = true;
+ state.currentVsyncTimeMillis = vsyncMillis;
+ }
+
+ /**
* Frees the time lock set in place by {@link #lockAnimationClock(long)}. Must be called
* to allow the animation clock to self-update.
*