Commit 786edf8e by ibaker Committed by Andrew Lewis

Tweak DefaultDrmSession acquire & release event behaviour

The new behaviour:
- If the session is successfully opened, an acquire event is dispatched
  to all attached dispatchers.
- If acquire() is called but the session is already open, the acquire
  event is dispatched only to the dispatcher provided in to acquire()
- If the session is successfully released, a release event is dispatched
  to all attached dispatchers (in theory at most one should ever be
  attached at this point).
- If release() is called but the session isn't released (because
  referenceCount > 0) then a release event is dispatched only to the
  dispatcher provided to release().

PiperOrigin-RevId: 312062422
parent b667a0e7
...@@ -273,13 +273,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -273,13 +273,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
if (openInternal(true)) { if (openInternal(true)) {
doLicense(true); doLicense(true);
} }
} else { } else if (eventDispatcher != null && isOpen()) {
// If the session is already open then send the acquire event only to the provided dispatcher.
// TODO: Add a parameter to onDrmSessionAcquired to indicate whether the session is being // TODO: Add a parameter to onDrmSessionAcquired to indicate whether the session is being
// re-used or not. // re-used or not.
if (eventDispatcher != null) { eventDispatcher.dispatch(
eventDispatcher.dispatch( DrmSessionEventListener::onDrmSessionAcquired, DrmSessionEventListener.class);
DrmSessionEventListener::onDrmSessionAcquired, DrmSessionEventListener.class);
}
} }
} }
...@@ -302,9 +301,15 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -302,9 +301,15 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
sessionId = null; sessionId = null;
} }
releaseCallback.onSessionReleased(this); releaseCallback.onSessionReleased(this);
dispatchEvent(DrmSessionEventListener::onDrmSessionReleased);
} }
dispatchEvent(DrmSessionEventListener::onDrmSessionReleased);
if (eventDispatcher != null) { if (eventDispatcher != null) {
if (isOpen()) {
// If the session is still open then send the release event only to the provided dispatcher
// before removing it.
eventDispatcher.dispatch(
DrmSessionEventListener::onDrmSessionReleased, DrmSessionEventListener.class);
}
eventDispatchers.remove(eventDispatcher); eventDispatchers.remove(eventDispatcher);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment