Linux + iPhone Continuity / iMessage / SMS
fix: le reconnect after out-of-range
Zack Bartel48a4d88fb170
diff --git a/docs/BLUETOOTH.md b/docs/BLUETOOTH.mdindex 24ff20f..d60028e 100644--- a/docs/BLUETOOTH.md+++ b/docs/BLUETOOTH.md@@ -3940,3 +3940,31 @@ before pairing. Only `0bda:8771` is listed, since it has two reports. CSR clonesno USB ID that tells them apart from working parts.Not verified: the reporter's `LinkKey Type`.++### 2026-11-04 - ANCS on a Type=5 bond, and no retry after a walk (#303)++| | |+|---|---|+| Controller | Mac mini built-in Broadcom BCM20702 (`usb:v05ACp8289`); TP-Link UB500 also tried |+| BlueZ | 5.87 (Linux Mint 22.3) |+| Phone | iPhone 16, iOS 26.5 |+| Tether | 0.3.2 |++The bond's `LinkKey` was `Type=5` (P-192), and `--bt-status` showed `Bearer API: unknown`. No+`Bearer.LE1` line appears anywhere in the log. Even so, after a re-pair ANCS reached+`Notification mirroring is active.` That status is only set when the phone answers+`GetAppAttributes`, so iOS had authorized access. The session dropped at the same moment as the+`BREDR1` supervision timeout during a walk out of range.++When the phone came back, BR/EDR reconnected and MAP and PBAP worked, but ANCS was never tried+again. `sync_ancs` kept the device path only while LE read up or within+`ANCS_BEARER_GRACE_SECONDS` of the drop. LE can never read up without a populated `Bearer.LE1`,+so once the grace window had passed the path stayed empty. `should_hold_ancs` now also keeps+the path while the classic link is up and there is no LE bearer, and discovery decides whether+ANCS answers. The same gap applies on BlueZ without the bearer API (#226).++Not settled: which transport carried ANCS on a bond with no LE keys from CTKD. It could be a+separate LE pairing that BlueZ never surfaced as `Bearer.LE1`, or ATT over BR/EDR. Apple's ANCS+spec only describes LE. The bond's `info` sections and a `btmon` capture would settle it. Also+not verified: whether the phone offers ANCS again after a walk on the fixed build, and that an+idle phone does not loop on rebuilds.diff --git a/src/core/include/tether/bluetooth/bearer_supervisor.hpp b/src/core/include/tether/bluetooth/bearer_supervisor.hppindex 05aa78f..8348848 100644--- a/src/core/include/tether/bluetooth/bearer_supervisor.hpp+++ b/src/core/include/tether/bluetooth/bearer_supervisor.hpp@@ -113,6 +113,14 @@ namespace tether::bluetooth {return ancs_enabled && bearer.le_available && !bearer.le_dialling && (!bearer.le_connected || link_dead);}+ // Whether the ANCS client keeps its device path. Without a populated+ // Bearer.LE1 the LE state is invisible, so the classic link being up is the+ // only sign the phone is back. Discovery decides whether ANCS answers.+ inline bool should_hold_ancs(bool ready, const BearerStatus& bearer, int64_t now, int64_t le_down_since) {+ return ready || bearer.le_connected || (bearer.classic_connected && !bearer.le_available) ||+ now - le_down_since < ANCS_BEARER_GRACE_SECONDS;+ }+// Whether the phone has been gone long enough, and for the right reason, to// lock the session.inline bool should_lock_on_away(bool enabled,diff --git a/src/core/src/bluetooth/connection.cpp b/src/core/src/bluetooth/connection.cppindex b5cf519..33cbd6a 100644--- a/src/core/src/bluetooth/connection.cpp+++ b/src/core/src/bluetooth/connection.cpp@@ -1232,7 +1232,7 @@ namespace tether::bluetooth {}// ponytail: one fixed grace window rather than per-phase tuning. Widen it// if a controller is seen flapping slower than this.- const bool hold = ready || le_up || now - le_down_since < ANCS_BEARER_GRACE_SECONDS;+ const bool hold = should_hold_ancs(ready, bearers->status(), now, le_down_since);std::string device_path;bool offers_ancs = false;diff --git a/test/test_bluetooth_supervisor.cpp b/test/test_bluetooth_supervisor.cppindex acbfb44..461680f 100644--- a/test/test_bluetooth_supervisor.cpp+++ b/test/test_bluetooth_supervisor.cpp@@ -1224,3 +1224,25 @@ TEST(AwayLock, NeverLocksBeforeAnythingHasGoneDown) {const BearerStatus gone = gone_bearer();EXPECT_FALSE(should_lock_on_away(true, gone, false, REASON_TIMEOUT, 300, -1, 30));}++// No Bearer.LE1, so LE never reads up; the phone walked out past the+// grace window and came back over BR/EDR. ANCS must be tried again.+TEST(HoldAncs, ClassicReturningHoldsWhenLeIsInvisible) {+ BearerStatus bearer = gone_bearer();+ const int64_t past_grace = ANCS_BEARER_GRACE_SECONDS + 60;+ EXPECT_FALSE(should_hold_ancs(false, bearer, past_grace, 0)) << "phone still away";++ bearer.classic_connected = true;+ EXPECT_TRUE(should_hold_ancs(false, bearer, past_grace, 0));+}++// With a populated LE bearer its state is known, so classic alone does not hold.+TEST(HoldAncs, ClassicAloneDoesNotHoldWhenLeIsVisible) {+ BearerStatus bearer = gone_bearer();+ bearer.classic_connected = true;+ bearer.le_available = true;+ const int64_t past_grace = ANCS_BEARER_GRACE_SECONDS + 60;+ EXPECT_FALSE(should_hold_ancs(false, bearer, past_grace, 0));+ EXPECT_TRUE(should_hold_ancs(false, bearer, ANCS_BEARER_GRACE_SECONDS - 1, 0)) << "inside the grace window";+ EXPECT_TRUE(should_hold_ancs(true, bearer, past_grace, 0)) << "a live session holds";+}