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

Commit 8d65862b authored by Rachel Lee's avatar Rachel Lee
Browse files

Minimum 1 frame timeline in java Choreographer

Sometimes the data from native gives an empty VsyncEventData (perhaps
erroneously), causing out-of-bound crashes in java Choreographer side.
Instead, the public FrameData should maintain at least 1 frame timeline
which will have the default data when accessed.

Bug: 290965823
Test: atest ChoreographerTest

Change-Id: I8b704433aca55bc9697fd843257ac62995e75a1f
parent ed36a343
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -1208,11 +1208,17 @@ public final class Choreographer {
        }

        private void allocateFrameTimelines(int length) {
            // Maintain one default frame timeline for API (such as getFrameTimelines and
            // getPreferredFrameTimeline) consistency. It should have default data when accessed.
            length = Math.max(1, length);

            if (mFrameTimelines == null || mFrameTimelines.length != length) {
                mFrameTimelines = new FrameTimeline[length];
                for (int i = 0; i < mFrameTimelines.length; i++) {
                    mFrameTimelines[i] = new FrameTimeline();
                }
            }
        }

        /**
         * Update the frame data with a {@code DisplayEventReceiver.VsyncEventData} received from
@@ -1220,12 +1226,7 @@ public final class Choreographer {
         */
        FrameTimeline update(
                long frameTimeNanos, DisplayEventReceiver.VsyncEventData vsyncEventData) {
            // Even if the frame timelines length is 0, continue with allocation for API
            // FrameData.getFrameTimelines consistency. The 0 length frame timelines code path
            // should only occur when USE_VSYNC property is false.
            if (mFrameTimelines.length != vsyncEventData.frameTimelinesLength) {
            allocateFrameTimelines(vsyncEventData.frameTimelinesLength);
            }
            mFrameTimeNanos = frameTimeNanos;
            mPreferredFrameTimelineIndex = vsyncEventData.preferredFrameTimelineIndex;
            for (int i = 0; i < mFrameTimelines.length; i++) {