Add missing @Nullable annotations

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190817805
This commit is contained in:
eguven 2018-03-28 12:52:34 -07:00 committed by Oliver Woodman
parent fbd7c0bd1f
commit acca4f238b
7 changed files with 50 additions and 21 deletions

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.offline; package com.google.android.exoplayer2.offline;
import android.support.annotation.Nullable;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -108,7 +109,7 @@ public abstract class DownloadAction {
private final String data; private final String data;
/** @param data Optional custom data for this action. If null, an empty string is used. */ /** @param data Optional custom data for this action. If null, an empty string is used. */
protected DownloadAction(String data) { protected DownloadAction(@Nullable String data) {
this.data = data != null ? data : ""; this.data = data != null ? data : "";
} }

View File

@ -15,7 +15,9 @@
*/ */
package com.google.android.exoplayer2.offline; package com.google.android.exoplayer2.offline;
import android.net.Uri;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.google.android.exoplayer2.upstream.cache.CacheUtil;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -49,13 +51,13 @@ public final class ProgressiveDownloadAction extends DownloadAction {
/** /**
* @param uri Uri of the data to be downloaded. * @param uri Uri of the data to be downloaded.
* @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache * @param customCacheKey A custom key that uniquely identifies the original stream. If not null it
* indexing. May be null. * is used for cache indexing.
* @param removeAction Whether the data should be downloaded or removed. * @param removeAction Whether the data should be downloaded or removed.
* @param data Optional custom data for this action. If null, an empty string is used. * @param data Optional custom data for this action. If null, an empty string is used.
*/ */
public ProgressiveDownloadAction(String uri, @Nullable String customCacheKey, public ProgressiveDownloadAction(
boolean removeAction, String data) { String uri, @Nullable String customCacheKey, boolean removeAction, @Nullable String data) {
super(data); super(data);
this.uri = Assertions.checkNotNull(uri); this.uri = Assertions.checkNotNull(uri);
this.customCacheKey = customCacheKey; this.customCacheKey = customCacheKey;
@ -94,9 +96,7 @@ public final class ProgressiveDownloadAction extends DownloadAction {
if (!(other instanceof ProgressiveDownloadAction)) { if (!(other instanceof ProgressiveDownloadAction)) {
return false; return false;
} }
ProgressiveDownloadAction action = (ProgressiveDownloadAction) other; return getCacheKey().equals(((ProgressiveDownloadAction) other).getCacheKey());
return customCacheKey != null ? customCacheKey.equals(action.customCacheKey)
: uri.equals(action.uri);
} }
@Override @Override
@ -119,4 +119,7 @@ public final class ProgressiveDownloadAction extends DownloadAction {
return result; return result;
} }
private String getCacheKey() {
return customCacheKey != null ? customCacheKey : CacheUtil.generateKey(Uri.parse(uri));
}
} }

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.offline; package com.google.android.exoplayer2.offline;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -72,15 +73,15 @@ public abstract class SegmentDownloadAction<K> extends DownloadAction {
* @param keys Keys of representations to be downloaded. If empty, all representations are * @param keys Keys of representations to be downloaded. If empty, all representations are
* downloaded. If {@code removeAction} is true, {@code keys} should be an empty array. * downloaded. If {@code removeAction} is true, {@code keys} should be an empty array.
*/ */
protected SegmentDownloadAction(Uri manifestUri, boolean removeAction, String data, K[] keys) { protected SegmentDownloadAction(
Uri manifestUri, boolean removeAction, @Nullable String data, K[] keys) {
super(data); super(data);
Assertions.checkNotNull(keys); this.manifestUri = manifestUri;
this.keys = Assertions.checkNotNull(keys);
this.removeAction = removeAction;
if (removeAction) { if (removeAction) {
Assertions.checkArgument(keys.length == 0); Assertions.checkArgument(keys.length == 0);
} }
this.manifestUri = manifestUri;
this.keys = keys;
this.removeAction = removeAction;
} }
@Override @Override

View File

@ -61,28 +61,35 @@ public class ProgressiveDownloadActionTest {
public void testSameUriCacheKeyDifferentAction_IsSameMedia() throws Exception { public void testSameUriCacheKeyDifferentAction_IsSameMedia() throws Exception {
ProgressiveDownloadAction action1 = new ProgressiveDownloadAction("uri", null, true, null); ProgressiveDownloadAction action1 = new ProgressiveDownloadAction("uri", null, true, null);
ProgressiveDownloadAction action2 = new ProgressiveDownloadAction("uri", null, false, null); ProgressiveDownloadAction action2 = new ProgressiveDownloadAction("uri", null, false, null);
assertThat(action1.isSameMedia(action2)).isTrue(); assertSameMedia(action1, action2);
} }
@Test @Test
public void testNullCacheKeyDifferentUriAction_IsNotSameMedia() throws Exception { public void testNullCacheKeyDifferentUriAction_IsNotSameMedia() throws Exception {
ProgressiveDownloadAction action3 = new ProgressiveDownloadAction("uri2", null, true, null); ProgressiveDownloadAction action3 = new ProgressiveDownloadAction("uri2", null, true, null);
ProgressiveDownloadAction action4 = new ProgressiveDownloadAction("uri", null, false, null); ProgressiveDownloadAction action4 = new ProgressiveDownloadAction("uri", null, false, null);
assertThat(action3.isSameMedia(action4)).isFalse(); assertNotSameMedia(action3, action4);
} }
@Test @Test
public void testSameCacheKeyDifferentUriAction_IsSameMedia() throws Exception { public void testSameCacheKeyDifferentUriAction_IsSameMedia() throws Exception {
ProgressiveDownloadAction action5 = new ProgressiveDownloadAction("uri2", "key", true, null); ProgressiveDownloadAction action5 = new ProgressiveDownloadAction("uri2", "key", true, null);
ProgressiveDownloadAction action6 = new ProgressiveDownloadAction("uri", "key", false, null); ProgressiveDownloadAction action6 = new ProgressiveDownloadAction("uri", "key", false, null);
assertThat(action5.isSameMedia(action6)).isTrue(); assertSameMedia(action5, action6);
} }
@Test @Test
public void testSameUriDifferentCacheKeyAction_IsNotSameMedia() throws Exception { public void testSameUriDifferentCacheKeyAction_IsNotSameMedia() throws Exception {
ProgressiveDownloadAction action7 = new ProgressiveDownloadAction("uri", "key", true, null); ProgressiveDownloadAction action7 = new ProgressiveDownloadAction("uri", "key", true, null);
ProgressiveDownloadAction action8 = new ProgressiveDownloadAction("uri", "key2", false, null); ProgressiveDownloadAction action8 = new ProgressiveDownloadAction("uri", "key2", false, null);
assertThat(action7.isSameMedia(action8)).isFalse(); assertNotSameMedia(action7, action8);
}
@Test
public void testSameUriNullCacheKeyAction_IsNotSameMedia() throws Exception {
ProgressiveDownloadAction action1 = new ProgressiveDownloadAction("uri", "key", true, null);
ProgressiveDownloadAction action2 = new ProgressiveDownloadAction("uri", null, false, null);
assertNotSameMedia(action1, action2);
} }
@Test @Test
@ -123,6 +130,18 @@ public class ProgressiveDownloadActionTest {
doTestSerializationRoundTrip(new ProgressiveDownloadAction("uri2", "key", true, null)); doTestSerializationRoundTrip(new ProgressiveDownloadAction("uri2", "key", true, null));
} }
private void assertSameMedia(
ProgressiveDownloadAction action1, ProgressiveDownloadAction action2) {
assertThat(action1.isSameMedia(action2)).isTrue();
assertThat(action2.isSameMedia(action1)).isTrue();
}
private void assertNotSameMedia(
ProgressiveDownloadAction action1, ProgressiveDownloadAction action2) {
assertThat(action1.isSameMedia(action2)).isFalse();
assertThat(action2.isSameMedia(action1)).isFalse();
}
private static void doTestSerializationRoundTrip(ProgressiveDownloadAction action1) private static void doTestSerializationRoundTrip(ProgressiveDownloadAction action1)
throws IOException { throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.dash.offline; package com.google.android.exoplayer2.source.dash.offline;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.offline.DownloadAction; import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper; import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.SegmentDownloadAction; import com.google.android.exoplayer2.offline.SegmentDownloadAction;
@ -56,8 +57,8 @@ public final class DashDownloadAction extends SegmentDownloadAction<Representati
private static final String TYPE = "DashDownloadAction"; private static final String TYPE = "DashDownloadAction";
/** @see SegmentDownloadAction#SegmentDownloadAction(Uri, boolean, String, Object[]) */ /** @see SegmentDownloadAction#SegmentDownloadAction(Uri, boolean, String, Object[]) */
public DashDownloadAction(Uri manifestUri, boolean removeAction, String data, public DashDownloadAction(
RepresentationKey... keys) { Uri manifestUri, boolean removeAction, @Nullable String data, RepresentationKey... keys) {
super(manifestUri, removeAction, data, keys); super(manifestUri, removeAction, data, keys);
} }

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.hls.offline; package com.google.android.exoplayer2.source.hls.offline;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.offline.DownloadAction; import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper; import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.SegmentDownloadAction; import com.google.android.exoplayer2.offline.SegmentDownloadAction;
@ -54,7 +55,8 @@ public final class HlsDownloadAction extends SegmentDownloadAction<String> {
private static final String TYPE = "HlsDownloadAction"; private static final String TYPE = "HlsDownloadAction";
/** @see SegmentDownloadAction#SegmentDownloadAction(Uri, boolean, String, Object[]) */ /** @see SegmentDownloadAction#SegmentDownloadAction(Uri, boolean, String, Object[]) */
public HlsDownloadAction(Uri manifestUri, boolean removeAction, String data, String... keys) { public HlsDownloadAction(
Uri manifestUri, boolean removeAction, @Nullable String data, String... keys) {
super(manifestUri, removeAction, data, keys); super(manifestUri, removeAction, data, keys);
} }

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.smoothstreaming.offline; package com.google.android.exoplayer2.source.smoothstreaming.offline;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.offline.DownloadAction; import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper; import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.SegmentDownloadAction; import com.google.android.exoplayer2.offline.SegmentDownloadAction;
@ -56,7 +57,8 @@ public final class SsDownloadAction extends SegmentDownloadAction<TrackKey> {
private static final String TYPE = "SsDownloadAction"; private static final String TYPE = "SsDownloadAction";
/** @see SegmentDownloadAction#SegmentDownloadAction(Uri, boolean, String, Object[]) */ /** @see SegmentDownloadAction#SegmentDownloadAction(Uri, boolean, String, Object[]) */
public SsDownloadAction(Uri manifestUri, boolean removeAction, String data, TrackKey... keys) { public SsDownloadAction(
Uri manifestUri, boolean removeAction, @Nullable String data, TrackKey... keys) {
super(manifestUri, removeAction, data, keys); super(manifestUri, removeAction, data, keys);
} }