Use Uri rather than string for ProgressiveDownloadAction
This makes it consistent with the other download types. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=194089486
This commit is contained in:
parent
f320d9e0ab
commit
c9bb102f93
@ -387,7 +387,7 @@ public class DownloadActivity extends Activity {
|
||||
@Override
|
||||
public List<RepresentationItem> getRepresentationItems() {
|
||||
ProgressiveDownloader downloader =
|
||||
new ProgressiveDownloader(manifestUri.toString(), null, constructorHelper);
|
||||
new ProgressiveDownloader(manifestUri, null, constructorHelper);
|
||||
ArrayList<RepresentationItem> items = new ArrayList<>();
|
||||
{
|
||||
downloader.init();
|
||||
@ -399,12 +399,12 @@ public class DownloadActivity extends Activity {
|
||||
@Override
|
||||
public DownloadAction getDownloadAction(
|
||||
String sampleName, ArrayList<Object> representationKeys) {
|
||||
return new ProgressiveDownloadAction(manifestUri.toString(), null, false, sampleName);
|
||||
return new ProgressiveDownloadAction(manifestUri, null, false, sampleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DownloadAction getRemoveAction() {
|
||||
return new ProgressiveDownloadAction(manifestUri.toString(), null, true, null);
|
||||
return new ProgressiveDownloadAction(manifestUri, null, true, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,25 +27,28 @@ import java.io.IOException;
|
||||
/** An action to download or remove downloaded progressive streams. */
|
||||
public final class ProgressiveDownloadAction extends DownloadAction {
|
||||
|
||||
public static final Deserializer DESERIALIZER = new Deserializer() {
|
||||
public static final Deserializer DESERIALIZER =
|
||||
new Deserializer() {
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressiveDownloadAction readFromStream(int version, DataInputStream input)
|
||||
throws IOException {
|
||||
return new ProgressiveDownloadAction(input.readUTF(),
|
||||
input.readBoolean() ? input.readUTF() : null, input.readBoolean(), input.readUTF());
|
||||
}
|
||||
|
||||
};
|
||||
@Override
|
||||
public ProgressiveDownloadAction readFromStream(int version, DataInputStream input)
|
||||
throws IOException {
|
||||
return new ProgressiveDownloadAction(
|
||||
Uri.parse(input.readUTF()),
|
||||
input.readBoolean() ? input.readUTF() : null,
|
||||
input.readBoolean(),
|
||||
input.readUTF());
|
||||
}
|
||||
};
|
||||
|
||||
private static final String TYPE = "ProgressiveDownloadAction";
|
||||
|
||||
private final String uri;
|
||||
private final Uri uri;
|
||||
private final @Nullable String customCacheKey;
|
||||
private final boolean removeAction;
|
||||
|
||||
@ -57,7 +60,7 @@ public final class ProgressiveDownloadAction extends DownloadAction {
|
||||
* @param data Optional custom data for this action. If null, an empty string is used.
|
||||
*/
|
||||
public ProgressiveDownloadAction(
|
||||
String uri, @Nullable String customCacheKey, boolean removeAction, @Nullable String data) {
|
||||
Uri uri, @Nullable String customCacheKey, boolean removeAction, @Nullable String data) {
|
||||
super(data);
|
||||
this.uri = Assertions.checkNotNull(uri);
|
||||
this.customCacheKey = customCacheKey;
|
||||
@ -81,7 +84,7 @@ public final class ProgressiveDownloadAction extends DownloadAction {
|
||||
|
||||
@Override
|
||||
protected void writeToStream(DataOutputStream output) throws IOException {
|
||||
output.writeUTF(uri);
|
||||
output.writeUTF(uri.toString());
|
||||
boolean customCacheKeyAvailable = customCacheKey != null;
|
||||
output.writeBoolean(customCacheKeyAvailable);
|
||||
if (customCacheKeyAvailable) {
|
||||
@ -120,6 +123,6 @@ public final class ProgressiveDownloadAction extends DownloadAction {
|
||||
}
|
||||
|
||||
private String getCacheKey() {
|
||||
return customCacheKey != null ? customCacheKey : CacheUtil.generateKey(Uri.parse(uri));
|
||||
return customCacheKey != null ? customCacheKey : CacheUtil.generateKey(uri);
|
||||
}
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ public final class ProgressiveDownloader implements Downloader {
|
||||
* @param constructorHelper a {@link DownloaderConstructorHelper} instance.
|
||||
*/
|
||||
public ProgressiveDownloader(
|
||||
String uri, String customCacheKey, DownloaderConstructorHelper constructorHelper) {
|
||||
this.dataSpec = new DataSpec(Uri.parse(uri), 0, C.LENGTH_UNSET, customCacheKey, 0);
|
||||
Uri uri, String customCacheKey, DownloaderConstructorHelper constructorHelper) {
|
||||
this.dataSpec = new DataSpec(uri, 0, C.LENGTH_UNSET, customCacheKey, 0);
|
||||
this.cache = constructorHelper.getCache();
|
||||
this.dataSource = constructorHelper.buildCacheDataSource(false);
|
||||
this.priorityTaskManager = constructorHelper.getPriorityTaskManager();
|
||||
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.offline;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.Uri;
|
||||
import com.google.android.exoplayer2.upstream.DummyDataSource;
|
||||
import com.google.android.exoplayer2.upstream.cache.Cache;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@ -24,6 +25,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
@ -36,22 +38,31 @@ import org.robolectric.RobolectricTestRunner;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ProgressiveDownloadActionTest {
|
||||
|
||||
private Uri uri1;
|
||||
private Uri uri2;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
uri1 = Uri.parse("http://test1.uri");
|
||||
uri2 = Uri.parse("http://test2.uri");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDownloadActionIsNotRemoveAction() throws Exception {
|
||||
ProgressiveDownloadAction action = new ProgressiveDownloadAction("uri", null, false, null);
|
||||
ProgressiveDownloadAction action = new ProgressiveDownloadAction(uri1, null, false, null);
|
||||
assertThat(action.isRemoveAction()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveActionIsRemoveAction() throws Exception {
|
||||
ProgressiveDownloadAction action2 = new ProgressiveDownloadAction("uri", null, true, null);
|
||||
ProgressiveDownloadAction action2 = new ProgressiveDownloadAction(uri1, null, true, null);
|
||||
assertThat(action2.isRemoveAction()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateDownloader() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ProgressiveDownloadAction action = new ProgressiveDownloadAction("uri", null, false, null);
|
||||
ProgressiveDownloadAction action = new ProgressiveDownloadAction(uri1, null, false, null);
|
||||
DownloaderConstructorHelper constructorHelper = new DownloaderConstructorHelper(
|
||||
Mockito.mock(Cache.class), DummyDataSource.FACTORY);
|
||||
assertThat(action.createDownloader(constructorHelper)).isNotNull();
|
||||
@ -59,75 +70,75 @@ public class ProgressiveDownloadActionTest {
|
||||
|
||||
@Test
|
||||
public void testSameUriCacheKeyDifferentAction_IsSameMedia() throws Exception {
|
||||
ProgressiveDownloadAction action1 = new ProgressiveDownloadAction("uri", null, true, null);
|
||||
ProgressiveDownloadAction action2 = new ProgressiveDownloadAction("uri", null, false, null);
|
||||
ProgressiveDownloadAction action1 = new ProgressiveDownloadAction(uri1, null, true, null);
|
||||
ProgressiveDownloadAction action2 = new ProgressiveDownloadAction(uri1, null, false, null);
|
||||
assertSameMedia(action1, action2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullCacheKeyDifferentUriAction_IsNotSameMedia() throws Exception {
|
||||
ProgressiveDownloadAction action3 = new ProgressiveDownloadAction("uri2", null, true, null);
|
||||
ProgressiveDownloadAction action4 = new ProgressiveDownloadAction("uri", null, false, null);
|
||||
ProgressiveDownloadAction action3 = new ProgressiveDownloadAction(uri2, null, true, null);
|
||||
ProgressiveDownloadAction action4 = new ProgressiveDownloadAction(uri1, null, false, null);
|
||||
assertNotSameMedia(action3, action4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameCacheKeyDifferentUriAction_IsSameMedia() throws Exception {
|
||||
ProgressiveDownloadAction action5 = new ProgressiveDownloadAction("uri2", "key", true, null);
|
||||
ProgressiveDownloadAction action6 = new ProgressiveDownloadAction("uri", "key", false, null);
|
||||
ProgressiveDownloadAction action5 = new ProgressiveDownloadAction(uri2, "key", true, null);
|
||||
ProgressiveDownloadAction action6 = new ProgressiveDownloadAction(uri1, "key", false, null);
|
||||
assertSameMedia(action5, action6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameUriDifferentCacheKeyAction_IsNotSameMedia() throws Exception {
|
||||
ProgressiveDownloadAction action7 = new ProgressiveDownloadAction("uri", "key", true, null);
|
||||
ProgressiveDownloadAction action8 = new ProgressiveDownloadAction("uri", "key2", false, null);
|
||||
ProgressiveDownloadAction action7 = new ProgressiveDownloadAction(uri1, "key", true, null);
|
||||
ProgressiveDownloadAction action8 = new ProgressiveDownloadAction(uri1, "key2", false, null);
|
||||
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);
|
||||
ProgressiveDownloadAction action1 = new ProgressiveDownloadAction(uri1, "key", true, null);
|
||||
ProgressiveDownloadAction action2 = new ProgressiveDownloadAction(uri1, null, false, null);
|
||||
assertNotSameMedia(action1, action2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() throws Exception {
|
||||
ProgressiveDownloadAction action1 = new ProgressiveDownloadAction("uri", null, true, null);
|
||||
ProgressiveDownloadAction action1 = new ProgressiveDownloadAction(uri1, null, true, null);
|
||||
assertThat(action1.equals(action1)).isTrue();
|
||||
|
||||
ProgressiveDownloadAction action2 = new ProgressiveDownloadAction("uri", null, true, null);
|
||||
ProgressiveDownloadAction action3 = new ProgressiveDownloadAction("uri", null, true, null);
|
||||
ProgressiveDownloadAction action2 = new ProgressiveDownloadAction(uri1, null, true, null);
|
||||
ProgressiveDownloadAction action3 = new ProgressiveDownloadAction(uri1, null, true, null);
|
||||
assertThat(action2.equals(action3)).isTrue();
|
||||
|
||||
ProgressiveDownloadAction action4 = new ProgressiveDownloadAction("uri", null, true, null);
|
||||
ProgressiveDownloadAction action5 = new ProgressiveDownloadAction("uri", null, false, null);
|
||||
ProgressiveDownloadAction action4 = new ProgressiveDownloadAction(uri1, null, true, null);
|
||||
ProgressiveDownloadAction action5 = new ProgressiveDownloadAction(uri1, null, false, null);
|
||||
assertThat(action4.equals(action5)).isFalse();
|
||||
|
||||
ProgressiveDownloadAction action6 = new ProgressiveDownloadAction("uri", null, true, null);
|
||||
ProgressiveDownloadAction action7 = new ProgressiveDownloadAction("uri", "key", true, null);
|
||||
ProgressiveDownloadAction action6 = new ProgressiveDownloadAction(uri1, null, true, null);
|
||||
ProgressiveDownloadAction action7 = new ProgressiveDownloadAction(uri1, "key", true, null);
|
||||
assertThat(action6.equals(action7)).isFalse();
|
||||
|
||||
ProgressiveDownloadAction action8 = new ProgressiveDownloadAction("uri", "key2", true, null);
|
||||
ProgressiveDownloadAction action9 = new ProgressiveDownloadAction("uri", "key", true, null);
|
||||
ProgressiveDownloadAction action8 = new ProgressiveDownloadAction(uri1, "key2", true, null);
|
||||
ProgressiveDownloadAction action9 = new ProgressiveDownloadAction(uri1, "key", true, null);
|
||||
assertThat(action8.equals(action9)).isFalse();
|
||||
|
||||
ProgressiveDownloadAction action10 = new ProgressiveDownloadAction("uri", null, true, null);
|
||||
ProgressiveDownloadAction action11 = new ProgressiveDownloadAction("uri2", null, true, null);
|
||||
ProgressiveDownloadAction action10 = new ProgressiveDownloadAction(uri1, null, true, null);
|
||||
ProgressiveDownloadAction action11 = new ProgressiveDownloadAction(uri2, null, true, null);
|
||||
assertThat(action10.equals(action11)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializerGetType() throws Exception {
|
||||
ProgressiveDownloadAction action = new ProgressiveDownloadAction("uri", null, false, null);
|
||||
ProgressiveDownloadAction action = new ProgressiveDownloadAction(uri1, null, false, null);
|
||||
assertThat(action.getType()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializerWriteRead() throws Exception {
|
||||
doTestSerializationRoundTrip(new ProgressiveDownloadAction("uri1", null, false, null));
|
||||
doTestSerializationRoundTrip(new ProgressiveDownloadAction("uri2", "key", true, null));
|
||||
doTestSerializationRoundTrip(new ProgressiveDownloadAction(uri1, null, false, null));
|
||||
doTestSerializationRoundTrip(new ProgressiveDownloadAction(uri2, "key", true, null));
|
||||
}
|
||||
|
||||
private void assertSameMedia(
|
||||
|
Loading…
x
Reference in New Issue
Block a user