DefaultDownloaderFactory: upgrade deprecated call

Replace the use of Downloader deprecrated constructor calls.

PiperOrigin-RevId: 322357118
This commit is contained in:
christosts 2020-07-21 15:39:03 +01:00 committed by Oliver Woodman
parent d77ce9eda0
commit 6ace2c9460
5 changed files with 24 additions and 21 deletions

View File

@ -51,15 +51,15 @@
# Constructors accessed via reflection in DefaultDownloaderFactory
-dontnote com.google.android.exoplayer2.source.dash.offline.DashDownloader
-keepclassmembers class com.google.android.exoplayer2.source.dash.offline.DashDownloader {
<init>(android.net.Uri, java.util.List, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
<init>(com.google.android.exoplayer2.MediaItem, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
}
-dontnote com.google.android.exoplayer2.source.hls.offline.HlsDownloader
-keepclassmembers class com.google.android.exoplayer2.source.hls.offline.HlsDownloader {
<init>(android.net.Uri, java.util.List, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
<init>(com.google.android.exoplayer2.MediaItem, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
}
-dontnote com.google.android.exoplayer2.source.smoothstreaming.offline.SsDownloader
-keepclassmembers class com.google.android.exoplayer2.source.smoothstreaming.offline.SsDownloader {
<init>(android.net.Uri, java.util.List, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
<init>(com.google.android.exoplayer2.MediaItem, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
}
# Constructors accessed via reflection in DefaultMediaSourceFactory

View File

@ -304,6 +304,8 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
}
private void putDownloadInternal(Download download, SQLiteDatabase database) {
byte[] keySetId =
download.request.keySetId == null ? Util.EMPTY_BYTE_ARRAY : download.request.keySetId;
ContentValues values = new ContentValues();
values.put(COLUMN_ID, download.request.id);
values.put(COLUMN_MIME_TYPE, download.request.mimeType);
@ -319,7 +321,7 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
values.put(COLUMN_FAILURE_REASON, download.failureReason);
values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded());
values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded());
values.put(COLUMN_KEY_SET_ID, download.request.keySetId);
values.put(COLUMN_KEY_SET_ID, keySetId);
database.replaceOrThrow(tableName, /* nullColumnHack= */ null, values);
}
@ -430,13 +432,14 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
}
private static Download getDownloadForCurrentRow(Cursor cursor) {
byte[] keySetId = cursor.getBlob(COLUMN_INDEX_KEY_SET_ID);
DownloadRequest request =
new DownloadRequest(
/* id= */ cursor.getString(COLUMN_INDEX_ID),
/* uri= */ Uri.parse(cursor.getString(COLUMN_INDEX_URI)),
/* mimeType= */ cursor.getString(COLUMN_INDEX_MIME_TYPE),
/* streamKeys= */ decodeStreamKeys(cursor.getString(COLUMN_INDEX_STREAM_KEYS)),
/* keySetId= */ cursor.getBlob(COLUMN_INDEX_KEY_SET_ID),
/* keySetId= */ keySetId.length > 0 ? keySetId : null,
/* customCacheKey= */ cursor.getString(COLUMN_INDEX_CUSTOM_CACHE_KEY),
/* data= */ cursor.getBlob(COLUMN_INDEX_DATA));
DownloadProgress downloadProgress = new DownloadProgress();

View File

@ -15,7 +15,6 @@
*/
package com.google.android.exoplayer2.offline;
import android.net.Uri;
import android.util.SparseArray;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
@ -24,7 +23,6 @@ import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.concurrent.Executor;
/**
@ -95,9 +93,15 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
if (constructor == null) {
throw new IllegalStateException("Module missing for content type " + contentType);
}
MediaItem mediaItem =
new MediaItem.Builder()
.setUri(request.uri)
.setStreamKeys(request.streamKeys)
.setCustomCacheKey(request.customCacheKey)
.setDrmKeySetId(request.keySetId)
.build();
try {
return constructor.newInstance(
request.uri, request.streamKeys, cacheDataSourceFactory, executor);
return constructor.newInstance(mediaItem, cacheDataSourceFactory, executor);
} catch (Exception e) {
throw new IllegalStateException(
"Failed to instantiate downloader for content type " + contentType);
@ -140,7 +144,7 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
try {
return clazz
.asSubclass(Downloader.class)
.getConstructor(Uri.class, List.class, CacheDataSource.Factory.class, Executor.class);
.getConstructor(MediaItem.class, CacheDataSource.Factory.class, Executor.class);
} catch (NoSuchMethodException e) {
// The downloader is present, but the expected constructor is missing.
throw new IllegalStateException("Downloader constructor missing", e);

View File

@ -48,11 +48,8 @@ public final class DownloadRequest implements Parcelable {
@Nullable public final String mimeType;
/** Stream keys to be downloaded. If empty, all streams will be downloaded. */
public final List<StreamKey> streamKeys;
/**
* The key set id of the offline licence if the content is protected with DRM, or empty if no
* license is needed.
*/
public final byte[] keySetId;
/** The key set id of the offline licence if the content is protected with DRM. */
@Nullable public final byte[] keySetId;
/**
* Custom key for cache indexing, or null. Must be null for DASH, HLS and SmoothStreaming
* downloads.
@ -88,8 +85,7 @@ public final class DownloadRequest implements Parcelable {
ArrayList<StreamKey> mutableKeys = new ArrayList<>(streamKeys);
Collections.sort(mutableKeys);
this.streamKeys = Collections.unmodifiableList(mutableKeys);
this.keySetId =
keySetId != null ? Arrays.copyOf(keySetId, keySetId.length) : Util.EMPTY_BYTE_ARRAY;
this.keySetId = keySetId != null ? Arrays.copyOf(keySetId, keySetId.length) : null;
this.customCacheKey = customCacheKey;
this.data = data != null ? Arrays.copyOf(data, data.length) : Util.EMPTY_BYTE_ARRAY;
}
@ -104,7 +100,7 @@ public final class DownloadRequest implements Parcelable {
mutableStreamKeys.add(in.readParcelable(StreamKey.class.getClassLoader()));
}
streamKeys = Collections.unmodifiableList(mutableStreamKeys);
keySetId = castNonNull(in.createByteArray());
keySetId = in.createByteArray();
customCacheKey = in.readString();
data = castNonNull(in.createByteArray());
}

View File

@ -41,7 +41,7 @@ public final class DownloadBuilder {
private Uri uri;
@Nullable private String mimeType;
private List<StreamKey> streamKeys;
private byte[] keySetId;
@Nullable private byte[] keySetId;
@Nullable private String cacheKey;
private byte[] customMetadata;
@ -63,7 +63,7 @@ public final class DownloadBuilder {
Uri.parse("uri"),
/* mimeType= */ null,
/* streamKeys= */ Collections.emptyList(),
/* keySetId= */ new byte[0],
/* keySetId= */ null,
/* cacheKey= */ null,
/* customMetadata= */ new byte[0]);
}
@ -90,7 +90,7 @@ public final class DownloadBuilder {
Uri uri,
@Nullable String mimeType,
List<StreamKey> streamKeys,
byte[] keySetId,
@Nullable byte[] keySetId,
@Nullable String cacheKey,
byte[] customMetadata) {
this.id = id;