Commit 5856e757 by eguven Committed by Oliver Woodman

Rename DownloadAction to DownloadRequest

PiperOrigin-RevId: 243806888
parent 9fc3ea79
Showing with 489 additions and 488 deletions
...@@ -75,13 +75,13 @@ public class DemoDownloadService extends DownloadService { ...@@ -75,13 +75,13 @@ public class DemoDownloadService extends DownloadService {
notificationHelper.buildDownloadCompletedNotification( notificationHelper.buildDownloadCompletedNotification(
R.drawable.ic_download_done, R.drawable.ic_download_done,
/* contentIntent= */ null, /* contentIntent= */ null,
Util.fromUtf8Bytes(download.action.data)); Util.fromUtf8Bytes(download.request.data));
} else if (download.state == Download.STATE_FAILED) { } else if (download.state == Download.STATE_FAILED) {
notification = notification =
notificationHelper.buildDownloadFailedNotification( notificationHelper.buildDownloadFailedNotification(
R.drawable.ic_download_done, R.drawable.ic_download_done,
/* contentIntent= */ null, /* contentIntent= */ null,
Util.fromUtf8Bytes(download.action.data)); Util.fromUtf8Bytes(download.request.data));
} else { } else {
return; return;
} }
......
...@@ -24,11 +24,11 @@ import android.widget.Toast; ...@@ -24,11 +24,11 @@ import android.widget.Toast;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.RenderersFactory; import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.offline.Download; import com.google.android.exoplayer2.offline.Download;
import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloadCursor; import com.google.android.exoplayer2.offline.DownloadCursor;
import com.google.android.exoplayer2.offline.DownloadHelper; import com.google.android.exoplayer2.offline.DownloadHelper;
import com.google.android.exoplayer2.offline.DownloadIndex; import com.google.android.exoplayer2.offline.DownloadIndex;
import com.google.android.exoplayer2.offline.DownloadManager; import com.google.android.exoplayer2.offline.DownloadManager;
import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.offline.DownloadService; import com.google.android.exoplayer2.offline.DownloadService;
import com.google.android.exoplayer2.offline.StreamKey; import com.google.android.exoplayer2.offline.StreamKey;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo; import com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo;
...@@ -89,7 +89,7 @@ public class DownloadTracker { ...@@ -89,7 +89,7 @@ public class DownloadTracker {
public List<StreamKey> getOfflineStreamKeys(Uri uri) { public List<StreamKey> getOfflineStreamKeys(Uri uri) {
Download download = downloads.get(uri); Download download = downloads.get(uri);
return download != null && download.state != Download.STATE_FAILED return download != null && download.state != Download.STATE_FAILED
? download.action.streamKeys ? download.request.streamKeys
: Collections.emptyList(); : Collections.emptyList();
} }
...@@ -102,7 +102,7 @@ public class DownloadTracker { ...@@ -102,7 +102,7 @@ public class DownloadTracker {
Download download = downloads.get(uri); Download download = downloads.get(uri);
if (download != null) { if (download != null) {
DownloadService.startWithRemoveDownload( DownloadService.startWithRemoveDownload(
context, DemoDownloadService.class, download.action.id, /* foreground= */ false); context, DemoDownloadService.class, download.request.id, /* foreground= */ false);
} else { } else {
if (startDownloadDialogHelper != null) { if (startDownloadDialogHelper != null) {
startDownloadDialogHelper.release(); startDownloadDialogHelper.release();
...@@ -117,18 +117,13 @@ public class DownloadTracker { ...@@ -117,18 +117,13 @@ public class DownloadTracker {
try (DownloadCursor loadedDownloads = downloadIndex.getDownloads()) { try (DownloadCursor loadedDownloads = downloadIndex.getDownloads()) {
while (loadedDownloads.moveToNext()) { while (loadedDownloads.moveToNext()) {
Download download = loadedDownloads.getDownload(); Download download = loadedDownloads.getDownload();
downloads.put(download.action.uri, download); downloads.put(download.request.uri, download);
} }
} catch (IOException e) { } catch (IOException e) {
Log.w(TAG, "Failed to query downloads", e); Log.w(TAG, "Failed to query downloads", e);
} }
} }
private void startServiceWithAction(DownloadAction action) {
DownloadService.startWithAction(
context, DemoDownloadService.class, action, /* foreground= */ false);
}
private DownloadHelper getDownloadHelper( private DownloadHelper getDownloadHelper(
Uri uri, String extension, RenderersFactory renderersFactory) { Uri uri, String extension, RenderersFactory renderersFactory) {
int type = Util.inferContentType(uri, extension); int type = Util.inferContentType(uri, extension);
...@@ -150,7 +145,7 @@ public class DownloadTracker { ...@@ -150,7 +145,7 @@ public class DownloadTracker {
@Override @Override
public void onDownloadChanged(DownloadManager downloadManager, Download download) { public void onDownloadChanged(DownloadManager downloadManager, Download download) {
downloads.put(download.action.uri, download); downloads.put(download.request.uri, download);
for (Listener listener : listeners) { for (Listener listener : listeners) {
listener.onDownloadsChanged(); listener.onDownloadsChanged();
} }
...@@ -158,7 +153,7 @@ public class DownloadTracker { ...@@ -158,7 +153,7 @@ public class DownloadTracker {
@Override @Override
public void onDownloadRemoved(DownloadManager downloadManager, Download download) { public void onDownloadRemoved(DownloadManager downloadManager, Download download) {
downloads.remove(download.action.uri); downloads.remove(download.request.uri);
for (Listener listener : listeners) { for (Listener listener : listeners) {
listener.onDownloadsChanged(); listener.onDownloadsChanged();
} }
...@@ -259,8 +254,9 @@ public class DownloadTracker { ...@@ -259,8 +254,9 @@ public class DownloadTracker {
// Internal methods. // Internal methods.
private void startDownload() { private void startDownload() {
DownloadAction downloadAction = downloadHelper.getDownloadAction(Util.getUtf8Bytes(name)); DownloadRequest downloadRequest = downloadHelper.getDownloadRequest(Util.getUtf8Bytes(name));
startServiceWithAction(downloadAction); DownloadService.startWithNewDownload(
context, DemoDownloadService.class, downloadRequest, /* foreground= */ false);
} }
} }
} }
...@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.offline; ...@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.offline;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.offline.DownloadAction.UnsupportedActionException; import com.google.android.exoplayer2.offline.DownloadRequest.UnsupportedRequestException;
import com.google.android.exoplayer2.util.AtomicFile; import com.google.android.exoplayer2.util.AtomicFile;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.DataInputStream; import java.io.DataInputStream;
...@@ -28,7 +28,7 @@ import java.util.ArrayList; ...@@ -28,7 +28,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Loads {@link DownloadAction DownloadActions} from legacy action files. * Loads {@link DownloadRequest DownloadRequests} from legacy action files.
* *
* @deprecated Legacy action files should be merged into download indices using {@link * @deprecated Legacy action files should be merged into download indices using {@link
* ActionFileUpgradeUtil}. * ActionFileUpgradeUtil}.
...@@ -41,7 +41,7 @@ import java.util.List; ...@@ -41,7 +41,7 @@ import java.util.List;
private final AtomicFile atomicFile; private final AtomicFile atomicFile;
/** /**
* @param actionFile The file from which {@link DownloadAction DownloadActions} will be loaded. * @param actionFile The file from which {@link DownloadRequest DownloadRequests} will be loaded.
*/ */
public ActionFile(File actionFile) { public ActionFile(File actionFile) {
atomicFile = new AtomicFile(actionFile); atomicFile = new AtomicFile(actionFile);
...@@ -58,15 +58,15 @@ import java.util.List; ...@@ -58,15 +58,15 @@ import java.util.List;
} }
/** /**
* Loads {@link DownloadAction DownloadActions} from the file. * Loads {@link DownloadRequest DownloadRequests} from the file.
* *
* @return The loaded {@link DownloadAction DownloadActions}, or an empty array if the file does * @return The loaded {@link DownloadRequest DownloadRequests}, or an empty array if the file does
* not exist. * not exist.
* @throws IOException If there is an error reading the file. * @throws IOException If there is an error reading the file.
*/ */
public DownloadAction[] load() throws IOException { public DownloadRequest[] load() throws IOException {
if (!exists()) { if (!exists()) {
return new DownloadAction[0]; return new DownloadRequest[0];
} }
InputStream inputStream = null; InputStream inputStream = null;
try { try {
...@@ -77,21 +77,21 @@ import java.util.List; ...@@ -77,21 +77,21 @@ import java.util.List;
throw new IOException("Unsupported action file version: " + version); throw new IOException("Unsupported action file version: " + version);
} }
int actionCount = dataInputStream.readInt(); int actionCount = dataInputStream.readInt();
ArrayList<DownloadAction> actions = new ArrayList<>(); ArrayList<DownloadRequest> actions = new ArrayList<>();
for (int i = 0; i < actionCount; i++) { for (int i = 0; i < actionCount; i++) {
try { try {
actions.add(readDownloadAction(dataInputStream)); actions.add(readDownloadRequest(dataInputStream));
} catch (UnsupportedActionException e) { } catch (UnsupportedRequestException e) {
// remove DownloadAction is not supported. Ignore the exception and continue loading rest. // remove DownloadRequest is not supported. Ignore and continue loading rest.
} }
} }
return actions.toArray(new DownloadAction[0]); return actions.toArray(new DownloadRequest[0]);
} finally { } finally {
Util.closeQuietly(inputStream); Util.closeQuietly(inputStream);
} }
} }
private static DownloadAction readDownloadAction(DataInputStream input) throws IOException { private static DownloadRequest readDownloadRequest(DataInputStream input) throws IOException {
String type = input.readUTF(); String type = input.readUTF();
int version = input.readInt(); int version = input.readInt();
...@@ -108,7 +108,7 @@ import java.util.List; ...@@ -108,7 +108,7 @@ import java.util.List;
} }
// Serialized version 0 progressive actions did not contain keys. // Serialized version 0 progressive actions did not contain keys.
boolean isLegacyProgressive = version == 0 && DownloadAction.TYPE_PROGRESSIVE.equals(type); boolean isLegacyProgressive = version == 0 && DownloadRequest.TYPE_PROGRESSIVE.equals(type);
List<StreamKey> keys = new ArrayList<>(); List<StreamKey> keys = new ArrayList<>();
if (!isLegacyProgressive) { if (!isLegacyProgressive) {
int keyCount = input.readInt(); int keyCount = input.readInt();
...@@ -120,22 +120,22 @@ import java.util.List; ...@@ -120,22 +120,22 @@ import java.util.List;
// Serialized version 0 and 1 DASH/HLS/SS actions did not contain a custom cache key. // Serialized version 0 and 1 DASH/HLS/SS actions did not contain a custom cache key.
boolean isLegacySegmented = boolean isLegacySegmented =
version < 2 version < 2
&& (DownloadAction.TYPE_DASH.equals(type) && (DownloadRequest.TYPE_DASH.equals(type)
|| DownloadAction.TYPE_HLS.equals(type) || DownloadRequest.TYPE_HLS.equals(type)
|| DownloadAction.TYPE_SS.equals(type)); || DownloadRequest.TYPE_SS.equals(type));
String customCacheKey = null; String customCacheKey = null;
if (!isLegacySegmented) { if (!isLegacySegmented) {
customCacheKey = input.readBoolean() ? input.readUTF() : null; customCacheKey = input.readBoolean() ? input.readUTF() : null;
} }
// Serialized version 0, 1 and 2 did not contain an id. We need to generate one. // Serialized version 0, 1 and 2 did not contain an id. We need to generate one.
String id = version < 3 ? generateDownloadActionId(uri, customCacheKey) : input.readUTF(); String id = version < 3 ? generateDownloadId(uri, customCacheKey) : input.readUTF();
if (isRemoveAction) { if (isRemoveAction) {
// Remove actions are not supported anymore. // Remove actions are not supported anymore.
throw new UnsupportedActionException(); throw new UnsupportedRequestException();
} }
return new DownloadAction(id, type, uri, keys, customCacheKey, data); return new DownloadRequest(id, type, uri, keys, customCacheKey, data);
} }
private static StreamKey readKey(String type, int version, DataInputStream input) private static StreamKey readKey(String type, int version, DataInputStream input)
...@@ -145,7 +145,7 @@ import java.util.List; ...@@ -145,7 +145,7 @@ import java.util.List;
int trackIndex; int trackIndex;
// Serialized version 0 HLS/SS actions did not contain a period index. // Serialized version 0 HLS/SS actions did not contain a period index.
if ((DownloadAction.TYPE_HLS.equals(type) || DownloadAction.TYPE_SS.equals(type)) if ((DownloadRequest.TYPE_HLS.equals(type) || DownloadRequest.TYPE_SS.equals(type))
&& version == 0) { && version == 0) {
periodIndex = 0; periodIndex = 0;
groupIndex = input.readInt(); groupIndex = input.readInt();
...@@ -158,7 +158,7 @@ import java.util.List; ...@@ -158,7 +158,7 @@ import java.util.List;
return new StreamKey(periodIndex, groupIndex, trackIndex); return new StreamKey(periodIndex, groupIndex, trackIndex);
} }
private static String generateDownloadActionId(Uri uri, @Nullable String customCacheKey) { private static String generateDownloadId(Uri uri, @Nullable String customCacheKey) {
return customCacheKey != null ? customCacheKey : uri.toString(); return customCacheKey != null ? customCacheKey : uri.toString();
} }
} }
...@@ -28,18 +28,18 @@ public final class ActionFileUpgradeUtil { ...@@ -28,18 +28,18 @@ public final class ActionFileUpgradeUtil {
public interface DownloadIdProvider { public interface DownloadIdProvider {
/** /**
* Returns a download id for given action. * Returns a download id for given request.
* *
* @param downloadAction The action for which an ID is required. * @param downloadRequest The request for which an ID is required.
* @return A corresponding download ID. * @return A corresponding download ID.
*/ */
String getId(DownloadAction downloadAction); String getId(DownloadRequest downloadRequest);
} }
private ActionFileUpgradeUtil() {} private ActionFileUpgradeUtil() {}
/** /**
* Merges {@link DownloadAction DownloadActions} contained in a legacy action file into a {@link * Merges {@link DownloadRequest DownloadRequests} contained in a legacy action file into a {@link
* DefaultDownloadIndex}, deleting the action file if the merge is successful or if {@code * DefaultDownloadIndex}, deleting the action file if the merge is successful or if {@code
* deleteOnFailure} is {@code true}. * deleteOnFailure} is {@code true}.
* *
...@@ -49,9 +49,9 @@ public final class ActionFileUpgradeUtil { ...@@ -49,9 +49,9 @@ public final class ActionFileUpgradeUtil {
* @param actionFilePath The action file path. * @param actionFilePath The action file path.
* @param downloadIdProvider A download ID provider, or {@code null}. If {@code null} then ID of * @param downloadIdProvider A download ID provider, or {@code null}. If {@code null} then ID of
* each download will be its custom cache key if one is specified, or else its URL. * each download will be its custom cache key if one is specified, or else its URL.
* @param downloadIndex The index into which the action will be merged. * @param downloadIndex The index into which the requests will be merged.
* @param deleteOnFailure Whether to delete the action file if the merge fails. * @param deleteOnFailure Whether to delete the action file if the merge fails.
* @throws IOException If an error occurs loading or merging the actions. * @throws IOException If an error occurs loading or merging the requests.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void upgradeAndDelete( public static void upgradeAndDelete(
...@@ -64,11 +64,11 @@ public final class ActionFileUpgradeUtil { ...@@ -64,11 +64,11 @@ public final class ActionFileUpgradeUtil {
if (actionFile.exists()) { if (actionFile.exists()) {
boolean success = false; boolean success = false;
try { try {
for (DownloadAction action : actionFile.load()) { for (DownloadRequest request : actionFile.load()) {
if (downloadIdProvider != null) { if (downloadIdProvider != null) {
action = action.copyWithId(downloadIdProvider.getId(action)); request = request.copyWithId(downloadIdProvider.getId(request));
} }
mergeAction(action, downloadIndex); mergeRequest(request, downloadIndex);
} }
success = true; success = true;
} finally { } finally {
...@@ -80,22 +80,22 @@ public final class ActionFileUpgradeUtil { ...@@ -80,22 +80,22 @@ public final class ActionFileUpgradeUtil {
} }
/** /**
* Merges a {@link DownloadAction} into a {@link DefaultDownloadIndex}. * Merges a {@link DownloadRequest} into a {@link DefaultDownloadIndex}.
* *
* @param action The action to be merged. * @param request The request to be merged.
* @param downloadIndex The index into which the action will be merged. * @param downloadIndex The index into which the request will be merged.
* @throws IOException If an error occurs merging the action. * @throws IOException If an error occurs merging the request.
*/ */
/* package */ static void mergeAction(DownloadAction action, DefaultDownloadIndex downloadIndex) /* package */ static void mergeRequest(
throws IOException { DownloadRequest request, DefaultDownloadIndex downloadIndex) throws IOException {
Download download = downloadIndex.getDownload(action.id); Download download = downloadIndex.getDownload(request.id);
if (download != null) { if (download != null) {
download = DownloadManager.mergeAction(download, action, download.manualStopReason); download = DownloadManager.mergeRequest(download, request, download.manualStopReason);
} else { } else {
long nowMs = System.currentTimeMillis(); long nowMs = System.currentTimeMillis();
download = download =
new Download( new Download(
action, request,
STATE_QUEUED, STATE_QUEUED,
Download.FAILURE_REASON_NONE, Download.FAILURE_REASON_NONE,
Download.MANUAL_STOP_REASON_NONE, Download.MANUAL_STOP_REASON_NONE,
......
...@@ -194,12 +194,12 @@ public final class DefaultDownloadIndex implements DownloadIndex { ...@@ -194,12 +194,12 @@ public final class DefaultDownloadIndex implements DownloadIndex {
public void putDownload(Download download) throws DatabaseIOException { public void putDownload(Download download) throws DatabaseIOException {
ensureInitialized(); ensureInitialized();
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(COLUMN_ID, download.action.id); values.put(COLUMN_ID, download.request.id);
values.put(COLUMN_TYPE, download.action.type); values.put(COLUMN_TYPE, download.request.type);
values.put(COLUMN_URI, download.action.uri.toString()); values.put(COLUMN_URI, download.request.uri.toString());
values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.action.streamKeys)); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys));
values.put(COLUMN_CUSTOM_CACHE_KEY, download.action.customCacheKey); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey);
values.put(COLUMN_DATA, download.action.data); values.put(COLUMN_DATA, download.request.data);
values.put(COLUMN_STATE, download.state); values.put(COLUMN_STATE, download.state);
values.put(COLUMN_DOWNLOAD_PERCENTAGE, download.getDownloadPercentage()); values.put(COLUMN_DOWNLOAD_PERCENTAGE, download.getDownloadPercentage());
values.put(COLUMN_DOWNLOADED_BYTES, download.getDownloadedBytes()); values.put(COLUMN_DOWNLOADED_BYTES, download.getDownloadedBytes());
...@@ -342,8 +342,8 @@ public final class DefaultDownloadIndex implements DownloadIndex { ...@@ -342,8 +342,8 @@ public final class DefaultDownloadIndex implements DownloadIndex {
} }
private static Download getDownloadForCurrentRow(Cursor cursor) { private static Download getDownloadForCurrentRow(Cursor cursor) {
DownloadAction action = DownloadRequest request =
new DownloadAction( new DownloadRequest(
cursor.getString(COLUMN_INDEX_ID), cursor.getString(COLUMN_INDEX_ID),
cursor.getString(COLUMN_INDEX_TYPE), cursor.getString(COLUMN_INDEX_TYPE),
Uri.parse(cursor.getString(COLUMN_INDEX_URI)), Uri.parse(cursor.getString(COLUMN_INDEX_URI)),
...@@ -355,7 +355,7 @@ public final class DefaultDownloadIndex implements DownloadIndex { ...@@ -355,7 +355,7 @@ public final class DefaultDownloadIndex implements DownloadIndex {
cachingCounters.contentLength = cursor.getLong(COLUMN_INDEX_TOTAL_BYTES); cachingCounters.contentLength = cursor.getLong(COLUMN_INDEX_TOTAL_BYTES);
cachingCounters.percentage = cursor.getFloat(COLUMN_INDEX_DOWNLOAD_PERCENTAGE); cachingCounters.percentage = cursor.getFloat(COLUMN_INDEX_DOWNLOAD_PERCENTAGE);
return new Download( return new Download(
action, request,
cursor.getInt(COLUMN_INDEX_STATE), cursor.getInt(COLUMN_INDEX_STATE),
cursor.getInt(COLUMN_INDEX_FAILURE_REASON), cursor.getInt(COLUMN_INDEX_FAILURE_REASON),
cursor.getInt(COLUMN_INDEX_MANUAL_STOP_REASON), cursor.getInt(COLUMN_INDEX_MANUAL_STOP_REASON),
......
...@@ -76,32 +76,32 @@ public class DefaultDownloaderFactory implements DownloaderFactory { ...@@ -76,32 +76,32 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
} }
@Override @Override
public Downloader createDownloader(DownloadAction action) { public Downloader createDownloader(DownloadRequest request) {
switch (action.type) { switch (request.type) {
case DownloadAction.TYPE_PROGRESSIVE: case DownloadRequest.TYPE_PROGRESSIVE:
return new ProgressiveDownloader( return new ProgressiveDownloader(
action.uri, action.customCacheKey, downloaderConstructorHelper); request.uri, request.customCacheKey, downloaderConstructorHelper);
case DownloadAction.TYPE_DASH: case DownloadRequest.TYPE_DASH:
return createDownloader(action, DASH_DOWNLOADER_CONSTRUCTOR); return createDownloader(request, DASH_DOWNLOADER_CONSTRUCTOR);
case DownloadAction.TYPE_HLS: case DownloadRequest.TYPE_HLS:
return createDownloader(action, HLS_DOWNLOADER_CONSTRUCTOR); return createDownloader(request, HLS_DOWNLOADER_CONSTRUCTOR);
case DownloadAction.TYPE_SS: case DownloadRequest.TYPE_SS:
return createDownloader(action, SS_DOWNLOADER_CONSTRUCTOR); return createDownloader(request, SS_DOWNLOADER_CONSTRUCTOR);
default: default:
throw new IllegalArgumentException("Unsupported type: " + action.type); throw new IllegalArgumentException("Unsupported type: " + request.type);
} }
} }
private Downloader createDownloader( private Downloader createDownloader(
DownloadAction action, @Nullable Constructor<? extends Downloader> constructor) { DownloadRequest request, @Nullable Constructor<? extends Downloader> constructor) {
if (constructor == null) { if (constructor == null) {
throw new IllegalStateException("Module missing for: " + action.type); throw new IllegalStateException("Module missing for: " + request.type);
} }
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.streamKeys, downloaderConstructorHelper); return constructor.newInstance(request.uri, request.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: " + request.type, e);
} }
} }
......
...@@ -94,8 +94,8 @@ public final class Download { ...@@ -94,8 +94,8 @@ public final class Download {
} }
} }
/** The download action. */ /** The download request. */
public final DownloadAction action; public final DownloadRequest request;
/** The state of the download. */ /** The state of the download. */
@State public final int state; @State public final int state;
...@@ -114,14 +114,14 @@ public final class Download { ...@@ -114,14 +114,14 @@ public final class Download {
/* package */ CachingCounters counters; /* package */ CachingCounters counters;
/* package */ Download( /* package */ Download(
DownloadAction action, DownloadRequest request,
@State int state, @State int state,
@FailureReason int failureReason, @FailureReason int failureReason,
int manualStopReason, int manualStopReason,
long startTimeMs, long startTimeMs,
long updateTimeMs) { long updateTimeMs) {
this( this(
action, request,
state, state,
failureReason, failureReason,
manualStopReason, manualStopReason,
...@@ -131,7 +131,7 @@ public final class Download { ...@@ -131,7 +131,7 @@ public final class Download {
} }
/* package */ Download( /* package */ Download(
DownloadAction action, DownloadRequest request,
@State int state, @State int state,
@FailureReason int failureReason, @FailureReason int failureReason,
int manualStopReason, int manualStopReason,
...@@ -143,7 +143,7 @@ public final class Download { ...@@ -143,7 +143,7 @@ public final class Download {
if (manualStopReason != 0) { if (manualStopReason != 0) {
Assertions.checkState(state != STATE_DOWNLOADING && state != STATE_QUEUED); Assertions.checkState(state != STATE_DOWNLOADING && state != STATE_QUEUED);
} }
this.action = action; this.request = request;
this.state = state; this.state = state;
this.failureReason = failureReason; this.failureReason = failureReason;
this.manualStopReason = manualStopReason; this.manualStopReason = manualStopReason;
......
...@@ -63,7 +63,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -63,7 +63,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* A helper for initializing and removing downloads. * A helper for initializing and removing downloads.
* *
* <p>The helper extracts track information from the media, selects tracks for downloading, and * <p>The helper extracts track information from the media, selects tracks for downloading, and
* creates {@link DownloadAction download actions} based on the selected tracks. * creates {@link DownloadRequest download requests} based on the selected tracks.
* *
* <p>A typical usage of DownloadHelper follows these steps: * <p>A typical usage of DownloadHelper follows these steps:
* *
...@@ -74,7 +74,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -74,7 +74,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* #getTrackSelections(int, int)}, and make adjustments using {@link * #getTrackSelections(int, int)}, and make adjustments using {@link
* #clearTrackSelections(int)}, {@link #replaceTrackSelections(int, Parameters)} and {@link * #clearTrackSelections(int)}, {@link #replaceTrackSelections(int, Parameters)} and {@link
* #addTrackSelection(int, Parameters)}. * #addTrackSelection(int, Parameters)}.
* <li>Create a download action for the selected track using {@link #getDownloadAction(byte[])}. * <li>Create a download request for the selected track using {@link #getDownloadRequest(byte[])}.
* <li>Release the helper using {@link #release()}. * <li>Release the helper using {@link #release()}.
* </ol> * </ol>
*/ */
...@@ -150,7 +150,7 @@ public final class DownloadHelper { ...@@ -150,7 +150,7 @@ public final class DownloadHelper {
*/ */
public static DownloadHelper forProgressive(Uri uri, @Nullable String cacheKey) { public static DownloadHelper forProgressive(Uri uri, @Nullable String cacheKey) {
return new DownloadHelper( return new DownloadHelper(
DownloadAction.TYPE_PROGRESSIVE, DownloadRequest.TYPE_PROGRESSIVE,
uri, uri,
cacheKey, cacheKey,
/* mediaSource= */ null, /* mediaSource= */ null,
...@@ -199,7 +199,7 @@ public final class DownloadHelper { ...@@ -199,7 +199,7 @@ public final class DownloadHelper {
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
DefaultTrackSelector.Parameters trackSelectorParameters) { DefaultTrackSelector.Parameters trackSelectorParameters) {
return new DownloadHelper( return new DownloadHelper(
DownloadAction.TYPE_DASH, DownloadRequest.TYPE_DASH,
uri, uri,
/* cacheKey= */ null, /* cacheKey= */ null,
createMediaSource( createMediaSource(
...@@ -249,7 +249,7 @@ public final class DownloadHelper { ...@@ -249,7 +249,7 @@ public final class DownloadHelper {
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
DefaultTrackSelector.Parameters trackSelectorParameters) { DefaultTrackSelector.Parameters trackSelectorParameters) {
return new DownloadHelper( return new DownloadHelper(
DownloadAction.TYPE_HLS, DownloadRequest.TYPE_HLS,
uri, uri,
/* cacheKey= */ null, /* cacheKey= */ null,
createMediaSource( createMediaSource(
...@@ -299,7 +299,7 @@ public final class DownloadHelper { ...@@ -299,7 +299,7 @@ public final class DownloadHelper {
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
DefaultTrackSelector.Parameters trackSelectorParameters) { DefaultTrackSelector.Parameters trackSelectorParameters) {
return new DownloadHelper( return new DownloadHelper(
DownloadAction.TYPE_SS, DownloadRequest.TYPE_SS,
uri, uri,
/* cacheKey= */ null, /* cacheKey= */ null,
createMediaSource(uri, dataSourceFactory, SS_FACTORY_CONSTRUCTOR, SS_FACTORY_CREATE_METHOD), createMediaSource(uri, dataSourceFactory, SS_FACTORY_CONSTRUCTOR, SS_FACTORY_CREATE_METHOD),
...@@ -327,7 +327,7 @@ public final class DownloadHelper { ...@@ -327,7 +327,7 @@ public final class DownloadHelper {
/** /**
* Creates download helper. * Creates download helper.
* *
* @param downloadType A download type. This value will be used as {@link DownloadAction#type}. * @param downloadType A download type. This value will be used as {@link DownloadRequest#type}.
* @param uri A {@link Uri}. * @param uri A {@link Uri}.
* @param cacheKey An optional cache key. * @param cacheKey An optional cache key.
* @param mediaSource A {@link MediaSource} for which tracks are selected, or null if no track * @param mediaSource A {@link MediaSource} for which tracks are selected, or null if no track
...@@ -577,16 +577,16 @@ public final class DownloadHelper { ...@@ -577,16 +577,16 @@ public final class DownloadHelper {
} }
/** /**
* Builds a {@link DownloadAction} for downloading the selected tracks. Must not be called until * Builds a {@link DownloadRequest} for downloading the selected tracks. Must not be called until
* after preparation completes. * after preparation completes.
* *
* @param data Application provided data to store in {@link DownloadAction#data}. * @param data Application provided data to store in {@link DownloadRequest#data}.
* @return The built {@link DownloadAction}. * @return The built {@link DownloadRequest}.
*/ */
public DownloadAction getDownloadAction(@Nullable byte[] data) { public DownloadRequest getDownloadRequest(@Nullable byte[] data) {
String downloadId = uri.toString(); String downloadId = uri.toString();
if (mediaSource == null) { if (mediaSource == null) {
return new DownloadAction( return new DownloadRequest(
downloadId, downloadType, uri, /* streamKeys= */ Collections.emptyList(), cacheKey, data); downloadId, downloadType, uri, /* streamKeys= */ Collections.emptyList(), cacheKey, data);
} }
assertPreparedWithMedia(); assertPreparedWithMedia();
...@@ -601,7 +601,7 @@ public final class DownloadHelper { ...@@ -601,7 +601,7 @@ public final class DownloadHelper {
} }
streamKeys.addAll(mediaPreparer.mediaPeriods[periodIndex].getStreamKeys(allSelections)); streamKeys.addAll(mediaPreparer.mediaPeriods[periodIndex].getStreamKeys(allSelections));
} }
return new DownloadAction(downloadId, downloadType, uri, streamKeys, cacheKey, data); return new DownloadRequest(downloadId, downloadType, uri, streamKeys, cacheKey, data);
} }
// Initialization of array of Lists. // Initialization of array of Lists.
......
...@@ -69,7 +69,7 @@ public final class DownloadManager { ...@@ -69,7 +69,7 @@ public final class DownloadManager {
public interface Listener { public interface Listener {
/** /**
* Called when all actions have been restored. * Called when all downloads have been restored.
* *
* @param downloadManager The reporting instance. * @param downloadManager The reporting instance.
*/ */
...@@ -382,25 +382,25 @@ public final class DownloadManager { ...@@ -382,25 +382,25 @@ public final class DownloadManager {
} }
/** /**
* Adds a download defined by the given action. * Adds a download defined by the given request.
* *
* @param action The download action. * @param request The download request.
*/ */
public void addDownload(DownloadAction action) { public void addDownload(DownloadRequest request) {
addDownload(action, Download.MANUAL_STOP_REASON_NONE); addDownload(request, Download.MANUAL_STOP_REASON_NONE);
} }
/** /**
* Adds a download defined by the given action and with the specified manual stop reason. * Adds a download defined by the given request and with the specified manual stop reason.
* *
* @param action The download action. * @param request The download request.
* @param manualStopReason An initial manual stop reason for the download, or {@link * @param manualStopReason An initial manual stop reason for the download, or {@link
* Download#MANUAL_STOP_REASON_NONE} if the download should be started. * Download#MANUAL_STOP_REASON_NONE} if the download should be started.
*/ */
public void addDownload(DownloadAction action, int manualStopReason) { public void addDownload(DownloadRequest request, int manualStopReason) {
pendingMessages++; pendingMessages++;
internalHandler internalHandler
.obtainMessage(MSG_ADD_DOWNLOAD, manualStopReason, /* unused */ 0, action) .obtainMessage(MSG_ADD_DOWNLOAD, manualStopReason, /* unused */ 0, request)
.sendToTarget(); .sendToTarget();
} }
...@@ -415,9 +415,8 @@ public final class DownloadManager { ...@@ -415,9 +415,8 @@ public final class DownloadManager {
} }
/** /**
* Stops all of the downloads and releases resources. If the action file isn't up to date, waits * Stops the downloads and releases resources. Waits until the downloads are persisted to the
* for the changes to be written. The manager must not be accessed after this method has been * download index. The manager must not be accessed after this method has been called.
* called.
*/ */
public void release() { public void release() {
synchronized (releaseLock) { synchronized (releaseLock) {
...@@ -498,7 +497,7 @@ public final class DownloadManager { ...@@ -498,7 +497,7 @@ public final class DownloadManager {
} }
private void onDownloadChanged(Download download) { private void onDownloadChanged(Download download) {
int downloadIndex = getDownloadIndex(download.action.id); int downloadIndex = getDownloadIndex(download.request.id);
if (download.isTerminalState()) { if (download.isTerminalState()) {
if (downloadIndex != C.INDEX_UNSET) { if (downloadIndex != C.INDEX_UNSET) {
downloads.remove(downloadIndex); downloads.remove(downloadIndex);
...@@ -514,7 +513,7 @@ public final class DownloadManager { ...@@ -514,7 +513,7 @@ public final class DownloadManager {
} }
private void onDownloadRemoved(Download download) { private void onDownloadRemoved(Download download) {
downloads.remove(getDownloadIndex(download.action.id)); downloads.remove(getDownloadIndex(download.request.id));
for (Listener listener : listeners) { for (Listener listener : listeners) {
listener.onDownloadRemoved(this, download); listener.onDownloadRemoved(this, download);
} }
...@@ -532,7 +531,7 @@ public final class DownloadManager { ...@@ -532,7 +531,7 @@ public final class DownloadManager {
private int getDownloadIndex(String id) { private int getDownloadIndex(String id) {
for (int i = 0; i < downloads.size(); i++) { for (int i = 0; i < downloads.size(); i++) {
if (downloads.get(i).action.id.equals(id)) { if (downloads.get(i).request.id.equals(id)) {
return i; return i;
} }
} }
...@@ -562,9 +561,9 @@ public final class DownloadManager { ...@@ -562,9 +561,9 @@ public final class DownloadManager {
setManualStopReasonInternal(id, manualStopReason); setManualStopReasonInternal(id, manualStopReason);
break; break;
case MSG_ADD_DOWNLOAD: case MSG_ADD_DOWNLOAD:
DownloadAction action = (DownloadAction) message.obj; DownloadRequest request = (DownloadRequest) message.obj;
manualStopReason = message.arg1; manualStopReason = message.arg1;
addDownloadInternal(action, manualStopReason); addDownloadInternal(request, manualStopReason);
break; break;
case MSG_REMOVE_DOWNLOAD: case MSG_REMOVE_DOWNLOAD:
id = (String) message.obj; id = (String) message.obj;
...@@ -657,27 +656,27 @@ public final class DownloadManager { ...@@ -657,27 +656,27 @@ public final class DownloadManager {
} }
} }
private void addDownloadInternal(DownloadAction action, int manualStopReason) { private void addDownloadInternal(DownloadRequest request, int manualStopReason) {
DownloadInternal downloadInternal = getDownload(action.id); DownloadInternal downloadInternal = getDownload(request.id);
if (downloadInternal != null) { if (downloadInternal != null) {
downloadInternal.addAction(action, manualStopReason); downloadInternal.addRequest(request, manualStopReason);
logd("Action is added to existing download", downloadInternal); logd("Request is added to existing download", downloadInternal);
} else { } else {
Download download = loadDownload(action.id); Download download = loadDownload(request.id);
if (download == null) { if (download == null) {
long nowMs = System.currentTimeMillis(); long nowMs = System.currentTimeMillis();
download = download =
new Download( new Download(
action, request,
manualStopReason != Download.MANUAL_STOP_REASON_NONE ? STATE_STOPPED : STATE_QUEUED, manualStopReason != Download.MANUAL_STOP_REASON_NONE ? STATE_STOPPED : STATE_QUEUED,
Download.FAILURE_REASON_NONE, Download.FAILURE_REASON_NONE,
manualStopReason, manualStopReason,
/* startTimeMs= */ nowMs, /* startTimeMs= */ nowMs,
/* updateTimeMs= */ nowMs); /* updateTimeMs= */ nowMs);
logd("Download state is created for " + action.id); logd("Download state is created for " + request.id);
} else { } else {
download = mergeAction(download, action, manualStopReason); download = mergeRequest(download, request, manualStopReason);
logd("Download state is loaded for " + action.id); logd("Download state is loaded for " + request.id);
} }
addDownloadForState(download); addDownloadForState(download);
} }
...@@ -698,8 +697,8 @@ public final class DownloadManager { ...@@ -698,8 +697,8 @@ public final class DownloadManager {
} }
private void onDownloadThreadStoppedInternal(DownloadThread downloadThread) { private void onDownloadThreadStoppedInternal(DownloadThread downloadThread) {
logd("Download is stopped", downloadThread.action); logd("Download is stopped", downloadThread.request);
String downloadId = downloadThread.action.id; String downloadId = downloadThread.request.id;
downloadThreads.remove(downloadId); downloadThreads.remove(downloadId);
boolean tryToStartDownloads = false; boolean tryToStartDownloads = false;
if (!downloadThread.isRemove) { if (!downloadThread.isRemove) {
...@@ -747,7 +746,7 @@ public final class DownloadManager { ...@@ -747,7 +746,7 @@ public final class DownloadManager {
private void onDownloadRemovedInternal(DownloadInternal downloadInternal, Download download) { private void onDownloadRemovedInternal(DownloadInternal downloadInternal, Download download) {
logd("Download is removed", downloadInternal); logd("Download is removed", downloadInternal);
try { try {
downloadIndex.removeDownload(download.action.id); downloadIndex.removeDownload(download.request.id);
} catch (DatabaseIOException e) { } catch (DatabaseIOException e) {
Log.e(TAG, "Failed to remove from index", e); Log.e(TAG, "Failed to remove from index", e);
} }
...@@ -757,8 +756,8 @@ public final class DownloadManager { ...@@ -757,8 +756,8 @@ public final class DownloadManager {
@StartThreadResults @StartThreadResults
private int startDownloadThread(DownloadInternal downloadInternal) { private int startDownloadThread(DownloadInternal downloadInternal) {
DownloadAction action = downloadInternal.download.action; DownloadRequest request = downloadInternal.download.request;
String downloadId = action.id; String downloadId = request.id;
if (downloadThreads.containsKey(downloadId)) { if (downloadThreads.containsKey(downloadId)) {
if (stopDownloadThreadInternal(downloadId)) { if (stopDownloadThreadInternal(downloadId)) {
return START_THREAD_WAIT_DOWNLOAD_CANCELLATION; return START_THREAD_WAIT_DOWNLOAD_CANCELLATION;
...@@ -772,9 +771,9 @@ public final class DownloadManager { ...@@ -772,9 +771,9 @@ public final class DownloadManager {
} }
simultaneousDownloads++; simultaneousDownloads++;
} }
Downloader downloader = downloaderFactory.createDownloader(action); Downloader downloader = downloaderFactory.createDownloader(request);
DownloadThread downloadThread = DownloadThread downloadThread =
new DownloadThread(action, downloader, isRemove, minRetryCount, internalHandler); new DownloadThread(request, downloader, isRemove, minRetryCount, internalHandler);
downloadThreads.put(downloadId, downloadThread); downloadThreads.put(downloadId, downloadThread);
downloadInternal.setCounters(downloadThread.downloader.getCounters()); downloadInternal.setCounters(downloadThread.downloader.getCounters());
downloadThread.start(); downloadThread.start();
...@@ -786,7 +785,7 @@ public final class DownloadManager { ...@@ -786,7 +785,7 @@ public final class DownloadManager {
DownloadThread downloadThread = downloadThreads.get(downloadId); DownloadThread downloadThread = downloadThreads.get(downloadId);
if (downloadThread != null && !downloadThread.isRemove) { if (downloadThread != null && !downloadThread.isRemove) {
downloadThread.cancel(/* released= */ false); downloadThread.cancel(/* released= */ false);
logd("Download is cancelled", downloadThread.action); logd("Download is cancelled", downloadThread.request);
return true; return true;
} }
return false; return false;
...@@ -796,7 +795,7 @@ public final class DownloadManager { ...@@ -796,7 +795,7 @@ public final class DownloadManager {
private DownloadInternal getDownload(String id) { private DownloadInternal getDownload(String id) {
for (int i = 0; i < downloadInternals.size(); i++) { for (int i = 0; i < downloadInternals.size(); i++) {
DownloadInternal downloadInternal = downloadInternals.get(i); DownloadInternal downloadInternal = downloadInternals.get(i);
if (downloadInternal.download.action.id.equals(id)) { if (downloadInternal.download.request.id.equals(id)) {
return downloadInternal; return downloadInternal;
} }
} }
...@@ -823,8 +822,8 @@ public final class DownloadManager { ...@@ -823,8 +822,8 @@ public final class DownloadManager {
return downloadsStarted && notMetRequirements == 0; return downloadsStarted && notMetRequirements == 0;
} }
/* package */ static Download mergeAction( /* package */ static Download mergeRequest(
Download download, DownloadAction action, int manualStopReason) { Download download, DownloadRequest request, int manualStopReason) {
@Download.State int state = download.state; @Download.State int state = download.state;
if (state == STATE_REMOVING || state == STATE_RESTARTING) { if (state == STATE_REMOVING || state == STATE_RESTARTING) {
state = STATE_RESTARTING; state = STATE_RESTARTING;
...@@ -836,7 +835,7 @@ public final class DownloadManager { ...@@ -836,7 +835,7 @@ public final class DownloadManager {
long nowMs = System.currentTimeMillis(); long nowMs = System.currentTimeMillis();
long startTimeMs = download.isTerminalState() ? nowMs : download.startTimeMs; long startTimeMs = download.isTerminalState() ? nowMs : download.startTimeMs;
return new Download( return new Download(
download.action.copyWithMergedAction(action), download.request.copyWithMergedRequest(request),
state, state,
FAILURE_REASON_NONE, FAILURE_REASON_NONE,
manualStopReason, manualStopReason,
...@@ -847,7 +846,7 @@ public final class DownloadManager { ...@@ -847,7 +846,7 @@ public final class DownloadManager {
private static Download copyWithState(Download download, @Download.State int state) { private static Download copyWithState(Download download, @Download.State int state) {
return new Download( return new Download(
download.action, download.request,
state, state,
FAILURE_REASON_NONE, FAILURE_REASON_NONE,
download.manualStopReason, download.manualStopReason,
...@@ -863,12 +862,12 @@ public final class DownloadManager { ...@@ -863,12 +862,12 @@ public final class DownloadManager {
} }
private static void logd(String message, DownloadInternal downloadInternal) { private static void logd(String message, DownloadInternal downloadInternal) {
logd(message, downloadInternal.download.action); logd(message, downloadInternal.download.request);
} }
private static void logd(String message, DownloadAction action) { private static void logd(String message, DownloadRequest request) {
if (DEBUG) { if (DEBUG) {
logd(message + ": " + action); logd(message + ": " + request);
} }
} }
...@@ -899,8 +898,8 @@ public final class DownloadManager { ...@@ -899,8 +898,8 @@ public final class DownloadManager {
initialize(download.state); initialize(download.state);
} }
public void addAction(DownloadAction newAction, int manualStopReason) { public void addRequest(DownloadRequest newRequest, int manualStopReason) {
download = mergeAction(download, newAction, manualStopReason); download = mergeRequest(download, newRequest, manualStopReason);
initialize(); initialize();
} }
...@@ -911,7 +910,7 @@ public final class DownloadManager { ...@@ -911,7 +910,7 @@ public final class DownloadManager {
public Download getUpdatedDownload() { public Download getUpdatedDownload() {
download = download =
new Download( new Download(
download.action, download.request,
state, state,
state != STATE_FAILED ? FAILURE_REASON_NONE : failureReason, state != STATE_FAILED ? FAILURE_REASON_NONE : failureReason,
manualStopReason, manualStopReason,
...@@ -927,7 +926,7 @@ public final class DownloadManager { ...@@ -927,7 +926,7 @@ public final class DownloadManager {
@Override @Override
public String toString() { public String toString() {
return download.action.id + ' ' + Download.getStateString(state); return download.request.id + ' ' + Download.getStateString(state);
} }
public void start() { public void start() {
...@@ -959,7 +958,7 @@ public final class DownloadManager { ...@@ -959,7 +958,7 @@ public final class DownloadManager {
} }
} else { } else {
if (state == STATE_DOWNLOADING || state == STATE_QUEUED) { if (state == STATE_DOWNLOADING || state == STATE_QUEUED) {
downloadManager.stopDownloadThreadInternal(download.action.id); downloadManager.stopDownloadThreadInternal(download.request.id);
setState(STATE_STOPPED); setState(STATE_STOPPED);
} }
} }
...@@ -1018,7 +1017,7 @@ public final class DownloadManager { ...@@ -1018,7 +1017,7 @@ public final class DownloadManager {
initialize(STATE_QUEUED); initialize(STATE_QUEUED);
} else { // STATE_DOWNLOADING } else { // STATE_DOWNLOADING
if (error != null) { if (error != null) {
Log.e(TAG, "Download failed: " + download.action.id, error); Log.e(TAG, "Download failed: " + download.request.id, error);
failureReason = FAILURE_REASON_UNKNOWN; failureReason = FAILURE_REASON_UNKNOWN;
setState(STATE_FAILED); setState(STATE_FAILED);
} else { } else {
...@@ -1030,7 +1029,7 @@ public final class DownloadManager { ...@@ -1030,7 +1029,7 @@ public final class DownloadManager {
private static class DownloadThread extends Thread { private static class DownloadThread extends Thread {
private final DownloadAction action; private final DownloadRequest request;
private final Downloader downloader; private final Downloader downloader;
private final boolean isRemove; private final boolean isRemove;
private final int minRetryCount; private final int minRetryCount;
...@@ -1040,12 +1039,12 @@ public final class DownloadManager { ...@@ -1040,12 +1039,12 @@ public final class DownloadManager {
private Throwable finalError; private Throwable finalError;
private DownloadThread( private DownloadThread(
DownloadAction action, DownloadRequest request,
Downloader downloader, Downloader downloader,
boolean isRemove, boolean isRemove,
int minRetryCount, int minRetryCount,
Handler onStoppedHandler) { Handler onStoppedHandler) {
this.action = action; this.request = request;
this.isRemove = isRemove; this.isRemove = isRemove;
this.downloader = downloader; this.downloader = downloader;
this.minRetryCount = minRetryCount; this.minRetryCount = minRetryCount;
...@@ -1069,7 +1068,7 @@ public final class DownloadManager { ...@@ -1069,7 +1068,7 @@ public final class DownloadManager {
@Override @Override
public void run() { public void run() {
logd("Download started", action); logd("Download started", request);
try { try {
if (isRemove) { if (isRemove) {
downloader.remove(); downloader.remove();
...@@ -1084,14 +1083,14 @@ public final class DownloadManager { ...@@ -1084,14 +1083,14 @@ public final class DownloadManager {
if (!isCanceled) { if (!isCanceled) {
long downloadedBytes = downloader.getDownloadedBytes(); long downloadedBytes = downloader.getDownloadedBytes();
if (downloadedBytes != errorPosition) { if (downloadedBytes != errorPosition) {
logd("Reset error count. downloadedBytes = " + downloadedBytes, action); logd("Reset error count. downloadedBytes = " + downloadedBytes, request);
errorPosition = downloadedBytes; errorPosition = downloadedBytes;
errorCount = 0; errorCount = 0;
} }
if (++errorCount > minRetryCount) { if (++errorCount > minRetryCount) {
throw e; throw e;
} }
logd("Download error. Retry " + errorCount, action); logd("Download error. Retry " + errorCount, request);
Thread.sleep(getRetryDelayMillis(errorCount)); Thread.sleep(getRetryDelayMillis(errorCount));
} }
} }
......
...@@ -30,10 +30,10 @@ import java.util.Collections; ...@@ -30,10 +30,10 @@ import java.util.Collections;
import java.util.List; import java.util.List;
/** Defines content to be downloaded. */ /** Defines content to be downloaded. */
public final class DownloadAction implements Parcelable { public final class DownloadRequest implements Parcelable {
/** Thrown when the encoded action data belongs to an unsupported DownloadAction type. */ /** Thrown when the encoded request data belongs to an unsupported request type. */
public static class UnsupportedActionException extends IOException {} public static class UnsupportedRequestException extends IOException {}
/** Type for progressive downloads. */ /** Type for progressive downloads. */
public static final String TYPE_PROGRESSIVE = "progressive"; public static final String TYPE_PROGRESSIVE = "progressive";
...@@ -46,7 +46,7 @@ public final class DownloadAction implements Parcelable { ...@@ -46,7 +46,7 @@ public final class DownloadAction implements Parcelable {
/** The unique content id. */ /** The unique content id. */
public final String id; public final String id;
/** The type of the action. */ /** The type of the request. */
public final String type; public final String type;
/** The uri being downloaded. */ /** The uri being downloaded. */
public final Uri uri; public final Uri uri;
...@@ -65,7 +65,7 @@ public final class DownloadAction implements Parcelable { ...@@ -65,7 +65,7 @@ public final class DownloadAction implements Parcelable {
* @param customCacheKey See {@link #customCacheKey}. * @param customCacheKey See {@link #customCacheKey}.
* @param data See {@link #data}. * @param data See {@link #data}.
*/ */
public DownloadAction( public DownloadRequest(
String id, String id,
String type, String type,
Uri uri, Uri uri,
...@@ -82,7 +82,7 @@ public final class DownloadAction implements Parcelable { ...@@ -82,7 +82,7 @@ public final class DownloadAction implements Parcelable {
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;
} }
/* package */ DownloadAction(Parcel in) { /* package */ DownloadRequest(Parcel in) {
id = castNonNull(in.readString()); id = castNonNull(in.readString());
type = castNonNull(in.readString()); type = castNonNull(in.readString());
uri = Uri.parse(castNonNull(in.readString())); uri = Uri.parse(castNonNull(in.readString()));
...@@ -103,40 +103,40 @@ public final class DownloadAction implements Parcelable { ...@@ -103,40 +103,40 @@ public final class DownloadAction implements Parcelable {
* @param id The ID of the copy. * @param id The ID of the copy.
* @return The copy with the specified ID. * @return The copy with the specified ID.
*/ */
public DownloadAction copyWithId(String id) { public DownloadRequest copyWithId(String id) {
return new DownloadAction(id, type, uri, streamKeys, customCacheKey, data); return new DownloadRequest(id, type, uri, streamKeys, customCacheKey, data);
} }
/** /**
* Returns the result of merging {@code newAction} into this action. The actions must have the * Returns the result of merging {@code newRequest} into this request. The requests must have the
* same {@link #id} and {@link #type}. * same {@link #id} and {@link #type}.
* *
* <p>If the actions have different {@link #uri}, {@link #customCacheKey} and {@link #data} * <p>If the requests have different {@link #uri}, {@link #customCacheKey} and {@link #data}
* values, then those from the action being merged are included in the result. * values, then those from the request being merged are included in the result.
* *
* @param newAction The action being merged. * @param newRequest The request being merged.
* @return The merged result. * @return The merged result.
* @throws IllegalArgumentException If the actions do not have the same {@link #id} and {@link * @throws IllegalArgumentException If the requests do not have the same {@link #id} and {@link
* #type}. * #type}.
*/ */
public DownloadAction copyWithMergedAction(DownloadAction newAction) { public DownloadRequest copyWithMergedRequest(DownloadRequest newRequest) {
Assertions.checkArgument(id.equals(newAction.id)); Assertions.checkArgument(id.equals(newRequest.id));
Assertions.checkArgument(type.equals(newAction.type)); Assertions.checkArgument(type.equals(newRequest.type));
List<StreamKey> mergedKeys; List<StreamKey> mergedKeys;
if (streamKeys.isEmpty() || newAction.streamKeys.isEmpty()) { if (streamKeys.isEmpty() || newRequest.streamKeys.isEmpty()) {
// If either streamKeys is empty then all streams should be downloaded. // If either streamKeys is empty then all streams should be downloaded.
mergedKeys = Collections.emptyList(); mergedKeys = Collections.emptyList();
} else { } else {
mergedKeys = new ArrayList<>(streamKeys); mergedKeys = new ArrayList<>(streamKeys);
for (int i = 0; i < newAction.streamKeys.size(); i++) { for (int i = 0; i < newRequest.streamKeys.size(); i++) {
StreamKey newKey = newAction.streamKeys.get(i); StreamKey newKey = newRequest.streamKeys.get(i);
if (!mergedKeys.contains(newKey)) { if (!mergedKeys.contains(newKey)) {
mergedKeys.add(newKey); mergedKeys.add(newKey);
} }
} }
} }
return new DownloadAction( return new DownloadRequest(
id, type, newAction.uri, mergedKeys, newAction.customCacheKey, newAction.data); id, type, newRequest.uri, mergedKeys, newRequest.customCacheKey, newRequest.data);
} }
@Override @Override
...@@ -146,10 +146,10 @@ public final class DownloadAction implements Parcelable { ...@@ -146,10 +146,10 @@ public final class DownloadAction implements Parcelable {
@Override @Override
public boolean equals(@Nullable Object o) { public boolean equals(@Nullable Object o) {
if (!(o instanceof DownloadAction)) { if (!(o instanceof DownloadRequest)) {
return false; return false;
} }
DownloadAction that = (DownloadAction) o; DownloadRequest that = (DownloadRequest) o;
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)
...@@ -191,17 +191,17 @@ public final class DownloadAction implements Parcelable { ...@@ -191,17 +191,17 @@ public final class DownloadAction implements Parcelable {
dest.writeByteArray(data); dest.writeByteArray(data);
} }
public static final Parcelable.Creator<DownloadAction> CREATOR = public static final Parcelable.Creator<DownloadRequest> CREATOR =
new Parcelable.Creator<DownloadAction>() { new Parcelable.Creator<DownloadRequest>() {
@Override @Override
public DownloadAction createFromParcel(Parcel in) { public DownloadRequest createFromParcel(Parcel in) {
return new DownloadAction(in); return new DownloadRequest(in);
} }
@Override @Override
public DownloadAction[] newArray(int size) { public DownloadRequest[] newArray(int size) {
return new DownloadAction[size]; return new DownloadRequest[size];
} }
}; };
} }
...@@ -39,7 +39,7 @@ import java.util.List; ...@@ -39,7 +39,7 @@ import java.util.List;
public abstract class DownloadService extends Service { public abstract class DownloadService extends Service {
/** /**
* Starts a download service without adding a new {@link DownloadAction}. Extras: * Starts a download service to resume any ongoing downloads. Extras:
* *
* <ul> * <ul>
* <li>{@link #KEY_FOREGROUND} - See {@link #KEY_FOREGROUND}. * <li>{@link #KEY_FOREGROUND} - See {@link #KEY_FOREGROUND}.
...@@ -56,7 +56,7 @@ public abstract class DownloadService extends Service { ...@@ -56,7 +56,7 @@ public abstract class DownloadService extends Service {
* Adds a new download. Extras: * Adds a new download. Extras:
* *
* <ul> * <ul>
* <li>{@link #KEY_DOWNLOAD_ACTION} - A {@link DownloadAction} defining the download to be * <li>{@link #KEY_DOWNLOAD_REQUEST} - A {@link DownloadRequest} defining the download to be
* added. * added.
* <li>{@link #KEY_MANUAL_STOP_REASON} - An initial manual stop reason for the download. If * <li>{@link #KEY_MANUAL_STOP_REASON} - An initial manual stop reason for the download. If
* omitted {@link Download#MANUAL_STOP_REASON_NONE} is used. * omitted {@link Download#MANUAL_STOP_REASON_NONE} is used.
...@@ -103,7 +103,7 @@ public abstract class DownloadService extends Service { ...@@ -103,7 +103,7 @@ public abstract class DownloadService extends Service {
"com.google.android.exoplayer.downloadService.action.SET_MANUAL_STOP_REASON"; "com.google.android.exoplayer.downloadService.action.SET_MANUAL_STOP_REASON";
/** /**
* Removes an existing download. Extras: * Removes a download. Extras:
* *
* <ul> * <ul>
* <li>{@link #KEY_CONTENT_ID} - The content id of a download to remove. * <li>{@link #KEY_CONTENT_ID} - The content id of a download to remove.
...@@ -113,11 +113,8 @@ public abstract class DownloadService extends Service { ...@@ -113,11 +113,8 @@ public abstract class DownloadService extends Service {
public static final String ACTION_REMOVE = public static final String ACTION_REMOVE =
"com.google.android.exoplayer.downloadService.action.REMOVE"; "com.google.android.exoplayer.downloadService.action.REMOVE";
/** /** Key for the {@link DownloadRequest} in {@link #ACTION_ADD} intents. */
* Key for the {@code byte[]} representation of the {@link DownloadAction} in {@link #ACTION_ADD} public static final String KEY_DOWNLOAD_REQUEST = "download_request";
* intents.
*/
public static final String KEY_DOWNLOAD_ACTION = "download_action";
/** /**
* Key for the content id in {@link #ACTION_START}, {@link #ACTION_STOP} and {@link * Key for the content id in {@link #ACTION_START}, {@link #ACTION_STOP} and {@link
...@@ -234,42 +231,42 @@ public abstract class DownloadService extends Service { ...@@ -234,42 +231,42 @@ public abstract class DownloadService extends Service {
} }
/** /**
* Builds an {@link Intent} for adding an action to be executed by the service. * Builds an {@link Intent} for adding a new download.
* *
* @param context A {@link Context}. * @param context A {@link Context}.
* @param clazz The concrete download service being targeted by the intent. * @param clazz The concrete download service being targeted by the intent.
* @param downloadAction The action to be executed. * @param downloadRequest The request to be executed.
* @param foreground Whether this intent will be used to start the service in the foreground. * @param foreground Whether this intent will be used to start the service in the foreground.
* @return Created Intent. * @return Created Intent.
*/ */
public static Intent buildAddActionIntent( public static Intent buildAddRequestIntent(
Context context, Context context,
Class<? extends DownloadService> clazz, Class<? extends DownloadService> clazz,
DownloadAction downloadAction, DownloadRequest downloadRequest,
boolean foreground) { boolean foreground) {
return buildAddActionIntent( return buildAddRequestIntent(
context, clazz, downloadAction, MANUAL_STOP_REASON_NONE, foreground); context, clazz, downloadRequest, MANUAL_STOP_REASON_NONE, foreground);
} }
/** /**
* Builds an {@link Intent} for adding an action to be executed by the service. * Builds an {@link Intent} for adding a new download.
* *
* @param context A {@link Context}. * @param context A {@link Context}.
* @param clazz The concrete download service being targeted by the intent. * @param clazz The concrete download service being targeted by the intent.
* @param downloadAction The action to be executed. * @param downloadRequest The request to be executed.
* @param manualStopReason An initial manual stop reason for the download, or {@link * @param manualStopReason An initial manual stop reason for the download, or {@link
* Download#MANUAL_STOP_REASON_NONE} if the download should be started. * Download#MANUAL_STOP_REASON_NONE} if the download should be started.
* @param foreground Whether this intent will be used to start the service in the foreground. * @param foreground Whether this intent will be used to start the service in the foreground.
* @return Created Intent. * @return Created Intent.
*/ */
public static Intent buildAddActionIntent( public static Intent buildAddRequestIntent(
Context context, Context context,
Class<? extends DownloadService> clazz, Class<? extends DownloadService> clazz,
DownloadAction downloadAction, DownloadRequest downloadRequest,
int manualStopReason, int manualStopReason,
boolean foreground) { boolean foreground) {
return getIntent(context, clazz, ACTION_ADD) return getIntent(context, clazz, ACTION_ADD)
.putExtra(KEY_DOWNLOAD_ACTION, downloadAction) .putExtra(KEY_DOWNLOAD_REQUEST, downloadRequest)
.putExtra(KEY_MANUAL_STOP_REASON, manualStopReason) .putExtra(KEY_MANUAL_STOP_REASON, manualStopReason)
.putExtra(KEY_FOREGROUND, foreground); .putExtra(KEY_FOREGROUND, foreground);
} }
...@@ -311,19 +308,19 @@ public abstract class DownloadService extends Service { ...@@ -311,19 +308,19 @@ public abstract class DownloadService extends Service {
} }
/** /**
* Starts the service, adding an action to be executed. * Starts the service, adding a new download.
* *
* @param context A {@link Context}. * @param context A {@link Context}.
* @param clazz The concrete download service to be started. * @param clazz The concrete download service to be started.
* @param downloadAction The action to be executed. * @param downloadRequest The request to be executed.
* @param foreground Whether the service is started in the foreground. * @param foreground Whether the service is started in the foreground.
*/ */
public static void startWithAction( public static void startWithNewDownload(
Context context, Context context,
Class<? extends DownloadService> clazz, Class<? extends DownloadService> clazz,
DownloadAction downloadAction, DownloadRequest downloadRequest,
boolean foreground) { boolean foreground) {
Intent intent = buildAddActionIntent(context, clazz, downloadAction, foreground); Intent intent = buildAddRequestIntent(context, clazz, downloadRequest, foreground);
if (foreground) { if (foreground) {
Util.startForegroundService(context, intent); Util.startForegroundService(context, intent);
} else { } else {
...@@ -350,8 +347,7 @@ public abstract class DownloadService extends Service { ...@@ -350,8 +347,7 @@ public abstract class DownloadService extends Service {
} }
/** /**
* Starts the service without adding a new action. If there are any not finished actions and the * Starts a download service to resume any ongoing downloads.
* requirements are met, the service resumes executing actions. Otherwise it stops immediately.
* *
* @param context A {@link Context}. * @param context A {@link Context}.
* @param clazz The concrete download service to be started. * @param clazz The concrete download service to be started.
...@@ -362,9 +358,9 @@ public abstract class DownloadService extends Service { ...@@ -362,9 +358,9 @@ public abstract class DownloadService extends Service {
} }
/** /**
* Starts the service in the foreground without adding a new action. If there are any not finished * Starts the service in the foreground without adding a new download request. If there are any
* actions and the requirements are met, the service resumes executing actions. Otherwise it stops * not finished downloads and the requirements are met, the service resumes downloading. Otherwise
* immediately. * it stops immediately.
* *
* @param context A {@link Context}. * @param context A {@link Context}.
* @param clazz The concrete download service to be started. * @param clazz The concrete download service to be started.
...@@ -417,13 +413,13 @@ public abstract class DownloadService extends Service { ...@@ -417,13 +413,13 @@ public abstract class DownloadService extends Service {
// Do nothing. // Do nothing.
break; break;
case ACTION_ADD: case ACTION_ADD:
DownloadAction downloadAction = intent.getParcelableExtra(KEY_DOWNLOAD_ACTION); DownloadRequest downloadRequest = intent.getParcelableExtra(KEY_DOWNLOAD_REQUEST);
if (downloadAction == null) { if (downloadRequest == null) {
Log.e(TAG, "Ignored ADD: Missing download_action extra"); Log.e(TAG, "Ignored ADD: Missing " + KEY_DOWNLOAD_REQUEST + " extra");
} else { } else {
int manualStopReason = int manualStopReason =
intent.getIntExtra(KEY_MANUAL_STOP_REASON, Download.MANUAL_STOP_REASON_NONE); intent.getIntExtra(KEY_MANUAL_STOP_REASON, Download.MANUAL_STOP_REASON_NONE);
downloadManager.addDownload(downloadAction, manualStopReason); downloadManager.addDownload(downloadRequest, manualStopReason);
} }
break; break;
case ACTION_START: case ACTION_START:
...@@ -434,7 +430,8 @@ public abstract class DownloadService extends Service { ...@@ -434,7 +430,8 @@ public abstract class DownloadService extends Service {
break; break;
case ACTION_SET_MANUAL_STOP_REASON: case ACTION_SET_MANUAL_STOP_REASON:
if (!intent.hasExtra(KEY_MANUAL_STOP_REASON)) { if (!intent.hasExtra(KEY_MANUAL_STOP_REASON)) {
Log.e(TAG, "Ignored SET_MANUAL_STOP_REASON: Missing manual_stop_reason extra"); Log.e(
TAG, "Ignored SET_MANUAL_STOP_REASON: Missing " + KEY_MANUAL_STOP_REASON + " extra");
} else { } else {
String contentId = intent.getStringExtra(KEY_CONTENT_ID); String contentId = intent.getStringExtra(KEY_CONTENT_ID);
int manualStopReason = int manualStopReason =
...@@ -445,7 +442,7 @@ public abstract class DownloadService extends Service { ...@@ -445,7 +442,7 @@ public abstract class DownloadService extends Service {
case ACTION_REMOVE: case ACTION_REMOVE:
String contentId = intent.getStringExtra(KEY_CONTENT_ID); String contentId = intent.getStringExtra(KEY_CONTENT_ID);
if (contentId == null) { if (contentId == null) {
Log.e(TAG, "Ignored REMOVE: Missing content_id extra"); Log.e(TAG, "Ignored REMOVE: Missing " + KEY_CONTENT_ID + " extra");
} else { } else {
downloadManager.removeDownload(contentId); downloadManager.removeDownload(contentId);
} }
......
...@@ -15,14 +15,14 @@ ...@@ -15,14 +15,14 @@
*/ */
package com.google.android.exoplayer2.offline; package com.google.android.exoplayer2.offline;
/** Creates {@link Downloader Downloaders} for given {@link DownloadAction DownloadActions}. */ /** Creates {@link Downloader Downloaders} for given {@link DownloadRequest DownloadRequests}. */
public interface DownloaderFactory { public interface DownloaderFactory {
/** /**
* Creates a {@link Downloader} to perform the given {@link DownloadAction}. * Creates a {@link Downloader} to perform the given {@link DownloadRequest}.
* *
* @param action The action. * @param action The action.
* @return The downloader. * @return The downloader.
*/ */
Downloader createDownloader(DownloadAction action); Downloader createDownloader(DownloadRequest action);
} }
...@@ -33,20 +33,21 @@ import org.junit.Test; ...@@ -33,20 +33,21 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** Unit tests for {@link ActionFile}. */ /** Unit tests for {@link ActionFile}. */
@SuppressWarnings("deprecation")
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class ActionFileTest { public class ActionFileTest {
private File tempFile; private File tempFile;
private DownloadAction expectedAction1; private DownloadRequest expectedAction1;
private DownloadAction expectedAction2; private DownloadRequest expectedAction2;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
tempFile = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ExoPlayerTest"); tempFile = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
expectedAction1 = expectedAction1 =
buildExpectedAction(Uri.parse("http://test1.uri"), TestUtil.buildTestData(16)); buildExpectedRequest(Uri.parse("http://test1.uri"), TestUtil.buildTestData(16));
expectedAction2 = expectedAction2 =
buildExpectedAction(Uri.parse("http://test2.uri"), TestUtil.buildTestData(32)); buildExpectedRequest(Uri.parse("http://test2.uri"), TestUtil.buildTestData(32));
} }
@After @After
...@@ -79,7 +80,7 @@ public class ActionFileTest { ...@@ -79,7 +80,7 @@ public class ActionFileTest {
@Test @Test
public void testLoadZeroActions() throws Exception { public void testLoadZeroActions() throws Exception {
ActionFile actionFile = getActionFile("offline/action_file_zero_actions.exi"); ActionFile actionFile = getActionFile("offline/action_file_zero_actions.exi");
DownloadAction[] actions = actionFile.load(); DownloadRequest[] actions = actionFile.load();
assertThat(actions).isNotNull(); assertThat(actions).isNotNull();
assertThat(actions).hasLength(0); assertThat(actions).hasLength(0);
} }
...@@ -87,7 +88,7 @@ public class ActionFileTest { ...@@ -87,7 +88,7 @@ public class ActionFileTest {
@Test @Test
public void testLoadOneAction() throws Exception { public void testLoadOneAction() throws Exception {
ActionFile actionFile = getActionFile("offline/action_file_one_action.exi"); ActionFile actionFile = getActionFile("offline/action_file_one_action.exi");
DownloadAction[] actions = actionFile.load(); DownloadRequest[] actions = actionFile.load();
assertThat(actions).hasLength(1); assertThat(actions).hasLength(1);
assertThat(actions[0]).isEqualTo(expectedAction1); assertThat(actions[0]).isEqualTo(expectedAction1);
} }
...@@ -95,7 +96,7 @@ public class ActionFileTest { ...@@ -95,7 +96,7 @@ public class ActionFileTest {
@Test @Test
public void testLoadTwoActions() throws Exception { public void testLoadTwoActions() throws Exception {
ActionFile actionFile = getActionFile("offline/action_file_two_actions.exi"); ActionFile actionFile = getActionFile("offline/action_file_two_actions.exi");
DownloadAction[] actions = actionFile.load(); DownloadRequest[] actions = actionFile.load();
assertThat(actions).hasLength(2); assertThat(actions).hasLength(2);
assertThat(actions[0]).isEqualTo(expectedAction1); assertThat(actions[0]).isEqualTo(expectedAction1);
assertThat(actions[1]).isEqualTo(expectedAction2); assertThat(actions[1]).isEqualTo(expectedAction2);
...@@ -123,10 +124,10 @@ public class ActionFileTest { ...@@ -123,10 +124,10 @@ public class ActionFileTest {
return new ActionFile(tempFile); return new ActionFile(tempFile);
} }
private static DownloadAction buildExpectedAction(Uri uri, byte[] data) { private static DownloadRequest buildExpectedRequest(Uri uri, byte[] data) {
return new DownloadAction( return new DownloadRequest(
/* id= */ uri.toString(), /* id= */ uri.toString(),
DownloadAction.TYPE_PROGRESSIVE, DownloadRequest.TYPE_PROGRESSIVE,
uri, uri,
/* streamKeys= */ Collections.emptyList(), /* streamKeys= */ Collections.emptyList(),
/* customCacheKey= */ null, /* customCacheKey= */ null,
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
package com.google.android.exoplayer2.offline; package com.google.android.exoplayer2.offline;
import static com.google.android.exoplayer2.offline.DownloadAction.TYPE_DASH; import static com.google.android.exoplayer2.offline.DownloadRequest.TYPE_DASH;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.net.Uri; import android.net.Uri;
...@@ -70,16 +70,16 @@ public class ActionFileUpgradeUtilTest { ...@@ -70,16 +70,16 @@ public class ActionFileUpgradeUtilTest {
new StreamKey(/* periodIndex= */ 3, /* groupIndex= */ 4, /* trackIndex= */ 5); new StreamKey(/* periodIndex= */ 3, /* groupIndex= */ 4, /* trackIndex= */ 5);
StreamKey expectedStreamKey2 = StreamKey expectedStreamKey2 =
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 2); new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 2);
DownloadAction expectedAction1 = DownloadRequest expectedRequest1 =
new DownloadAction( new DownloadRequest(
"key123", "key123",
TYPE_DASH, TYPE_DASH,
Uri.parse("https://www.test.com/download1"), Uri.parse("https://www.test.com/download1"),
asList(expectedStreamKey1), asList(expectedStreamKey1),
/* customCacheKey= */ "key123", /* customCacheKey= */ "key123",
new byte[] {1, 2, 3, 4}); new byte[] {1, 2, 3, 4});
DownloadAction expectedAction2 = DownloadRequest expectedRequest2 =
new DownloadAction( new DownloadRequest(
"key234", "key234",
TYPE_DASH, TYPE_DASH,
Uri.parse("https://www.test.com/download2"), Uri.parse("https://www.test.com/download2"),
...@@ -90,15 +90,15 @@ public class ActionFileUpgradeUtilTest { ...@@ -90,15 +90,15 @@ public class ActionFileUpgradeUtilTest {
ActionFileUpgradeUtil.upgradeAndDelete( ActionFileUpgradeUtil.upgradeAndDelete(
tempFile, /* downloadIdProvider= */ null, downloadIndex, /* deleteOnFailure= */ true); tempFile, /* downloadIdProvider= */ null, downloadIndex, /* deleteOnFailure= */ true);
assertDownloadIndexContainsAction(expectedAction1, Download.STATE_QUEUED); assertDownloadIndexContainsRequest(expectedRequest1, Download.STATE_QUEUED);
assertDownloadIndexContainsAction(expectedAction2, Download.STATE_QUEUED); assertDownloadIndexContainsRequest(expectedRequest2, Download.STATE_QUEUED);
} }
@Test @Test
public void mergeAction_nonExistingDownload_createsNewDownload() throws IOException { public void mergeRequest_nonExistingDownload_createsNewDownload() throws IOException {
byte[] data = new byte[] {1, 2, 3, 4}; byte[] data = new byte[] {1, 2, 3, 4};
DownloadAction action = DownloadRequest request =
new DownloadAction( new DownloadRequest(
"id", "id",
TYPE_DASH, TYPE_DASH,
Uri.parse("https://www.test.com/download"), Uri.parse("https://www.test.com/download"),
...@@ -108,50 +108,50 @@ public class ActionFileUpgradeUtilTest { ...@@ -108,50 +108,50 @@ public class ActionFileUpgradeUtilTest {
/* customCacheKey= */ "key123", /* customCacheKey= */ "key123",
data); data);
ActionFileUpgradeUtil.mergeAction(action, downloadIndex); ActionFileUpgradeUtil.mergeRequest(request, downloadIndex);
assertDownloadIndexContainsAction(action, Download.STATE_QUEUED); assertDownloadIndexContainsRequest(request, Download.STATE_QUEUED);
} }
@Test @Test
public void mergeAction_existingDownload_createsMergedDownload() throws IOException { public void mergeRequest_existingDownload_createsMergedDownload() throws IOException {
StreamKey streamKey1 = StreamKey streamKey1 =
new StreamKey(/* periodIndex= */ 3, /* groupIndex= */ 4, /* trackIndex= */ 5); new StreamKey(/* periodIndex= */ 3, /* groupIndex= */ 4, /* trackIndex= */ 5);
StreamKey streamKey2 = StreamKey streamKey2 =
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 2); new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 2);
DownloadAction action1 = DownloadRequest request1 =
new DownloadAction( new DownloadRequest(
"id", "id",
TYPE_DASH, TYPE_DASH,
Uri.parse("https://www.test.com/download1"), Uri.parse("https://www.test.com/download1"),
asList(streamKey1), asList(streamKey1),
/* customCacheKey= */ "key123", /* customCacheKey= */ "key123",
new byte[] {1, 2, 3, 4}); new byte[] {1, 2, 3, 4});
DownloadAction action2 = DownloadRequest request2 =
new DownloadAction( new DownloadRequest(
"id", "id",
TYPE_DASH, TYPE_DASH,
Uri.parse("https://www.test.com/download2"), Uri.parse("https://www.test.com/download2"),
asList(streamKey2), asList(streamKey2),
/* customCacheKey= */ "key123", /* customCacheKey= */ "key123",
new byte[] {5, 4, 3, 2, 1}); new byte[] {5, 4, 3, 2, 1});
ActionFileUpgradeUtil.mergeAction(action1, downloadIndex); ActionFileUpgradeUtil.mergeRequest(request1, downloadIndex);
ActionFileUpgradeUtil.mergeAction(action2, downloadIndex); ActionFileUpgradeUtil.mergeRequest(request2, downloadIndex);
Download download = downloadIndex.getDownload(action2.id); Download download = downloadIndex.getDownload(request2.id);
assertThat(download).isNotNull(); assertThat(download).isNotNull();
assertThat(download.action.type).isEqualTo(action2.type); assertThat(download.request.type).isEqualTo(request2.type);
assertThat(download.action.customCacheKey).isEqualTo(action2.customCacheKey); assertThat(download.request.customCacheKey).isEqualTo(request2.customCacheKey);
assertThat(download.action.data).isEqualTo(action2.data); assertThat(download.request.data).isEqualTo(request2.data);
assertThat(download.action.uri).isEqualTo(action2.uri); assertThat(download.request.uri).isEqualTo(request2.uri);
assertThat(download.action.streamKeys).containsExactly(streamKey1, streamKey2); assertThat(download.request.streamKeys).containsExactly(streamKey1, streamKey2);
assertThat(download.state).isEqualTo(Download.STATE_QUEUED); assertThat(download.state).isEqualTo(Download.STATE_QUEUED);
} }
private void assertDownloadIndexContainsAction(DownloadAction action, int state) private void assertDownloadIndexContainsRequest(DownloadRequest request, int state)
throws IOException { throws IOException {
Download download = downloadIndex.getDownload(action.id); Download download = downloadIndex.getDownload(request.id);
assertThat(download.action).isEqualTo(action); assertThat(download.request).isEqualTo(request);
assertThat(download.state).isEqualTo(state); assertThat(download.state).isEqualTo(state);
} }
......
...@@ -301,7 +301,7 @@ public class DefaultDownloadIndexTest { ...@@ -301,7 +301,7 @@ public class DefaultDownloadIndexTest {
} }
private static void assertEqual(Download download, Download that) { private static void assertEqual(Download download, Download that) {
assertThat(download.action).isEqualTo(that.action); assertThat(download.request).isEqualTo(that.request);
assertThat(download.state).isEqualTo(that.state); assertThat(download.state).isEqualTo(that.state);
assertThat(download.startTimeMs).isEqualTo(that.startTimeMs); assertThat(download.startTimeMs).isEqualTo(that.startTimeMs);
assertThat(download.updateTimeMs).isEqualTo(that.updateTimeMs); assertThat(download.updateTimeMs).isEqualTo(that.updateTimeMs);
......
...@@ -38,9 +38,9 @@ public final class DefaultDownloaderFactoryTest { ...@@ -38,9 +38,9 @@ public final class DefaultDownloaderFactoryTest {
Downloader downloader = Downloader downloader =
factory.createDownloader( factory.createDownloader(
new DownloadAction( new DownloadRequest(
"id", "id",
DownloadAction.TYPE_PROGRESSIVE, DownloadRequest.TYPE_PROGRESSIVE,
Uri.parse("https://www.test.com/download"), Uri.parse("https://www.test.com/download"),
/* streamKeys= */ Collections.emptyList(), /* streamKeys= */ Collections.emptyList(),
/* customCacheKey= */ null, /* customCacheKey= */ null,
......
...@@ -47,8 +47,14 @@ class DownloadBuilder { ...@@ -47,8 +47,14 @@ class DownloadBuilder {
this(id, "type", Uri.parse("uri"), /* cacheKey= */ null, new byte[0], Collections.emptyList()); this(id, "type", Uri.parse("uri"), /* cacheKey= */ null, new byte[0], Collections.emptyList());
} }
DownloadBuilder(DownloadAction action) { DownloadBuilder(DownloadRequest request) {
this(action.id, action.type, action.uri, action.customCacheKey, action.data, action.streamKeys); this(
request.id,
request.type,
request.uri,
request.customCacheKey,
request.data,
request.streamKeys);
} }
DownloadBuilder( DownloadBuilder(
...@@ -147,8 +153,9 @@ class DownloadBuilder { ...@@ -147,8 +153,9 @@ class DownloadBuilder {
} }
public Download build() { public Download build() {
DownloadAction action = new DownloadAction(id, type, uri, streamKeys, cacheKey, customMetadata); DownloadRequest request =
new DownloadRequest(id, type, uri, streamKeys, cacheKey, customMetadata);
return new Download( return new Download(
action, state, failureReason, manualStopReason, startTimeMs, updateTimeMs, counters); request, state, failureReason, manualStopReason, startTimeMs, updateTimeMs, counters);
} }
} }
...@@ -379,7 +379,7 @@ public class DownloadHelperTest { ...@@ -379,7 +379,7 @@ public class DownloadHelperTest {
} }
@Test @Test
public void getDownloadAction_createsDownloadAction_withAllSelectedTracks() throws Exception { public void getDownloadRequest_createsDownloadRequest_withAllSelectedTracks() throws Exception {
prepareDownloadHelper(downloadHelper); prepareDownloadHelper(downloadHelper);
// Ensure we have track groups with multiple indices, renderers with multiple track groups and // Ensure we have track groups with multiple indices, renderers with multiple track groups and
// also renderers without any track groups. // also renderers without any track groups.
...@@ -392,13 +392,13 @@ public class DownloadHelperTest { ...@@ -392,13 +392,13 @@ public class DownloadHelperTest {
byte[] data = new byte[10]; byte[] data = new byte[10];
Arrays.fill(data, (byte) 123); Arrays.fill(data, (byte) 123);
DownloadAction downloadAction = downloadHelper.getDownloadAction(data); DownloadRequest downloadRequest = downloadHelper.getDownloadRequest(data);
assertThat(downloadAction.type).isEqualTo(TEST_DOWNLOAD_TYPE); assertThat(downloadRequest.type).isEqualTo(TEST_DOWNLOAD_TYPE);
assertThat(downloadAction.uri).isEqualTo(testUri); assertThat(downloadRequest.uri).isEqualTo(testUri);
assertThat(downloadAction.customCacheKey).isEqualTo(TEST_CACHE_KEY); assertThat(downloadRequest.customCacheKey).isEqualTo(TEST_CACHE_KEY);
assertThat(downloadAction.data).isEqualTo(data); assertThat(downloadRequest.data).isEqualTo(data);
assertThat(downloadAction.streamKeys) assertThat(downloadRequest.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),
......
...@@ -104,29 +104,29 @@ public class DownloadManagerTest { ...@@ -104,29 +104,29 @@ public class DownloadManagerTest {
} }
@Test @Test
public void multipleActionsForTheSameContent_executedOnTheSameTask() { public void multipleRequestsForTheSameContent_executedOnTheSameTask() {
// Two download actions on first task // Two download requests on first task
new DownloadRunner(uri1).postDownloadAction().postDownloadAction(); new DownloadRunner(uri1).postDownloadRequest().postDownloadRequest();
// One download, one remove actions on second task // One download, one remove requests on second task
new DownloadRunner(uri2).postDownloadAction().postRemoveAction(); new DownloadRunner(uri2).postDownloadRequest().postRemoveRequest();
// Two remove actions on third task // Two remove requests on third task
new DownloadRunner(uri3).postRemoveAction().postRemoveAction(); new DownloadRunner(uri3).postRemoveRequest().postRemoveRequest();
} }
@Test @Test
public void actionsForDifferentContent_executedOnDifferentTasks() { public void requestsForDifferentContent_executedOnDifferentTasks() {
TaskWrapper task1 = new DownloadRunner(uri1).postDownloadAction().getTask(); TaskWrapper task1 = new DownloadRunner(uri1).postDownloadRequest().getTask();
TaskWrapper task2 = new DownloadRunner(uri2).postDownloadAction().getTask(); TaskWrapper task2 = new DownloadRunner(uri2).postDownloadRequest().getTask();
TaskWrapper task3 = new DownloadRunner(uri3).postRemoveAction().getTask(); TaskWrapper task3 = new DownloadRunner(uri3).postRemoveRequest().getTask();
assertThat(task1).isNoneOf(task2, task3); assertThat(task1).isNoneOf(task2, task3);
assertThat(task2).isNotEqualTo(task3); assertThat(task2).isNotEqualTo(task3);
} }
@Test @Test
public void postDownloadAction_downloads() throws Throwable { public void postDownloadRequest_downloads() throws Throwable {
DownloadRunner runner = new DownloadRunner(uri1); DownloadRunner runner = new DownloadRunner(uri1);
TaskWrapper task = runner.postDownloadAction().getTask(); TaskWrapper task = runner.postDownloadRequest().getTask();
task.assertDownloading(); task.assertDownloading();
runner.getDownloader(0).unblock().assertReleased().assertStartCount(1); runner.getDownloader(0).unblock().assertReleased().assertStartCount(1);
task.assertCompleted(); task.assertCompleted();
...@@ -135,9 +135,9 @@ public class DownloadManagerTest { ...@@ -135,9 +135,9 @@ public class DownloadManagerTest {
} }
@Test @Test
public void postRemoveAction_removes() throws Throwable { public void postRemoveRequest_removes() throws Throwable {
DownloadRunner runner = new DownloadRunner(uri1); DownloadRunner runner = new DownloadRunner(uri1);
TaskWrapper task = runner.postDownloadAction().postRemoveAction().getTask(); TaskWrapper task = runner.postDownloadRequest().postRemoveRequest().getTask();
task.assertRemoving(); task.assertRemoving();
runner.getDownloader(1).unblock().assertReleased().assertStartCount(1); runner.getDownloader(1).unblock().assertReleased().assertStartCount(1);
task.assertRemoved(); task.assertRemoved();
...@@ -148,7 +148,7 @@ public class DownloadManagerTest { ...@@ -148,7 +148,7 @@ public class DownloadManagerTest {
@Test @Test
public void downloadFails_retriesThenTaskFails() throws Throwable { public void downloadFails_retriesThenTaskFails() throws Throwable {
DownloadRunner runner = new DownloadRunner(uri1); DownloadRunner runner = new DownloadRunner(uri1);
runner.postDownloadAction(); runner.postDownloadRequest();
FakeDownloader downloader = runner.getDownloader(0); FakeDownloader downloader = runner.getDownloader(0);
for (int i = 0; i <= MIN_RETRY_COUNT; i++) { for (int i = 0; i <= MIN_RETRY_COUNT; i++) {
...@@ -163,7 +163,7 @@ public class DownloadManagerTest { ...@@ -163,7 +163,7 @@ public class DownloadManagerTest {
@Test @Test
public void downloadFails_retries() throws Throwable { public void downloadFails_retries() throws Throwable {
DownloadRunner runner = new DownloadRunner(uri1); DownloadRunner runner = new DownloadRunner(uri1);
runner.postDownloadAction(); runner.postDownloadRequest();
FakeDownloader downloader = runner.getDownloader(0); FakeDownloader downloader = runner.getDownloader(0);
for (int i = 0; i < MIN_RETRY_COUNT; i++) { for (int i = 0; i < MIN_RETRY_COUNT; i++) {
...@@ -179,7 +179,7 @@ public class DownloadManagerTest { ...@@ -179,7 +179,7 @@ public class DownloadManagerTest {
@Test @Test
public void downloadProgressOnRetry_retryCountResets() throws Throwable { public void downloadProgressOnRetry_retryCountResets() throws Throwable {
DownloadRunner runner = new DownloadRunner(uri1); DownloadRunner runner = new DownloadRunner(uri1);
runner.postDownloadAction(); runner.postDownloadRequest();
FakeDownloader downloader = runner.getDownloader(0); FakeDownloader downloader = runner.getDownloader(0);
int tooManyRetries = MIN_RETRY_COUNT + 10; int tooManyRetries = MIN_RETRY_COUNT + 10;
...@@ -199,9 +199,9 @@ public class DownloadManagerTest { ...@@ -199,9 +199,9 @@ public class DownloadManagerTest {
DownloadRunner runner = new DownloadRunner(uri1); DownloadRunner runner = new DownloadRunner(uri1);
FakeDownloader downloader1 = runner.getDownloader(0); FakeDownloader downloader1 = runner.getDownloader(0);
runner.postDownloadAction(); runner.postDownloadRequest();
downloader1.assertStarted(); downloader1.assertStarted();
runner.postRemoveAction(); runner.postRemoveRequest();
downloader1.assertCanceled().assertStartCount(1); downloader1.assertCanceled().assertStartCount(1);
runner.getDownloader(1).unblock().assertNotCanceled(); runner.getDownloader(1).unblock().assertNotCanceled();
...@@ -213,9 +213,9 @@ public class DownloadManagerTest { ...@@ -213,9 +213,9 @@ public class DownloadManagerTest {
DownloadRunner runner = new DownloadRunner(uri1); DownloadRunner runner = new DownloadRunner(uri1);
FakeDownloader downloader1 = runner.getDownloader(1); FakeDownloader downloader1 = runner.getDownloader(1);
runner.postDownloadAction().postRemoveAction(); runner.postDownloadRequest().postRemoveRequest();
downloader1.assertStarted(); downloader1.assertStarted();
runner.postDownloadAction(); runner.postDownloadRequest();
downloader1.unblock().assertNotCanceled(); downloader1.unblock().assertNotCanceled();
runner.getDownloader(2).unblock().assertNotCanceled(); runner.getDownloader(2).unblock().assertNotCanceled();
...@@ -223,13 +223,13 @@ public class DownloadManagerTest { ...@@ -223,13 +223,13 @@ public class DownloadManagerTest {
} }
@Test @Test
public void secondSameRemoveActionIgnored() throws Throwable { public void secondSameRemoveRequestIgnored() throws Throwable {
DownloadRunner runner = new DownloadRunner(uri1); DownloadRunner runner = new DownloadRunner(uri1);
FakeDownloader downloader1 = runner.getDownloader(1); FakeDownloader downloader1 = runner.getDownloader(1);
runner.postDownloadAction().postRemoveAction(); runner.postDownloadRequest().postRemoveRequest();
downloader1.assertStarted(); downloader1.assertStarted();
runner.postRemoveAction(); runner.postRemoveRequest();
downloader1.unblock().assertNotCanceled(); downloader1.unblock().assertNotCanceled();
runner.getTask().assertRemoved(); runner.getTask().assertRemoved();
...@@ -238,22 +238,22 @@ public class DownloadManagerTest { ...@@ -238,22 +238,22 @@ public class DownloadManagerTest {
} }
@Test @Test
public void differentDownloadActionsMerged() throws Throwable { public void differentDownloadRequestsMerged() throws Throwable {
DownloadRunner runner = new DownloadRunner(uri1); DownloadRunner runner = new DownloadRunner(uri1);
FakeDownloader downloader1 = runner.getDownloader(0); FakeDownloader downloader1 = runner.getDownloader(0);
StreamKey streamKey1 = new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0); StreamKey streamKey1 = new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0);
StreamKey streamKey2 = new StreamKey(/* groupIndex= */ 1, /* trackIndex= */ 1); StreamKey streamKey2 = new StreamKey(/* groupIndex= */ 1, /* trackIndex= */ 1);
runner.postDownloadAction(streamKey1); runner.postDownloadRequest(streamKey1);
downloader1.assertStarted(); downloader1.assertStarted();
runner.postDownloadAction(streamKey2); runner.postDownloadRequest(streamKey2);
downloader1.assertCanceled(); downloader1.assertCanceled();
FakeDownloader downloader2 = runner.getDownloader(1); FakeDownloader downloader2 = runner.getDownloader(1);
downloader2.assertStarted(); downloader2.assertStarted();
assertThat(downloader2.action.streamKeys).containsExactly(streamKey1, streamKey2); assertThat(downloader2.request.streamKeys).containsExactly(streamKey1, streamKey2);
downloader2.unblock(); downloader2.unblock();
runner.getTask().assertCompleted(); runner.getTask().assertCompleted();
...@@ -262,9 +262,9 @@ public class DownloadManagerTest { ...@@ -262,9 +262,9 @@ public class DownloadManagerTest {
} }
@Test @Test
public void actionsForDifferentContent_executedInParallel() throws Throwable { public void requestsForDifferentContent_executedInParallel() throws Throwable {
DownloadRunner runner1 = new DownloadRunner(uri1).postDownloadAction(); DownloadRunner runner1 = new DownloadRunner(uri1).postDownloadRequest();
DownloadRunner runner2 = new DownloadRunner(uri2).postDownloadAction(); DownloadRunner runner2 = new DownloadRunner(uri2).postDownloadRequest();
FakeDownloader downloader1 = runner1.getDownloader(0); FakeDownloader downloader1 = runner1.getDownloader(0);
FakeDownloader downloader2 = runner2.getDownloader(0); FakeDownloader downloader2 = runner2.getDownloader(0);
...@@ -279,10 +279,10 @@ public class DownloadManagerTest { ...@@ -279,10 +279,10 @@ public class DownloadManagerTest {
} }
@Test @Test
public void actionsForDifferentContent_ifMaxDownloadIs1_executedSequentially() throws Throwable { public void requestsForDifferentContent_ifMaxDownloadIs1_executedSequentially() throws Throwable {
setUpDownloadManager(1); setUpDownloadManager(1);
DownloadRunner runner1 = new DownloadRunner(uri1).postDownloadAction(); DownloadRunner runner1 = new DownloadRunner(uri1).postDownloadRequest();
DownloadRunner runner2 = new DownloadRunner(uri2).postDownloadAction(); DownloadRunner runner2 = new DownloadRunner(uri2).postDownloadRequest();
FakeDownloader downloader1 = runner1.getDownloader(0); FakeDownloader downloader1 = runner1.getDownloader(0);
FakeDownloader downloader2 = runner2.getDownloader(0); FakeDownloader downloader2 = runner2.getDownloader(0);
...@@ -299,11 +299,11 @@ public class DownloadManagerTest { ...@@ -299,11 +299,11 @@ public class DownloadManagerTest {
} }
@Test @Test
public void removeActionForDifferentContent_ifMaxDownloadIs1_executedInParallel() public void removeRequestForDifferentContent_ifMaxDownloadIs1_executedInParallel()
throws Throwable { throws Throwable {
setUpDownloadManager(1); setUpDownloadManager(1);
DownloadRunner runner1 = new DownloadRunner(uri1).postDownloadAction(); DownloadRunner runner1 = new DownloadRunner(uri1).postDownloadRequest();
DownloadRunner runner2 = new DownloadRunner(uri2).postDownloadAction().postRemoveAction(); DownloadRunner runner2 = new DownloadRunner(uri2).postDownloadRequest().postRemoveRequest();
FakeDownloader downloader1 = runner1.getDownloader(0); FakeDownloader downloader1 = runner1.getDownloader(0);
FakeDownloader downloader2 = runner2.getDownloader(0); FakeDownloader downloader2 = runner2.getDownloader(0);
...@@ -318,11 +318,11 @@ public class DownloadManagerTest { ...@@ -318,11 +318,11 @@ public class DownloadManagerTest {
} }
@Test @Test
public void downloadActionFollowingRemove_ifMaxDownloadIs1_isNotStarted() throws Throwable { public void downloadRequestFollowingRemove_ifMaxDownloadIs1_isNotStarted() throws Throwable {
setUpDownloadManager(1); setUpDownloadManager(1);
DownloadRunner runner1 = new DownloadRunner(uri1).postDownloadAction(); DownloadRunner runner1 = new DownloadRunner(uri1).postDownloadRequest();
DownloadRunner runner2 = new DownloadRunner(uri2).postDownloadAction().postRemoveAction(); DownloadRunner runner2 = new DownloadRunner(uri2).postDownloadRequest().postRemoveRequest();
runner2.postDownloadAction(); runner2.postDownloadRequest();
FakeDownloader downloader1 = runner1.getDownloader(0); FakeDownloader downloader1 = runner1.getDownloader(0);
FakeDownloader downloader2 = runner2.getDownloader(0); FakeDownloader downloader2 = runner2.getDownloader(0);
FakeDownloader downloader3 = runner2.getDownloader(1); FakeDownloader downloader3 = runner2.getDownloader(1);
...@@ -342,9 +342,10 @@ public class DownloadManagerTest { ...@@ -342,9 +342,10 @@ public class DownloadManagerTest {
@Test @Test
public void getTasks_returnTasks() { public void getTasks_returnTasks() {
TaskWrapper task1 = new DownloadRunner(uri1).postDownloadAction().getTask(); TaskWrapper task1 = new DownloadRunner(uri1).postDownloadRequest().getTask();
TaskWrapper task2 = new DownloadRunner(uri2).postDownloadAction().getTask(); TaskWrapper task2 = new DownloadRunner(uri2).postDownloadRequest().getTask();
TaskWrapper task3 = new DownloadRunner(uri3).postDownloadAction().postRemoveAction().getTask(); TaskWrapper task3 =
new DownloadRunner(uri3).postDownloadRequest().postRemoveRequest().getTask();
task3.assertRemoving(); task3.assertRemoving();
List<Download> downloads = downloadManager.getCurrentDownloads(); List<Download> downloads = downloadManager.getCurrentDownloads();
...@@ -352,7 +353,7 @@ public class DownloadManagerTest { ...@@ -352,7 +353,7 @@ public class DownloadManagerTest {
assertThat(downloads).hasSize(3); assertThat(downloads).hasSize(3);
String[] taskIds = {task1.taskId, task2.taskId, task3.taskId}; String[] taskIds = {task1.taskId, task2.taskId, task3.taskId};
String[] downloadIds = { String[] downloadIds = {
downloads.get(0).action.id, downloads.get(1).action.id, downloads.get(2).action.id downloads.get(0).request.id, downloads.get(1).request.id, downloads.get(2).request.id
}; };
assertThat(downloadIds).isEqualTo(taskIds); assertThat(downloadIds).isEqualTo(taskIds);
} }
...@@ -363,27 +364,27 @@ public class DownloadManagerTest { ...@@ -363,27 +364,27 @@ public class DownloadManagerTest {
DownloadRunner runner2 = new DownloadRunner(uri2); DownloadRunner runner2 = new DownloadRunner(uri2);
DownloadRunner runner3 = new DownloadRunner(uri3); DownloadRunner runner3 = new DownloadRunner(uri3);
runner1.postDownloadAction().getTask().assertDownloading(); runner1.postDownloadRequest().getTask().assertDownloading();
runner2.postDownloadAction().postRemoveAction().getTask().assertRemoving(); runner2.postDownloadRequest().postRemoveRequest().getTask().assertRemoving();
runner2.postDownloadAction(); runner2.postDownloadRequest();
runOnMainThread(() -> downloadManager.stopDownloads()); runOnMainThread(() -> downloadManager.stopDownloads());
runner1.getTask().assertStopped(); runner1.getTask().assertStopped();
// remove actions aren't stopped. // remove requests aren't stopped.
runner2.getDownloader(1).unblock().assertReleased(); runner2.getDownloader(1).unblock().assertReleased();
runner2.getTask().assertStopped(); runner2.getTask().assertStopped();
// Although remove2 is finished, download2 doesn't start. // Although remove2 is finished, download2 doesn't start.
runner2.getDownloader(2).assertDoesNotStart(); runner2.getDownloader(2).assertDoesNotStart();
// When a new remove action is added, it cancels stopped download actions with the same media. // When a new remove request is added, it cancels stopped download requests with the same media.
runner1.postRemoveAction(); runner1.postRemoveRequest();
runner1.getDownloader(1).assertStarted().unblock(); runner1.getDownloader(1).assertStarted().unblock();
runner1.getTask().assertRemoved(); runner1.getTask().assertRemoved();
// New download actions can be added but they don't start. // New download requests can be added but they don't start.
runner3.postDownloadAction().getDownloader(0).assertDoesNotStart(); runner3.postDownloadRequest().getDownloader(0).assertDoesNotStart();
runOnMainThread(() -> downloadManager.startDownloads()); runOnMainThread(() -> downloadManager.startDownloads());
...@@ -395,7 +396,7 @@ public class DownloadManagerTest { ...@@ -395,7 +396,7 @@ public class DownloadManagerTest {
@Test @Test
public void manuallyStopAndResumeSingleDownload() throws Throwable { public void manuallyStopAndResumeSingleDownload() throws Throwable {
DownloadRunner runner = new DownloadRunner(uri1).postDownloadAction(); DownloadRunner runner = new DownloadRunner(uri1).postDownloadRequest();
TaskWrapper task = runner.getTask(); TaskWrapper task = runner.getTask();
task.assertDownloading(); task.assertDownloading();
...@@ -414,7 +415,7 @@ public class DownloadManagerTest { ...@@ -414,7 +415,7 @@ public class DownloadManagerTest {
@Test @Test
public void manuallyStoppedDownloadCanBeCancelled() throws Throwable { public void manuallyStoppedDownloadCanBeCancelled() throws Throwable {
DownloadRunner runner = new DownloadRunner(uri1).postDownloadAction(); DownloadRunner runner = new DownloadRunner(uri1).postDownloadRequest();
TaskWrapper task = runner.getTask(); TaskWrapper task = runner.getTask();
task.assertDownloading(); task.assertDownloading();
...@@ -423,7 +424,7 @@ public class DownloadManagerTest { ...@@ -423,7 +424,7 @@ public class DownloadManagerTest {
task.assertStopped(); task.assertStopped();
runner.postRemoveAction(); runner.postRemoveRequest();
runner.getDownloader(1).assertStarted().unblock(); runner.getDownloader(1).assertStarted().unblock();
task.assertRemoved(); task.assertRemoved();
...@@ -436,8 +437,8 @@ public class DownloadManagerTest { ...@@ -436,8 +437,8 @@ public class DownloadManagerTest {
DownloadRunner runner2 = new DownloadRunner(uri2); DownloadRunner runner2 = new DownloadRunner(uri2);
DownloadRunner runner3 = new DownloadRunner(uri3); DownloadRunner runner3 = new DownloadRunner(uri3);
runner1.postDownloadAction().getTask().assertDownloading(); runner1.postDownloadRequest().getTask().assertDownloading();
runner2.postDownloadAction().postRemoveAction().getTask().assertRemoving(); runner2.postDownloadRequest().postRemoveRequest().getTask().assertRemoving();
runOnMainThread( runOnMainThread(
() -> downloadManager.setManualStopReason(runner1.getTask().taskId, APP_STOP_REASON)); () -> downloadManager.setManualStopReason(runner1.getTask().taskId, APP_STOP_REASON));
...@@ -447,37 +448,37 @@ public class DownloadManagerTest { ...@@ -447,37 +448,37 @@ public class DownloadManagerTest {
// Other downloads aren't affected. // Other downloads aren't affected.
runner2.getDownloader(1).unblock().assertReleased(); runner2.getDownloader(1).unblock().assertReleased();
// New download actions can be added and they start. // New download requests can be added and they start.
runner3.postDownloadAction().getDownloader(0).assertStarted().unblock(); runner3.postDownloadRequest().getDownloader(0).assertStarted().unblock();
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError(); downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
} }
@Test @Test
public void mergeAction_removingDownload_becomesRestarting() { public void mergeRequest_removingDownload_becomesRestarting() {
DownloadAction downloadAction = createDownloadAction(); DownloadRequest downloadRequest = createDownloadRequest();
DownloadBuilder downloadBuilder = DownloadBuilder downloadBuilder =
new DownloadBuilder(downloadAction).setState(Download.STATE_REMOVING); new DownloadBuilder(downloadRequest).setState(Download.STATE_REMOVING);
Download download = downloadBuilder.build(); Download download = downloadBuilder.build();
Download mergedDownload = Download mergedDownload =
DownloadManager.mergeAction(download, downloadAction, download.manualStopReason); DownloadManager.mergeRequest(download, downloadRequest, download.manualStopReason);
Download expectedDownload = downloadBuilder.setState(Download.STATE_RESTARTING).build(); Download expectedDownload = downloadBuilder.setState(Download.STATE_RESTARTING).build();
assertEqualIgnoringTimeFields(mergedDownload, expectedDownload); assertEqualIgnoringTimeFields(mergedDownload, expectedDownload);
} }
@Test @Test
public void mergeAction_failedDownload_becomesQueued() { public void mergeRequest_failedDownload_becomesQueued() {
DownloadAction downloadAction = createDownloadAction(); DownloadRequest downloadRequest = createDownloadRequest();
DownloadBuilder downloadBuilder = DownloadBuilder downloadBuilder =
new DownloadBuilder(downloadAction) new DownloadBuilder(downloadRequest)
.setState(Download.STATE_FAILED) .setState(Download.STATE_FAILED)
.setFailureReason(Download.FAILURE_REASON_UNKNOWN); .setFailureReason(Download.FAILURE_REASON_UNKNOWN);
Download download = downloadBuilder.build(); Download download = downloadBuilder.build();
Download mergedDownload = Download mergedDownload =
DownloadManager.mergeAction(download, downloadAction, download.manualStopReason); DownloadManager.mergeRequest(download, downloadRequest, download.manualStopReason);
Download expectedDownload = Download expectedDownload =
downloadBuilder downloadBuilder
...@@ -488,31 +489,31 @@ public class DownloadManagerTest { ...@@ -488,31 +489,31 @@ public class DownloadManagerTest {
} }
@Test @Test
public void mergeAction_stoppedDownload_staysStopped() { public void mergeRequest_stoppedDownload_staysStopped() {
DownloadAction downloadAction = createDownloadAction(); DownloadRequest downloadRequest = createDownloadRequest();
DownloadBuilder downloadBuilder = DownloadBuilder downloadBuilder =
new DownloadBuilder(downloadAction) new DownloadBuilder(downloadRequest)
.setState(Download.STATE_STOPPED) .setState(Download.STATE_STOPPED)
.setManualStopReason(/* manualStopReason= */ 1); .setManualStopReason(/* manualStopReason= */ 1);
Download download = downloadBuilder.build(); Download download = downloadBuilder.build();
Download mergedDownload = Download mergedDownload =
DownloadManager.mergeAction(download, downloadAction, download.manualStopReason); DownloadManager.mergeRequest(download, downloadRequest, download.manualStopReason);
assertEqualIgnoringTimeFields(mergedDownload, download); assertEqualIgnoringTimeFields(mergedDownload, download);
} }
@Test @Test
public void mergeAction_manualStopReasonSetButNotStopped_becomesStopped() { public void mergeRequest_manualStopReasonSetButNotStopped_becomesStopped() {
DownloadAction downloadAction = createDownloadAction(); DownloadRequest downloadRequest = createDownloadRequest();
DownloadBuilder downloadBuilder = DownloadBuilder downloadBuilder =
new DownloadBuilder(downloadAction) new DownloadBuilder(downloadRequest)
.setState(Download.STATE_COMPLETED) .setState(Download.STATE_COMPLETED)
.setManualStopReason(/* manualStopReason= */ 1); .setManualStopReason(/* manualStopReason= */ 1);
Download download = downloadBuilder.build(); Download download = downloadBuilder.build();
Download mergedDownload = Download mergedDownload =
DownloadManager.mergeAction(download, downloadAction, download.manualStopReason); DownloadManager.mergeRequest(download, downloadRequest, download.manualStopReason);
Download expectedDownload = downloadBuilder.setState(Download.STATE_STOPPED).build(); Download expectedDownload = downloadBuilder.setState(Download.STATE_STOPPED).build();
assertEqualIgnoringTimeFields(mergedDownload, expectedDownload); assertEqualIgnoringTimeFields(mergedDownload, expectedDownload);
...@@ -556,7 +557,7 @@ public class DownloadManagerTest { ...@@ -556,7 +557,7 @@ public class DownloadManagerTest {
} }
private static void assertEqualIgnoringTimeFields(Download download, Download that) { private static void assertEqualIgnoringTimeFields(Download download, Download that) {
assertThat(download.action).isEqualTo(that.action); assertThat(download.request).isEqualTo(that.request);
assertThat(download.state).isEqualTo(that.state); assertThat(download.state).isEqualTo(that.state);
assertThat(download.failureReason).isEqualTo(that.failureReason); assertThat(download.failureReason).isEqualTo(that.failureReason);
assertThat(download.manualStopReason).isEqualTo(that.manualStopReason); assertThat(download.manualStopReason).isEqualTo(that.manualStopReason);
...@@ -565,10 +566,10 @@ public class DownloadManagerTest { ...@@ -565,10 +566,10 @@ public class DownloadManagerTest {
assertThat(download.getTotalBytes()).isEqualTo(that.getTotalBytes()); assertThat(download.getTotalBytes()).isEqualTo(that.getTotalBytes());
} }
private static DownloadAction createDownloadAction() { private static DownloadRequest createDownloadRequest() {
return new DownloadAction( return new DownloadRequest(
"id", "id",
DownloadAction.TYPE_DASH, DownloadRequest.TYPE_DASH,
Uri.parse("https://www.test.com/download"), Uri.parse("https://www.test.com/download"),
Collections.emptyList(), Collections.emptyList(),
/* customCacheKey= */ null, /* customCacheKey= */ null,
...@@ -593,21 +594,21 @@ public class DownloadManagerTest { ...@@ -593,21 +594,21 @@ public class DownloadManagerTest {
taskWrapper = new TaskWrapper(id); taskWrapper = new TaskWrapper(id);
} }
private DownloadRunner postRemoveAction() { private DownloadRunner postRemoveRequest() {
runOnMainThread(() -> downloadManager.removeDownload(id)); runOnMainThread(() -> downloadManager.removeDownload(id));
return this; return this;
} }
private DownloadRunner postDownloadAction(StreamKey... keys) { private DownloadRunner postDownloadRequest(StreamKey... keys) {
DownloadAction downloadAction = DownloadRequest downloadRequest =
new DownloadAction( new DownloadRequest(
id, id,
DownloadAction.TYPE_PROGRESSIVE, DownloadRequest.TYPE_PROGRESSIVE,
uri, uri,
Arrays.asList(keys), Arrays.asList(keys),
/* customCacheKey= */ null, /* customCacheKey= */ null,
/* data= */ null); /* data= */ null);
runOnMainThread(() -> downloadManager.addDownload(downloadAction)); runOnMainThread(() -> downloadManager.addDownload(downloadRequest));
return this; return this;
} }
...@@ -624,9 +625,9 @@ public class DownloadManagerTest { ...@@ -624,9 +625,9 @@ public class DownloadManagerTest {
return downloaders.get(index); return downloaders.get(index);
} }
private synchronized Downloader createDownloader(DownloadAction action) { private synchronized Downloader createDownloader(DownloadRequest request) {
downloader = getDownloader(createdDownloaderCount++); downloader = getDownloader(createdDownloaderCount++);
downloader.action = action; downloader.request = request;
return downloader; return downloader;
} }
...@@ -710,8 +711,8 @@ public class DownloadManagerTest { ...@@ -710,8 +711,8 @@ public class DownloadManagerTest {
} }
@Override @Override
public Downloader createDownloader(DownloadAction action) { public Downloader createDownloader(DownloadRequest request) {
return downloaders.get(action.uri).createDownloader(action); return downloaders.get(request.uri).createDownloader(request);
} }
} }
...@@ -719,7 +720,7 @@ public class DownloadManagerTest { ...@@ -719,7 +720,7 @@ public class DownloadManagerTest {
private final com.google.android.exoplayer2.util.ConditionVariable blocker; private final com.google.android.exoplayer2.util.ConditionVariable blocker;
private DownloadAction action; private DownloadRequest request;
private CountDownLatch started; private CountDownLatch started;
private volatile boolean interrupted; private volatile boolean interrupted;
private volatile boolean cancelled; private volatile boolean cancelled;
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
*/ */
package com.google.android.exoplayer2.offline; package com.google.android.exoplayer2.offline;
import static com.google.android.exoplayer2.offline.DownloadAction.TYPE_DASH; import static com.google.android.exoplayer2.offline.DownloadRequest.TYPE_DASH;
import static com.google.android.exoplayer2.offline.DownloadAction.TYPE_HLS; import static com.google.android.exoplayer2.offline.DownloadRequest.TYPE_HLS;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
...@@ -30,9 +30,9 @@ import org.junit.Before; ...@@ -30,9 +30,9 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** Unit tests for {@link DownloadAction}. */ /** Unit tests for {@link DownloadRequest}. */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class DownloadActionTest { public class DownloadRequestTest {
private Uri uri1; private Uri uri1;
private Uri uri2; private Uri uri2;
...@@ -44,17 +44,17 @@ public class DownloadActionTest { ...@@ -44,17 +44,17 @@ public class DownloadActionTest {
} }
@Test @Test
public void testMergeActions_withDifferentIds_fails() { public void testMergeRequests_withDifferentIds_fails() {
DownloadAction action1 = DownloadRequest request1 =
new DownloadAction( new DownloadRequest(
"id1", "id1",
TYPE_DASH, TYPE_DASH,
uri1, uri1,
/* streamKeys= */ Collections.emptyList(), /* streamKeys= */ Collections.emptyList(),
/* customCacheKey= */ null, /* customCacheKey= */ null,
/* data= */ null); /* data= */ null);
DownloadAction action2 = DownloadRequest request2 =
new DownloadAction( new DownloadRequest(
"id2", "id2",
TYPE_DASH, TYPE_DASH,
uri2, uri2,
...@@ -62,7 +62,7 @@ public class DownloadActionTest { ...@@ -62,7 +62,7 @@ public class DownloadActionTest {
/* customCacheKey= */ null, /* customCacheKey= */ null,
/* data= */ null); /* data= */ null);
try { try {
action1.copyWithMergedAction(action2); request1.copyWithMergedRequest(request2);
fail(); fail();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Expected. // Expected.
...@@ -70,17 +70,17 @@ public class DownloadActionTest { ...@@ -70,17 +70,17 @@ public class DownloadActionTest {
} }
@Test @Test
public void testMergeActions_withDifferentTypes_fails() { public void testMergeRequests_withDifferentTypes_fails() {
DownloadAction action1 = DownloadRequest request1 =
new DownloadAction( new DownloadRequest(
"id1", "id1",
TYPE_DASH, TYPE_DASH,
uri1, uri1,
/* streamKeys= */ Collections.emptyList(), /* streamKeys= */ Collections.emptyList(),
/* customCacheKey= */ null, /* customCacheKey= */ null,
/* data= */ null); /* data= */ null);
DownloadAction action2 = DownloadRequest request2 =
new DownloadAction( new DownloadRequest(
"id1", "id1",
TYPE_HLS, TYPE_HLS,
uri1, uri1,
...@@ -88,7 +88,7 @@ public class DownloadActionTest { ...@@ -88,7 +88,7 @@ public class DownloadActionTest {
/* customCacheKey= */ null, /* customCacheKey= */ null,
/* data= */ null); /* data= */ null);
try { try {
action1.copyWithMergedAction(action2); request1.copyWithMergedRequest(request2);
fail(); fail();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Expected. // Expected.
...@@ -96,56 +96,56 @@ public class DownloadActionTest { ...@@ -96,56 +96,56 @@ public class DownloadActionTest {
} }
@Test @Test
public void testMergeAction_withSameAction() { public void testMergeRequest_withSameRequest() {
DownloadAction action1 = createAction(uri1, new StreamKey(0, 0, 0)); DownloadRequest request1 = createRequest(uri1, new StreamKey(0, 0, 0));
DownloadAction mergedAction = action1.copyWithMergedAction(action1); DownloadRequest mergedRequest = request1.copyWithMergedRequest(request1);
assertEqual(action1, mergedAction); assertEqual(request1, mergedRequest);
} }
@Test @Test
public void testMergeActions_withEmptyStreamKeys() { public void testMergeRequests_withEmptyStreamKeys() {
DownloadAction action1 = createAction(uri1, new StreamKey(0, 0, 0)); DownloadRequest request1 = createRequest(uri1, new StreamKey(0, 0, 0));
DownloadAction action2 = createAction(uri1); DownloadRequest request2 = createRequest(uri1);
// If either of the actions have empty streamKeys, the merge should have empty streamKeys. // If either of the requests have empty streamKeys, the merge should have empty streamKeys.
DownloadAction mergedAction = action1.copyWithMergedAction(action2); DownloadRequest mergedRequest = request1.copyWithMergedRequest(request2);
assertThat(mergedAction.streamKeys).isEmpty(); assertThat(mergedRequest.streamKeys).isEmpty();
mergedAction = action2.copyWithMergedAction(action1); mergedRequest = request2.copyWithMergedRequest(request1);
assertThat(mergedAction.streamKeys).isEmpty(); assertThat(mergedRequest.streamKeys).isEmpty();
} }
@Test @Test
public void testMergeActions_withOverlappingStreamKeys() { public void testMergeRequests_withOverlappingStreamKeys() {
StreamKey streamKey1 = new StreamKey(0, 1, 2); StreamKey streamKey1 = new StreamKey(0, 1, 2);
StreamKey streamKey2 = new StreamKey(3, 4, 5); StreamKey streamKey2 = new StreamKey(3, 4, 5);
StreamKey streamKey3 = new StreamKey(6, 7, 8); StreamKey streamKey3 = new StreamKey(6, 7, 8);
DownloadAction action1 = createAction(uri1, streamKey1, streamKey2); DownloadRequest request1 = createRequest(uri1, streamKey1, streamKey2);
DownloadAction action2 = createAction(uri1, streamKey2, streamKey3); DownloadRequest request2 = createRequest(uri1, streamKey2, streamKey3);
// Merged streamKeys should be in their original order without duplicates. // Merged streamKeys should be in their original order without duplicates.
DownloadAction mergedAction = action1.copyWithMergedAction(action2); DownloadRequest mergedRequest = request1.copyWithMergedRequest(request2);
assertThat(mergedAction.streamKeys).containsExactly(streamKey1, streamKey2, streamKey3); assertThat(mergedRequest.streamKeys).containsExactly(streamKey1, streamKey2, streamKey3);
mergedAction = action2.copyWithMergedAction(action1); mergedRequest = request2.copyWithMergedRequest(request1);
assertThat(mergedAction.streamKeys).containsExactly(streamKey2, streamKey3, streamKey1); assertThat(mergedRequest.streamKeys).containsExactly(streamKey2, streamKey3, streamKey1);
} }
@Test @Test
public void testMergeActions_withDifferentFields() { public void testMergeRequests_withDifferentFields() {
byte[] data1 = new byte[] {0, 1, 2}; byte[] data1 = new byte[] {0, 1, 2};
byte[] data2 = new byte[] {3, 4, 5}; byte[] data2 = new byte[] {3, 4, 5};
DownloadAction action1 = DownloadRequest request1 =
new DownloadAction( new DownloadRequest(
"id1", "id1",
TYPE_DASH, TYPE_DASH,
uri1, uri1,
/* streamKeys= */ Collections.emptyList(), /* streamKeys= */ Collections.emptyList(),
"key1", "key1",
/* data= */ data1); /* data= */ data1);
DownloadAction action2 = DownloadRequest request2 =
new DownloadAction( new DownloadRequest(
"id1", "id1",
TYPE_DASH, TYPE_DASH,
uri2, uri2,
...@@ -153,16 +153,16 @@ public class DownloadActionTest { ...@@ -153,16 +153,16 @@ public class DownloadActionTest {
"key2", "key2",
/* data= */ data2); /* data= */ data2);
// uri, customCacheKey and data should be from the action being merged. // uri, customCacheKey and data should be from the request being merged.
DownloadAction mergedAction = action1.copyWithMergedAction(action2); DownloadRequest mergedRequest = request1.copyWithMergedRequest(request2);
assertThat(mergedAction.uri).isEqualTo(uri2); assertThat(mergedRequest.uri).isEqualTo(uri2);
assertThat(mergedAction.customCacheKey).isEqualTo("key2"); assertThat(mergedRequest.customCacheKey).isEqualTo("key2");
assertThat(mergedAction.data).isEqualTo(data2); assertThat(mergedRequest.data).isEqualTo(data2);
mergedAction = action2.copyWithMergedAction(action1); mergedRequest = request2.copyWithMergedRequest(request1);
assertThat(mergedAction.uri).isEqualTo(uri1); assertThat(mergedRequest.uri).isEqualTo(uri1);
assertThat(mergedAction.customCacheKey).isEqualTo("key1"); assertThat(mergedRequest.customCacheKey).isEqualTo("key1");
assertThat(mergedAction.data).isEqualTo(data1); assertThat(mergedRequest.data).isEqualTo(data1);
} }
@Test @Test
...@@ -170,8 +170,8 @@ public class DownloadActionTest { ...@@ -170,8 +170,8 @@ public class DownloadActionTest {
ArrayList<StreamKey> streamKeys = new ArrayList<>(); ArrayList<StreamKey> streamKeys = new ArrayList<>();
streamKeys.add(new StreamKey(1, 2, 3)); streamKeys.add(new StreamKey(1, 2, 3));
streamKeys.add(new StreamKey(4, 5, 6)); streamKeys.add(new StreamKey(4, 5, 6));
DownloadAction actionToParcel = DownloadRequest requestToParcel =
new DownloadAction( new DownloadRequest(
"id", "id",
"type", "type",
Uri.parse("https://abc.def/ghi"), Uri.parse("https://abc.def/ghi"),
...@@ -179,11 +179,11 @@ public class DownloadActionTest { ...@@ -179,11 +179,11 @@ public class DownloadActionTest {
"key", "key",
new byte[] {1, 2, 3, 4, 5}); new byte[] {1, 2, 3, 4, 5});
Parcel parcel = Parcel.obtain(); Parcel parcel = Parcel.obtain();
actionToParcel.writeToParcel(parcel, 0); requestToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0); parcel.setDataPosition(0);
DownloadAction actionFromParcel = DownloadAction.CREATOR.createFromParcel(parcel); DownloadRequest requestFromParcel = DownloadRequest.CREATOR.createFromParcel(parcel);
assertThat(actionFromParcel).isEqualTo(actionToParcel); assertThat(requestFromParcel).isEqualTo(requestToParcel);
parcel.recycle(); parcel.recycle();
} }
...@@ -191,50 +191,50 @@ public class DownloadActionTest { ...@@ -191,50 +191,50 @@ public class DownloadActionTest {
@SuppressWarnings("EqualsWithItself") @SuppressWarnings("EqualsWithItself")
@Test @Test
public void testEquals() { public void testEquals() {
DownloadAction action1 = createAction(uri1); DownloadRequest request1 = createRequest(uri1);
assertThat(action1.equals(action1)).isTrue(); assertThat(request1.equals(request1)).isTrue();
DownloadAction action2 = createAction(uri1); DownloadRequest request2 = createRequest(uri1);
DownloadAction action3 = createAction(uri1); DownloadRequest request3 = createRequest(uri1);
assertEqual(action2, action3); assertEqual(request2, request3);
DownloadAction action4 = createAction(uri1); DownloadRequest request4 = createRequest(uri1);
DownloadAction action5 = createAction(uri1, new StreamKey(0, 0, 0)); DownloadRequest request5 = createRequest(uri1, new StreamKey(0, 0, 0));
assertNotEqual(action4, action5); assertNotEqual(request4, request5);
DownloadAction action6 = createAction(uri1, new StreamKey(0, 1, 1)); DownloadRequest request6 = createRequest(uri1, new StreamKey(0, 1, 1));
DownloadAction action7 = createAction(uri1, new StreamKey(0, 0, 0)); DownloadRequest request7 = createRequest(uri1, new StreamKey(0, 0, 0));
assertNotEqual(action6, action7); assertNotEqual(request6, request7);
DownloadAction action8 = createAction(uri1); DownloadRequest request8 = createRequest(uri1);
DownloadAction action9 = createAction(uri2); DownloadRequest request9 = createRequest(uri2);
assertNotEqual(action8, action9); assertNotEqual(request8, request9);
DownloadAction action10 = createAction(uri1, new StreamKey(0, 0, 0), new StreamKey(0, 1, 1)); DownloadRequest request10 = createRequest(uri1, new StreamKey(0, 0, 0), new StreamKey(0, 1, 1));
DownloadAction action11 = createAction(uri1, new StreamKey(0, 1, 1), new StreamKey(0, 0, 0)); DownloadRequest request11 = createRequest(uri1, new StreamKey(0, 1, 1), new StreamKey(0, 0, 0));
assertEqual(action10, action11); assertEqual(request10, request11);
DownloadAction action12 = createAction(uri1, new StreamKey(0, 0, 0)); DownloadRequest request12 = createRequest(uri1, new StreamKey(0, 0, 0));
DownloadAction action13 = createAction(uri1, new StreamKey(0, 1, 1), new StreamKey(0, 0, 0)); DownloadRequest request13 = createRequest(uri1, new StreamKey(0, 1, 1), new StreamKey(0, 0, 0));
assertNotEqual(action12, action13); assertNotEqual(request12, request13);
DownloadAction action14 = createAction(uri1); DownloadRequest request14 = createRequest(uri1);
DownloadAction action15 = createAction(uri1); DownloadRequest request15 = createRequest(uri1);
assertEqual(action14, action15); assertEqual(request14, request15);
} }
private static void assertNotEqual(DownloadAction action1, DownloadAction action2) { private static void assertNotEqual(DownloadRequest request1, DownloadRequest request2) {
assertThat(action1).isNotEqualTo(action2); assertThat(request1).isNotEqualTo(request2);
assertThat(action2).isNotEqualTo(action1); assertThat(request2).isNotEqualTo(request1);
} }
private static void assertEqual(DownloadAction action1, DownloadAction action2) { private static void assertEqual(DownloadRequest request1, DownloadRequest request2) {
assertThat(action1).isEqualTo(action2); assertThat(request1).isEqualTo(request2);
assertThat(action2).isEqualTo(action1); assertThat(request2).isEqualTo(request1);
} }
private static DownloadAction createAction(Uri uri, StreamKey... keys) { private static DownloadRequest createRequest(Uri uri, StreamKey... keys) {
return new DownloadAction( return new DownloadRequest(
uri.toString(), TYPE_DASH, uri, toList(keys), /* customCacheKey= */ null, /* data= */ null); uri.toString(), TYPE_DASH, uri, toList(keys), /* customCacheKey= */ null, /* data= */ null);
} }
......
...@@ -29,8 +29,8 @@ import android.net.Uri; ...@@ -29,8 +29,8 @@ import android.net.Uri;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory; import com.google.android.exoplayer2.offline.DefaultDownloaderFactory;
import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloadException; import com.google.android.exoplayer2.offline.DownloadException;
import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.offline.Downloader; import com.google.android.exoplayer2.offline.Downloader;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper; import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.DownloaderFactory; import com.google.android.exoplayer2.offline.DownloaderFactory;
...@@ -84,9 +84,9 @@ public class DashDownloaderTest { ...@@ -84,9 +84,9 @@ public class DashDownloaderTest {
Downloader downloader = Downloader downloader =
factory.createDownloader( factory.createDownloader(
new DownloadAction( new DownloadRequest(
"id", "id",
DownloadAction.TYPE_DASH, DownloadRequest.TYPE_DASH,
Uri.parse("https://www.test.com/download"), Uri.parse("https://www.test.com/download"),
Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)), Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)),
/* customCacheKey= */ null, /* customCacheKey= */ null,
......
...@@ -28,8 +28,8 @@ import androidx.test.core.app.ApplicationProvider; ...@@ -28,8 +28,8 @@ import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.offline.DefaultDownloadIndex; import com.google.android.exoplayer2.offline.DefaultDownloadIndex;
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory; import com.google.android.exoplayer2.offline.DefaultDownloaderFactory;
import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloadManager; import com.google.android.exoplayer2.offline.DownloadManager;
import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper; import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.StreamKey; import com.google.android.exoplayer2.offline.StreamKey;
import com.google.android.exoplayer2.scheduler.Requirements; import com.google.android.exoplayer2.scheduler.Requirements;
...@@ -132,7 +132,7 @@ public class DownloadManagerDashTest { ...@@ -132,7 +132,7 @@ public class DownloadManagerDashTest {
dummyMainThread.runOnMainThread( dummyMainThread.runOnMainThread(
() -> { () -> {
// Setup an Action and immediately release the DM. // Setup an Action and immediately release the DM.
handleDownloadAction(fakeStreamKey1, fakeStreamKey2); handleDownloadRequest(fakeStreamKey1, fakeStreamKey2);
downloadManager.release(); downloadManager.release();
}); });
...@@ -149,29 +149,29 @@ public class DownloadManagerDashTest { ...@@ -149,29 +149,29 @@ public class DownloadManagerDashTest {
} }
@Test @Test
public void testHandleDownloadAction() throws Throwable { public void testHandleDownloadRequest() throws Throwable {
handleDownloadAction(fakeStreamKey1, fakeStreamKey2); handleDownloadRequest(fakeStreamKey1, fakeStreamKey2);
blockUntilTasksCompleteAndThrowAnyDownloadError(); blockUntilTasksCompleteAndThrowAnyDownloadError();
assertCachedData(cache, fakeDataSet); assertCachedData(cache, fakeDataSet);
} }
@Test @Test
public void testHandleMultipleDownloadAction() throws Throwable { public void testHandleMultipleDownloadRequest() throws Throwable {
handleDownloadAction(fakeStreamKey1); handleDownloadRequest(fakeStreamKey1);
handleDownloadAction(fakeStreamKey2); handleDownloadRequest(fakeStreamKey2);
blockUntilTasksCompleteAndThrowAnyDownloadError(); blockUntilTasksCompleteAndThrowAnyDownloadError();
assertCachedData(cache, fakeDataSet); assertCachedData(cache, fakeDataSet);
} }
@Test @Test
public void testHandleInterferingDownloadAction() throws Throwable { public void testHandleInterferingDownloadRequest() throws Throwable {
fakeDataSet fakeDataSet
.newData("audio_segment_2") .newData("audio_segment_2")
.appendReadAction(() -> handleDownloadAction(fakeStreamKey2)) .appendReadAction(() -> handleDownloadRequest(fakeStreamKey2))
.appendReadData(TestUtil.buildTestData(5)) .appendReadData(TestUtil.buildTestData(5))
.endData(); .endData();
handleDownloadAction(fakeStreamKey1); handleDownloadRequest(fakeStreamKey1);
blockUntilTasksCompleteAndThrowAnyDownloadError(); blockUntilTasksCompleteAndThrowAnyDownloadError();
assertCachedData(cache, fakeDataSet); assertCachedData(cache, fakeDataSet);
...@@ -179,7 +179,7 @@ public class DownloadManagerDashTest { ...@@ -179,7 +179,7 @@ public class DownloadManagerDashTest {
@Test @Test
public void testHandleRemoveAction() throws Throwable { public void testHandleRemoveAction() throws Throwable {
handleDownloadAction(fakeStreamKey1); handleDownloadRequest(fakeStreamKey1);
blockUntilTasksCompleteAndThrowAnyDownloadError(); blockUntilTasksCompleteAndThrowAnyDownloadError();
...@@ -194,7 +194,7 @@ public class DownloadManagerDashTest { ...@@ -194,7 +194,7 @@ public class DownloadManagerDashTest {
@Ignore @Ignore
@Test @Test
public void testHandleRemoveActionBeforeDownloadFinish() throws Throwable { public void testHandleRemoveActionBeforeDownloadFinish() throws Throwable {
handleDownloadAction(fakeStreamKey1); handleDownloadRequest(fakeStreamKey1);
handleRemoveAction(); handleRemoveAction();
blockUntilTasksCompleteAndThrowAnyDownloadError(); blockUntilTasksCompleteAndThrowAnyDownloadError();
...@@ -213,7 +213,7 @@ public class DownloadManagerDashTest { ...@@ -213,7 +213,7 @@ public class DownloadManagerDashTest {
.appendReadData(TestUtil.buildTestData(5)) .appendReadData(TestUtil.buildTestData(5))
.endData(); .endData();
handleDownloadAction(fakeStreamKey1); handleDownloadRequest(fakeStreamKey1);
assertThat(downloadInProgressCondition.block(ASSERT_TRUE_TIMEOUT)).isTrue(); assertThat(downloadInProgressCondition.block(ASSERT_TRUE_TIMEOUT)).isTrue();
...@@ -228,13 +228,13 @@ public class DownloadManagerDashTest { ...@@ -228,13 +228,13 @@ public class DownloadManagerDashTest {
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError(); downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
} }
private void handleDownloadAction(StreamKey... keys) { private void handleDownloadRequest(StreamKey... keys) {
ArrayList<StreamKey> keysList = new ArrayList<>(); ArrayList<StreamKey> keysList = new ArrayList<>();
Collections.addAll(keysList, keys); Collections.addAll(keysList, keys);
DownloadAction action = DownloadRequest action =
new DownloadAction( new DownloadRequest(
TEST_ID, TEST_ID,
DownloadAction.TYPE_DASH, DownloadRequest.TYPE_DASH,
TEST_MPD_URI, TEST_MPD_URI,
keysList, keysList,
/* customCacheKey= */ null, /* customCacheKey= */ null,
......
...@@ -30,8 +30,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; ...@@ -30,8 +30,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.offline.DefaultDownloadIndex; import com.google.android.exoplayer2.offline.DefaultDownloadIndex;
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory; import com.google.android.exoplayer2.offline.DefaultDownloaderFactory;
import com.google.android.exoplayer2.offline.Download; import com.google.android.exoplayer2.offline.Download;
import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.offline.DownloadManager; import com.google.android.exoplayer2.offline.DownloadManager;
import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.offline.DownloadService; import com.google.android.exoplayer2.offline.DownloadService;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper; import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.StreamKey; import com.google.android.exoplayer2.offline.StreamKey;
...@@ -159,7 +159,7 @@ public class DownloadServiceDashTest { ...@@ -159,7 +159,7 @@ public class DownloadServiceDashTest {
@Ignore // b/78877092 @Ignore // b/78877092
@Test @Test
public void testMultipleDownloadAction() throws Throwable { public void testMultipleDownloadRequest() throws Throwable {
downloadKeys(fakeStreamKey1); downloadKeys(fakeStreamKey1);
downloadKeys(fakeStreamKey2); downloadKeys(fakeStreamKey2);
...@@ -208,10 +208,10 @@ public class DownloadServiceDashTest { ...@@ -208,10 +208,10 @@ public class DownloadServiceDashTest {
private void downloadKeys(StreamKey... keys) { private void downloadKeys(StreamKey... keys) {
ArrayList<StreamKey> keysList = new ArrayList<>(); ArrayList<StreamKey> keysList = new ArrayList<>();
Collections.addAll(keysList, keys); Collections.addAll(keysList, keys);
DownloadAction action = DownloadRequest action =
new DownloadAction( new DownloadRequest(
TEST_ID, TEST_ID,
DownloadAction.TYPE_DASH, DownloadRequest.TYPE_DASH,
TEST_MPD_URI, TEST_MPD_URI,
keysList, keysList,
/* customCacheKey= */ null, /* customCacheKey= */ null,
...@@ -219,7 +219,7 @@ public class DownloadServiceDashTest { ...@@ -219,7 +219,7 @@ public class DownloadServiceDashTest {
dummyMainThread.runOnMainThread( dummyMainThread.runOnMainThread(
() -> { () -> {
Intent startIntent = Intent startIntent =
DownloadService.buildAddActionIntent( DownloadService.buildAddRequestIntent(
context, DownloadService.class, action, /* foreground= */ false); context, DownloadService.class, action, /* foreground= */ false);
dashDownloadService.onStartCommand(startIntent, 0, 0); dashDownloadService.onStartCommand(startIntent, 0, 0);
}); });
......
...@@ -38,7 +38,7 @@ import android.net.Uri; ...@@ -38,7 +38,7 @@ import android.net.Uri;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory; import com.google.android.exoplayer2.offline.DefaultDownloaderFactory;
import com.google.android.exoplayer2.offline.DownloadAction; import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.offline.Downloader; import com.google.android.exoplayer2.offline.Downloader;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper; import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.DownloaderFactory; import com.google.android.exoplayer2.offline.DownloaderFactory;
...@@ -101,9 +101,9 @@ public class HlsDownloaderTest { ...@@ -101,9 +101,9 @@ public class HlsDownloaderTest {
Downloader downloader = Downloader downloader =
factory.createDownloader( factory.createDownloader(
new DownloadAction( new DownloadRequest(
"id", "id",
DownloadAction.TYPE_HLS, DownloadRequest.TYPE_HLS,
Uri.parse("https://www.test.com/download"), Uri.parse("https://www.test.com/download"),
Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)), Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)),
/* customCacheKey= */ null, /* customCacheKey= */ null,
......
...@@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat; ...@@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.net.Uri; import android.net.Uri;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory; import com.google.android.exoplayer2.offline.DefaultDownloaderFactory;
import com.google.android.exoplayer2.offline.DownloadAction; import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.offline.Downloader; import com.google.android.exoplayer2.offline.Downloader;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper; import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.DownloaderFactory; import com.google.android.exoplayer2.offline.DownloaderFactory;
...@@ -44,9 +44,9 @@ public final class SsDownloaderTest { ...@@ -44,9 +44,9 @@ public final class SsDownloaderTest {
Downloader downloader = Downloader downloader =
factory.createDownloader( factory.createDownloader(
new DownloadAction( new DownloadRequest(
"id", "id",
DownloadAction.TYPE_SS, DownloadRequest.TYPE_SS,
Uri.parse("https://www.test.com/download"), Uri.parse("https://www.test.com/download"),
Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)), Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)),
/* customCacheKey= */ null, /* customCacheKey= */ null,
......
...@@ -38,7 +38,7 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen ...@@ -38,7 +38,7 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
private final DownloadManager downloadManager; private final DownloadManager downloadManager;
private final DummyMainThread dummyMainThread; private final DummyMainThread dummyMainThread;
private final HashMap<String, ArrayBlockingQueue<Integer>> actionStates; private final HashMap<String, ArrayBlockingQueue<Integer>> downloadStates;
private final ConditionVariable initializedCondition; private final ConditionVariable initializedCondition;
private CountDownLatch downloadFinishedCondition; private CountDownLatch downloadFinishedCondition;
...@@ -48,7 +48,7 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen ...@@ -48,7 +48,7 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
DownloadManager downloadManager, DummyMainThread dummyMainThread) { DownloadManager downloadManager, DummyMainThread dummyMainThread) {
this.downloadManager = downloadManager; this.downloadManager = downloadManager;
this.dummyMainThread = dummyMainThread; this.dummyMainThread = dummyMainThread;
actionStates = new HashMap<>(); downloadStates = new HashMap<>();
initializedCondition = new ConditionVariable(); initializedCondition = new ConditionVariable();
downloadManager.addListener(this); downloadManager.addListener(this);
} }
...@@ -73,12 +73,12 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen ...@@ -73,12 +73,12 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
if (download.state == Download.STATE_FAILED) { if (download.state == Download.STATE_FAILED) {
failureReason = download.failureReason; failureReason = download.failureReason;
} }
getStateQueue(download.action.id).add(download.state); getStateQueue(download.request.id).add(download.state);
} }
@Override @Override
public void onDownloadRemoved(DownloadManager downloadManager, Download download) { public void onDownloadRemoved(DownloadManager downloadManager, Download download) {
getStateQueue(download.action.id).add(STATE_REMOVED); getStateQueue(download.request.id).add(STATE_REMOVED);
} }
@Override @Override
...@@ -114,11 +114,11 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen ...@@ -114,11 +114,11 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
} }
private ArrayBlockingQueue<Integer> getStateQueue(String taskId) { private ArrayBlockingQueue<Integer> getStateQueue(String taskId) {
synchronized (actionStates) { synchronized (downloadStates) {
if (!actionStates.containsKey(taskId)) { if (!downloadStates.containsKey(taskId)) {
actionStates.put(taskId, new ArrayBlockingQueue<>(10)); downloadStates.put(taskId, new ArrayBlockingQueue<>(10));
} }
return actionStates.get(taskId); return downloadStates.get(taskId);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment