Cleanup key request parameters

- Make NonNull, which is already the case when using the manager builder.
- Better document PLAYREADY_CUSTOM_DATA_KEY, now that newPlayReadyInstance
  is no more.

PiperOrigin-RevId: 281079288
This commit is contained in:
olly 2019-11-18 16:56:52 +00:00 committed by Oliver Woodman
parent d984a8cdd3
commit 0db1fc67fa
2 changed files with 27 additions and 24 deletions

View File

@ -107,7 +107,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private final ReleaseCallback<T> releaseCallback; private final ReleaseCallback<T> releaseCallback;
private final @DefaultDrmSessionManager.Mode int mode; private final @DefaultDrmSessionManager.Mode int mode;
private final boolean isPlaceholderSession; private final boolean isPlaceholderSession;
@Nullable private final HashMap<String, String> optionalKeyRequestParameters; private final HashMap<String, String> keyRequestParameters;
private final EventDispatcher<DefaultDrmSessionEventListener> eventDispatcher; private final EventDispatcher<DefaultDrmSessionEventListener> eventDispatcher;
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy; private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
@ -140,7 +140,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* @param isPlaceholderSession Whether this session is not expected to acquire any keys. * @param isPlaceholderSession Whether this session is not expected to acquire any keys.
* @param offlineLicenseKeySetId The offline license key set identifier, or null when not using * @param offlineLicenseKeySetId The offline license key set identifier, or null when not using
* offline keys. * offline keys.
* @param optionalKeyRequestParameters The optional key request parameters. * @param keyRequestParameters Key request parameters.
* @param callback The media DRM callback. * @param callback The media DRM callback.
* @param playbackLooper The playback looper. * @param playbackLooper The playback looper.
* @param eventDispatcher The dispatcher for DRM session manager events. * @param eventDispatcher The dispatcher for DRM session manager events.
@ -156,7 +156,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@DefaultDrmSessionManager.Mode int mode, @DefaultDrmSessionManager.Mode int mode,
boolean isPlaceholderSession, boolean isPlaceholderSession,
@Nullable byte[] offlineLicenseKeySetId, @Nullable byte[] offlineLicenseKeySetId,
@Nullable HashMap<String, String> optionalKeyRequestParameters, HashMap<String, String> keyRequestParameters,
MediaDrmCallback callback, MediaDrmCallback callback,
Looper playbackLooper, Looper playbackLooper,
EventDispatcher<DefaultDrmSessionEventListener> eventDispatcher, EventDispatcher<DefaultDrmSessionEventListener> eventDispatcher,
@ -177,7 +177,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} else { } else {
this.schemeDatas = Collections.unmodifiableList(Assertions.checkNotNull(schemeDatas)); this.schemeDatas = Collections.unmodifiableList(Assertions.checkNotNull(schemeDatas));
} }
this.optionalKeyRequestParameters = optionalKeyRequestParameters; this.keyRequestParameters = keyRequestParameters;
this.callback = callback; this.callback = callback;
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy; this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
@ -417,8 +417,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private void postKeyRequest(byte[] scope, int type, boolean allowRetry) { private void postKeyRequest(byte[] scope, int type, boolean allowRetry) {
try { try {
currentKeyRequest = currentKeyRequest = mediaDrm.getKeyRequest(scope, schemeDatas, type, keyRequestParameters);
mediaDrm.getKeyRequest(scope, schemeDatas, type, optionalKeyRequestParameters);
Util.castNonNull(requestHandler) Util.castNonNull(requestHandler)
.post(MSG_KEYS, Assertions.checkNotNull(currentKeyRequest), allowRetry); .post(MSG_KEYS, Assertions.checkNotNull(currentKeyRequest), allowRetry);
} catch (Exception e) { } catch (Exception e) {

View File

@ -86,7 +86,10 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
} }
/** /**
* Sets the parameters to pass to {@link ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}. * Sets the key request parameters to pass as the last argument to {@link
* ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}.
*
* <p>Custom data for PlayReady should be set under {@link #PLAYREADY_CUSTOM_DATA_KEY}.
* *
* @param keyRequestParameters A map with parameters. * @param keyRequestParameters A map with parameters.
* @return This builder. * @return This builder.
@ -206,7 +209,8 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
} }
/** /**
* The key to use when passing CustomData to a PlayReady instance in an optional parameter map. * A key for specifying PlayReady custom data in the key request parameters passed to {@link
* Builder#setKeyRequestParameters(Map)}.
*/ */
public static final String PLAYREADY_CUSTOM_DATA_KEY = "PRCustomData"; public static final String PLAYREADY_CUSTOM_DATA_KEY = "PRCustomData";
@ -237,7 +241,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
private final UUID uuid; private final UUID uuid;
private final ExoMediaDrm.Provider<T> exoMediaDrmProvider; private final ExoMediaDrm.Provider<T> exoMediaDrmProvider;
private final MediaDrmCallback callback; private final MediaDrmCallback callback;
@Nullable private final HashMap<String, String> optionalKeyRequestParameters; private final HashMap<String, String> keyRequestParameters;
private final EventDispatcher<DefaultDrmSessionEventListener> eventDispatcher; private final EventDispatcher<DefaultDrmSessionEventListener> eventDispatcher;
private final boolean multiSession; private final boolean multiSession;
private final int[] useDrmSessionsForClearContentTrackTypes; private final int[] useDrmSessionsForClearContentTrackTypes;
@ -262,8 +266,8 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
* @param uuid The UUID of the drm scheme. * @param uuid The UUID of the drm scheme.
* @param exoMediaDrm An underlying {@link ExoMediaDrm} for use by the manager. * @param exoMediaDrm An underlying {@link ExoMediaDrm} for use by the manager.
* @param callback Performs key and provisioning requests. * @param callback Performs key and provisioning requests.
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument * @param keyRequestParameters An optional map of parameters to pass as the last argument to
* to {@link ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}. May be null. * {@link ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}. May be null.
* @deprecated Use {@link Builder} instead. * @deprecated Use {@link Builder} instead.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -272,12 +276,12 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
UUID uuid, UUID uuid,
ExoMediaDrm<T> exoMediaDrm, ExoMediaDrm<T> exoMediaDrm,
MediaDrmCallback callback, MediaDrmCallback callback,
@Nullable HashMap<String, String> optionalKeyRequestParameters) { @Nullable HashMap<String, String> keyRequestParameters) {
this( this(
uuid, uuid,
exoMediaDrm, exoMediaDrm,
callback, callback,
optionalKeyRequestParameters, keyRequestParameters == null ? new HashMap<>() : keyRequestParameters,
/* multiSession= */ false, /* multiSession= */ false,
INITIAL_DRM_REQUEST_RETRY_COUNT); INITIAL_DRM_REQUEST_RETRY_COUNT);
} }
@ -286,8 +290,8 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
* @param uuid The UUID of the drm scheme. * @param uuid The UUID of the drm scheme.
* @param exoMediaDrm An underlying {@link ExoMediaDrm} for use by the manager. * @param exoMediaDrm An underlying {@link ExoMediaDrm} for use by the manager.
* @param callback Performs key and provisioning requests. * @param callback Performs key and provisioning requests.
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument * @param keyRequestParameters An optional map of parameters to pass as the last argument to
* to {@link ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}. May be null. * {@link ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}. May be null.
* @param multiSession A boolean that specify whether multiple key session support is enabled. * @param multiSession A boolean that specify whether multiple key session support is enabled.
* Default is false. * Default is false.
* @deprecated Use {@link Builder} instead. * @deprecated Use {@link Builder} instead.
@ -297,13 +301,13 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
UUID uuid, UUID uuid,
ExoMediaDrm<T> exoMediaDrm, ExoMediaDrm<T> exoMediaDrm,
MediaDrmCallback callback, MediaDrmCallback callback,
@Nullable HashMap<String, String> optionalKeyRequestParameters, @Nullable HashMap<String, String> keyRequestParameters,
boolean multiSession) { boolean multiSession) {
this( this(
uuid, uuid,
exoMediaDrm, exoMediaDrm,
callback, callback,
optionalKeyRequestParameters, keyRequestParameters == null ? new HashMap<>() : keyRequestParameters,
multiSession, multiSession,
INITIAL_DRM_REQUEST_RETRY_COUNT); INITIAL_DRM_REQUEST_RETRY_COUNT);
} }
@ -312,8 +316,8 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
* @param uuid The UUID of the drm scheme. * @param uuid The UUID of the drm scheme.
* @param exoMediaDrm An underlying {@link ExoMediaDrm} for use by the manager. * @param exoMediaDrm An underlying {@link ExoMediaDrm} for use by the manager.
* @param callback Performs key and provisioning requests. * @param callback Performs key and provisioning requests.
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument * @param keyRequestParameters An optional map of parameters to pass as the last argument to
* to {@link ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}. May be null. * {@link ExoMediaDrm#getKeyRequest(byte[], List, int, HashMap)}. May be null.
* @param multiSession A boolean that specify whether multiple key session support is enabled. * @param multiSession A boolean that specify whether multiple key session support is enabled.
* Default is false. * Default is false.
* @param initialDrmRequestRetryCount The number of times to retry for initial provisioning and * @param initialDrmRequestRetryCount The number of times to retry for initial provisioning and
@ -325,14 +329,14 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
UUID uuid, UUID uuid,
ExoMediaDrm<T> exoMediaDrm, ExoMediaDrm<T> exoMediaDrm,
MediaDrmCallback callback, MediaDrmCallback callback,
@Nullable HashMap<String, String> optionalKeyRequestParameters, @Nullable HashMap<String, String> keyRequestParameters,
boolean multiSession, boolean multiSession,
int initialDrmRequestRetryCount) { int initialDrmRequestRetryCount) {
this( this(
uuid, uuid,
new ExoMediaDrm.AppManagedProvider<>(exoMediaDrm), new ExoMediaDrm.AppManagedProvider<>(exoMediaDrm),
callback, callback,
optionalKeyRequestParameters, keyRequestParameters == null ? new HashMap<>() : keyRequestParameters,
multiSession, multiSession,
/* useDrmSessionsForClearContentTrackTypes= */ new int[0], /* useDrmSessionsForClearContentTrackTypes= */ new int[0],
/* flags= */ 0, /* flags= */ 0,
@ -345,7 +349,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
UUID uuid, UUID uuid,
ExoMediaDrm.Provider<T> exoMediaDrmProvider, ExoMediaDrm.Provider<T> exoMediaDrmProvider,
MediaDrmCallback callback, MediaDrmCallback callback,
@Nullable HashMap<String, String> optionalKeyRequestParameters, HashMap<String, String> keyRequestParameters,
boolean multiSession, boolean multiSession,
int[] useDrmSessionsForClearContentTrackTypes, int[] useDrmSessionsForClearContentTrackTypes,
@Flags int flags, @Flags int flags,
@ -355,7 +359,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
this.uuid = uuid; this.uuid = uuid;
this.exoMediaDrmProvider = exoMediaDrmProvider; this.exoMediaDrmProvider = exoMediaDrmProvider;
this.callback = callback; this.callback = callback;
this.optionalKeyRequestParameters = optionalKeyRequestParameters; this.keyRequestParameters = keyRequestParameters;
this.eventDispatcher = new EventDispatcher<>(); this.eventDispatcher = new EventDispatcher<>();
this.multiSession = multiSession; this.multiSession = multiSession;
this.useDrmSessionsForClearContentTrackTypes = useDrmSessionsForClearContentTrackTypes; this.useDrmSessionsForClearContentTrackTypes = useDrmSessionsForClearContentTrackTypes;
@ -576,7 +580,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
mode, mode,
isPlaceholderSession, isPlaceholderSession,
offlineLicenseKeySetId, offlineLicenseKeySetId,
optionalKeyRequestParameters, keyRequestParameters,
callback, callback,
Assertions.checkNotNull(playbackLooper), Assertions.checkNotNull(playbackLooper),
eventDispatcher, eventDispatcher,