Skip to content

fix(cast): stop Remote Control media session from crashing the app - #254

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-d0f7
Draft

fix(cast): stop Remote Control media session from crashing the app#254
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-d0f7

Conversation

@cursor

@cursor cursor Bot commented Aug 28, 2026

Copy link
Copy Markdown

Bug and impact

Connecting Remote Control to a TV that is playing (phone app in the foreground) started SiloCastMediaSessionService with startForegroundService(). Media3 never called startForeground(), so Android killed the whole process after 5–10 seconds with RemoteServiceException / 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.

  1. SiloCastMediaSessionStarter used ContextCompat.startForegroundService() whenever TV playback was active. That arms the platform start-foreground watchdog.
  2. SiloCastMediaSessionService is started explicitly and has no MediaSessionService intent-filter, so no MediaController bind ever hits onGetSession().
  3. The service never called addSession(), so Media3's MediaNotificationManager never tracked the session, never showed a notification, and never called startForeground().

Local playback avoids this because PlayerScreen binds a MediaController to SiloPlaybackService, which is what registers the session. The new Remote Control service had no equivalent bind.

Fix

  • Register the session with addSession() in SiloCastMediaSessionService.onCreate() so Media3 can show the media notification and promote to a foreground service itself.
  • Start the service with a plain startService(). Do not call startForegroundService() from the starter — Media3's notification manager does that atomically with startForeground().

Validation

./gradlew :androidApp:testDebugUnitTest --tests org.siloserver.silo.android.cast.SiloCastMediaSessionStarterTest — 4 tests, 0 failures. New contract tests lock in “no startForegroundService() in the starter” and “service calls addSession()”.

Could not exercise the live Remote Control + TV path in this environment (no running Silo server / devices).

Open in Web View Automation 

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>
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.

1 participant