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