Skip to content

Device: Show the correct case battery when the AirPods' broadcast is stuck - #766

Closed
ztancrell wants to merge 1 commit into
d4rken-org:mainfrom
ztancrell:fix/case-battery-frozen-broadcast
Closed

ztancrell wants to merge 1 commit into
d4rken-org:mainfrom
ztancrell:fix/case-battery-frozen-broadcast

Conversation

@ztancrell

Copy link
Copy Markdown

What changed

On some AirPods the public Bluetooth broadcast gets stuck on an old case level (for example 10%) while the case is actually near full. When the phone wasn't holding the AirPods' paired connection (e.g. they were connected to a Mac), CAPod showed that stuck value. CAPod now keeps showing the last accurate reading from the paired connection, marked as cached with its age, for up to 30 minutes when the broadcast disagrees with it.

Technical Context

  • Root cause: confirmed on genuine AirPods Pro 2. The BLE proximity advert stayed byte-identical (07 19 01 14 20 75 AA 31 33 00 10 …) for 15+ minutes across lid cycles and a pod removal, with case nibble 1 (10%). At the same moment the AAP session reported CASE=95% NOT_CHARGING. PodDevice prefers AAP, then BLE, then cache, so with no live AAP session the frozen BLE value won.
  • Fix: CachedBatterySlot records fromAap. A shared rule (bleBatteryUnlessOutranked in PodDevice.kt) skips a BLE value when a cached AAP reading under 30 minutes old disagrees with it by more than one decile. The battery getters, isBatteryCached/cachedBatteryAt, batteryCaseReading and the cache write path (toCachedState) all use it. A skipped BLE value never overwrites the AAP slot, so the window counts from the last real AAP reading.
  • Why 30 minutes and one decile: a case drains slowly enough that a real change rarely exceeds one 10% step in 30 minutes, so for adverts that are correct the BLE value still wins. Treating every disagreement as frozen would hide real drops after a long disconnect.
  • Not routed through the rule: BatteryEstimator.liveReading and ChargedReaction.liveChargingSlots read live BLE only and never display a value.
  • Old persisted cache JSON without fromAap decodes as BLE-sourced, which keeps the previous behaviour.
  • Testing: the full CI suite passed on the fork (unit tests for both flavors, lint vitals, builds, emulator tests on API 30 and 36 including the upgrade test from v5.6.0-rc0). Not yet tried on a real phone in the Mac-holds-the-session scenario.

🤖 Generated with Claude Code

…ng broadcast

Some AirPods broadcast a frozen BLE advert (e.g. case stuck at 10% while
AAP reports 95%). Cached AAP readings now record their source, and for
30 minutes a BLE value that disagrees with one by more than a decile is
skipped in favour of the cached AAP value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@d4rken

d4rken commented Nov 14, 2026

Copy link
Copy Markdown
Member

Thanks for the PR, will try to review it ASAP

@d4rken

d4rken commented Nov 15, 2026

Copy link
Copy Markdown
Member

Not merging this as is. If the phone's AAP session drops while the pods or case charge, the fresh BLE level gets replaced by the older AAP value for up to 30 minutes. The cached label never shows while BLE is live, so it looks current.

Can you attach a CAPod debug log covering the stuck period? I'd like to see the raw advert and AAP battery lines over time first.

@d4rken d4rken added coms/BLE Uses Apple's Proximity Payloads, based on BLE broadcasted advertisements. coms/AAP Uses Apples AirPod Protocol. Requires Android ROM with fixed L2CAP support on the Bluetooth sockets. labels Nov 15, 2026
@ztancrell

ztancrell commented Nov 15, 2026 •

Copy link
Copy Markdown
Author

capod-core-redacted.log

Here is a redacted log with raw advert data captured from CAPods,

I held the AirPod case near my Android, slowly opened the lid, waited for the popup to appear, Checked the case charge number - it read 10%, and then slowly closed the lid, Stopping the capture afterwards.

I should have checked the ACTUAL charge of the case, but I did not think of that. I know it isn't 10% charge though.

@ztancrell

Copy link
Copy Markdown
Author

Follow-up: I checked the case on my MacBook Pro 2019. It reads 62%.

The log above shows the advert at 10% (case nibble 1 in ... 31 ...). Those bytes are identical
to the advert quoted in the PR description from days earlier, so the advert has not changed
across that span.

Note: the AAP session in this log never got past HANDSHAKING (batteries={}, 3 failed
reconnects), so there is no AAP battery line in it. I'll try to capture one with the pods
connected for audio.

@d4rken

d4rken commented Nov 16, 2026

Copy link
Copy Markdown
Member

The log shows why this can't help here: the phone's AAP session never gets past the first response (3 attempts, no battery update), so there's never an AAP value to prefer. With the PR applied the popup would still show 10%.

The capture you offered would help most: pods out of the case, playing audio from the phone, Bluetooth off on the Mac.

@ztancrell

Copy link
Copy Markdown
Author

I have got another log for you, doing what you asked. I disabled Bluetooth on Mac, connected to my Android, enabled debug logging in CAPod, opened the case, took the AirPods out, played some random video with them out on my desk. Here is another redacted log file of that run -

capod-core-20261116-redacted.log

@d4rken

d4rken commented Nov 16, 2026

Copy link
Copy Markdown
Member

Not merging this. Your pods don't behave like genuine AirPods Pro 2: after connecting they send no device info or settings, never answer the key request, and the encrypted part of the advert barely changes across days. The public advert also claims both pods are in the case and charging while AAP reports them in your ears.

The PR would only cover the first 30 minutes after an AAP session, and for genuine pods it would hide fresh BLE levels after recharging.

CAPod shows what the device broadcasts, so there won't be a workaround. The serial can be checked at checkcoverage.apple.com.

@ztancrell

Copy link
Copy Markdown
Author

You were right. I checked the serials at checkcoverage.apple.com: the one printed in the case lid isn't valid, and the one the pods report over Bluetooth has been deactivated. Together with what you found in the logs, these look counterfeit, so the frozen case level comes from the pods themselves, not CAPod.

Thank you for taking the time to go through both logs and explain what they showed. Closing this.

@ztancrell ztancrell closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coms/AAP Uses Apples AirPod Protocol. Requires Android ROM with fixed L2CAP support on the Bluetooth sockets. coms/BLE Uses Apple's Proximity Payloads, based on BLE broadcasted advertisements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants