Commit 5856e757 by eguven Committed by Oliver Woodman

Rename DownloadAction to DownloadRequest

PiperOrigin-RevId: 243806888
parent 9fc3ea79
Showing with 258 additions and 257 deletions
......@@ -75,13 +75,13 @@ public class DemoDownloadService extends DownloadService {
notificationHelper.buildDownloadCompletedNotification(
R.drawable.ic_download_done,
/* contentIntent= */ null,
Util.fromUtf8Bytes(download.action.data));
Util.fromUtf8Bytes(download.request.data));
} else if (download.state == Download.STATE_FAILED) {
notification =
notificationHelper.buildDownloadFailedNotification(
R.drawable.ic_download_done,
/* contentIntent= */ null,
Util.fromUtf8Bytes(download.action.data));
Util.fromUtf8Bytes(download.request.data));
} else {
return;
}
......
......@@ -24,11 +24,11 @@ import android.widget.Toast;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.RenderersFactory;
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.DownloadHelper;
import com.google.android.exoplayer2.offline.DownloadIndex;
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.StreamKey;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo;
......@@ -89,7 +89,7 @@ public class DownloadTracker {
public List<StreamKey> getOfflineStreamKeys(Uri uri) {
Download download = downloads.get(uri);
return download != null && download.state != Download.STATE_FAILED
? download.action.streamKeys
? download.request.streamKeys
: Collections.emptyList();
}
......@@ -102,7 +102,7 @@ public class DownloadTracker {
Download download = downloads.get(uri);
if (download != null) {
DownloadService.startWithRemoveDownload(
context, DemoDownloadService.class, download.action.id, /* foreground= */ false);
context, DemoDownloadService.class, download.request.id, /* foreground= */ false);
} else {
if (startDownloadDialogHelper != null) {
startDownloadDialogHelper.release();
......@@ -117,18 +117,13 @@ public class DownloadTracker {
try (DownloadCursor loadedDownloads = downloadIndex.getDownloads()) {
while (loadedDownloads.moveToNext()) {
Download download = loadedDownloads.getDownload();
downloads.put(download.action.uri, download);
downloads.put(download.request.uri, download);
}
} catch (IOException 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(
Uri uri, String extension, RenderersFactory renderersFactory) {
int type = Util.inferContentType(uri, extension);
......@@ -150,7 +145,7 @@ public class DownloadTracker {
@Override
public void onDownloadChanged(DownloadManager downloadManager, Download download) {
downloads.put(download.action.uri, download);
downloads.put(download.request.uri, download);
for (Listener listener : listeners) {
listener.onDownloadsChanged();
}
......@@ -158,7 +153,7 @@ public class DownloadTracker {
@Override
public void onDownloadRemoved(DownloadManager downloadManager, Download download) {
downloads.remove(download.action.uri);
downloads.remove(download.request.uri);
for (Listener listener : listeners) {
listener.onDownloadsChanged();
}
......@@ -259,8 +254,9 @@ public class DownloadTracker {
// Internal methods.
private void startDownload() {
DownloadAction downloadAction = downloadHelper.getDownloadAction(Util.getUtf8Bytes(name));
startServiceWithAction(downloadAction);
DownloadRequest downloadRequest = downloadHelper.getDownloadRequest(Util.getUtf8Bytes(name));
DownloadService.startWithNewDownload(
context, DemoDownloadService.class, downloadRequest, /* foreground= */ false);
}
}
}
......@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.offline;
import android.net.Uri;
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.Util;
import java.io.DataInputStream;
......@@ -28,7 +28,7 @@ import java.util.ArrayList;
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
* ActionFileUpgradeUtil}.
......@@ -41,7 +41,7 @@ import java.util.List;
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) {
atomicFile = new AtomicFile(actionFile);
......@@ -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.
* @throws IOException If there is an error reading the file.
*/
public DownloadAction[] load() throws IOException {
public DownloadRequest[] load() throws IOException {
if (!exists()) {
return new DownloadAction[0];
return new DownloadRequest[0];
}
InputStream inputStream = null;
try {
......@@ -77,21 +77,21 @@ import java.util.List;
throw new IOException("Unsupported action file version: " + version);
}
int actionCount = dataInputStream.readInt();
ArrayList<DownloadAction> actions = new ArrayList<>();
ArrayList<DownloadRequest> actions = new ArrayList<>();
for (int i = 0; i < actionCount; i++) {
try {
actions.add(readDownloadAction(dataInputStream));
} catch (UnsupportedActionException e) {
// remove DownloadAction is not supported. Ignore the exception and continue loading rest.
actions.add(readDownloadRequest(dataInputStream));
} catch (UnsupportedRequestException e) {
// remove DownloadRequest is not supported. Ignore and continue loading rest.
}
}
return actions.toArray(new DownloadAction[0]);
return actions.toArray(new DownloadRequest[0]);
} finally {
Util.closeQuietly(inputStream);
}
}
private static DownloadAction readDownloadAction(DataInputStream input) throws IOException {
private static DownloadRequest readDownloadRequest(DataInputStream input) throws IOException {
String type = input.readUTF();
int version = input.readInt();
......@@ -108,7 +108,7 @@ import java.util.List;
}
// 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<>();
if (!isLegacyProgressive) {
int keyCount = input.readInt();
......@@ -120,22 +120,22 @@ import java.util.List;
// Serialized version 0 and 1 DASH/HLS/SS actions did not contain a custom cache key.
boolean isLegacySegmented =
version < 2
&& (DownloadAction.TYPE_DASH.equals(type)
|| DownloadAction.TYPE_HLS.equals(type)
|| DownloadAction.TYPE_SS.equals(type));
&& (DownloadRequest.TYPE_DASH.equals(type)
|| DownloadRequest.TYPE_HLS.equals(type)
|| DownloadRequest.TYPE_SS.equals(type));
String customCacheKey = null;
if (!isLegacySegmented) {
customCacheKey = input.readBoolean() ? input.readUTF() : null;
}
// 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) {
// 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)
......@@ -145,7 +145,7 @@ import java.util.List;
int trackIndex;
// 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) {
periodIndex = 0;
groupIndex = input.readInt();
......@@ -158,7 +158,7 @@ import java.util.List;
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();
}
}
......@@ -28,18 +28,18 @@ public final class ActionFileUpgradeUtil {
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.
*/
String getId(DownloadAction downloadAction);
String getId(DownloadRequest downloadRequest);
}
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
* deleteOnFailure} is {@code true}.
*
......@@ -49,9 +49,9 @@ public final class ActionFileUpgradeUtil {
* @param actionFilePath The action file path.
* @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.
* @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.
* @throws IOException If an error occurs loading or merging the actions.
* @throws IOException If an error occurs loading or merging the requests.
*/
@SuppressWarnings("deprecation")
public static void upgradeAndDelete(
......@@ -64,11 +64,11 @@ public final class ActionFileUpgradeUtil {
if (actionFile.exists()) {
boolean success = false;
try {
for (DownloadAction action : actionFile.load()) {
for (DownloadRequest request : actionFile.load()) {
if (downloadIdProvider != null) {
action = action.copyWithId(downloadIdProvider.getId(action));
request = request.copyWithId(downloadIdProvider.getId(request));
}
mergeAction(action, downloadIndex);
mergeRequest(request, downloadIndex);
}
success = true;
} finally {
......@@ -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 downloadIndex The index into which the action will be merged.
* @throws IOException If an error occurs merging the action.
* @param request The request to be merged.
* @param downloadIndex The index into which the request will be merged.
* @throws IOException If an error occurs merging the request.
*/
/* package */ static void mergeAction(DownloadAction action, DefaultDownloadIndex downloadIndex)
throws IOException {
Download download = downloadIndex.getDownload(action.id);
/* package */ static void mergeRequest(
DownloadRequest request, DefaultDownloadIndex downloadIndex) throws IOException {
Download download = downloadIndex.getDownload(request.id);
if (download != null) {
download = DownloadManager.mergeAction(download, action, download.manualStopReason);
download = DownloadManager.mergeRequest(download, request, download.manualStopReason);
} else {
long nowMs = System.currentTimeMillis();
download =
new Download(
action,
request,
STATE_QUEUED,
Download.FAILURE_REASON_NONE,
Download.MANUAL_STOP_REASON_NONE,
......
......@@ -194,12 +194,12 @@ public final class DefaultDownloadIndex implements DownloadIndex {
public void putDownload(Download download) throws DatabaseIOException {
ensureInitialized();
ContentValues values = new ContentValues();
values.put(COLUMN_ID, download.action.id);
values.put(COLUMN_TYPE, download.action.type);
values.put(COLUMN_URI, download.action.uri.toString());
values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.action.streamKeys));
values.put(COLUMN_CUSTOM_CACHE_KEY, download.action.customCacheKey);
values.put(COLUMN_DATA, download.action.data);
values.put(COLUMN_ID, download.request.id);
values.put(COLUMN_TYPE, download.request.type);
values.put(COLUMN_URI, download.request.uri.toString());
values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys));
values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey);
values.put(COLUMN_DATA, download.request.data);
values.put(COLUMN_STATE, download.state);
values.put(COLUMN_DOWNLOAD_PERCENTAGE, download.getDownloadPercentage());
values.put(COLUMN_DOWNLOADED_BYTES, download.getDownloadedBytes());
......@@ -342,8 +342,8 @@ public final class DefaultDownloadIndex implements DownloadIndex {
}
private static Download getDownloadForCurrentRow(Cursor cursor) {
DownloadAction action =
new DownloadAction(
DownloadRequest request =
new DownloadRequest(
cursor.getString(COLUMN_INDEX_ID),
cursor.getString(COLUMN_INDEX_TYPE),
Uri.parse(cursor.getString(COLUMN_INDEX_URI)),
......@@ -355,7 +355,7 @@ public final class DefaultDownloadIndex implements DownloadIndex {
cachingCounters.contentLength = cursor.getLong(COLUMN_INDEX_TOTAL_BYTES);
cachingCounters.percentage = cursor.getFloat(COLUMN_INDEX_DOWNLOAD_PERCENTAGE);
return new Download(
action,
request,
cursor.getInt(COLUMN_INDEX_STATE),
cursor.getInt(COLUMN_INDEX_FAILURE_REASON),
cursor.getInt(COLUMN_INDEX_MANUAL_STOP_REASON),
......
......@@ -76,32 +76,32 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
}
@Override
public Downloader createDownloader(DownloadAction action) {
switch (action.type) {
case DownloadAction.TYPE_PROGRESSIVE:
public Downloader createDownloader(DownloadRequest request) {
switch (request.type) {
case DownloadRequest.TYPE_PROGRESSIVE:
return new ProgressiveDownloader(
action.uri, action.customCacheKey, downloaderConstructorHelper);
case DownloadAction.TYPE_DASH:
return createDownloader(action, DASH_DOWNLOADER_CONSTRUCTOR);
case DownloadAction.TYPE_HLS:
return createDownloader(action, HLS_DOWNLOADER_CONSTRUCTOR);
case DownloadAction.TYPE_SS:
return createDownloader(action, SS_DOWNLOADER_CONSTRUCTOR);
request.uri, request.customCacheKey, downloaderConstructorHelper);
case DownloadRequest.TYPE_DASH:
return createDownloader(request, DASH_DOWNLOADER_CONSTRUCTOR);
case DownloadRequest.TYPE_HLS:
return createDownloader(request, HLS_DOWNLOADER_CONSTRUCTOR);
case DownloadRequest.TYPE_SS:
return createDownloader(request, SS_DOWNLOADER_CONSTRUCTOR);
default:
throw new IllegalArgumentException("Unsupported type: " + action.type);
throw new IllegalArgumentException("Unsupported type: " + request.type);
}
}
private Downloader createDownloader(
DownloadAction action, @Nullable Constructor<? extends Downloader> constructor) {
DownloadRequest request, @Nullable Constructor<? extends Downloader> constructor) {
if (constructor == null) {
throw new IllegalStateException("Module missing for: " + action.type);
throw new IllegalStateException("Module missing for: " + request.type);
}
try {
// 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) {
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 {
}
}
/** The download action. */
public final DownloadAction action;
/** The download request. */
public final DownloadRequest request;
/** The state of the download. */
@State public final int state;
......@@ -114,14 +114,14 @@ public final class Download {
/* package */ CachingCounters counters;
/* package */ Download(
DownloadAction action,
DownloadRequest request,
@State int state,
@FailureReason int failureReason,
int manualStopReason,
long startTimeMs,
long updateTimeMs) {
this(
action,
request,
state,
failureReason,
manualStopReason,
......@@ -131,7 +131,7 @@ public final class Download {
}
/* package */ Download(
DownloadAction action,
DownloadRequest request,
@State int state,
@FailureReason int failureReason,
int manualStopReason,
......@@ -143,7 +143,7 @@ public final class Download {
if (manualStopReason != 0) {
Assertions.checkState(state != STATE_DOWNLOADING && state != STATE_QUEUED);
}
this.action = action;
this.request = request;
this.state = state;
this.failureReason = failureReason;
this.manualStopReason = manualStopReason;
......
......@@ -63,7 +63,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* A helper for initializing and removing downloads.
*
* <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:
*
......@@ -74,7 +74,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* #getTrackSelections(int, int)}, and make adjustments using {@link
* #clearTrackSelections(int)}, {@link #replaceTrackSelections(int, Parameters)} and {@link
* #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()}.
* </ol>
*/
......@@ -150,7 +150,7 @@ public final class DownloadHelper {
*/
public static DownloadHelper forProgressive(Uri uri, @Nullable String cacheKey) {
return new DownloadHelper(
DownloadAction.TYPE_PROGRESSIVE,
DownloadRequest.TYPE_PROGRESSIVE,
uri,
cacheKey,
/* mediaSource= */ null,
......@@ -199,7 +199,7 @@ public final class DownloadHelper {
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
DefaultTrackSelector.Parameters trackSelectorParameters) {
return new DownloadHelper(
DownloadAction.TYPE_DASH,
DownloadRequest.TYPE_DASH,
uri,
/* cacheKey= */ null,
createMediaSource(
......@@ -249,7 +249,7 @@ public final class DownloadHelper {
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
DefaultTrackSelector.Parameters trackSelectorParameters) {
return new DownloadHelper(
DownloadAction.TYPE_HLS,
DownloadRequest.TYPE_HLS,
uri,
/* cacheKey= */ null,
createMediaSource(
......@@ -299,7 +299,7 @@ public final class DownloadHelper {
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
DefaultTrackSelector.Parameters trackSelectorParameters) {
return new DownloadHelper(
DownloadAction.TYPE_SS,
DownloadRequest.TYPE_SS,
uri,
/* cacheKey= */ null,
createMediaSource(uri, dataSourceFactory, SS_FACTORY_CONSTRUCTOR, SS_FACTORY_CREATE_METHOD),
......@@ -327,7 +327,7 @@ public final class DownloadHelper {
/**
* 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 cacheKey An optional cache key.
* @param mediaSource A {@link MediaSource} for which tracks are selected, or null if no track
......@@ -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.
*
* @param data Application provided data to store in {@link DownloadAction#data}.
* @return The built {@link DownloadAction}.
* @param data Application provided data to store in {@link DownloadRequest#data}.
* @return The built {@link DownloadRequest}.
*/
public DownloadAction getDownloadAction(@Nullable byte[] data) {
public DownloadRequest getDownloadRequest(@Nullable byte[] data) {
String downloadId = uri.toString();
if (mediaSource == null) {
return new DownloadAction(
return new DownloadRequest(
downloadId, downloadType, uri, /* streamKeys= */ Collections.emptyList(), cacheKey, data);
}
assertPreparedWithMedia();
......@@ -601,7 +601,7 @@ public final class DownloadHelper {
}
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.
......
......@@ -30,10 +30,10 @@ import java.util.Collections;
import java.util.List;
/** 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. */
public static class UnsupportedActionException extends IOException {}
/** Thrown when the encoded request data belongs to an unsupported request type. */
public static class UnsupportedRequestException extends IOException {}
/** Type for progressive downloads. */
public static final String TYPE_PROGRESSIVE = "progressive";
......@@ -46,7 +46,7 @@ public final class DownloadAction implements Parcelable {
/** The unique content id. */
public final String id;
/** The type of the action. */
/** The type of the request. */
public final String type;
/** The uri being downloaded. */
public final Uri uri;
......@@ -65,7 +65,7 @@ public final class DownloadAction implements Parcelable {
* @param customCacheKey See {@link #customCacheKey}.
* @param data See {@link #data}.
*/
public DownloadAction(
public DownloadRequest(
String id,
String type,
Uri uri,
......@@ -82,7 +82,7 @@ public final class DownloadAction implements Parcelable {
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());
type = castNonNull(in.readString());
uri = Uri.parse(castNonNull(in.readString()));
......@@ -103,40 +103,40 @@ public final class DownloadAction implements Parcelable {
* @param id The ID of the copy.
* @return The copy with the specified ID.
*/
public DownloadAction copyWithId(String id) {
return new DownloadAction(id, type, uri, streamKeys, customCacheKey, data);
public DownloadRequest copyWithId(String id) {
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}.
*
* <p>If the actions have different {@link #uri}, {@link #customCacheKey} and {@link #data}
* values, then those from the action being merged are included in the result.
* <p>If the requests have different {@link #uri}, {@link #customCacheKey} and {@link #data}
* 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.
* @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}.
*/
public DownloadAction copyWithMergedAction(DownloadAction newAction) {
Assertions.checkArgument(id.equals(newAction.id));
Assertions.checkArgument(type.equals(newAction.type));
public DownloadRequest copyWithMergedRequest(DownloadRequest newRequest) {
Assertions.checkArgument(id.equals(newRequest.id));
Assertions.checkArgument(type.equals(newRequest.type));
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.
mergedKeys = Collections.emptyList();
} else {
mergedKeys = new ArrayList<>(streamKeys);
for (int i = 0; i < newAction.streamKeys.size(); i++) {
StreamKey newKey = newAction.streamKeys.get(i);
for (int i = 0; i < newRequest.streamKeys.size(); i++) {
StreamKey newKey = newRequest.streamKeys.get(i);
if (!mergedKeys.contains(newKey)) {
mergedKeys.add(newKey);
}
}
}
return new DownloadAction(
id, type, newAction.uri, mergedKeys, newAction.customCacheKey, newAction.data);
return new DownloadRequest(
id, type, newRequest.uri, mergedKeys, newRequest.customCacheKey, newRequest.data);
}
@Override
......@@ -146,10 +146,10 @@ public final class DownloadAction implements Parcelable {
@Override
public boolean equals(@Nullable Object o) {
if (!(o instanceof DownloadAction)) {
if (!(o instanceof DownloadRequest)) {
return false;
}
DownloadAction that = (DownloadAction) o;
DownloadRequest that = (DownloadRequest) o;
return id.equals(that.id)
&& type.equals(that.type)
&& uri.equals(that.uri)
......@@ -191,17 +191,17 @@ public final class DownloadAction implements Parcelable {
dest.writeByteArray(data);
}
public static final Parcelable.Creator<DownloadAction> CREATOR =
new Parcelable.Creator<DownloadAction>() {
public static final Parcelable.Creator<DownloadRequest> CREATOR =
new Parcelable.Creator<DownloadRequest>() {
@Override
public DownloadAction createFromParcel(Parcel in) {
return new DownloadAction(in);
public DownloadRequest createFromParcel(Parcel in) {
return new DownloadRequest(in);
}
@Override
public DownloadAction[] newArray(int size) {
return new DownloadAction[size];
public DownloadRequest[] newArray(int size) {
return new DownloadRequest[size];
}
};
}
......@@ -39,7 +39,7 @@ import java.util.List;
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>
* <li>{@link #KEY_FOREGROUND} - See {@link #KEY_FOREGROUND}.
......@@ -56,7 +56,7 @@ public abstract class DownloadService extends Service {
* Adds a new download. Extras:
*
* <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.
* <li>{@link #KEY_MANUAL_STOP_REASON} - An initial manual stop reason for the download. If
* omitted {@link Download#MANUAL_STOP_REASON_NONE} is used.
......@@ -103,7 +103,7 @@ public abstract class DownloadService extends Service {
"com.google.android.exoplayer.downloadService.action.SET_MANUAL_STOP_REASON";
/**
* Removes an existing download. Extras:
* Removes a download. Extras:
*
* <ul>
* <li>{@link #KEY_CONTENT_ID} - The content id of a download to remove.
......@@ -113,11 +113,8 @@ public abstract class DownloadService extends Service {
public static final String ACTION_REMOVE =
"com.google.android.exoplayer.downloadService.action.REMOVE";
/**
* Key for the {@code byte[]} representation of the {@link DownloadAction} in {@link #ACTION_ADD}
* intents.
*/
public static final String KEY_DOWNLOAD_ACTION = "download_action";
/** Key for the {@link DownloadRequest} in {@link #ACTION_ADD} intents. */
public static final String KEY_DOWNLOAD_REQUEST = "download_request";
/**
* Key for the content id in {@link #ACTION_START}, {@link #ACTION_STOP} and {@link
......@@ -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 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.
* @return Created Intent.
*/
public static Intent buildAddActionIntent(
public static Intent buildAddRequestIntent(
Context context,
Class<? extends DownloadService> clazz,
DownloadAction downloadAction,
DownloadRequest downloadRequest,
boolean foreground) {
return buildAddActionIntent(
context, clazz, downloadAction, MANUAL_STOP_REASON_NONE, foreground);
return buildAddRequestIntent(
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 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
* 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.
* @return Created Intent.
*/
public static Intent buildAddActionIntent(
public static Intent buildAddRequestIntent(
Context context,
Class<? extends DownloadService> clazz,
DownloadAction downloadAction,
DownloadRequest downloadRequest,
int manualStopReason,
boolean foreground) {
return getIntent(context, clazz, ACTION_ADD)
.putExtra(KEY_DOWNLOAD_ACTION, downloadAction)
.putExtra(KEY_DOWNLOAD_REQUEST, downloadRequest)
.putExtra(KEY_MANUAL_STOP_REASON, manualStopReason)
.putExtra(KEY_FOREGROUND, foreground);
}
......@@ -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 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.
*/
public static void startWithAction(
public static void startWithNewDownload(
Context context,
Class<? extends DownloadService> clazz,
DownloadAction downloadAction,
DownloadRequest downloadRequest,
boolean foreground) {
Intent intent = buildAddActionIntent(context, clazz, downloadAction, foreground);
Intent intent = buildAddRequestIntent(context, clazz, downloadRequest, foreground);
if (foreground) {
Util.startForegroundService(context, intent);
} else {
......@@ -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
* requirements are met, the service resumes executing actions. Otherwise it stops immediately.
* Starts a download service to resume any ongoing downloads.
*
* @param context A {@link Context}.
* @param clazz The concrete download service to be started.
......@@ -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
* actions and the requirements are met, the service resumes executing actions. Otherwise it stops
* immediately.
* Starts the service in the foreground without adding a new download request. If there are any
* not finished downloads and the requirements are met, the service resumes downloading. Otherwise
* it stops immediately.
*
* @param context A {@link Context}.
* @param clazz The concrete download service to be started.
......@@ -417,13 +413,13 @@ public abstract class DownloadService extends Service {
// Do nothing.
break;
case ACTION_ADD:
DownloadAction downloadAction = intent.getParcelableExtra(KEY_DOWNLOAD_ACTION);
if (downloadAction == null) {
Log.e(TAG, "Ignored ADD: Missing download_action extra");
DownloadRequest downloadRequest = intent.getParcelableExtra(KEY_DOWNLOAD_REQUEST);
if (downloadRequest == null) {
Log.e(TAG, "Ignored ADD: Missing " + KEY_DOWNLOAD_REQUEST + " extra");
} else {
int manualStopReason =
intent.getIntExtra(KEY_MANUAL_STOP_REASON, Download.MANUAL_STOP_REASON_NONE);
downloadManager.addDownload(downloadAction, manualStopReason);
downloadManager.addDownload(downloadRequest, manualStopReason);
}
break;
case ACTION_START:
......@@ -434,7 +430,8 @@ public abstract class DownloadService extends Service {
break;
case ACTION_SET_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 {
String contentId = intent.getStringExtra(KEY_CONTENT_ID);
int manualStopReason =
......@@ -445,7 +442,7 @@ public abstract class DownloadService extends Service {
case ACTION_REMOVE:
String contentId = intent.getStringExtra(KEY_CONTENT_ID);
if (contentId == null) {
Log.e(TAG, "Ignored REMOVE: Missing content_id extra");
Log.e(TAG, "Ignored REMOVE: Missing " + KEY_CONTENT_ID + " extra");
} else {
downloadManager.removeDownload(contentId);
}
......
......@@ -15,14 +15,14 @@
*/
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 {
/**
* Creates a {@link Downloader} to perform the given {@link DownloadAction}.
* Creates a {@link Downloader} to perform the given {@link DownloadRequest}.
*
* @param action The action.
* @return The downloader.
*/
Downloader createDownloader(DownloadAction action);
Downloader createDownloader(DownloadRequest action);
}
......@@ -33,20 +33,21 @@ import org.junit.Test;
import org.junit.runner.RunWith;
/** Unit tests for {@link ActionFile}. */
@SuppressWarnings("deprecation")
@RunWith(AndroidJUnit4.class)
public class ActionFileTest {
private File tempFile;
private DownloadAction expectedAction1;
private DownloadAction expectedAction2;
private DownloadRequest expectedAction1;
private DownloadRequest expectedAction2;
@Before
public void setUp() throws Exception {
tempFile = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
expectedAction1 =
buildExpectedAction(Uri.parse("http://test1.uri"), TestUtil.buildTestData(16));
buildExpectedRequest(Uri.parse("http://test1.uri"), TestUtil.buildTestData(16));
expectedAction2 =
buildExpectedAction(Uri.parse("http://test2.uri"), TestUtil.buildTestData(32));
buildExpectedRequest(Uri.parse("http://test2.uri"), TestUtil.buildTestData(32));
}
@After
......@@ -79,7 +80,7 @@ public class ActionFileTest {
@Test
public void testLoadZeroActions() throws Exception {
ActionFile actionFile = getActionFile("offline/action_file_zero_actions.exi");
DownloadAction[] actions = actionFile.load();
DownloadRequest[] actions = actionFile.load();
assertThat(actions).isNotNull();
assertThat(actions).hasLength(0);
}
......@@ -87,7 +88,7 @@ public class ActionFileTest {
@Test
public void testLoadOneAction() throws Exception {
ActionFile actionFile = getActionFile("offline/action_file_one_action.exi");
DownloadAction[] actions = actionFile.load();
DownloadRequest[] actions = actionFile.load();
assertThat(actions).hasLength(1);
assertThat(actions[0]).isEqualTo(expectedAction1);
}
......@@ -95,7 +96,7 @@ public class ActionFileTest {
@Test
public void testLoadTwoActions() throws Exception {
ActionFile actionFile = getActionFile("offline/action_file_two_actions.exi");
DownloadAction[] actions = actionFile.load();
DownloadRequest[] actions = actionFile.load();
assertThat(actions).hasLength(2);
assertThat(actions[0]).isEqualTo(expectedAction1);
assertThat(actions[1]).isEqualTo(expectedAction2);
......@@ -123,10 +124,10 @@ public class ActionFileTest {
return new ActionFile(tempFile);
}
private static DownloadAction buildExpectedAction(Uri uri, byte[] data) {
return new DownloadAction(
private static DownloadRequest buildExpectedRequest(Uri uri, byte[] data) {
return new DownloadRequest(
/* id= */ uri.toString(),
DownloadAction.TYPE_PROGRESSIVE,
DownloadRequest.TYPE_PROGRESSIVE,
uri,
/* streamKeys= */ Collections.emptyList(),
/* customCacheKey= */ null,
......
......@@ -15,7 +15,7 @@
*/
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 android.net.Uri;
......@@ -70,16 +70,16 @@ public class ActionFileUpgradeUtilTest {
new StreamKey(/* periodIndex= */ 3, /* groupIndex= */ 4, /* trackIndex= */ 5);
StreamKey expectedStreamKey2 =
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 2);
DownloadAction expectedAction1 =
new DownloadAction(
DownloadRequest expectedRequest1 =
new DownloadRequest(
"key123",
TYPE_DASH,
Uri.parse("https://www.test.com/download1"),
asList(expectedStreamKey1),
/* customCacheKey= */ "key123",
new byte[] {1, 2, 3, 4});
DownloadAction expectedAction2 =
new DownloadAction(
DownloadRequest expectedRequest2 =
new DownloadRequest(
"key234",
TYPE_DASH,
Uri.parse("https://www.test.com/download2"),
......@@ -90,15 +90,15 @@ public class ActionFileUpgradeUtilTest {
ActionFileUpgradeUtil.upgradeAndDelete(
tempFile, /* downloadIdProvider= */ null, downloadIndex, /* deleteOnFailure= */ true);
assertDownloadIndexContainsAction(expectedAction1, Download.STATE_QUEUED);
assertDownloadIndexContainsAction(expectedAction2, Download.STATE_QUEUED);
assertDownloadIndexContainsRequest(expectedRequest1, Download.STATE_QUEUED);
assertDownloadIndexContainsRequest(expectedRequest2, Download.STATE_QUEUED);
}
@Test
public void mergeAction_nonExistingDownload_createsNewDownload() throws IOException {
public void mergeRequest_nonExistingDownload_createsNewDownload() throws IOException {
byte[] data = new byte[] {1, 2, 3, 4};
DownloadAction action =
new DownloadAction(
DownloadRequest request =
new DownloadRequest(
"id",
TYPE_DASH,
Uri.parse("https://www.test.com/download"),
......@@ -108,50 +108,50 @@ public class ActionFileUpgradeUtilTest {
/* customCacheKey= */ "key123",
data);
ActionFileUpgradeUtil.mergeAction(action, downloadIndex);
ActionFileUpgradeUtil.mergeRequest(request, downloadIndex);
assertDownloadIndexContainsAction(action, Download.STATE_QUEUED);
assertDownloadIndexContainsRequest(request, Download.STATE_QUEUED);
}
@Test
public void mergeAction_existingDownload_createsMergedDownload() throws IOException {
public void mergeRequest_existingDownload_createsMergedDownload() throws IOException {
StreamKey streamKey1 =
new StreamKey(/* periodIndex= */ 3, /* groupIndex= */ 4, /* trackIndex= */ 5);
StreamKey streamKey2 =
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 2);
DownloadAction action1 =
new DownloadAction(
DownloadRequest request1 =
new DownloadRequest(
"id",
TYPE_DASH,
Uri.parse("https://www.test.com/download1"),
asList(streamKey1),
/* customCacheKey= */ "key123",
new byte[] {1, 2, 3, 4});
DownloadAction action2 =
new DownloadAction(
DownloadRequest request2 =
new DownloadRequest(
"id",
TYPE_DASH,
Uri.parse("https://www.test.com/download2"),
asList(streamKey2),
/* customCacheKey= */ "key123",
new byte[] {5, 4, 3, 2, 1});
ActionFileUpgradeUtil.mergeAction(action1, downloadIndex);
ActionFileUpgradeUtil.mergeAction(action2, downloadIndex);
ActionFileUpgradeUtil.mergeRequest(request1, downloadIndex);
ActionFileUpgradeUtil.mergeRequest(request2, downloadIndex);
Download download = downloadIndex.getDownload(action2.id);
Download download = downloadIndex.getDownload(request2.id);
assertThat(download).isNotNull();
assertThat(download.action.type).isEqualTo(action2.type);
assertThat(download.action.customCacheKey).isEqualTo(action2.customCacheKey);
assertThat(download.action.data).isEqualTo(action2.data);
assertThat(download.action.uri).isEqualTo(action2.uri);
assertThat(download.action.streamKeys).containsExactly(streamKey1, streamKey2);
assertThat(download.request.type).isEqualTo(request2.type);
assertThat(download.request.customCacheKey).isEqualTo(request2.customCacheKey);
assertThat(download.request.data).isEqualTo(request2.data);
assertThat(download.request.uri).isEqualTo(request2.uri);
assertThat(download.request.streamKeys).containsExactly(streamKey1, streamKey2);
assertThat(download.state).isEqualTo(Download.STATE_QUEUED);
}
private void assertDownloadIndexContainsAction(DownloadAction action, int state)
private void assertDownloadIndexContainsRequest(DownloadRequest request, int state)
throws IOException {
Download download = downloadIndex.getDownload(action.id);
assertThat(download.action).isEqualTo(action);
Download download = downloadIndex.getDownload(request.id);
assertThat(download.request).isEqualTo(request);
assertThat(download.state).isEqualTo(state);
}
......
......@@ -301,7 +301,7 @@ public class DefaultDownloadIndexTest {
}
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.startTimeMs).isEqualTo(that.startTimeMs);
assertThat(download.updateTimeMs).isEqualTo(that.updateTimeMs);
......
......@@ -38,9 +38,9 @@ public final class DefaultDownloaderFactoryTest {
Downloader downloader =
factory.createDownloader(
new DownloadAction(
new DownloadRequest(
"id",
DownloadAction.TYPE_PROGRESSIVE,
DownloadRequest.TYPE_PROGRESSIVE,
Uri.parse("https://www.test.com/download"),
/* streamKeys= */ Collections.emptyList(),
/* customCacheKey= */ null,
......
......@@ -47,8 +47,14 @@ class DownloadBuilder {
this(id, "type", Uri.parse("uri"), /* cacheKey= */ null, new byte[0], Collections.emptyList());
}
DownloadBuilder(DownloadAction action) {
this(action.id, action.type, action.uri, action.customCacheKey, action.data, action.streamKeys);
DownloadBuilder(DownloadRequest request) {
this(
request.id,
request.type,
request.uri,
request.customCacheKey,
request.data,
request.streamKeys);
}
DownloadBuilder(
......@@ -147,8 +153,9 @@ class DownloadBuilder {
}
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(
action, state, failureReason, manualStopReason, startTimeMs, updateTimeMs, counters);
request, state, failureReason, manualStopReason, startTimeMs, updateTimeMs, counters);
}
}
......@@ -379,7 +379,7 @@ public class DownloadHelperTest {
}
@Test
public void getDownloadAction_createsDownloadAction_withAllSelectedTracks() throws Exception {
public void getDownloadRequest_createsDownloadRequest_withAllSelectedTracks() throws Exception {
prepareDownloadHelper(downloadHelper);
// Ensure we have track groups with multiple indices, renderers with multiple track groups and
// also renderers without any track groups.
......@@ -392,13 +392,13 @@ public class DownloadHelperTest {
byte[] data = new byte[10];
Arrays.fill(data, (byte) 123);
DownloadAction downloadAction = downloadHelper.getDownloadAction(data);
DownloadRequest downloadRequest = downloadHelper.getDownloadRequest(data);
assertThat(downloadAction.type).isEqualTo(TEST_DOWNLOAD_TYPE);
assertThat(downloadAction.uri).isEqualTo(testUri);
assertThat(downloadAction.customCacheKey).isEqualTo(TEST_CACHE_KEY);
assertThat(downloadAction.data).isEqualTo(data);
assertThat(downloadAction.streamKeys)
assertThat(downloadRequest.type).isEqualTo(TEST_DOWNLOAD_TYPE);
assertThat(downloadRequest.uri).isEqualTo(testUri);
assertThat(downloadRequest.customCacheKey).isEqualTo(TEST_CACHE_KEY);
assertThat(downloadRequest.data).isEqualTo(data);
assertThat(downloadRequest.streamKeys)
.containsExactly(
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 0),
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 1),
......
......@@ -29,8 +29,8 @@ import android.net.Uri;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
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.DownloadRequest;
import com.google.android.exoplayer2.offline.Downloader;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.DownloaderFactory;
......@@ -84,9 +84,9 @@ public class DashDownloaderTest {
Downloader downloader =
factory.createDownloader(
new DownloadAction(
new DownloadRequest(
"id",
DownloadAction.TYPE_DASH,
DownloadRequest.TYPE_DASH,
Uri.parse("https://www.test.com/download"),
Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)),
/* customCacheKey= */ null,
......
......@@ -28,8 +28,8 @@ import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.offline.DefaultDownloadIndex;
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.DownloadRequest;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.StreamKey;
import com.google.android.exoplayer2.scheduler.Requirements;
......@@ -132,7 +132,7 @@ public class DownloadManagerDashTest {
dummyMainThread.runOnMainThread(
() -> {
// Setup an Action and immediately release the DM.
handleDownloadAction(fakeStreamKey1, fakeStreamKey2);
handleDownloadRequest(fakeStreamKey1, fakeStreamKey2);
downloadManager.release();
});
......@@ -149,29 +149,29 @@ public class DownloadManagerDashTest {
}
@Test
public void testHandleDownloadAction() throws Throwable {
handleDownloadAction(fakeStreamKey1, fakeStreamKey2);
public void testHandleDownloadRequest() throws Throwable {
handleDownloadRequest(fakeStreamKey1, fakeStreamKey2);
blockUntilTasksCompleteAndThrowAnyDownloadError();
assertCachedData(cache, fakeDataSet);
}
@Test
public void testHandleMultipleDownloadAction() throws Throwable {
handleDownloadAction(fakeStreamKey1);
handleDownloadAction(fakeStreamKey2);
public void testHandleMultipleDownloadRequest() throws Throwable {
handleDownloadRequest(fakeStreamKey1);
handleDownloadRequest(fakeStreamKey2);
blockUntilTasksCompleteAndThrowAnyDownloadError();
assertCachedData(cache, fakeDataSet);
}
@Test
public void testHandleInterferingDownloadAction() throws Throwable {
public void testHandleInterferingDownloadRequest() throws Throwable {
fakeDataSet
.newData("audio_segment_2")
.appendReadAction(() -> handleDownloadAction(fakeStreamKey2))
.appendReadAction(() -> handleDownloadRequest(fakeStreamKey2))
.appendReadData(TestUtil.buildTestData(5))
.endData();
handleDownloadAction(fakeStreamKey1);
handleDownloadRequest(fakeStreamKey1);
blockUntilTasksCompleteAndThrowAnyDownloadError();
assertCachedData(cache, fakeDataSet);
......@@ -179,7 +179,7 @@ public class DownloadManagerDashTest {
@Test
public void testHandleRemoveAction() throws Throwable {
handleDownloadAction(fakeStreamKey1);
handleDownloadRequest(fakeStreamKey1);
blockUntilTasksCompleteAndThrowAnyDownloadError();
......@@ -194,7 +194,7 @@ public class DownloadManagerDashTest {
@Ignore
@Test
public void testHandleRemoveActionBeforeDownloadFinish() throws Throwable {
handleDownloadAction(fakeStreamKey1);
handleDownloadRequest(fakeStreamKey1);
handleRemoveAction();
blockUntilTasksCompleteAndThrowAnyDownloadError();
......@@ -213,7 +213,7 @@ public class DownloadManagerDashTest {
.appendReadData(TestUtil.buildTestData(5))
.endData();
handleDownloadAction(fakeStreamKey1);
handleDownloadRequest(fakeStreamKey1);
assertThat(downloadInProgressCondition.block(ASSERT_TRUE_TIMEOUT)).isTrue();
......@@ -228,13 +228,13 @@ public class DownloadManagerDashTest {
downloadManagerListener.blockUntilTasksCompleteAndThrowAnyDownloadError();
}
private void handleDownloadAction(StreamKey... keys) {
private void handleDownloadRequest(StreamKey... keys) {
ArrayList<StreamKey> keysList = new ArrayList<>();
Collections.addAll(keysList, keys);
DownloadAction action =
new DownloadAction(
DownloadRequest action =
new DownloadRequest(
TEST_ID,
DownloadAction.TYPE_DASH,
DownloadRequest.TYPE_DASH,
TEST_MPD_URI,
keysList,
/* customCacheKey= */ null,
......
......@@ -30,8 +30,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.offline.DefaultDownloadIndex;
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory;
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.DownloadRequest;
import com.google.android.exoplayer2.offline.DownloadService;
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.StreamKey;
......@@ -159,7 +159,7 @@ public class DownloadServiceDashTest {
@Ignore // b/78877092
@Test
public void testMultipleDownloadAction() throws Throwable {
public void testMultipleDownloadRequest() throws Throwable {
downloadKeys(fakeStreamKey1);
downloadKeys(fakeStreamKey2);
......@@ -208,10 +208,10 @@ public class DownloadServiceDashTest {
private void downloadKeys(StreamKey... keys) {
ArrayList<StreamKey> keysList = new ArrayList<>();
Collections.addAll(keysList, keys);
DownloadAction action =
new DownloadAction(
DownloadRequest action =
new DownloadRequest(
TEST_ID,
DownloadAction.TYPE_DASH,
DownloadRequest.TYPE_DASH,
TEST_MPD_URI,
keysList,
/* customCacheKey= */ null,
......@@ -219,7 +219,7 @@ public class DownloadServiceDashTest {
dummyMainThread.runOnMainThread(
() -> {
Intent startIntent =
DownloadService.buildAddActionIntent(
DownloadService.buildAddRequestIntent(
context, DownloadService.class, action, /* foreground= */ false);
dashDownloadService.onStartCommand(startIntent, 0, 0);
});
......
......@@ -38,7 +38,7 @@ import android.net.Uri;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
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.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.DownloaderFactory;
......@@ -101,9 +101,9 @@ public class HlsDownloaderTest {
Downloader downloader =
factory.createDownloader(
new DownloadAction(
new DownloadRequest(
"id",
DownloadAction.TYPE_HLS,
DownloadRequest.TYPE_HLS,
Uri.parse("https://www.test.com/download"),
Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)),
/* customCacheKey= */ null,
......
......@@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.net.Uri;
import androidx.test.ext.junit.runners.AndroidJUnit4;
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.DownloaderConstructorHelper;
import com.google.android.exoplayer2.offline.DownloaderFactory;
......@@ -44,9 +44,9 @@ public final class SsDownloaderTest {
Downloader downloader =
factory.createDownloader(
new DownloadAction(
new DownloadRequest(
"id",
DownloadAction.TYPE_SS,
DownloadRequest.TYPE_SS,
Uri.parse("https://www.test.com/download"),
Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)),
/* customCacheKey= */ null,
......
......@@ -38,7 +38,7 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
private final DownloadManager downloadManager;
private final DummyMainThread dummyMainThread;
private final HashMap<String, ArrayBlockingQueue<Integer>> actionStates;
private final HashMap<String, ArrayBlockingQueue<Integer>> downloadStates;
private final ConditionVariable initializedCondition;
private CountDownLatch downloadFinishedCondition;
......@@ -48,7 +48,7 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
DownloadManager downloadManager, DummyMainThread dummyMainThread) {
this.downloadManager = downloadManager;
this.dummyMainThread = dummyMainThread;
actionStates = new HashMap<>();
downloadStates = new HashMap<>();
initializedCondition = new ConditionVariable();
downloadManager.addListener(this);
}
......@@ -73,12 +73,12 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
if (download.state == Download.STATE_FAILED) {
failureReason = download.failureReason;
}
getStateQueue(download.action.id).add(download.state);
getStateQueue(download.request.id).add(download.state);
}
@Override
public void onDownloadRemoved(DownloadManager downloadManager, Download download) {
getStateQueue(download.action.id).add(STATE_REMOVED);
getStateQueue(download.request.id).add(STATE_REMOVED);
}
@Override
......@@ -114,11 +114,11 @@ public final class TestDownloadManagerListener implements DownloadManager.Listen
}
private ArrayBlockingQueue<Integer> getStateQueue(String taskId) {
synchronized (actionStates) {
if (!actionStates.containsKey(taskId)) {
actionStates.put(taskId, new ArrayBlockingQueue<>(10));
synchronized (downloadStates) {
if (!downloadStates.containsKey(taskId)) {
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