Skip to content

Linux + iPhone Continuity / iMessage / SMS

feat: moar airpods handoff improvements

Zack Bartel24a2904ce36d
diff --git a/docs/BLUETOOTH.md b/docs/BLUETOOTH.md
index 73fab0d..fdcfb30 100644
--- a/docs/BLUETOOTH.md
+++ b/docs/BLUETOOTH.md
@@ -530,14 +530,27 @@ connected-devices 04 00 04 00 2E 00 [?] [?] [count] ([mac] * 6 [role] [state])
audio-source 04 00 04 00 0E 00 [mac] * 6 [type]
```
-`state` is the ownership field. **The owner carries bit `0x02`**; never compare exact values.
-The numbers differ between buds: an iPhone idles at `0x15` and owns at `0x17` on the buds the
-first implementation was written against, and at `0x05` and `0x07` on AirPods Pro 3 measured
-2026-09-10, where this machine reads `0x00` and `0x02`. Pro 1 leaves an idle iPhone at `0x01`.
-An earlier threshold rule (`0x17` and above owns) never fired on the Pro 3 values.
-
-A peer blocks a claim when it sits at `0x10` or above and is not `0x15`. Owning alone does
-not: on Pro 3 the iPhone keeps `0x02` after its call ends, until another host claims.
+`state` carries ownership in **bit `0x02`**, and nothing here should be compared for equality.
+Measured 2026-09-11 across five handoffs, each one confirmed by the firmware's own verdict packet
+arriving in the same instant:
+
+| host | idle | owning |
+|---|---|---|
+| this machine | `0x00` | `0x02` |
+| the iPhone, AirPods Pro 3 | `0x05` | `0x07` |
+| the models the AC reference was written against | `0x15` | `0x17` |
+
+Bit `0x10` is separate: it marks a host that firmware treats as engaged, and a claim sent into
+that range leaves this host contested. So a peer blocks a claim when it sits at `0x10` or above
+and is not `0x15` -- **owning does not block one**, because an owner that has finished its call is
+exactly what a reclaim takes the buds from. The iPhone keeps the owner bit until another host
+claims, so ownership alone never means "still using them" either; that needs the audio source.
+
+The AC reference reads the low values as validation state instead (`0x00` validated,
+`0x01` pending, `0x02` unvalidated, `0x03` both, `0x05` a stuck session) and says ownership is not
+in this field. That does not match this hardware: our own entry alternates `0x00` and `0x02` in
+lockstep with the verdict packet, which would mean flapping between validated and unvalidated on
+every handoff. Both readings agree that `0x10` and up is engagement.
`0x15` is carved out because it is what a **connected, idle iPhone** reports, permanently, and
it is the state this machine claims the buds *out of*. Treating it as "a peer has them" means
the claim is never sent and the phone keeps the buds -- which is exactly what a first cut of
@@ -644,6 +657,14 @@ Music on the phone reaches this path only through the buds.
While the buds are given up the watcher sends no claim of its own -- not the one a session
sends when it opens, and not one for local playback. Only the reclaim claims.
+**Every other host in the buds' list is registered, once per session.** Two `0x10` smart-routing
+packets, `tipi_add_device()` and `tipi_media_info()`, carry the target's address and this
+machine's. Android sends them, and so does the AC fork, which holds that they are what
+moves a host from unvalidated to validated. That rationale rests on a B-field reading this
+hardware contradicts, so treat the packets as unproven here until a capture shows them changing
+something. **The session's notification request goes out again 500ms after every claim**: the
+firmware resets its AAP state on each handoff and silently drops what a session set up before it.
+
**The call has to arrive before the phone moves the audio.** When the phone takes A2DP the
Bluetooth sink fails and WirePlumber moves any stream still playing to the laptop speakers, so
a pause that lands after that is heard as a burst of music from the speakers. The supervisor
@@ -802,7 +823,7 @@ Three attempts in a row that reach a deadline having delivered nothing are repor
`busy` rather than retried quietly, because the remedy is to stop the other program and
nothing in the log would otherwise say so.
-Anything else on the machine speaking AAP is such a program: LibrePods, AirPods Center,
+Anything else on the machine speaking AAP is such a program: LibrePods, AC,
a status-bar widget that reads battery itself. Only one of them can hold the channel.
## Conflicts
@@ -867,7 +888,7 @@ checks the daemon does not make.
| The link reads down forever with `br-connection-unknown`, while messages, contacts and notifications all work | This computer offers the iPhone no BR/EDR profile to connect to, and BlueZ only reports a link up while some local profile is connected | Nothing. Tether no longer waits on that link -- see 2026-08-23 below. Call support does not change this: BlueZ's hands-free profile is not one of the local profiles BlueZ counts |
| The iPhone's audio moves to the computer when Tether connects | The machine advertises itself as a Bluetooth speaker/headset, and iOS routes to it. Not caused by Tether beyond bringing the link up | See "Keeping the phone's audio on the phone" below |
| `tether --bt-calls` reports call control off | PipeWire took the profile *and* its telephony D-Bus service is off, the iPhone reconnected on its own and never opened hands-free, or `bluetoothd` is running without `--experimental` | Either give BlueZ the profile by dropping `hfp_hf` from `bluez5.roles`, or set `bluez5.telephony-dbus-service = true` and let Tether drive PipeWire's gateway -- see "Calls". The daemon cycles the BR/EDR bearer once per outage for the second cause; confirm with `busctl --system tree org.bluez \| grep telephony` and `busctl --user tree org.pipewire.Telephony` |
-| AirPods are listed but the battery stays blank, and the row says another program is using the channel | The AAP channel takes one client, and something else has it | Stop the other AirPods program (LibrePods, AirPods Center, a status-bar widget that reads battery), or hand it over with `tether --bt-airpods-enable off` |
+| AirPods are listed but the battery stays blank, and the row says another program is using the channel | The AAP channel takes one client, and something else has it | Stop the other AirPods program (LibrePods, AC, a status-bar widget that reads battery), or hand it over with `tether --bt-airpods-enable off` |
| Setting the AirPods listening mode to `off` does nothing, while the other three work | The buds declined it. Apple leaves Off out of the noise-control rotation by default on Pro models, and there is no refusal to report | Add Off to the rotation on the phone, under Settings > Bluetooth > (i) > Noise Control. Tether keeps showing the mode the buds are actually in |
| The AirPods handoff checkbox is greyed out | Neither path is available: the adapter does not present itself as Apple hardware, so handoff would have to trigger on the iPhone's call state, and call control is off | Set the adapter Device ID for ownership handoff, or turn on calls: `tether --bt-calls-enable on` |
| A call started but the AirPods stayed on this computer | They were not connected here when it started, handoff is off, or the call was dialled from this computer | Nothing to do in the first and last case -- pick the AirPods on the phone. Otherwise `tether --bt-airpods-handoff on` |
@@ -3165,10 +3186,12 @@ The second run, 10:05 to 10:10, was worse:
source none, while the iPhone still read `0x07` and its call was still going.
- The night before, 20:33:39, the iPhone took `0x07` for a call and still held it at 20:37:48,
with Linux playing in between. The owner bit does not mark the end of a call either.
-- Calls at 09:51:10, 10:05:31 and 10:08:56 put SCO on this machine (`corrupted SCO packet` in
- the kernel log): iOS routed the call to the laptop's hands-free link, not the buds. At 10:05
- the iPhone read `0x01` while an iMac on the same iCloud account held the buds at `0x07`
- playing media. 10:08:56 came seven seconds after the early reclaim.
+- Calls at 09:51:10, 10:05:31 and 10:08:56 put SCO on this machine (`corrupted SCO packet` in the
+ kernel log). That was first read as "iOS routed the call here"; it is not. Measured at 17:09 and
+ 17:10, the same lines appear while the call plays in the buds, so they only say the iPhone set
+ up a hands-free link with the laptop. At 10:05 the iPhone read `0x01` while an iMac on the same
+ iCloud account held the buds at `0x07` playing media, which is the better explanation of why
+ the call went to the phone's speaker: the buds' second slot was taken.
- 10:05:15 the claim a session sends when it opens took the buds from that iMac mid-media,
while this machine had given them up.
@@ -3181,6 +3204,30 @@ transport failure at 12.000 and the release, which pauses first, logged at 12.05
35.569 and 35.626. SCO had reached this machine 300 to 550ms before each failure, so the phone
was already committed to the call while Tether waited for its one-second call-list tick.
+Later the same day the reporter sent the source of their fork, AC v2.3.0, whose
+`DOCUMENTATION.md` records ~15 versions spent on these same failures. Three things it does that
+Tether did not, now adopted: the host registration packets above, re-sending configuration after
+each handoff, and a three-second claim cooldown rather than one.
+
+Its B-field table briefly retired the owner-bit reading here, which was a mistake, corrected the
+same evening by five handoffs at 17:09 and 17:10: our own entry alternates `0x00` and `0x02`, the
+iPhone `0x05` and `0x07`, each transition arriving with the matching verdict packet. Bit `0x02` is
+ownership on this hardware whatever it means on theirs, and the wire protocol section above now
+records the measurement rather than either guess.
+
+The suspicion that Tether's own LE work spoils call routing, taken from the fork's v2.3.0 entry,
+does not survive measurement either. Three calls dialled on the iPhone with the buds attached to
+this machine -- tetherd stopped, tetherd running, tetherd running with ANCS off -- all routed to
+the AirPods. An earlier round of the same test looked damning until the logs showed the buds had
+dropped off this machine before two of the three runs; a run where the buds are not attached here
+proves nothing, so check `Device1.Connected` before each call.
+
+Two of its findings are not adopted. It releases A2DP proactively during a three-second grace at
+connect, with a 15s watchdog, to dodge a firmware disconnect timer this project has not measured.
+And its own v2.3.0 entry reports that its BLE scan, run while Tether brings up its BR/EDR link,
+leaves that link degraded and iOS then refuses the buds for calls -- its fix was a startup delay.
+Whether Tether's own LE work does the same to it is worth measuring before any code changes.
+
Not yet verified on hardware: the full sequence on Pro 3, iPhone media rather than a call,
the owner bit on Pro 2, and whether an `off` profile persists if tetherd dies while the buds
are away. WirePlumber restores a saved `off` profile unless `session.dont-restore-off-profile`
diff --git a/src/core/include/tether/bluetooth/airpods.hpp b/src/core/include/tether/bluetooth/airpods.hpp
index 48b05cd..7cd6168 100644
--- a/src/core/include/tether/bluetooth/airpods.hpp
+++ b/src/core/include/tether/bluetooth/airpods.hpp
@@ -35,9 +35,8 @@ namespace tether::bluetooth {
const char* to_string(AncMode mode);
std::optional<AncMode> anc_mode_from_string(const std::string& name);
- // Ownership state of one host attached to the buds, the `B` field of a
- // connected-devices notification. The owner carries bit 0x02 on every model measured:
- // an iPhone idles at 0x15 and owns at 0x17 on some buds, 0x05 and 0x07 on others.
+ // Ownership state of one host attached to the buds, the `B` field of a connected-devices
+ // notification. **Bit 0x02 is the owner**.
inline constexpr uint8_t AAP_PEER_OWNER = 0x02;
inline constexpr uint8_t AAP_PEER_ENGAGED = 0x10;
// Connected and idle. An iPhone sits here for as long as it is paired and doing
@@ -52,10 +51,10 @@ namespace tether::bluetooth {
uint8_t role = 0;
uint8_t state = 0;
- // Owns the buds, which is not the same as using them: an iPhone keeps the bit after a call.
bool active() const { return (state & AAP_PEER_OWNER) != 0; }
- // Escalating towards taking the buds, or holding them, on buds that report 0x10 and up.
- // Claiming against this leaves the host contested and the firmware closes the link.
+ // Escalating towards taking the buds, on the models that report 0x10 and up. Claiming
+ // against this leaves the host contested and the firmware closes the link. Owning is
+ // deliberately not part of it: an owner that has finished is what a reclaim claims from.
bool taking_over() const { return state >= AAP_PEER_ENGAGED && state != AAP_PEER_PASSIVE; }
bool operator==(const AapPeer&) const = default;
@@ -135,7 +134,8 @@ namespace tether::bluetooth {
// Written for display, shown verbatim.
std::string reason;
- // A peer owns the buds and is playing through them: what handoff yields to.
+ // A peer owns the buds and is playing through them: what handoff yields to. Ownership
+ // alone is not enough, because the phone keeps it until another host claims.
bool peer_busy() const { return peer_active && peer_audio; }
bool operator==(const AirPodsState&) const = default;
@@ -172,6 +172,11 @@ namespace tether::bluetooth {
std::optional<bool> owns,
bool peer_audio);
+ // The two registration packets a host sends for every other host in the buds' list, which is
+ // what moves it from unvalidated to validated. Empty for an address that will not parse.
+ std::vector<uint8_t> tipi_add_device(const std::string& self, const std::string& target);
+ std::vector<uint8_t> tipi_media_info(const std::string& self, const std::string& target);
+
// Whether any host other than `local` is engaged with the buds, or actively
// holding them. A machine's own entry is never a peer.
struct PeerSummary {
diff --git a/src/core/src/bluetooth/airpods.cpp b/src/core/src/bluetooth/airpods.cpp
index f7c7d39..17057f2 100644
--- a/src/core/src/bluetooth/airpods.cpp
+++ b/src/core/src/bluetooth/airpods.cpp
@@ -74,8 +74,9 @@ namespace tether::bluetooth {
// The firmware's own ownership verdict arrives on the same shape.
constexpr uint8_t OWNS_CONNECTION_PREFIX[] = {0x04, 0x00, 0x04, 0x00, 0x09, 0x00, 0x06};
- // Claims are answered slowly and the firmware saturates on a burst of them.
- constexpr int CLAIM_COOLDOWN_MS = 1000;
+ // Claims are answered slowly and the firmware saturates on a burst of them. Three seconds
+ // is what the AirPods Center reference settled on after seek storms disconnected the buds.
+ constexpr int CLAIM_COOLDOWN_MS = 3000;
constexpr uint8_t HANDSHAKE_ACK[] = {0x01, 0x00, 0x04, 0x00};
constexpr uint8_t FEATURES_ACK[] = {0x04, 0x00, 0x04, 0x00, 0x2b, 0x00};
@@ -114,6 +115,9 @@ namespace tether::bluetooth {
// How long the buds must stop reporting a peer's audio before it counts as over:
// some models report no audio source every twenty seconds or so during a call.
constexpr int PEER_AUDIO_SETTLE_MS = 3000;
+ // After a claim, before the session's notification request goes out again. The
+ // firmware discards anything sent while it is still broadcasting its own state.
+ constexpr int CONFIG_RESEND_MS = 500;
constexpr int CONNECT_TIMEOUT_MS = 8000;
constexpr int FIRST_PACKET_TIMEOUT_MS = 8000;
@@ -421,6 +425,52 @@ namespace tether::bluetooth {
!peer_audio;
}
+ namespace {
+
+ // Both TiPi packets are opcode 0x10 (smart routing) and look alike. The target's
+ // address least-significant byte first, then a body of length-tagged ASCII keys.
+ std::vector<uint8_t> tipi_packet(const std::string& self,
+ const std::string& target,
+ const char* head,
+ size_t head_len,
+ const char* tail,
+ size_t tail_len) {
+ uint8_t addr[6] = {};
+ if (self.size() != 17 || !parse_address(target, addr))
+ return {};
+ static constexpr uint8_t PREFIX[] = {0x04, 0x00, 0x04, 0x00, 0x10, 0x00};
+ std::vector<uint8_t> packet(std::begin(PREFIX), std::end(PREFIX));
+ packet.insert(packet.end(), std::begin(addr), std::end(addr));
+ packet.insert(packet.end(), head, head + head_len);
+ packet.insert(packet.end(), self.begin(), self.end());
+ packet.insert(packet.end(), tail, tail + tail_len);
+ return packet;
+ }
+
+ constexpr char TIPI_ADD_HEAD[] = "\x52\x00\x01\xe5\x48idleTime\x08\x47newTipi\x01\x49"
+ "btAddress\x51";
+ constexpr char TIPI_ADD_TAIL[] = "\x46"
+ "btName\x47"
+ "Android\x50nearbyAudioScore\x0e";
+ constexpr char TIPI_MEDIA_HEAD[] = "\x6c\x00\x01\xe5\x4a"
+ "playingApp\x42NA\x52hostStreamingState\x42NO\x49"
+ "btAddress\x51";
+ constexpr char TIPI_MEDIA_TAIL[] = "\x46"
+ "btName\x47"
+ "Android\x58otherDeviceAudioCategory\x30\x64";
+
+ } // namespace
+
+ std::vector<uint8_t> tipi_add_device(const std::string& self, const std::string& target) {
+ return tipi_packet(
+ self, target, TIPI_ADD_HEAD, sizeof(TIPI_ADD_HEAD) - 1, TIPI_ADD_TAIL, sizeof(TIPI_ADD_TAIL) - 1);
+ }
+
+ std::vector<uint8_t> tipi_media_info(const std::string& self, const std::string& target) {
+ return tipi_packet(
+ self, target, TIPI_MEDIA_HEAD, sizeof(TIPI_MEDIA_HEAD) - 1, TIPI_MEDIA_TAIL, sizeof(TIPI_MEDIA_TAIL) - 1);
+ }
+
PeerSummary summarize_peers(const std::vector<AapPeer>& peers, const std::string& local) {
PeerSummary summary;
for (const auto& peer : peers) {
@@ -493,6 +543,9 @@ namespace tether::bluetooth {
std::optional<bool> pending_ownership;
// This machine gave the buds up: no claim of the watcher's own goes out until it takes them back.
bool yielded = false;
+ // A claim has just gone out, so the session's notification request is due again: the
+ // firmware resets its AAP state on every handoff and silently drops what was set before.
+ bool config_resend_due = false;
std::chrono::steady_clock::time_point last_claim{};
bool stopping = false;
bool enabled = true;
@@ -578,6 +631,35 @@ namespace tether::bluetooth {
publish(delivered ? AirPodsStatus::Live : AirPodsStatus::Connecting, "");
}
+ // Registers every other host in the buds' list, once each per session. A host the
+ // firmware has not been told about stays unvalidated, and an unvalidated host is the
+ // one it evicts when the pods move while another host is engaged.
+ bool register_hosts(int fd, const std::vector<AapPeer>& peers, std::vector<std::string>& sent) {
+ std::string local;
+ {
+ std::lock_guard<std::mutex> lock(mutex);
+ local = local_address;
+ }
+ if (local.empty())
+ return true;
+ for (const auto& peer : peers) {
+ if (peer.address == local || std::find(sent.begin(), sent.end(), peer.address) != sent.end())
+ continue;
+ sent.push_back(peer.address);
+ for (const auto& packet :
+ {tipi_media_info(local, peer.address), tipi_add_device(local, peer.address)}) {
+ if (packet.empty())
+ continue;
+ if (!write_all(fd, packet.data(), packet.size())) {
+ debug::log(DEBUG, "airpods: host registration write failed: {}", std::strerror(errno));
+ return false;
+ }
+ }
+ debug::log(DEBUG, "airpods: registered host {} with the buds", peer.address);
+ }
+ return true;
+ }
+
// Takes or gives up ownership, on the worker thread. A claim sent while a peer
// is taking the buds is the one packet that reliably kills the link, so the
// peer state from the last connected-devices notification gates it. An idle
@@ -607,6 +689,8 @@ namespace tether::bluetooth {
}
if (write_all(fd, CLAIM, sizeof(CLAIM))) {
debug::log(DEBUG, "airpods: claim sent");
+ std::lock_guard<std::mutex> lock(mutex);
+ config_resend_due = true;
return true;
}
debug::log(DEBUG, "airpods: claim write failed: {}", std::strerror(errno));
@@ -739,6 +823,10 @@ namespace tether::bluetooth {
};
std::map<std::string, uint8_t> peer_states;
+ // Hosts this session has registered with the buds, once each.
+ std::vector<std::string> tipi_sent;
+ // When the session's notification request is due again after a claim.
+ std::optional<clock::time_point> config_at;
bool warned_unlisted = false;
std::optional<bool> owns;
bool peer_audio = false;
@@ -756,6 +844,13 @@ namespace tether::bluetooth {
std::array<uint8_t, 1024> buffer{};
while (!retargeted(address)) {
const auto now = clock::now();
+ {
+ std::lock_guard<std::mutex> lock(mutex);
+ if (config_resend_due) {
+ config_resend_due = false;
+ config_at = now + std::chrono::milliseconds(CONFIG_RESEND_MS);
+ }
+ }
// Until the buds send a notification, stray bytes do not keep an attempt alive:
// a channel another client holds stays open and says nothing useful.
const auto quiet_since = delivered ? last_packet : opened;
@@ -770,6 +865,8 @@ namespace tether::bluetooth {
timeout = std::min(timeout, until(*claim_at));
if (peer_audio_ends_at)
timeout = std::min(timeout, until(*peer_audio_ends_at));
+ if (config_at)
+ timeout = std::min(timeout, until(*config_at));
const int ready = wait_for(fd, wake_fd, POLLIN, std::max(timeout, 0));
if (ready == 0) {
drain_wake();
@@ -791,6 +888,15 @@ namespace tether::bluetooth {
set_peer_audio(false);
continue;
}
+ // The firmware drops what a session set up before a handoff, so the
+ // notification request goes out again after taking the buds back.
+ if (config_at && fired >= *config_at) {
+ config_at.reset();
+ if (!write_all(fd, REQUEST_NOTIFICATIONS, sizeof(REQUEST_NOTIFICATIONS)))
+ break;
+ debug::log(DEBUG, "airpods: notification request re-sent after claiming");
+ continue;
+ }
if (claim_at && fired >= *claim_at) {
claim_at.reset();
std::string local;
@@ -857,6 +963,8 @@ namespace tether::bluetooth {
if (auto peers = parse_connected_devices(buffer.data(), size)) {
delivered = true;
note_peers(*peers, peer_states, warned_unlisted, delivered);
+ if (!register_hosts(fd, *peers, tipi_sent))
+ break;
// The host list proves the channel is ours; the claim waits for the audio link.
if (!claim_sent && !claim_at)
claim_at = std::max(last_packet, opened + std::chrono::milliseconds(CLAIM_SETTLE_MS));
diff --git a/test/test_airpods.cpp b/test/test_airpods.cpp
index 960601b..f21dcec 100644
--- a/test/test_airpods.cpp
+++ b/test/test_airpods.cpp
@@ -241,18 +241,57 @@ TEST(AirPods, SeparatesAnIdlePeerFromOneTakingTheBuds) {
EXPECT_FALSE(peer(0x15).active());
// AirPods Pro 1 leaves a healthy iPhone at 0x01 forever.
EXPECT_FALSE(peer(0x01).taking_over());
+}
- // AirPods Pro 3 never report 0x10 and up: the iPhone read 0x05 and 0x07 on 2026-09-10, and
- // 0x02 on 2026-09-11, where it kept 0x02 after the call ended. Owning must not block a claim.
+// Ownership moves with bit 0x02. Captured 2026-09-11 over five handoffs, each confirmed by the
+// firmware's own verdict packet: the iPhone idles at 0x05 and owns at 0x07, this machine 0x00 and
+// 0x02, and neither ever reaches 0x10. An owner that has finished is what a reclaim claims from,
+// so owning must not read as taking over.
+TEST(AirPods, ReadsOwnershipFromTheOwnerBit) {
+ const auto peer = [](uint8_t state) { return AapPeer{"81:71:C8:30:6A:F3", 0x02, state}; };
EXPECT_FALSE(peer(0x05).active());
EXPECT_TRUE(peer(0x07).active());
+ EXPECT_FALSE(peer(0x00).active());
EXPECT_TRUE(peer(0x02).active());
- EXPECT_FALSE(peer(0x02).taking_over());
EXPECT_FALSE(peer(0x07).taking_over());
+ EXPECT_FALSE(peer(0x02).taking_over());
+ // The same bit separates the pair reported by the models the reference was written against.
+ EXPECT_FALSE(peer(0x15).active());
+ EXPECT_TRUE(peer(0x17).active());
+}
+
+// The registration packets the buds expect for every other host, ported from a working
+// implementation. The layout is fixed: opcode, the target address least-significant byte first,
+// then ASCII keys with this machine's address in the middle.
+TEST(AirPods, BuildsTheHostRegistrationPackets) {
+ const std::string self = "AC:F2:3C:AF:52:9C";
+ const auto add = tipi_add_device(self, "60:57:C8:30:6A:F7");
+ ASSERT_EQ(add.size(), 96u);
+ EXPECT_EQ(std::vector<uint8_t>(add.begin(), add.begin() + 6),
+ (std::vector<uint8_t>{0x04, 0x00, 0x04, 0x00, 0x10, 0x00}));
+ EXPECT_EQ(std::vector<uint8_t>(add.begin() + 6, add.begin() + 12),
+ (std::vector<uint8_t>{0xf7, 0x6a, 0x30, 0xc8, 0x57, 0x60}));
+ // Body offsets counted from the end of the prefix.
+ EXPECT_EQ(std::string(add.begin() + 6 + 11, add.begin() + 6 + 19), "idleTime");
+ EXPECT_EQ(std::string(add.begin() + 6 + 40, add.begin() + 6 + 57), self);
+ EXPECT_EQ(std::string(add.begin() + 6 + 65, add.begin() + 6 + 72), "Android");
+ EXPECT_EQ(add.back(), 0x0e);
+
+ const auto media = tipi_media_info(self, "60:57:C8:30:6A:F7");
+ ASSERT_EQ(media.size(), 122u);
+ EXPECT_EQ(std::string(media.begin() + 6 + 11, media.begin() + 6 + 21), "playingApp");
+ EXPECT_EQ(std::string(media.begin() + 6 + 25, media.begin() + 6 + 43), "hostStreamingState");
+ EXPECT_EQ(std::string(media.begin() + 6 + 57, media.begin() + 6 + 74), self);
+ EXPECT_EQ(media.back(), 0x64);
+
+ // An address that will not parse is no packet at all.
+ EXPECT_TRUE(tipi_add_device(self, "nonsense").empty());
+ EXPECT_TRUE(tipi_media_info("", "60:57:C8:30:6A:F7").empty());
}
-// Handoff yields to a phone that owns the buds and plays through them, never to ownership alone.
-TEST(AirPods, AnOwnerThatStoppedPlayingIsNotBusy) {
+// Handoff yields to a phone that owns the buds and is playing through them. Ownership alone is a
+// phone that finished its call and kept the bit; audio alone is a host that owns nothing.
+TEST(AirPods, YieldsOnlyToAnOwnerWithAudio) {
AirPodsState state;
state.peer_active = true;
EXPECT_FALSE(state.peer_busy());