-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[APT-10393] Support Rotating Content URLs #46
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ internal interface DownloadEngine { | |
fun removeDownload(audioPlayable: AudioPlayable) | ||
fun removeAllDownloads() | ||
fun updateProgress() | ||
fun redownloadDrmLicense(request: AudioPlayable.MediaRequest) | ||
fun redownloadDrmLicense(id: String, request: AudioPlayable.MediaRequest) | ||
} | ||
|
||
/** | ||
|
@@ -70,15 +70,20 @@ internal class ExoplayerDownloadEngine @Inject constructor( | |
scope.launch(errorHandler) { | ||
launch { | ||
// Download DRM license for offline use | ||
offlineDrmManager.downloadDrmLicenseForOffline(audioPlayable.request) | ||
offlineDrmManager.downloadDrmLicenseForOffline(id = audioPlayable.id.toString(), request = audioPlayable.request) | ||
} | ||
|
||
launch { | ||
val downloadHelper = downloadHelper(context, audioPlayable.request) | ||
val downloadHelper = downloadHelper( | ||
id = audioPlayable.id.toString(), | ||
context = context, | ||
mediaRequest = audioPlayable.request | ||
) | ||
|
||
downloadHelper.prepare(object : DownloadHelper.Callback { | ||
override fun onPrepared(helper: DownloadHelper) { | ||
val request = helper.getDownloadRequest(audioPlayable.id.encodeInByteArray()) | ||
var request = helper.getDownloadRequest(audioPlayable.id.encodeInByteArray()) | ||
request = request.copyWithId(audioPlayable.id.toString()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we changing from the byte array to the string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's string everywhere else, and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of scope: I don't think we use the Also, the Any reason not to do:
|
||
try { | ||
startDownload(context, request) | ||
} catch (e: Exception) { | ||
|
@@ -99,8 +104,8 @@ internal class ExoplayerDownloadEngine @Inject constructor( | |
|
||
override fun removeDownload(audioPlayable: AudioPlayable) { | ||
scope.launch(errorHandler) { | ||
launch { downloadManager.removeDownload(audioPlayable.request.url) } | ||
launch { offlineDrmManager.removeDownloadedDrmLicense(audioPlayable.request) } | ||
launch { downloadManager.removeDownload(audioPlayable.id.toString()) } | ||
launch { offlineDrmManager.removeDownloadedDrmLicense(id = audioPlayable.id.toString(), request = audioPlayable.request) } | ||
} | ||
} | ||
|
||
|
@@ -113,10 +118,10 @@ internal class ExoplayerDownloadEngine @Inject constructor( | |
|
||
override fun updateProgress() = downloadTracker.updateProgress() | ||
|
||
override fun redownloadDrmLicense(request: AudioPlayable.MediaRequest) { | ||
override fun redownloadDrmLicense(id: String, request: AudioPlayable.MediaRequest) { | ||
scope.launch(errorHandler) { | ||
try { | ||
offlineDrmManager.downloadDrmLicenseForOffline(request) | ||
offlineDrmManager.downloadDrmLicenseForOffline(id = id, request = request) | ||
} catch (ex: DrmDownloadException){ | ||
//continue to try and use old license - a playback error appears elsewhere | ||
} | ||
|
@@ -126,7 +131,7 @@ internal class ExoplayerDownloadEngine @Inject constructor( | |
private fun startDownload(context: Context, downloadRequest: DownloadRequest) = | ||
DownloadService.sendAddDownload(context, downloadService, downloadRequest, true) | ||
|
||
private fun downloadHelper(context: Context, mediaRequest: AudioPlayable.MediaRequest): DownloadHelper { | ||
private fun downloadHelper(id: String, context: Context, mediaRequest: AudioPlayable.MediaRequest): DownloadHelper { | ||
val uri = mediaRequest.url.toUri() | ||
val renderersFactory = createRenderersFactory(context) | ||
val dataSourceFactory = DefaultHttpDataSource.Factory().setUserAgent(Constants.getUserAgent(context)) | ||
|
@@ -139,6 +144,7 @@ internal class ExoplayerDownloadEngine @Inject constructor( | |
} | ||
val mediaItem = MediaItem.Builder() | ||
.setUri(uri) | ||
.setMediaId(id) | ||
.build() | ||
return when (@C.ContentType val type = Util.inferContentType(uri)) { | ||
C.TYPE_HLS, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exception can actually happen here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I think this one should maybe fall back to unencrypted storage? It seems better than not being able to do anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont know exactly, im following second hand reports on problems with EncryptedSharedPrefs.
Failing into an insecure mode would not be appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tink-crypto/tink#535 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend maybe doing something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you may be fine to use
MasterKeys.AES256_GCM_SPEC
for both instead of a custom keyspec for each too, but your call