mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-26 05:14:09 +02:00
Android Auto browsing could freeze and crash the app (phone app "closes", Android Auto shows a generic connection error) whenever the Capacitor webview had not yet established the server connection. Root cause: onLoadChildren runs on the media browser service main thread. It calls loadAndroidAutoItems -> checkSetValidServerConnectionConfig, which used runBlocking to ping every saved server config and authorize the user. That blocked the main thread on network I/O. Android Auto (plus Assistant) re-request the browse root every ~2s, and every onGetRoot flags a reload while disconnected, so the blocking work was triggered repeatedly and re-entrantly, producing an ANR. Changes: - checkSetValidServerConnectionConfig now runs on a dedicated Dispatchers.IO scope instead of runBlocking, so pings/authorize never block the caller. The callback contract is unchanged; downstream Android Auto callbacks already ran off the main thread. - loadAndroidAutoItems coalesces overlapping calls into a single in-flight load and fires all queued callbacks on completion, so the browse-root polling storm can no longer spawn concurrent loads racing shared state. - Fix latent bug in checkResetServerItems: server config id was compared with !== (reference identity) instead of != (value), causing spurious cache resets that fed the reload storm. Co-authored-by: databoy2k <18686442+databoy2k@users.noreply.github.com>