Sanitize naming of keys variable.
PiperOrigin-RevId: 242460786
This commit is contained in:
parent
a0c21461aa
commit
e7d717b96c
@ -99,7 +99,7 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// TODO: Support customCacheKey in DASH/HLS/SS, for completeness.
|
// TODO: Support customCacheKey in DASH/HLS/SS, for completeness.
|
||||||
return constructor.newInstance(action.uri, action.getKeys(), downloaderConstructorHelper);
|
return constructor.newInstance(action.uri, action.streamKeys, downloaderConstructorHelper);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to instantiate downloader for: " + action.type, e);
|
throw new RuntimeException("Failed to instantiate downloader for: " + action.type, e);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public final class DownloadAction {
|
|||||||
private static final int VERSION = 3;
|
private static final int VERSION = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserializes an action from the {@code data}.
|
* Deserializes a download action from the {@code data}.
|
||||||
*
|
*
|
||||||
* @param data The action data to deserialize.
|
* @param data The action data to deserialize.
|
||||||
* @return The deserialized action.
|
* @return The deserialized action.
|
||||||
@ -62,10 +62,7 @@ public final class DownloadAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserializes one action that was serialized with {@link #serializeToStream(OutputStream)} from
|
* Deserializes a single download action from {@code input}.
|
||||||
* the {@code input}.
|
|
||||||
*
|
|
||||||
* <p>The caller is responsible for closing the given {@link InputStream}.
|
|
||||||
*
|
*
|
||||||
* @param input The stream from which to read.
|
* @param input The stream from which to read.
|
||||||
* @return The deserialized action.
|
* @return The deserialized action.
|
||||||
@ -104,35 +101,35 @@ public final class DownloadAction {
|
|||||||
public final String type;
|
public final String type;
|
||||||
/** The uri being downloaded. */
|
/** The uri being downloaded. */
|
||||||
public final Uri uri;
|
public final Uri uri;
|
||||||
/** Keys of streams to be downloaded. If empty, all streams will be downloaded. */
|
/** Stream keys to be downloaded. If empty, all streams will be downloaded. */
|
||||||
public final List<StreamKey> keys;
|
public final List<StreamKey> streamKeys;
|
||||||
/** A custom key for cache indexing, or null. */
|
/** Custom key for cache indexing, or null. */
|
||||||
@Nullable public final String customCacheKey;
|
@Nullable public final String customCacheKey;
|
||||||
/** Custom data for this action. May be empty. */
|
/** Application defined data associated with the download. May be empty. */
|
||||||
public final byte[] data;
|
public final byte[] data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id The content id.
|
* @param id See {@link #id}.
|
||||||
* @param type The type of the action.
|
* @param type See {@link #type}.
|
||||||
* @param uri The uri being downloaded.
|
* @param uri See {@link #uri}.
|
||||||
* @param keys Keys of streams to be downloaded. If empty, all streams will be downloaded.
|
* @param streamKeys See {@link #streamKeys}.
|
||||||
* @param customCacheKey A custom key for cache indexing, or null.
|
* @param customCacheKey See {@link #customCacheKey}.
|
||||||
* @param data Custom data for this action.
|
* @param data See {@link #data}.
|
||||||
*/
|
*/
|
||||||
private DownloadAction(
|
private DownloadAction(
|
||||||
String id,
|
String id,
|
||||||
String type,
|
String type,
|
||||||
Uri uri,
|
Uri uri,
|
||||||
List<StreamKey> keys,
|
List<StreamKey> streamKeys,
|
||||||
@Nullable String customCacheKey,
|
@Nullable String customCacheKey,
|
||||||
@Nullable byte[] data) {
|
@Nullable byte[] data) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
this.customCacheKey = customCacheKey;
|
this.customCacheKey = customCacheKey;
|
||||||
ArrayList<StreamKey> mutableKeys = new ArrayList<>(keys);
|
ArrayList<StreamKey> mutableKeys = new ArrayList<>(streamKeys);
|
||||||
Collections.sort(mutableKeys);
|
Collections.sort(mutableKeys);
|
||||||
this.keys = Collections.unmodifiableList(mutableKeys);
|
this.streamKeys = Collections.unmodifiableList(mutableKeys);
|
||||||
this.data = data != null ? Arrays.copyOf(data, data.length) : Util.EMPTY_BYTE_ARRAY;
|
this.data = data != null ? Arrays.copyOf(data, data.length) : Util.EMPTY_BYTE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,11 +145,6 @@ public final class DownloadAction {
|
|||||||
return output.toByteArray();
|
return output.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns keys of streams to be downloaded. */
|
|
||||||
public List<StreamKey> getKeys() {
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object o) {
|
public boolean equals(@Nullable Object o) {
|
||||||
if (!(o instanceof DownloadAction)) {
|
if (!(o instanceof DownloadAction)) {
|
||||||
@ -162,7 +154,7 @@ public final class DownloadAction {
|
|||||||
return id.equals(that.id)
|
return id.equals(that.id)
|
||||||
&& type.equals(that.type)
|
&& type.equals(that.type)
|
||||||
&& uri.equals(that.uri)
|
&& uri.equals(that.uri)
|
||||||
&& keys.equals(that.keys)
|
&& streamKeys.equals(that.streamKeys)
|
||||||
&& Util.areEqual(customCacheKey, that.customCacheKey)
|
&& Util.areEqual(customCacheKey, that.customCacheKey)
|
||||||
&& Arrays.equals(data, that.data);
|
&& Arrays.equals(data, that.data);
|
||||||
}
|
}
|
||||||
@ -172,7 +164,7 @@ public final class DownloadAction {
|
|||||||
int result = type.hashCode();
|
int result = type.hashCode();
|
||||||
result = 31 * result + id.hashCode();
|
result = 31 * result + id.hashCode();
|
||||||
result = 31 * result + uri.hashCode();
|
result = 31 * result + uri.hashCode();
|
||||||
result = 31 * result + keys.hashCode();
|
result = 31 * result + streamKeys.hashCode();
|
||||||
result = 31 * result + (customCacheKey != null ? customCacheKey.hashCode() : 0);
|
result = 31 * result + (customCacheKey != null ? customCacheKey.hashCode() : 0);
|
||||||
result = 31 * result + Arrays.hashCode(data);
|
result = 31 * result + Arrays.hashCode(data);
|
||||||
return result;
|
return result;
|
||||||
@ -194,9 +186,9 @@ public final class DownloadAction {
|
|||||||
dataOutputStream.writeBoolean(false);
|
dataOutputStream.writeBoolean(false);
|
||||||
dataOutputStream.writeInt(data.length);
|
dataOutputStream.writeInt(data.length);
|
||||||
dataOutputStream.write(data);
|
dataOutputStream.write(data);
|
||||||
dataOutputStream.writeInt(keys.size());
|
dataOutputStream.writeInt(streamKeys.size());
|
||||||
for (int i = 0; i < keys.size(); i++) {
|
for (int i = 0; i < streamKeys.size(); i++) {
|
||||||
StreamKey key = keys.get(i);
|
StreamKey key = streamKeys.get(i);
|
||||||
dataOutputStream.writeInt(key.periodIndex);
|
dataOutputStream.writeInt(key.periodIndex);
|
||||||
dataOutputStream.writeInt(key.groupIndex);
|
dataOutputStream.writeInt(key.groupIndex);
|
||||||
dataOutputStream.writeInt(key.trackIndex);
|
dataOutputStream.writeInt(key.trackIndex);
|
||||||
|
@ -165,7 +165,7 @@ public final class DownloadState {
|
|||||||
/* manualStopReason= */ 0,
|
/* manualStopReason= */ 0,
|
||||||
/* startTimeMs= */ currentTimeMs,
|
/* startTimeMs= */ currentTimeMs,
|
||||||
/* updateTimeMs= */ currentTimeMs,
|
/* updateTimeMs= */ currentTimeMs,
|
||||||
action.keys.toArray(new StreamKey[0]),
|
action.streamKeys.toArray(new StreamKey[0]),
|
||||||
action.data,
|
action.data,
|
||||||
new CachingCounters());
|
new CachingCounters());
|
||||||
}
|
}
|
||||||
@ -289,10 +289,10 @@ public final class DownloadState {
|
|||||||
private static StreamKey[] mergeStreamKeys(DownloadState downloadState, DownloadAction action) {
|
private static StreamKey[] mergeStreamKeys(DownloadState downloadState, DownloadAction action) {
|
||||||
StreamKey[] streamKeys = downloadState.streamKeys;
|
StreamKey[] streamKeys = downloadState.streamKeys;
|
||||||
if (streamKeys.length > 0) {
|
if (streamKeys.length > 0) {
|
||||||
if (action.keys.isEmpty()) {
|
if (action.streamKeys.isEmpty()) {
|
||||||
streamKeys = new StreamKey[0];
|
streamKeys = new StreamKey[0];
|
||||||
} else {
|
} else {
|
||||||
HashSet<StreamKey> keys = new HashSet<>(action.keys);
|
HashSet<StreamKey> keys = new HashSet<>(action.streamKeys);
|
||||||
Collections.addAll(keys, downloadState.streamKeys);
|
Collections.addAll(keys, downloadState.streamKeys);
|
||||||
streamKeys = keys.toArray(new StreamKey[0]);
|
streamKeys = keys.toArray(new StreamKey[0]);
|
||||||
}
|
}
|
||||||
|
@ -398,7 +398,7 @@ public class DownloadHelperTest {
|
|||||||
assertThat(downloadAction.uri).isEqualTo(testUri);
|
assertThat(downloadAction.uri).isEqualTo(testUri);
|
||||||
assertThat(downloadAction.customCacheKey).isEqualTo(TEST_CACHE_KEY);
|
assertThat(downloadAction.customCacheKey).isEqualTo(TEST_CACHE_KEY);
|
||||||
assertThat(downloadAction.data).isEqualTo(data);
|
assertThat(downloadAction.data).isEqualTo(data);
|
||||||
assertThat(downloadAction.keys)
|
assertThat(downloadAction.streamKeys)
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 0),
|
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 0),
|
||||||
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 1),
|
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 1),
|
||||||
|
@ -147,7 +147,8 @@ public class DownloadIndexUtilTest {
|
|||||||
assertThat(downloadState.cacheKey).isEqualTo(action.customCacheKey);
|
assertThat(downloadState.cacheKey).isEqualTo(action.customCacheKey);
|
||||||
assertThat(downloadState.customMetadata).isEqualTo(action.data);
|
assertThat(downloadState.customMetadata).isEqualTo(action.data);
|
||||||
assertThat(downloadState.uri).isEqualTo(action.uri);
|
assertThat(downloadState.uri).isEqualTo(action.uri);
|
||||||
assertThat(Arrays.asList(downloadState.streamKeys)).containsExactlyElementsIn(action.keys);
|
assertThat(Arrays.asList(downloadState.streamKeys))
|
||||||
|
.containsExactlyElementsIn(action.streamKeys);
|
||||||
assertThat(downloadState.state).isEqualTo(state);
|
assertThat(downloadState.state).isEqualTo(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ public class DownloadManagerTest {
|
|||||||
|
|
||||||
FakeDownloader downloader2 = runner.getDownloader(1);
|
FakeDownloader downloader2 = runner.getDownloader(1);
|
||||||
downloader2.assertStarted();
|
downloader2.assertStarted();
|
||||||
assertThat(downloader2.action.keys).containsExactly(streamKey1, streamKey2);
|
assertThat(downloader2.action.streamKeys).containsExactly(streamKey1, streamKey2);
|
||||||
downloader2.unblock();
|
downloader2.unblock();
|
||||||
|
|
||||||
runner.getTask().assertCompleted();
|
runner.getTask().assertCompleted();
|
||||||
|
@ -52,7 +52,7 @@ class DownloadStateBuilder {
|
|||||||
action.uri,
|
action.uri,
|
||||||
action.customCacheKey,
|
action.customCacheKey,
|
||||||
action.data,
|
action.data,
|
||||||
action.keys.toArray(new StreamKey[0]));
|
action.streamKeys.toArray(new StreamKey[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadStateBuilder(
|
DownloadStateBuilder(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user