From e7d717b96c8530fb7d78b09304e44e262a050859 Mon Sep 17 00:00:00 2001 From: olly Date: Mon, 8 Apr 2019 15:41:20 +0100 Subject: [PATCH] Sanitize naming of keys variable. PiperOrigin-RevId: 242460786 --- .../offline/DefaultDownloaderFactory.java | 2 +- .../exoplayer2/offline/DownloadAction.java | 48 ++++++++----------- .../exoplayer2/offline/DownloadState.java | 6 +-- .../offline/DownloadHelperTest.java | 2 +- .../offline/DownloadIndexUtilTest.java | 3 +- .../offline/DownloadManagerTest.java | 2 +- .../offline/DownloadStateBuilder.java | 2 +- 7 files changed, 29 insertions(+), 36 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloaderFactory.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloaderFactory.java index db8090c22e..03421dfdff 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloaderFactory.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloaderFactory.java @@ -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); } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadAction.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadAction.java index 0998ef1865..32f36d051d 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadAction.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadAction.java @@ -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}. - * - *

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 keys; - /** A custom key for cache indexing, or null. */ + /** Stream keys to be downloaded. If empty, all streams will be downloaded. */ + public final List 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 keys, + List streamKeys, @Nullable String customCacheKey, @Nullable byte[] data) { this.id = id; this.type = type; this.uri = uri; this.customCacheKey = customCacheKey; - ArrayList mutableKeys = new ArrayList<>(keys); + ArrayList 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 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); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadState.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadState.java index 251bcc1a45..c98f1dcf39 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadState.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadState.java @@ -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 keys = new HashSet<>(action.keys); + HashSet keys = new HashSet<>(action.streamKeys); Collections.addAll(keys, downloadState.streamKeys); streamKeys = keys.toArray(new StreamKey[0]); } diff --git a/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadHelperTest.java b/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadHelperTest.java index ae4816a80d..737bcec183 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadHelperTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadHelperTest.java @@ -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), diff --git a/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadIndexUtilTest.java b/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadIndexUtilTest.java index 3f4b3f7798..b752d83bf0 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadIndexUtilTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadIndexUtilTest.java @@ -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); } diff --git a/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java b/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java index a6bdc89a97..2c1dd233d3 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java @@ -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(); diff --git a/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadStateBuilder.java b/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadStateBuilder.java index 084071cf7a..d536fd8176 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadStateBuilder.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadStateBuilder.java @@ -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(