Skip to content

Commit

Permalink
Make lists Immuteable in KeyRequestInfo
Browse files Browse the repository at this point in the history
This should cover the comments:

1. androidx#1134 (comment)
2. androidx#1134 (comment)

Also, fixed lint issues and deaI will the nullability of `schemeDatas`
note will need addtional idenfitying info in KeyRequestInfo to support
offline
  • Loading branch information
stevemayhew authored and icbaker committed Apr 22, 2024
1 parent 2ae3798 commit ebec293
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,11 +16,11 @@
public class KeyRequestInfo {

public static class Builder {
private LoadEventInfo loadEventInfo;
@MonotonicNonNull private LoadEventInfo loadEventInfo;
private final List<LoadEventInfo> retriedLoadRequests;
private final List<SchemeData> schemeDatas;
@Nullable private final List<SchemeData> schemeDatas;

public Builder(List<SchemeData> schemeDatas) {
public Builder(@Nullable List<SchemeData> schemeDatas) {
this.schemeDatas = schemeDatas;
retriedLoadRequests = new ArrayList<>();
loadEventInfo = null;
Expand All @@ -33,6 +37,7 @@ public Builder addRetryLoadRequest(LoadEventInfo loadEventInfo) {
}

public KeyRequestInfo build() {
Assertions.checkNotNull(loadEventInfo, "build() called before setMainLoadRequest()");
return new KeyRequestInfo(this);
}
}
Expand All @@ -43,15 +48,19 @@ public KeyRequestInfo build() {

/** If the load required multiple retries, the {@link LoadEventInfo} for each retry
*/
public final List<LoadEventInfo> retriedLoadRequests;
public final ImmutableList<LoadEventInfo> 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<SchemeData> schemeDatas;
@Nullable public final ImmutableList<SchemeData> schemeDatas;

private KeyRequestInfo(Builder builder) {
retriedLoadRequests = builder.retriedLoadRequests;
retriedLoadRequests = new ImmutableList.Builder<LoadEventInfo>()
.addAll(builder.retriedLoadRequests)
.build();
loadEventInfo = builder.loadEventInfo;
schemeDatas = builder.schemeDatas;
schemeDatas =
builder.schemeDatas == null ? null : ImmutableList.copyOf(builder.schemeDatas);
}
}

0 comments on commit ebec293

Please sign in to comment.