Skip to content

fix(android): Don't SDP-query every bonded device on service start - #794

Open
vishu1038 wants to merge 1 commit into
librepods-org:mainfrom
vishu1038:fix/startup-sdp-burst
Open

vishu1038 wants to merge 1 commit into
librepods-org:mainfrom
vishu1038:fix/startup-sdp-burst

Conversation

@vishu1038

Copy link
Copy Markdown

Problem

On service start, AirPodsService calls fetchUuidsWithSdp() on every bonded device. Each device that isn't nearby takes about 5 s to page-timeout, so the SDP queue stays busy for about a minute after every start. (With 8 bonded devices, 8 fetches are queued.)

  • When the queue reaches the AirPods while they're on another host, the page pulls them away from that host.
  • Other apps' SDP requests (for example Sony Headphones Connect) wait behind the queue, and can fire just after a handoff and steal the AirPods again.

Fix

Use the cached device.uuids at startup and drop the blanket fetchUuidsWithSdp(). The ACL_CONNECTED path still fetches UUIDs when the AirPods actually connect and the cache is empty.

Evidence

Before: 8 fetchRemoteUuidsWithSdp from LibrePods' uid right after install/restart, and bta_dm_discover_services … 62:cc repeating for about 50 s. After: 0 in the first 15 s.

Tested on a Pixel 6a running Android 17 (API 37, unrooted, FOSS debug build) with AirPods 4 (ANC). Not tested on other devices or AirPods models.

These changes were written with AI assistance (Claude Code) and debugged against logcat captures from the device above.

🤖 Generated with Claude Code

fetchUuidsWithSdp() on all bonded devices pages each one; absent devices
take ~5 s to page-timeout, so the queue ran for about a minute after every
service start. When it reached the AirPods it pulled them off the iPad,
and it delayed other apps' queued SDP requests (e.g. Sony Headphones
Connect) until after the iPad had taken over, causing another steal.

Changes:
- AirPodsService.onCreate: stop calling fetchUuidsWithSdp() for every
  bonded device; identify the AirPods from cached UUIDs only.
- The ACL_CONNECTED path still fetches UUIDs when a device actually
  connects without the AAP UUID cached.

Tested: Pixel 6a, Android 17 (API 37), unrooted, AirPods 4 (ANC); verified in logcat. Before: 8 SDP requests queued per service start;
after: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vishu1038
vishu1038 force-pushed the fix/startup-sdp-burst branch from 34d4653 to baf44c6 Compare September 26, 2026 13:46
@vishu1038 vishu1038 changed the title Don't SDP-query every bonded device on service start fix(android): Don't SDP-query every bonded device on service start Sep 26, 2026
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