From ebec29367295da0ba7ba8d20c27dc1e1a1383950 Mon Sep 17 00:00:00 2001 From: Steve Mayhew Date: Fri, 19 Apr 2024 11:16:52 -0700 Subject: [PATCH] Make lists Immuteable in KeyRequestInfo This should cover the comments: 1. https://github.com/androidx/media/pull/1134#discussion_r1567064538 2. https://github.com/androidx/media/pull/1134#discussion_r1567067827 Also, fixed lint issues and deaI will the nullability of `schemeDatas` note will need addtional idenfitying info in KeyRequestInfo to support offline --- .../media3/exoplayer/drm/KeyRequestInfo.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/KeyRequestInfo.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/KeyRequestInfo.java index 7499c3721ec..0321d81dfd3 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/KeyRequestInfo.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/drm/KeyRequestInfo.java @@ -1,9 +1,13 @@ package androidx.media3.exoplayer.drm; +import androidx.annotation.Nullable; import androidx.media3.common.DrmInitData.SchemeData; +import androidx.media3.common.util.Assertions; import androidx.media3.exoplayer.source.LoadEventInfo; +import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; /** * Encapsulates info for the sequence of load requests ({@link LoadEventInfo}, which were required @@ -12,11 +16,11 @@ public class KeyRequestInfo { public static class Builder { - private LoadEventInfo loadEventInfo; + @MonotonicNonNull private LoadEventInfo loadEventInfo; private final List retriedLoadRequests; - private final List schemeDatas; + @Nullable private final List schemeDatas; - public Builder(List schemeDatas) { + public Builder(@Nullable List schemeDatas) { this.schemeDatas = schemeDatas; retriedLoadRequests = new ArrayList<>(); loadEventInfo = null; @@ -33,6 +37,7 @@ public Builder addRetryLoadRequest(LoadEventInfo loadEventInfo) { } public KeyRequestInfo build() { + Assertions.checkNotNull(loadEventInfo, "build() called before setMainLoadRequest()"); return new KeyRequestInfo(this); } } @@ -43,15 +48,19 @@ public KeyRequestInfo build() { /** If the load required multiple retries, the {@link LoadEventInfo} for each retry */ - public final List retriedLoadRequests; + public final ImmutableList retriedLoadRequests; - /** The DRM {@link SchemeData} that identifes the loaded key + /** The DRM {@link SchemeData} that identifies the loaded key, or null if this session uses + * offline keys. // TODO add sessionId to the KeyLoadInfo maybe? */ - public final List schemeDatas; + @Nullable public final ImmutableList schemeDatas; private KeyRequestInfo(Builder builder) { - retriedLoadRequests = builder.retriedLoadRequests; + retriedLoadRequests = new ImmutableList.Builder() + .addAll(builder.retriedLoadRequests) + .build(); loadEventInfo = builder.loadEventInfo; - schemeDatas = builder.schemeDatas; + schemeDatas = + builder.schemeDatas == null ? null : ImmutableList.copyOf(builder.schemeDatas); } }