From bcaadf434f9824433135e6ba693670a482a2d098 Mon Sep 17 00:00:00 2001 From: ibaker Date: Mon, 18 Oct 2021 14:35:34 +0100 Subject: [PATCH] Remove checkState calls from DefaultDrmSession#acquire() and release() Issue: #9392 reports occasional IllegalStateExceptions from release() in crashlytics,`with no way to reproduce locally. It seems likely there is a bug somewhere in DRM handling, and ideally we would find that and fix it. However we haven't been able to find the problem, and in the meantime these exceptions cause the entire app to crash. Although this is arguably useful from a debugging perspective, it's obviously a poor experience for developers and users, since all we're actually trying to do is release the session, so maybe we shouldn't strictly care that it's already released? This change replaces the exception with an error log, which might be a useful debugging hint if we see other DRM unexpected behaviour due to references to released sessions being held for too long. PiperOrigin-RevId: 403942546 --- RELEASENOTES.md | 4 ++++ .../android/exoplayer2/drm/DefaultDrmSession.java | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 078f53df86..2ace17dc48 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -28,6 +28,10 @@ * Fix bug in `MediaCodecVideoRenderer` that resulted in re-using a released `Surface` when playing without an app-provided `Surface` ([#9476](https://github.com/google/ExoPlayer/issues/9476)). +* DRM: + * Log an error (instead of throwing `IllegalStateException`) when calling + `DefaultDrmSession#release()` on a fully released session + ([#9392](https://github.com/google/ExoPlayer/issues/9392)). * Android 12 compatibility: * Keep `DownloadService` started and in the foreground whilst waiting for requirements to be met on Android 12. This is necessary due to new diff --git a/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java b/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java index 5e5bce8340..fff8ab9e7b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java @@ -296,7 +296,10 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; @Override public void acquire(@Nullable DrmSessionEventListener.EventDispatcher eventDispatcher) { - checkState(referenceCount >= 0); + if (referenceCount < 0) { + Log.e(TAG, "Session reference count less than zero: " + referenceCount); + referenceCount = 0; + } if (eventDispatcher != null) { eventDispatchers.add(eventDispatcher); } @@ -320,7 +323,10 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; @Override public void release(@Nullable DrmSessionEventListener.EventDispatcher eventDispatcher) { - checkState(referenceCount > 0); + if (referenceCount <= 0) { + Log.e(TAG, "release() called on a session that's already fully released."); + return; + } if (--referenceCount == 0) { // Assigning null to various non-null variables for clean-up. state = STATE_RELEASED;