Skip to content

Commit

Permalink
[APT-10650] Better DrmInfo Resilience
Browse files Browse the repository at this point in the history
Armadillo to simply took the DRMInfo passed into it for granted without checking whether the content even needed a key to play. Exoplayer can raise an exception on its own and didn't need the DrmMediaSourceHelper to throw its own exceptions separately.
  • Loading branch information
kabliz committed Oct 23, 2024
1 parent 1ad0659 commit f1d892f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
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

0 comments on commit f1d892f

Please sign in to comment.