Fix Timeline.toBundle for empty timeline

PiperOrigin-RevId: 364513299
This commit is contained in:
gyumin 2021-03-23 09:26:54 +00:00 committed by Ian Baker
parent bb1261da3c
commit 3fbfc0ec0e
2 changed files with 8 additions and 1 deletions

View file

@ -1291,7 +1291,9 @@ public abstract class Timeline implements Bundleable {
}
int[] shuffledWindowIndices = new int[windowCount];
shuffledWindowIndices[0] = getFirstWindowIndex(/* shuffleModeEnabled= */ true);
if (windowCount > 0) {
shuffledWindowIndices[0] = getFirstWindowIndex(/* shuffleModeEnabled= */ true);
}
for (int i = 1; i < windowCount; i++) {
shuffledWindowIndices[i] =
getNextWindowIndex(

View file

@ -278,6 +278,11 @@ public class TimelineTest {
timeline, restoredTimeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */ true);
}
@Test
public void roundtripViaBundle_ofEmptyTimeline_returnsEmptyTimeline() {
TimelineAsserts.assertEmpty(Timeline.CREATOR.fromBundle(Timeline.EMPTY.toBundle()));
}
@Test
public void roundtripViaBundle_ofWindow_yieldsEqualInstanceExceptUidAndManifest() {
Timeline.Window window = new Timeline.Window();