Skip to content

Commit

Permalink
Ensure DrmSessionManager.setPlayer() is called before prepare()
Browse files Browse the repository at this point in the history
`prepare()` now logs a warning if it's called before `setPlayer()`
because it's not possible to tell if it's being called on the wrong
thread (since androidx/media@3480a27).

This change finds all the places one is called immediately after the
other and flips the order to be more correct.

Issue: androidx/media#350

#minor-release

PiperOrigin-RevId: 526582294
  • Loading branch information
icbaker authored and rohitjoins committed Apr 24, 2023
1 parent de32536 commit 6aacbc6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ public MediaItem getMediaItem() {
@Override
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
transferListener = mediaTransferListener;
drmSessionManager.prepare();
drmSessionManager.setPlayer(
/* playbackLooper= */ checkNotNull(Looper.myLooper()), getPlayerId());
drmSessionManager.prepare();
notifySourceInfoRefreshed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public void acquireSession_triggersKeyLoadAndSessionIsOpened() throws Exception
new DefaultDrmSessionManager.Builder()
.setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm())
.build(/* mediaDrmCallback= */ licenseServer);
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand All @@ -91,8 +91,8 @@ public void keepaliveEnabled_sessionsKeptForRequestedTime() throws Exception {
.setSessionKeepaliveMs(10_000)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand All @@ -116,8 +116,8 @@ public void keepaliveDisabled_sessionsReleasedImmediately() throws Exception {
.setSessionKeepaliveMs(C.TIME_UNSET)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand All @@ -138,8 +138,8 @@ public void managerRelease_allKeepaliveSessionsImmediatelyReleased() throws Exce
.setSessionKeepaliveMs(10_000)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand All @@ -162,8 +162,8 @@ public void managerRelease_keepaliveDisabled_doesntReleaseAnySessions() throws E
.setSessionKeepaliveMs(C.TIME_UNSET)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand All @@ -188,8 +188,8 @@ public void managerRelease_mediaDrmNotReleasedUntilLastSessionReleased() throws
.setSessionKeepaliveMs(10_000)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand Down Expand Up @@ -233,8 +233,8 @@ public void managerRelease_mediaDrmNotReleasedUntilLastSessionReleased() throws
.setSessionKeepaliveMs(10_000)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand Down Expand Up @@ -272,8 +272,8 @@ public void maxConcurrentSessionsExceeded_allKeepAliveSessionsEagerlyReleased()
.setMultiSession(true)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession firstDrmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand Down Expand Up @@ -313,8 +313,8 @@ public void maxConcurrentSessionsExceeded_allPreacquiredAndKeepaliveSessionsEage
.setMultiSession(true)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSessionReference firstDrmSessionReference =
checkNotNull(
drmSessionManager.preacquireSession(
Expand Down Expand Up @@ -358,8 +358,8 @@ public void sessionReacquired_keepaliveTimeOutCancelled() throws Exception {
.setSessionKeepaliveMs(10_000)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession firstDrmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand Down Expand Up @@ -405,8 +405,8 @@ public void onDrmKeysLoaded(
.setSessionKeepaliveMs(C.TIME_UNSET)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();

DrmSessionReference sessionReference =
drmSessionManager.preacquireSession(eventDispatcher, FORMAT_WITH_DRM_INIT_DATA);
Expand Down Expand Up @@ -450,8 +450,8 @@ public void onDrmKeysLoaded(
.setSessionKeepaliveMs(C.TIME_UNSET)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();

DrmSessionReference sessionReference =
drmSessionManager.preacquireSession(/* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA);
Expand Down Expand Up @@ -486,8 +486,8 @@ public void preacquireSession_releaseManagerBeforeAcquisition_acquisitionDoesntH
.setSessionKeepaliveMs(C.TIME_UNSET)
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();

DrmSessionReference sessionReference =
drmSessionManager.preacquireSession(/* eventDispatcher= */ null, FORMAT_WITH_DRM_INIT_DATA);
Expand Down Expand Up @@ -530,8 +530,8 @@ public void keyRefreshEvent_triggersKeyRefresh() throws Exception {
.setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, new AppManagedProvider(exoMediaDrm))
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();

DefaultDrmSession drmSession =
(DefaultDrmSession)
Expand Down Expand Up @@ -571,8 +571,8 @@ public void keyRefreshEvent_whileManagerIsReleasing_triggersKeyRefresh() throws
.setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, new AppManagedProvider(exoMediaDrm))
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();

DefaultDrmSession drmSession =
(DefaultDrmSession)
Expand Down Expand Up @@ -615,8 +615,8 @@ public void keyRefreshEvent_whileManagerIsReleasing_triggersKeyRefresh() throws
DRM_SCHEME_UUID,
uuid -> new FakeExoMediaDrm.Builder().setProvisionsRequired(1).build())
.build(/* mediaDrmCallback= */ licenseServer);
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand Down Expand Up @@ -648,8 +648,8 @@ public void keyRefreshEvent_whileManagerIsReleasing_triggersKeyRefresh() throws
.throwNotProvisionedExceptionFromGetKeyRequest()
.build())
.build(/* mediaDrmCallback= */ licenseServer);
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand All @@ -674,8 +674,8 @@ public void deviceNotProvisioned_doubleProvisioningHandledAndOpenSessionRetried(
DRM_SCHEME_UUID,
uuid -> new FakeExoMediaDrm.Builder().setProvisionsRequired(2).build())
.build(/* mediaDrmCallback= */ licenseServer);
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand All @@ -702,8 +702,8 @@ public void keyResponseIndicatesProvisioningRequired_provisioningDone() {
.setUuidAndExoMediaDrmProvider(
DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm.Builder().build())
.build(/* mediaDrmCallback= */ licenseServer);
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand All @@ -728,8 +728,8 @@ public void provisioningUndoneWhileManagerIsActive_deviceReprovisioned() {
.setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, new AppManagedProvider(mediaDrm))
.setSessionKeepaliveMs(C.TIME_UNSET)
.build(/* mediaDrmCallback= */ licenseServer);
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand Down Expand Up @@ -783,8 +783,8 @@ public void managerReleasing_acquireSessionAndPreacquireSessionFail() throws Exc
.setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm())
.build(/* mediaDrmCallback= */ licenseServer);

drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), PlayerId.UNSET);
drmSessionManager.prepare();
DrmSession drmSession =
checkNotNull(
drmSessionManager.acquireSession(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ public MediaItem getMediaItem() {
@Override
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
this.mediaTransferListener = mediaTransferListener;
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), getPlayerId());
drmSessionManager.prepare();
if (sideloadedManifest) {
processManifest(false);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ public MediaItem getMediaItem() {
@Override
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
this.mediaTransferListener = mediaTransferListener;
drmSessionManager.prepare();
drmSessionManager.setPlayer(
/* playbackLooper= */ checkNotNull(Looper.myLooper()), getPlayerId());
drmSessionManager.prepare();
MediaSourceEventListener.EventDispatcher eventDispatcher =
createEventDispatcher(/* mediaPeriodId= */ null);
playlistTracker.start(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ public MediaItem getMediaItem() {
@Override
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
this.mediaTransferListener = mediaTransferListener;
drmSessionManager.prepare();
drmSessionManager.setPlayer(/* playbackLooper= */ Looper.myLooper(), getPlayerId());
drmSessionManager.prepare();
if (sideloadedManifest) {
manifestLoaderErrorThrower = new LoaderErrorThrower.Dummy();
processManifest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ public boolean isSingleWindow() {
public synchronized void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
assertThat(preparedSource).isFalse();
transferListener = mediaTransferListener;
drmSessionManager.prepare();
drmSessionManager.setPlayer(
/* playbackLooper= */ checkNotNull(Looper.myLooper()), getPlayerId());
drmSessionManager.prepare();
preparedSource = true;
releasedSource = false;
sourceInfoRefreshHandler = Util.createHandlerForCurrentLooper();
Expand Down

0 comments on commit 6aacbc6

Please sign in to comment.