Assert customCacheKey is null for DASH, HLS and SmoothStreaming downloads

PiperOrigin-RevId: 243954989
This commit is contained in:
eguven 2019-04-17 09:30:25 +01:00 committed by Andrew Lewis
parent af5131e393
commit d92e6bfaf8
4 changed files with 17 additions and 9 deletions

View file

@ -52,7 +52,10 @@ public final class DownloadRequest implements Parcelable {
public final Uri uri;
/** Stream keys to be downloaded. If empty, all streams will be downloaded. */
public final List<StreamKey> streamKeys;
/** Custom key for cache indexing, or null. */
/**
* Custom key for cache indexing, or null. Must be null for DASH, HLS and SmoothStreaming
* downloads.
*/
@Nullable public final String customCacheKey;
/** Application defined data associated with the download. May be empty. */
public final byte[] data;
@ -72,6 +75,10 @@ public final class DownloadRequest implements Parcelable {
List<StreamKey> streamKeys,
@Nullable String customCacheKey,
@Nullable byte[] data) {
if (TYPE_DASH.equals(type) || TYPE_HLS.equals(type) || TYPE_SS.equals(type)) {
Assertions.checkArgument(
customCacheKey == null, "customCacheKey must be null for type: " + type);
}
this.id = id;
this.type = type;
this.uri = uri;

View file

@ -15,7 +15,7 @@
*/
package com.google.android.exoplayer2.offline;
import static com.google.android.exoplayer2.offline.DownloadRequest.TYPE_DASH;
import static com.google.android.exoplayer2.offline.DownloadRequest.TYPE_PROGRESSIVE;
import static com.google.common.truth.Truth.assertThat;
import android.net.Uri;
@ -73,7 +73,7 @@ public class ActionFileUpgradeUtilTest {
DownloadRequest expectedRequest1 =
new DownloadRequest(
"key123",
TYPE_DASH,
/* type= */ "test",
Uri.parse("https://www.test.com/download1"),
asList(expectedStreamKey1),
/* customCacheKey= */ "key123",
@ -81,7 +81,7 @@ public class ActionFileUpgradeUtilTest {
DownloadRequest expectedRequest2 =
new DownloadRequest(
"key234",
TYPE_DASH,
/* type= */ "test",
Uri.parse("https://www.test.com/download2"),
asList(expectedStreamKey2),
/* customCacheKey= */ "key234",
@ -100,7 +100,7 @@ public class ActionFileUpgradeUtilTest {
DownloadRequest request =
new DownloadRequest(
"id",
TYPE_DASH,
TYPE_PROGRESSIVE,
Uri.parse("https://www.test.com/download"),
asList(
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 2),
@ -122,7 +122,7 @@ public class ActionFileUpgradeUtilTest {
DownloadRequest request1 =
new DownloadRequest(
"id",
TYPE_DASH,
TYPE_PROGRESSIVE,
Uri.parse("https://www.test.com/download1"),
asList(streamKey1),
/* customCacheKey= */ "key123",
@ -130,7 +130,7 @@ public class ActionFileUpgradeUtilTest {
DownloadRequest request2 =
new DownloadRequest(
"id",
TYPE_DASH,
TYPE_PROGRESSIVE,
Uri.parse("https://www.test.com/download2"),
asList(streamKey2),
/* customCacheKey= */ "key123",

View file

@ -17,6 +17,7 @@ package com.google.android.exoplayer2.offline;
import static com.google.android.exoplayer2.offline.DownloadRequest.TYPE_DASH;
import static com.google.android.exoplayer2.offline.DownloadRequest.TYPE_HLS;
import static com.google.android.exoplayer2.offline.DownloadRequest.TYPE_PROGRESSIVE;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
@ -139,7 +140,7 @@ public class DownloadRequestTest {
DownloadRequest request1 =
new DownloadRequest(
"id1",
TYPE_DASH,
TYPE_PROGRESSIVE,
uri1,
/* streamKeys= */ Collections.emptyList(),
"key1",
@ -147,7 +148,7 @@ public class DownloadRequestTest {
DownloadRequest request2 =
new DownloadRequest(
"id1",
TYPE_DASH,
TYPE_PROGRESSIVE,
uri2,
/* streamKeys= */ Collections.emptyList(),
"key2",