[draft] Cast: move route socket operations off main thread#3470
Draft
emulatronicGIT wants to merge 5 commits into
Draft
[draft] Cast: move route socket operations off main thread#3470emulatronicGIT wants to merge 5 commits into
emulatronicGIT wants to merge 5 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
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() 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
….onSelect() Same fix as CastDeviceControllerImpl: chromecast.connect() throws both IOException and GeneralSecurityException. Update the catch clause to handle both using a multi-catch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a small follow-up branch for #3351, based on the current
masterbranch and including the existing Cast connection lifecycle commits from that PR plus one additional fix for the crash reported in #3351 (comment).The additional change moves
CastMediaRouteControllerroute connect/disconnect/release work onto a single background executor. That avoids callingChromeCast.connect()from the media route provider handler/main path, which is what triggers the reportedNetworkOnMainThreadExceptionwhen selecting a Cast route.What changed in the follow-up commit:
onSelect()scheduleschromecast.connect()on a single-thread executor.onUnselect()andonRelease()schedule disconnect on the same executor.Validation:
git diff --check fork/master..HEADJAVA_HOME=/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home ANDROID_HOME=/opt/homebrew/share/android-commandlinetools ./gradlew :play-services-cast-core:compileDebugJavaWithJavacI cannot test actual Chromecast playback from this machine. The useful runtime check is whether the LogFox
NetworkOnMainThreadExceptionis gone and whether YouTube progresses past route selection.