Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 869b2f61 authored by Jian-Syuan (Shane) Wong's avatar Jian-Syuan (Shane) Wong Committed by Android (Google) Code Review
Browse files

Merge "Add old lockAnimationClock(long) back" into main

parents 922a3212 36bef401
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3735,6 +3735,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();
  }

+34 −0
Original line number Diff line number Diff line
@@ -108,6 +108,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.