fix(cast): stop Remote Control media session from crashing the app - #254
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(cast): stop Remote Control media session from crashing the app#254cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
SiloCastMediaSessionStarter called startForegroundService() while the MediaSessionService never addSession()'d, so Media3 never called startForeground(). Android then killed the process with ForegroundServiceDidNotStartInTimeException whenever TV playback was active in the foregrounded phone app. Start the service with a plain startService() and register the session so Media3 can promote to foreground itself. Co-authored-by: Quick <Quick104@users.noreply.github.com>
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.
Bug and impact
Connecting Remote Control to a TV that is playing (phone app in the foreground) started
SiloCastMediaSessionServicewithstartForegroundService(). Media3 never calledstartForeground(), so Android killed the whole process after 5–10 seconds withRemoteServiceException/ForegroundServiceDidNotStartInTimeException.Trigger: Open Silo on the phone, connect Remote Control to a TV that is playing (or start playback on that TV while the phone app is foregrounded). The app crashes shortly after.
Root cause
Introduced in #252.
SiloCastMediaSessionStarterusedContextCompat.startForegroundService()whenever TV playback was active. That arms the platform start-foreground watchdog.SiloCastMediaSessionServiceis started explicitly and has noMediaSessionServiceintent-filter, so noMediaControllerbind ever hitsonGetSession().addSession(), so Media3'sMediaNotificationManagernever tracked the session, never showed a notification, and never calledstartForeground().Local playback avoids this because
PlayerScreenbinds aMediaControllertoSiloPlaybackService, which is what registers the session. The new Remote Control service had no equivalent bind.Fix
addSession()inSiloCastMediaSessionService.onCreate()so Media3 can show the media notification and promote to a foreground service itself.startService(). Do not callstartForegroundService()from the starter — Media3's notification manager does that atomically withstartForeground().Validation
./gradlew :androidApp:testDebugUnitTest --tests org.siloserver.silo.android.cast.SiloCastMediaSessionStarterTest— 4 tests, 0 failures. New contract tests lock in “nostartForegroundService()in the starter” and “service callsaddSession()”.Could not exercise the live Remote Control + TV path in this environment (no running Silo server / devices).