Skip to content

fix(android-auto): handle unhandled exceptions and empty track lists in playItem/getScreen#153

Open
shinodanpen wants to merge 1 commit intoDJDoubleD:masterfrom
shinodanpen:fix/android-auto-playback
Open

fix(android-auto): handle unhandled exceptions and empty track lists in playItem/getScreen#153
shinodanpen wants to merge 1 commit intoDJDoubleD:masterfrom
shinodanpen:fix/android-auto-playback

Conversation

@shinodanpen
Copy link
Copy Markdown

Description

Fixes #68 — Android Auto shows the library but tapping a track returns to the main screen without playing anything.

Root cause analysis

Static analysis identified two main failure points:

1. Unhandled exceptions in playItem()

playItem() in android_auto.dart makes async Deezer API calls (fullPlaylist, album, smartTrackList) with no error handling. If any of these throw (expired token, network error, null response), the exception propagates silently through the audio_service framework, which swallows it and leaves Android Auto in its previous state — causing the "returns to main screen" symptom.

2. Empty track list crash

p.tracks?[0] and a.tracks?[0] are only null-guarded, not empty-guarded. If the API returns an object with an empty track list, this throws a RangeError.

Changes

lib/ui/android_auto.dart

  • Wrapped the entire body of playItem() in a try-catch with Logger.root.severe logging
  • Added explicit null and empty checks before accessing tracks[0] for both playlists and albums
  • Wrapped each branch of getScreen() in individual try-catch blocks, consistent with the existing pattern already used for the homescreen branch
  • Replaced debug-only print calls with Logger.root.severe in the _aa_tracks branch
  • Added missing import 'package:logging/logging.dart'

lib/service/audio_service.dart

  • Wrapped the _androidAuto.playItem(mediaId) call in playFromMediaId() with a try-catch as a safety net

What's not included

The auth race condition in main.dart (authorize() not awaited before Android Auto calls) was identified during analysis but is out of scope for this fix — it deserves a separate issue.

Testing

Changes were developed and verified through static analysis and code review with the assistance of AI tools (Claude). Runtime testing on a physical Android Auto setup was not possible due to build environment constraints. The fix addresses all identified failure paths that match the reported symptom.

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.

[Bug] Android auto

1 participant