Skip to content
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-10650] Better DrmInfo Resilience #53

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import com.google.android.exoplayer2.ExoPlaybackException.TYPE_RENDERER
import com.google.android.exoplayer2.ExoPlaybackException.TYPE_SOURCE
import com.google.android.exoplayer2.ParserException
import com.google.android.exoplayer2.audio.AudioSink
import com.google.android.exoplayer2.drm.DrmSession.DrmSessionException
import com.google.android.exoplayer2.drm.MediaDrmCallbackException
import com.google.android.exoplayer2.upstream.DataSpec
import com.google.android.exoplayer2.upstream.HttpDataSource
import com.scribd.armadillo.error.ArmadilloException
import com.scribd.armadillo.error.ArmadilloIOException
import com.scribd.armadillo.error.ConnectivityException
import com.scribd.armadillo.error.DrmPlaybackException
import com.scribd.armadillo.error.HttpResponseCodeException
import com.scribd.armadillo.error.ParsingException
import com.scribd.armadillo.error.RendererConfigurationException
Expand Down Expand Up @@ -39,6 +41,9 @@ internal fun ExoPlaybackException.toArmadilloException(context: Context): Armadi
HttpResponseCodeException(httpCause?.responseCode
?: 0, httpCause?.dataSpec?.uri.toString(), source, source.dataSpec.toAnalyticsMap(context))
}
is DrmSessionException -> {
DrmPlaybackException(cause = this)
}

is UnknownHostException,
is SocketTimeoutException -> ConnectivityException(source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,28 @@ internal class DrmMediaSourceHelperImpl @Inject constructor(private val secureSt
MediaItem.Builder()
.setUri(request.url)
.apply {
// Apply DRM config if content is DRM-protected
request.drmInfo?.let { drmInfo ->
MediaItem.DrmConfiguration.Builder(drmInfo.drmType.toExoplayerConstant())
.setLicenseUri(drmInfo.licenseServer)
.setLicenseRequestHeaders(drmInfo.drmHeaders)
.apply {
// If the content is a download content, use the saved offline DRM key id.
// This ID is needed to retrieve the local DRM license for content decryption.
if (isDownload) {
secureStorage.getDrmDownload(context = context, id = id, drmType = drmInfo.drmType)?.let { drmDownload ->
setKeySetId(drmDownload.drmKeyId)
} ?: throw DrmPlaybackException(IllegalStateException("No DRM key id saved for download content"))
try {
// Apply DRM config if content is DRM-protected
request.drmInfo?.let { drmInfo ->
MediaItem.DrmConfiguration.Builder(drmInfo.drmType.toExoplayerConstant())
.setLicenseUri(drmInfo.licenseServer)
.setLicenseRequestHeaders(drmInfo.drmHeaders)
.apply {
// If the content is a download content, use the saved offline DRM key id.
// This ID is needed to retrieve the local DRM license for content decryption.
if (isDownload) {
secureStorage.getDrmDownload(context = context, id = id, drmType = drmInfo.drmType)?.let { drmDownload ->
setKeySetId(drmDownload.drmKeyId)
} ?: throw DrmPlaybackException(IllegalStateException("No DRM key id saved for download content"))
}
}
}
.build()
}?.let { drmConfig ->
setDrmConfiguration(drmConfig)
.build()
}?.let { drmConfig ->
setDrmConfiguration(drmConfig)
}
} catch (ex: DrmPlaybackException) {
//attempt to load unencrypted, there's a chance the user supplied excessive DRMInfo. An exception will
// be raised elsewhere if this content can't be decrypted.
}
}
.build()
Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.6.8
- Fixes an app startup crash to EncryptedSharedPreference faults.
- Adds resilience to playing unencrypted content if it is optionally drm enabled.

## 1.6.7
- Adds additional data in audio player errors: HttpResponseCodeException, DownloadFailed
Expand Down
Loading