Commit 5461d5cb by tonihei Committed by christosts

Make availableCommands known when bundling PlayerInfo

When bundling PlayerInfo, we remove data when the controller is not
allowed to access this data via getters. We also remove data for
performance reasons. In the toBundle() method, it's currently hard to
make the connection between allowed commands and filtering, because
the values are checked at a different place. This can be made more
readable by forwarding the applicable Commands directly.

The only functional fix is to filter the Timeline when sending the
first PlayerInfo after a connecting a controller if the command to
get the Timeline is not available. This also allows us to remove a
path to filter MediaItems from Timelines as it isn't used.

PiperOrigin-RevId: 502607391
parent 2cc64a03
...@@ -429,17 +429,16 @@ public abstract class Timeline implements Bundleable { ...@@ -429,17 +429,16 @@ public abstract class Timeline implements Bundleable {
private static final String FIELD_POSITION_IN_FIRST_PERIOD_US = Util.intToStringMaxRadix(13); private static final String FIELD_POSITION_IN_FIRST_PERIOD_US = Util.intToStringMaxRadix(13);
/** /**
* Returns a {@link Bundle} representing the information stored in this object. * {@inheritDoc}
* *
* <p>It omits the {@link #uid} and {@link #manifest} fields. The {@link #uid} of an instance * <p>It omits the {@link #uid} and {@link #manifest} fields. The {@link #uid} of an instance
* restored by {@link #CREATOR} will be a fake {@link Object} and the {@link #manifest} of the * restored by {@link #CREATOR} will be a fake {@link Object} and the {@link #manifest} of the
* instance will be {@code null}. * instance will be {@code null}.
*
* @param excludeMediaItem Whether to exclude {@link #mediaItem} of window.
*/ */
public Bundle toBundle(boolean excludeMediaItem) { @Override
public Bundle toBundle() {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
if (!excludeMediaItem) { if (!MediaItem.EMPTY.equals(mediaItem)) {
bundle.putBundle(FIELD_MEDIA_ITEM, mediaItem.toBundle()); bundle.putBundle(FIELD_MEDIA_ITEM, mediaItem.toBundle());
} }
if (presentationStartTimeMs != C.TIME_UNSET) { if (presentationStartTimeMs != C.TIME_UNSET) {
...@@ -484,19 +483,6 @@ public abstract class Timeline implements Bundleable { ...@@ -484,19 +483,6 @@ public abstract class Timeline implements Bundleable {
} }
/** /**
* {@inheritDoc}
*
* <p>It omits the {@link #uid} and {@link #manifest} fields. The {@link #uid} of an instance
* restored by {@link #CREATOR} will be a fake {@link Object} and the {@link #manifest} of the
* instance will be {@code null}.
*/
// TODO(b/166765820): See if missing fields would be okay and add them to the Bundle otherwise.
@Override
public Bundle toBundle() {
return toBundle(/* excludeMediaItem= */ false);
}
/**
* Object that can restore {@link Period} from a {@link Bundle}. * Object that can restore {@link Period} from a {@link Bundle}.
* *
* <p>The {@link #uid} of a restored instance will be a fake {@link Object} and the {@link * <p>The {@link #uid} of a restored instance will be a fake {@link Object} and the {@link
...@@ -1384,17 +1370,14 @@ public abstract class Timeline implements Bundleable { ...@@ -1384,17 +1370,14 @@ public abstract class Timeline implements Bundleable {
* <p>The {@link #getWindow(int, Window)} windows} and {@link #getPeriod(int, Period) periods} of * <p>The {@link #getWindow(int, Window)} windows} and {@link #getPeriod(int, Period) periods} of
* an instance restored by {@link #CREATOR} may have missing fields as described in {@link * an instance restored by {@link #CREATOR} may have missing fields as described in {@link
* Window#toBundle()} and {@link Period#toBundle()}. * Window#toBundle()} and {@link Period#toBundle()}.
*
* @param excludeMediaItems Whether to exclude all {@link Window#mediaItem media items} of windows
* in the timeline.
*/ */
public final Bundle toBundle(boolean excludeMediaItems) { @Override
public final Bundle toBundle() {
List<Bundle> windowBundles = new ArrayList<>(); List<Bundle> windowBundles = new ArrayList<>();
int windowCount = getWindowCount(); int windowCount = getWindowCount();
Window window = new Window(); Window window = new Window();
for (int i = 0; i < windowCount; i++) { for (int i = 0; i < windowCount; i++) {
windowBundles.add( windowBundles.add(getWindow(i, window, /* defaultPositionProjectionUs= */ 0).toBundle());
getWindow(i, window, /* defaultPositionProjectionUs= */ 0).toBundle(excludeMediaItems));
} }
List<Bundle> periodBundles = new ArrayList<>(); List<Bundle> periodBundles = new ArrayList<>();
...@@ -1422,18 +1405,6 @@ public abstract class Timeline implements Bundleable { ...@@ -1422,18 +1405,6 @@ public abstract class Timeline implements Bundleable {
} }
/** /**
* {@inheritDoc}
*
* <p>The {@link #getWindow(int, Window)} windows} and {@link #getPeriod(int, Period) periods} of
* an instance restored by {@link #CREATOR} may have missing fields as described in {@link
* Window#toBundle()} and {@link Period#toBundle()}.
*/
@Override
public final Bundle toBundle() {
return toBundle(/* excludeMediaItems= */ false);
}
/**
* Object that can restore a {@link Timeline} from a {@link Bundle}. * Object that can restore a {@link Timeline} from a {@link Bundle}.
* *
* <p>The {@link #getWindow(int, Window)} windows} and {@link #getPeriod(int, Period) periods} of * <p>The {@link #getWindow(int, Window)} windows} and {@link #getPeriod(int, Period) periods} of
......
...@@ -351,10 +351,8 @@ public class TimelineTest { ...@@ -351,10 +351,8 @@ public class TimelineTest {
Bundle windowBundle = window.toBundle(); Bundle windowBundle = window.toBundle();
// Check that default values are skipped when bundling. MediaItem key is not added to the bundle // Check that default values are skipped when bundling.
// only when excludeMediaItem is true. assertThat(windowBundle.keySet()).isEmpty();
assertThat(windowBundle.keySet()).hasSize(1);
assertThat(window.toBundle(/* excludeMediaItem= */ true).keySet()).isEmpty();
Timeline.Window restoredWindow = Timeline.Window.CREATOR.fromBundle(windowBundle); Timeline.Window restoredWindow = Timeline.Window.CREATOR.fromBundle(windowBundle);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment