Sanitize naming of keys variable.

PiperOrigin-RevId: 242460786
This commit is contained in:
olly 2019-04-08 15:41:20 +01:00 committed by Oliver Woodman
parent a0c21461aa
commit e7d717b96c
7 changed files with 29 additions and 36 deletions

View File

@ -99,7 +99,7 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
}
try {
// 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) {
throw new RuntimeException("Failed to instantiate downloader for: " + action.type, e);
}

View File

@ -48,7 +48,7 @@ public final class DownloadAction {
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.
* @return The deserialized action.
@ -62,10 +62,7 @@ public final class DownloadAction {
}
/**
* Deserializes one action that was serialized with {@link #serializeToStream(OutputStream)} from
* the {@code input}.
*
* <p>The caller is responsible for closing the given {@link InputStream}.
* Deserializes a single download action from {@code input}.
*
* @param input The stream from which to read.
* @return The deserialized action.
@ -104,35 +101,35 @@ public final class DownloadAction {
public final String type;
/** The uri being downloaded. */
public final Uri uri;
/** Keys of streams to be downloaded. If empty, all streams will be downloaded. */
public final List<StreamKey> keys;
/** A custom key for cache indexing, or null. */
/** Stream keys to be downloaded. If empty, all streams will be downloaded. */
public final List<StreamKey> streamKeys;
/** Custom key for cache indexing, or null. */
@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;
/**
* @param id The content id.
* @param type The type of the action.
* @param uri The uri being downloaded.
* @param keys Keys of streams to be downloaded. If empty, all streams will be downloaded.
* @param customCacheKey A custom key for cache indexing, or null.
* @param data Custom data for this action.
* @param id See {@link #id}.
* @param type See {@link #type}.
* @param uri See {@link #uri}.
* @param streamKeys See {@link #streamKeys}.
* @param customCacheKey See {@link #customCacheKey}.
* @param data See {@link #data}.
*/
private DownloadAction(
String id,
String type,
Uri uri,
List<StreamKey> keys,
List<StreamKey> streamKeys,
@Nullable String customCacheKey,
@Nullable byte[] data) {
this.id = id;
this.type = type;
this.uri = uri;
this.customCacheKey = customCacheKey;
ArrayList<StreamKey> mutableKeys = new ArrayList<>(keys);
ArrayList<StreamKey> mutableKeys = new ArrayList<>(streamKeys);
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;
}
@ -148,11 +145,6 @@ public final class DownloadAction {
return output.toByteArray();
}
/** Returns keys of streams to be downloaded. */
public List<StreamKey> getKeys() {
return keys;
}
@Override
public boolean equals(@Nullable Object o) {
if (!(o instanceof DownloadAction)) {
@ -162,7 +154,7 @@ public final class DownloadAction {
return id.equals(that.id)
&& type.equals(that.type)
&& uri.equals(that.uri)
&& keys.equals(that.keys)
&& streamKeys.equals(that.streamKeys)
&& Util.areEqual(customCacheKey, that.customCacheKey)
&& Arrays.equals(data, that.data);
}
@ -172,7 +164,7 @@ public final class DownloadAction {
int result = type.hashCode();
result = 31 * result + id.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 + Arrays.hashCode(data);
return result;
@ -194,9 +186,9 @@ public final class DownloadAction {
dataOutputStream.writeBoolean(false);
dataOutputStream.writeInt(data.length);
dataOutputStream.write(data);
dataOutputStream.writeInt(keys.size());
for (int i = 0; i < keys.size(); i++) {
StreamKey key = keys.get(i);
dataOutputStream.writeInt(streamKeys.size());
for (int i = 0; i < streamKeys.size(); i++) {
StreamKey key = streamKeys.get(i);
dataOutputStream.writeInt(key.periodIndex);
dataOutputStream.writeInt(key.groupIndex);
dataOutputStream.writeInt(key.trackIndex);

View File

@ -165,7 +165,7 @@ public final class DownloadState {
/* manualStopReason= */ 0,
/* startTimeMs= */ currentTimeMs,
/* updateTimeMs= */ currentTimeMs,
action.keys.toArray(new StreamKey[0]),
action.streamKeys.toArray(new StreamKey[0]),
action.data,
new CachingCounters());
}
@ -289,10 +289,10 @@ public final class DownloadState {
private static StreamKey[] mergeStreamKeys(DownloadState downloadState, DownloadAction action) {
StreamKey[] streamKeys = downloadState.streamKeys;
if (streamKeys.length > 0) {
if (action.keys.isEmpty()) {
if (action.streamKeys.isEmpty()) {
streamKeys = new StreamKey[0];
} else {
HashSet<StreamKey> keys = new HashSet<>(action.keys);
HashSet<StreamKey> keys = new HashSet<>(action.streamKeys);
Collections.addAll(keys, downloadState.streamKeys);
streamKeys = keys.toArray(new StreamKey[0]);
}

View File

@ -398,7 +398,7 @@ public class DownloadHelperTest {
assertThat(downloadAction.uri).isEqualTo(testUri);
assertThat(downloadAction.customCacheKey).isEqualTo(TEST_CACHE_KEY);
assertThat(downloadAction.data).isEqualTo(data);
assertThat(downloadAction.keys)
assertThat(downloadAction.streamKeys)
.containsExactly(
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 0),
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 1),

View File

@ -147,7 +147,8 @@ public class DownloadIndexUtilTest {
assertThat(downloadState.cacheKey).isEqualTo(action.customCacheKey);
assertThat(downloadState.customMetadata).isEqualTo(action.data);
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);
}

View File

@ -249,7 +249,7 @@ public class DownloadManagerTest {
FakeDownloader downloader2 = runner.getDownloader(1);
downloader2.assertStarted();
assertThat(downloader2.action.keys).containsExactly(streamKey1, streamKey2);
assertThat(downloader2.action.streamKeys).containsExactly(streamKey1, streamKey2);
downloader2.unblock();
runner.getTask().assertCompleted();

View File

@ -52,7 +52,7 @@ class DownloadStateBuilder {
action.uri,
action.customCacheKey,
action.data,
action.keys.toArray(new StreamKey[0]));
action.streamKeys.toArray(new StreamKey[0]));
}
DownloadStateBuilder(