Skip to content

Commit 824cbf4

Browse files
toniheimicrokatz
authored andcommitted
Avoid notifying connection twice from MediaControllerImplLegacy.
The connection to a legacy MediaSession may receive additional onSessionReady callbacks that are treated as additional state updates. We currently also set the "notifyConnected" flag for these updates even though we are connected already, causing an IllegalStateException. Fix the exception by not setting this flag. We can also remove the wording about "locked" updates since this class operates everything on a single application thread. Issue: #49 PiperOrigin-RevId: 487487286 (cherry picked from commit b24161a)
1 parent afb0f12 commit 824cbf4

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

RELEASENOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Release notes
9999
`DefaultNotificationProvider` on API 26 and API 27 (the badge is
100100
automatically hidden on API 28+)
101101
([#131](https://github.com/androidx/media/issues/131)).
102+
* Fix bug where a second binder connection from a legacy MediaSession to a
103+
Media3 MediaController causes IllegalStateExceptions
104+
([#49](https://github.com/androidx/media/issues/49)).
102105
* RTSP:
103106
* Add H263 fragmented packet handling
104107
([#119](https://github.com/androidx/media/pull/119)).

libraries/session/src/main/java/androidx/media3/session/MediaControllerImplLegacy.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,7 @@ public MediaBrowserCompat getBrowserCompat() {
12111211
return browserCompat;
12121212
}
12131213

1214-
// Should be used without a lock to prevent potential deadlock.
1215-
void onConnectedNotLocked() {
1214+
void onConnected() {
12161215
if (released || connected) {
12171216
return;
12181217
}
@@ -1240,18 +1239,16 @@ private void connectToSession(MediaSessionCompat.Token sessionCompatToken) {
12401239
controllerCompat.registerCallback(
12411240
controllerCompatCallback, getInstance().applicationHandler);
12421241
});
1243-
// Post a runnable to prevent callbacks from being called by onConnectedNotLocked()
1242+
// Post a runnable to prevent callbacks from being called by onConnected()
12441243
// before the constructor returns (b/196941334).
12451244
getInstance()
12461245
.applicationHandler
12471246
.post(
12481247
() -> {
12491248
if (!controllerCompat.isSessionReady()) {
1250-
// If the session not ready here, then call onConnectedNotLocked() immediately. The
1251-
// session may be a framework MediaSession and we cannot know whether it can be
1252-
// ready
1253-
// later.
1254-
onConnectedNotLocked();
1249+
// If the session not ready here, then call onConnected() immediately. The session
1250+
// may be a framework MediaSession and we cannot know whether it can be ready later.
1251+
onConnected();
12551252
}
12561253
});
12571254
}
@@ -1608,7 +1605,7 @@ public void release() {
16081605
@Override
16091606
public void onSessionReady() {
16101607
if (!connected) {
1611-
onConnectedNotLocked();
1608+
onConnected();
16121609
} else {
16131610
// Handle the case when extra binder is available after connectToSession().
16141611
// Initial values are notified already, so only notify values that are available when
@@ -1622,7 +1619,7 @@ public void onSessionReady() {
16221619
onCaptioningEnabledChanged(isCaptioningEnabled);
16231620

16241621
pendingChangesHandler.removeMessages(MSG_HANDLE_PENDING_UPDATES);
1625-
handleNewLegacyParameters(/* notifyConnected= */ true, pendingLegacyPlayerInfo);
1622+
handleNewLegacyParameters(/* notifyConnected= */ false, pendingLegacyPlayerInfo);
16261623
}
16271624
}
16281625

0 commit comments

Comments
 (0)