Skip to content

Commit eaf4a2b

Browse files
icbakertianyif
authored andcommitted
Tighten the demo app's handling of DrmInitData for downloads
This code is Widevine specific. `OfflineLicenseHelper.downloadLicense` requires the passed `Format` to have a `DrmInitData.SchemeData` with Widevine UUID and non-null `data` field. The demo app tries to check this in advance (to avoid an exception later), but its checks are looser than those made by `OfflineLicenseHelper`. This change tightens the checks to match. Issue: androidx#512 PiperOrigin-RevId: 549587506 (cherry picked from commit 1ccedf8)
1 parent 7352a1b commit eaf4a2b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

demos/main/src/main/java/androidx/media3/demo/main/DownloadTracker.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import androidx.annotation.OptIn;
2727
import androidx.annotation.RequiresApi;
2828
import androidx.fragment.app.FragmentManager;
29+
import androidx.media3.common.C;
2930
import androidx.media3.common.DrmInitData;
3031
import androidx.media3.common.Format;
3132
import androidx.media3.common.MediaItem;
@@ -51,6 +52,7 @@
5152
import androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo;
5253
import java.io.IOException;
5354
import java.util.HashMap;
55+
import java.util.UUID;
5456
import java.util.concurrent.CopyOnWriteArraySet;
5557

5658
/** Tracks media that has been downloaded. */
@@ -202,7 +204,7 @@ public void onPrepared(DownloadHelper helper) {
202204
return;
203205
}
204206
// TODO(internal b/163107948): Support cases where DrmInitData are not in the manifest.
205-
if (!hasSchemaData(format.drmInitData)) {
207+
if (!hasNonNullWidevineSchemaData(format.drmInitData)) {
206208
Toast.makeText(context, R.string.download_start_error_offline_license, Toast.LENGTH_LONG)
207209
.show();
208210
Log.e(
@@ -323,12 +325,14 @@ private void onDownloadPrepared(DownloadHelper helper) {
323325
}
324326

325327
/**
326-
* Returns whether any the {@link DrmInitData.SchemeData} contained in {@code drmInitData} has
327-
* non-null {@link DrmInitData.SchemeData#data}.
328+
* Returns whether any {@link DrmInitData.SchemeData} that {@linkplain
329+
* DrmInitData.SchemeData#matches(UUID) matches} {@link C#WIDEVINE_UUID} has non-null {@link
330+
* DrmInitData.SchemeData#data}.
328331
*/
329-
private boolean hasSchemaData(DrmInitData drmInitData) {
332+
private boolean hasNonNullWidevineSchemaData(DrmInitData drmInitData) {
330333
for (int i = 0; i < drmInitData.schemeDataCount; i++) {
331-
if (drmInitData.get(i).hasData()) {
334+
DrmInitData.SchemeData schemeData = drmInitData.get(i);
335+
if (schemeData.matches(C.WIDEVINE_UUID) && schemeData.hasData()) {
332336
return true;
333337
}
334338
}

0 commit comments

Comments
 (0)