Skip to content

Cast: fix connectionless listener lifecycle - #1

Merged
peterhel merged 1 commit into
peterhel:feat/cast-connectionlessfrom
paulcakeface:cast-listener-lifecycle-fix
Aug 31, 2026
Merged

peterhel merged 1 commit into
peterhel:feat/cast-connectionlessfrom
paulcakeface:cast-listener-lifecycle-fix

Conversation

@paulcakeface

Copy link
Copy Markdown

This is a small follow-up to your connectionless Cast controller work.

The current setListener path links one shared Binder death recipient each time a listener is installed, but replacing or unregistering the listener does not unlink the old registration. If listener A is replaced by listener B and A later dies, the stale callback can call disconnect() and tear down B's active Cast session.

There is also an ordering issue in normal disconnect(): ChromeCast.disconnect() synchronously calls Channel.close(), which emits the connection event used for onDisconnected() before the socket is closed. Unlinking or clearing the listener before that call can suppress the legitimate disconnect callback.

This patch:

  • tracks the Binder and DeathRecipient for the current listener
  • unlinks the exact old registration on replacement and unregister
  • ignores already queued death callbacks from superseded listeners
  • disconnects only when the currently registered Binder dies
  • keeps the live listener until normal onDisconnected() has been delivered

Validation on the branch based directly on your PR head:

  • :play-services-cast-core:compileDebugJavaWithJavac passed
  • :play-services-cast-framework-core:compileDebugJavaWithJavac passed
  • release variants of both modules passed
  • git diff --check passed

The diff is intentionally limited to CastDeviceControllerImpl.java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants