Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
[intent to join](https://developers.google.com/cast/docs/android_sender/intent_to_join),
automatically deferring session startup if `Cast` initialization is
still in progress.
* Fix `RemoteCastPlayer` retaining a dead `CastSession` when
`onSessionStartFailed` or `onSessionResumeFailed` is invoked for the
active session ([#3580](https://github.com/androidx/media/issues/3580)).
* Test Utilities:
* Demo app:
* Remove deprecated symbols:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,9 @@ public void onSessionResumeFailed(CastSession castSession, int statusCode) {
+ statusCode
+ ": "
+ CastUtils.getLogString(statusCode));
if (castSession != null && castSession == RemoteCastPlayer.this.castSession) {
setCastSession(null, SessionAvailabilityListener.SESSION_UNAVAILABLE_REASON_DISCONNECTED);
}
}

@Override
Expand All @@ -2068,6 +2071,9 @@ public void onSessionStartFailed(CastSession castSession, int statusCode) {
+ statusCode
+ ": "
+ CastUtils.getLogString(statusCode));
if (castSession != null && castSession == RemoteCastPlayer.this.castSession) {
setCastSession(null, SessionAvailabilityListener.SESSION_UNAVAILABLE_REASON_DISCONNECTED);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,30 @@ public void playerTransfer_whenSessionSuspended_pausesLocalPlayer() {
assertThat(localPlayer.getPlayWhenReady()).isFalse();
}

@Test
public void playerTransfer_whenSessionStartFailed_transfersToLocalPlayerAndPauses() {
castSessionListener.onSessionStarted(mockCastSession, /* sessionId= */ "");
castPlayer = castPlayerBuilder.build();
castPlayer.setPlayWhenReady(true);

castSessionListener.onSessionStartFailed(mockCastSession, /* statusCode= */ 2259);

assertThat(castPlayer.getDeviceInfo().playbackType).isEqualTo(DeviceInfo.PLAYBACK_TYPE_LOCAL);
assertThat(localPlayer.getPlayWhenReady()).isFalse();
}

@Test
public void playerTransfer_whenSessionResumeFailed_transfersToLocalPlayerAndPauses() {
castSessionListener.onSessionStarted(mockCastSession, /* sessionId= */ "");
castPlayer = castPlayerBuilder.build();
castPlayer.setPlayWhenReady(true);

castSessionListener.onSessionResumeFailed(mockCastSession, /* statusCode= */ 2259);

assertThat(castPlayer.getDeviceInfo().playbackType).isEqualTo(DeviceInfo.PLAYBACK_TYPE_LOCAL);
assertThat(localPlayer.getPlayWhenReady()).isFalse();
}

@Test
public void playerTransfer_whenSessionStarted_doesNotPauseRemotePlayer() {
castPlayer = castPlayerBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3175,6 +3175,54 @@ public void onSessionSuspended_notifiesUnavailableWithDisconnectedReason() {
SessionAvailabilityListener.SESSION_UNAVAILABLE_REASON_DISCONNECTED);
}

@Test
public void
onSessionStartFailed_forCurrentSession_clearsSessionAndNotifiesUnavailableWithDisconnectedReason() {
remoteCastPlayer.setSessionAvailabilityListener(mockSessionAvailabilityListener);

sessionManagerListener.onSessionStartFailed(mockCastSession, /* statusCode= */ 2259);

assertThat(remoteCastPlayer.isCastSessionAvailable()).isFalse();
verify(mockSessionAvailabilityListener)
.onCastSessionUnavailable(
SessionAvailabilityListener.SESSION_UNAVAILABLE_REASON_DISCONNECTED);
}

@Test
public void onSessionStartFailed_forDifferentSession_keepsCurrentSession() {
remoteCastPlayer.setSessionAvailabilityListener(mockSessionAvailabilityListener);
CastSession otherCastSession = mock(CastSession.class);

sessionManagerListener.onSessionStartFailed(otherCastSession, /* statusCode= */ 2259);

assertThat(remoteCastPlayer.isCastSessionAvailable()).isTrue();
verify(mockSessionAvailabilityListener, never()).onCastSessionUnavailable(anyInt());
}

@Test
public void
onSessionResumeFailed_forCurrentSession_clearsSessionAndNotifiesUnavailableWithDisconnectedReason() {
remoteCastPlayer.setSessionAvailabilityListener(mockSessionAvailabilityListener);

sessionManagerListener.onSessionResumeFailed(mockCastSession, /* statusCode= */ 2259);

assertThat(remoteCastPlayer.isCastSessionAvailable()).isFalse();
verify(mockSessionAvailabilityListener)
.onCastSessionUnavailable(
SessionAvailabilityListener.SESSION_UNAVAILABLE_REASON_DISCONNECTED);
}

@Test
public void onSessionResumeFailed_forDifferentSession_keepsCurrentSession() {
remoteCastPlayer.setSessionAvailabilityListener(mockSessionAvailabilityListener);
CastSession otherCastSession = mock(CastSession.class);

sessionManagerListener.onSessionResumeFailed(otherCastSession, /* statusCode= */ 2259);

assertThat(remoteCastPlayer.isCastSessionAvailable()).isTrue();
verify(mockSessionAvailabilityListener, never()).onCastSessionUnavailable(anyInt());
}

@Test
@SuppressWarnings("deprecation") // Testing deprecated listener method.
public void onCastSessionUnavailable_notifiesLegacyListener() {
Expand Down