Skip to content

android: make AACP reconnect sessions control-safe#691

Open
beeemT wants to merge 5 commits into
librepods-org:mainfrom
beeemT:fix/aacp-session-reconnect
Open

android: make AACP reconnect sessions control-safe#691
beeemT wants to merge 5 commits into
librepods-org:mainfrom
beeemT:fix/aacp-session-reconnect

Conversation

@beeemT

@beeemT beeemT commented Jul 25, 2026

Copy link
Copy Markdown

Summary

This PR addresses the Android AACP control-connection lifecycle behind the AirPods Pro 3 press-and-hold failure reported in #690 and the related service-restart issue in #571.

It:

  • resets shared AACP state before a new connection attempt;
  • binds initialization, packet reads, and side effects to a connection generation and socket identity;
  • cancels and closes stale readers, initialization jobs, and sockets;
  • waits for the first valid AACP frame before replaying persistent control state;
  • replays listening-mode availability, the Off option, and stem-action configuration for each fresh session; and
  • emits the connected notification only after those configuration writes succeed.

The protocol notes explain why this matters: stem configuration is accessory state and must be overwritten when the AirPods connect to a new device (Configure Stem Long Press).

Root-cause model

The failure is consistent with overlapping AACP initialization/readers racing socket replacement. In that state, telemetry and direct listening-mode writes can continue working while the AirPods' physical stem configuration is stale or missing. The Android BLUETOOTH_PRIVILEGED warnings are not treated as the cause; the normal AACP socket and control path remain usable without root.

Validation

  • Existing Android build completed successfully before this PR was opened.
  • Tested on Pixel 10 Pro, Android 17, with AirPods Pro 3 model A3065.
  • Clean connection: both stems worked.
  • Force-stop/restart while Bluetooth remained connected: both stems worked.
  • Bluetooth off/on reconnect: new session replayed configuration and both stems worked.
  • Two rapid Bluetooth interruptions: stale sockets closed, fresh sessions replayed configuration, and both stems worked afterward.
  • Observed listening-mode packets for values 01, 02, and 03 after reconnects.

Representative logs include:

AACP session 4 ready; persistent configuration sent: listeningModes=true, allowOffMode=true, stemConfig=true
AACP session 7 ready; persistent configuration sent: listeningModes=true, allowOffMode=true, stemConfig=true
socket closed (bytesRead = -1)
AACP session 10 ready; persistent configuration sent: listeningModes=true, allowOffMode=true, stemConfig=true

Scope and limitations

  • This PR was generated using AI.
  • The maintainer can use it as-is, adapt/cherry-pick parts of it, or use it only as inspiration for the correct fix to the AACP control-connection issue.
  • Please review the lifecycle/concurrency design carefully before merging; this is not presented as guaranteed merge-ready code.
  • The physical validation used the reviewed candidate APK, not the Play Store APK, and did not include an overnight soak or every custom stem-action mapping.

Related

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