Cast: fix device connection lifecycle and implement joinApplication#3351
Cast: fix device connection lifecycle and implement joinApplication#3351FloodExLLC wants to merge 4 commits into
Conversation
The ChromeCast object was created but connect() was never called before launchApp(), sendRawRequest() etc., causing all outgoing operations to fail with IOException because no socket existed. - Add ensureConnected() helper; call it at the top of every outgoing operation (launchApplication, joinApplication, sendMessage, stopApplication) - Fix launchApplication() to guard against a null Application response instead of NPE-ing on app.sessionId - Implement joinApplication() properly: query device status, join an already-running matching session (wasLaunched=false), and only fall back to launching when the app is absent
onSelect() and onUnselect() were stubs. The Cast device connection lifecycle must mirror the route selection lifecycle so the socket is open before the Cast session begins and closed when the user switches away. - onSelect(): open TCP/TLS connection to the Cast device - onUnselect() / onUnselect(int): close the connection - onRelease(): close the connection when the controller is destroyed
|
Does not even build which makes it clear you didn't test this |
|
Hey! Thank you for this PR. Seems on the surface you have done some great work. |
chromecast.connect() throws both IOException and GeneralSecurityException (a checked exception). The ensureConnected() helper only declared throws IOException, causing a compile error. Wrap the connect() call to catch GeneralSecurityException and rethrow as IOException so all callers remain unchanged. Fixes: microg#3351
….onSelect() Same fix as CastDeviceControllerImpl: chromecast.connect() throws both IOException and GeneralSecurityException. Update the catch clause to handle both using a multi-catch.
Why do you say so? |
it was not building as at the time of that comment |
|
Just chiming in to say I have been hanging out for this and fingers crossed it all works and is pulled! |
IMO, we're quite a pack of fans awaiting that Christmas gift for years 💪😍👍 We all hope that it's not dust in the wind 🤞 |
|
Any update on this @FloodExLLC ? |
|
Hi, I will at last spend some time today setting up my test environment. Sorry for the long wait, I really have to make time for this. |
|
I just did a basic test: Device: Oneplus5, running LineageOS 21-20240930 (Yes I know old version, because this is my old phone) My test is simple: Have GMS installed with all self-checks passing (except for work-profile but that should be irrelevant). I am not logged into a Google account. Then I look up a Youtube Video using search. Then I use the cast button to cast to my chromecast. Then I see if the video starts playing. Test #1: On my phone running real Google Play Services: Video starts playing. Details of the crash: FATAL EXCEPTION: main @FloodExLLC Did you test this and run into this problem? |
|
I took a look at the crash reported in #3351 (comment). The What changed in the follow-up:
Local verification:
I cannot verify actual Chromecast playback from this machine. @Tthecreator, if you can test a build with this small patch, the first thing to check is whether the LogFox Follow-up PR for testing: #3470 |
Fixes the two root causes that prevent Cast from working in practice.
Problem
The
ChromeCastobject (from the chromecast-java-api-v2 library) requiresan explicit
connect()call to open a TLS socket before any operation cansucceed. The existing code created the
ChromeCastinstance but never calledconnect(), solaunchApp(),sendRawRequest(),stopSession()etc. allthrew
IOExceptionimmediately, making Cast non-functional for all apps.A second issue was that
joinApplication()always launched a new instanceinstead of joining an existing session, breaking multi-sender scenarios
and session resume.
Changes
CastDeviceControllerImplensureConnected()helper that callschromecast.connect()if notalready connected; invoke it at the start of every outgoing operation
launchApplication()to handle anullapp response gracefullyrather than NPE-ing on
app.sessionIdjoinApplication()correctly: query device status, jointhe already-running matching session (
wasLaunched = false), fall backto launching only when the app is not present
CastMediaRouteControlleronSelect(): open TLS connection when user selects routeonUnselect()/onUnselect(int): close connection on deselectonRelease(): close connection when controller is destroyedCloses #580