Linux + iPhone Continuity / iMessage / SMS
fix: le improvements
Zack Bartelf1c70dd783f6
diff --git a/docs/BLUETOOTH.md b/docs/BLUETOOTH.mdindex f81269f..e24f035 100644--- a/docs/BLUETOOTH.md+++ b/docs/BLUETOOTH.md@@ -122,9 +122,9 @@ checks the daemon does not make.| Pairing fails with `br-connection-key-missing` | A stale bond on one side, or the adapter is not `Pairable` | Delete the computer's entry on the phone (Forget This Device) and `tether --bt-unpair <addr>` locally, then pair again || The phone shows two entries for this computer | A failed pairing left both a Classic and an LE record | Delete both on the phone before retrying || LE never connects and the log repeats `org.bluez.Error.InProgress` | BlueZ is holding an auto-connect registration that never completed | `sudo systemctl restart bluetooth` -- nothing short of that clears it, see 2026-08-19 below. With `tether-btclass@hci0` enabled the class survives the restart |-| The status says "Nothing is listening for the iPhone's LE link" | BlueZ refused to register for the phone's LE connection, so nothing is waiting for it | `sudo systemctl restart bluetooth`. This is different from waiting on the phone, which the status says instead when a registration is open |+| The log says `could not re-arm the ANCS solicitation` | BlueZ refused to register the advertisement, so nothing is on air for the iPhone to answer | `sudo systemctl restart bluetooth`. Nothing else brings it back, and the LE link cannot form without it || LE never connects and the log repeats `le-connection-abort-by-local` | Something on this side is cancelling the connection. Tether's own cause was a `PreferredBearer` write racing the async connect, fixed; anything else writing that property during a connect will do the same | Check no other Bluetooth tool is driving the same device. The phone is not the cause: `abort-by-local` means the local host cancelled |-| Notifications stopped and never came back, while messages and contacts kept working | Fixed. The bearer supervisor used to stop retrying LE after six attempts, and only a Classic drop or a daemon restart re-armed it | Nothing. LE is now retried indefinitely at the five-minute ceiling, and the ANCS solicitation is kept on air whenever LE is down |+| Notifications stopped and never came back, while messages and contacts kept working | Fixed. The bearer supervisor used to stop retrying LE after six attempts, and only a Classic drop or a daemon restart re-armed it | Nothing. The solicitation is kept on air whenever LE is down, which is what the iPhone answers -- see 2026-08-22 || `tether --bt-status` reports `Bond: BR/EDR only` | The bond was made without cross-transport key derivation, so it has no LE half and can never carry ANCS | Forget this computer on the iPhone and pair again. Check `secure-connections` in the same output first: re-pairing cannot help while it is off || The status says the iPhone is not answering on LE, and its permission is on | The phone's Bluetooth stack is wedged, which the granted permission does not prevent | Turn Bluetooth off and back on **on the iPhone**. Re-pairing and re-toggling the permission do not clear this || Everything connects but `ancs_ready` stays false | Compatibility mode, or iOS has not authorized notification content yet | Check `Mode:` in `tether --bt-status`. In full mode the daemon retries, the first request returns `NotPermitted` until the prompt on the phone is approved |@@ -686,6 +686,60 @@ broken. LE now backs off to its own 60s ceiling. A dial costs nothing since oneis never issued while another is outstanding, and the failure it recovers fromis the one a human has just cleared by hand.+### 2026-08-22 - The advert opens the link in 1.3s; the dial never opened one++Same hardware. Captured across a `bluetoothd` restart, a daemon start, and a+Bluetooth cycle on the iPhone, with the phone in the silent state described on+2026-08-19 and then brought back by hand.++The moment the link forms is unambiguous:++```+t=81.858 LE Set Extended Advertising Enable: Disabled <- dial window opens+t=127.668 LE Set Extended Advertising Enable: Enabled, Handle 0x01, Success+t=128.962 LE Enhanced Connection Complete, Role: Peripheral, Success+```++**1.29 seconds.** `Role: Peripheral` means the iPhone was the central: it dialled+us, inbound, in answer to the solicitation. Peer address `59:71:0E:41:74:AA+(Resolvable)`, resolved to the identity address.++The dial had every chance and took none of it. Across three captures totalling+roughly 700 seconds, no `Bearer.LE1.Connect` produced an HCI connect attempt, let+alone a link -- BlueZ implements it as an accept-list-filtered passive scan, as+recorded on 2026-08-19. In this capture the phone was reported advertising at+t=75.0, 90.8, 91.1 and 92.6 while that scan had already been torn down by the+45s dial timeout at t=53.8, so nothing was armed when it was there.++So the two routes are not equals taking turns. One of them works in about a+second and the other has never worked here, while the dial window costs the+working route 45 seconds of airtime out of every 225 -- worse in practice,+because `reset()` on a Classic flap restarts the window. Measured over the first+127 seconds of this capture the advert was on air for 27.6 of them.++The supervisor now dials once per daemon and then leaves the radio to the+solicitation. `reset()` deliberately does not refund the dial: a Classic flap is+not a reason to take the advert down for another attempt. The dial is kept at all+only because a cold start is the one case with no evidence either way.++`BearerStatus::le_dialling` still gates the solicitation, so the advert cannot go+up while that single dial is in flight -- the abort recorded on 2026-08-20. It is+assigned *after* the attempt in the same tick, not before; reading it first let+the advert go up alongside the dial it was meant to protect.++Two leads closed. The advert's `Flags` byte reads `0x06` (`BR/EDR Not Supported`)+where the iPhone's own adverts read `0x1a`, on the same public address the phone+holds a BR/EDR link to. It is synthesised by the kernel, identical for every+BlueZ client, and `LEAdvertisement1` rejects a client-supplied AD type `0x01`+("Failed to parse advertisement"). It is not the differentiator. Separately, the+controller's resolving list is never programmed and the accept list gets a single+entry, yet the inbound RPA above still resolved -- not a fault either.++None of this explains a phone that will not answer. `[IdentityResolvingKey]` and+an LE-SC `[PeripheralLongTermKey]` with `Authenticated=3` were present throughout,+so re-pairing is not the remedy and was not needed; cycling Bluetooth on the+iPhone was, exactly as on 2026-08-19.+### PBAP`Select("int", "pb")` followed by `PullAll` with `Format: vcard30` and `MaxCount` returned 456 contacts on the first attempt.diff --git a/src/core/include/tether/bluetooth/bearer_supervisor.hpp b/src/core/include/tether/bluetooth/bearer_supervisor.hppindex f937983..d0f300f 100644--- a/src/core/include/tether/bluetooth/bearer_supervisor.hpp+++ b/src/core/include/tether/bluetooth/bearer_supervisor.hpp@@ -9,13 +9,14 @@ namespace tether::bluetooth {inline constexpr int BEARER_SETTLE_SECONDS = 3;inline constexpr int BEARER_BACKOFF_MIN_SECONDS = 5;inline constexpr int BEARER_BACKOFF_MAX_SECONDS = 300;- inline constexpr int LE_BACKOFF_MAX_SECONDS = 60;// How many refused attempts before the status stops saying "connecting"inline constexpr int CLASSIC_FAILURES_BEFORE_ADVICE = 6;- inline constexpr int LE_ATTEMPTS_BEFORE_ADVICE = 6;- inline constexpr int LE_DIAL_WINDOW_SECONDS = 45;- inline constexpr int LE_SOLICIT_WINDOW_SECONDS = 180;+ // How long LE may stay down, with the solicitation broadcasting, before the+ // status stops saying "waiting" and names the phone-side Bluetooth cycle.+ // A phone that is answering does so in about a second, so silence this far+ // past that is the iPhone having gone quiet, not a slow connect.+ inline constexpr int LE_SILENT_SECONDS = 180;// How long an ANCS session is held across an LE outage before the path is// dropped. The bearer flaps faster than a GATT subscription can be rebuilt,@@ -57,7 +58,6 @@ namespace tether::bluetooth {bool le_available = false;bool le_dialling = false;int classic_backoff = 0;- int le_backoff = 0;std::string reason;bool operator==(const BearerStatus&) const = default;@@ -87,14 +87,10 @@ namespace tether::bluetooth {BearerStatus status_;int classic_failures_ = 0;- int le_failures_ = 0;- bool le_listening_ = false;- bool le_phone_silent_ = false;- bool le_stuck_locally_ = false;+ bool le_dial_spent_ = false;int64_t classic_connected_since_ = -1;int64_t le_down_since_ = -1;int64_t next_classic_attempt_ = 0;- int64_t next_le_attempt_ = 0;};} // namespace tether::bluetoothdiff --git a/src/core/src/bluetooth/bearer_supervisor.cpp b/src/core/src/bluetooth/bearer_supervisor.cppindex b55cc67..5b7bad8 100644--- a/src/core/src/bluetooth/bearer_supervisor.cpp+++ b/src/core/src/bluetooth/bearer_supervisor.cpp@@ -69,16 +69,10 @@ namespace tether::bluetooth {void BearerSupervisor::reset() {classic_failures_ = 0;- le_failures_ = 0;- le_listening_ = false;- le_phone_silent_ = false;le_down_since_ = -1;- le_stuck_locally_ = false;classic_connected_since_ = -1;next_classic_attempt_ = 0;- next_le_attempt_ = 0;status_.classic_backoff = 0;- status_.le_backoff = 0;}bool BearerSupervisor::tick(int64_t now) {@@ -103,14 +97,8 @@ namespace tether::bluetooth {else if (le_down_since_ < 0)le_down_since_ = now;- if (status_.le_connected) {- // Neither route is in use once the link is up.+ if (status_.le_connected)status_.le_dialling = false;- le_failures_ = 0;- le_stuck_locally_ = false;- status_.le_backoff = 0;- next_le_attempt_ = 0;- }if (status_.classic_connected) {if (classic_connected_since_ < 0)@@ -172,52 +160,27 @@ namespace tether::bluetooth {}if (!status_.le_connected) {- // alternate the two routes rather than running both- const int64_t phase = (now - le_down_since_) % (LE_DIAL_WINDOW_SECONDS + LE_SOLICIT_WINDOW_SECONDS);-- status_.le_dialling = phase < LE_DIAL_WINDOW_SECONDS || ops_.le_connect_outstanding();-+ // solicitation owns the radio; the dial gets one shot per daemon and then stands aside.const bool settled =classic_connected_since_ >= 0 && now - classic_connected_since_ >= BEARER_SETTLE_SECONDS;- if (settled && status_.le_dialling && !ops_.le_connect_outstanding() && now >= next_le_attempt_) {+ if (!le_dial_spent_ && settled && !ops_.le_connect_outstanding()) {std::string err;const ConnectResult result = classify(ops_.connect_le(err), err);-- switch (result) {- case ConnectResult::Requested:- case ConnectResult::Busy:- le_listening_ = true;- le_stuck_locally_ = false;- status_.le_backoff = 0;- next_le_attempt_ = now + BEARER_POLL_SECONDS;- break;- case ConnectResult::Failed:- ++le_failures_;- le_listening_ = false;- le_stuck_locally_ = false;- le_phone_silent_ = is_transient(err);- status_.le_backoff = next_backoff(status_.le_backoff, err, LE_BACKOFF_MAX_SECONDS);- next_le_attempt_ = now + status_.le_backoff;- debug::log(WARN, "bluetooth: LE connect failed ({}), retrying in {}s", err, status_.le_backoff);- break;- }- }- if (!status_.le_connected) {- if (le_phone_silent_ && le_failures_ >= LE_ATTEMPTS_BEFORE_ADVICE)- status_.reason = LE_PHONE_SILENT_ADVICE;- else if (ops_.le_connect_outstanding() || le_listening_)- status_.reason = "Connected. Waiting for the iPhone to open the LE link that carries "- "notifications. If it does not, open Settings > Bluetooth > (i) on the "- "iPhone and check Share System Notifications.";- else if (le_phone_silent_)- status_.reason = LE_PHONE_SILENT_ADVICE;- else- status_.reason = "Nothing is listening for the iPhone's LE link. BlueZ refused to register "- "for it, which only \"sudo systemctl restart bluetooth\" clears. Messages "- "and contacts are unaffected.";- return !(status_ == previous);+ le_dial_spent_ = true;+ if (result == ConnectResult::Failed)+ debug::log(WARN, "bluetooth: LE connect failed ({}), leaving it to the solicitation", err);}++ // read after the attempt, never before+ status_.le_dialling = ops_.le_connect_outstanding();++ status_.reason = le_down_since_ >= 0 && now - le_down_since_ >= LE_SILENT_SECONDS+ ? LE_PHONE_SILENT_ADVICE+ : "Connected. Waiting for the iPhone to open the LE link that carries "+ "notifications. If it does not, open Settings > Bluetooth > (i) on the "+ "iPhone and check Share System Notifications.";+ return !(status_ == previous);}status_.reason = "Connected over BR/EDR and LE.";diff --git a/test/test_bluetooth_supervisor.cpp b/test/test_bluetooth_supervisor.cppindex e7092a7..6b9da17 100644--- a/test/test_bluetooth_supervisor.cpp+++ b/test/test_bluetooth_supervisor.cpp@@ -158,33 +158,81 @@ TEST(BearerSupervisor, InProgressWidensTheClassicWindow) {EXPECT_EQ(ops.classic_attempts, 5);}-// A refusal is different: the phone said no, and hammering it was observed to-// hold the bond in a half-connected flapping state.-TEST(BearerSupervisor, RefusalStillGrowsTheLeBackoff) {+// One dial per daemon, then the advert owns the radio. Measured 2026-08-22: the+// solicitation went on air at t=127.668 and the iPhone opened the link inbound+// 1.3s later, while three captures totalling ~700s produced no link from a dial+// -- including one where the phone was advertising with a dial armed. reset()+// must not refund the dial: a Classic flap would otherwise take the advert back+// off air for the length of another attempt.+TEST(BearerSupervisor, DialsLeOnceThenLeavesItToTheSolicitation) {FakeBearer ops;- ops.le_succeeds = false;+ ops.le_succeeds = false; // BlueZ answers, no link followsBearerSupervisor sup(ops, true);- sup.tick(0);- sup.tick(1);- sup.tick(1 + BEARER_SETTLE_SECONDS);- EXPECT_EQ(sup.status().le_backoff, BEARER_BACKOFF_MIN_SECONDS);+ int64_t now = 0;+ for (; now < 400; ++now)+ sup.tick(now);+ EXPECT_EQ(ops.le_attempts, 1) << "kept dialling past the one attempt";- sup.tick(1 + BEARER_SETTLE_SECONDS + BEARER_BACKOFF_MIN_SECONDS);- EXPECT_EQ(sup.status().le_backoff, BEARER_BACKOFF_MIN_SECONDS * 2);+ // A Classic flap, and the phone coming back, must not buy another.+ ops.classic = false;+ sup.tick(now++);+ sup.reset();+ ops.classic_succeeds = true;+ for (int i = 0; i < 400; ++i)+ sup.tick(now++);+ EXPECT_EQ(ops.le_attempts, 1) << "reset() refunded the dial and took the advert off air again";}-TEST(BearerSupervisor, LeBackoffDoesNotBlockClassic) {+// The advert must not go up while a dial is in flight -- that is what aborted+// the connect once per cycle (2026-08-20). le_dialling gates the solicitation,+// so it stays true until the reply lands and false forever after.+TEST(BearerSupervisor, SolicitationIsHeldOffOnlyWhileTheOneDialIsInFlight) {+ class ListeningBearer : public FakeBearer {+ public:+ ConnectResult connect_le(std::string&) override {+ ++le_attempts;+ outstanding = true;+ return ConnectResult::Requested;+ }+ } ops;++ BearerSupervisor sup(ops, true);+ int64_t now = 0;+ sup.tick(now);+ sup.tick(++now);+ now += BEARER_SETTLE_SECONDS;+ sup.tick(now);+ ASSERT_EQ(ops.le_attempts, 1);+ EXPECT_TRUE(sup.status().le_dialling) << "solicited on top of a dial still in flight";++ ops.outstanding = false;+ sup.tick(++now);+ EXPECT_FALSE(sup.status().le_dialling);+ for (int i = 0; i < 500; ++i) {+ sup.tick(++now);+ ASSERT_FALSE(sup.status().le_dialling) << "took the solicitation off air again at t=" << now;+ }+}++// A phone that is answering answers in about a second. A long silence with the+// advert up is the iPhone having gone quiet, and only cycling Bluetooth on the+// phone clears that -- so the status has to say so rather than "waiting" forever.+TEST(BearerSupervisor, NamesThePhoneCycleAfterALongSilence) {FakeBearer ops;ops.le_succeeds = false;BearerSupervisor sup(ops, true);- sup.tick(0);- sup.tick(1);- sup.tick(1 + BEARER_SETTLE_SECONDS);- EXPECT_EQ(ops.le_attempts, 1);- EXPECT_GT(sup.status().le_backoff, 0);- EXPECT_TRUE(sup.status().classic_connected) << "an LE failure must not tear down Classic";+ int64_t now = 0;+ sup.tick(now);+ sup.tick(++now);+ now += BEARER_SETTLE_SECONDS;+ sup.tick(now);+ EXPECT_NE(sup.status().reason.find("Waiting for the iPhone to open the LE link"), std::string::npos);++ sup.tick(now + LE_SILENT_SECONDS);+ EXPECT_NE(sup.status().reason.find("not answering on LE"), std::string::npos);+ EXPECT_NE(sup.status().reason.find("turn Bluetooth off"), std::string::npos);}TEST(BearerSupervisor, RecoversAfterDisconnect) {@@ -205,9 +253,10 @@ TEST(BearerSupervisor, RecoversAfterDisconnect) {EXPECT_FALSE(sup.status().le_connected);EXPECT_EQ(ops.classic_attempts, 2);- // ...and comes back.+ // ...and comes back, with the iPhone answering the solicitation as it does+ // on real hardware -- the daemon spent its one dial long ago.sup.tick(101);- sup.tick(101 + BEARER_SETTLE_SECONDS);+ ops.le = true;sup.tick(102 + BEARER_SETTLE_SECONDS);EXPECT_TRUE(sup.status().classic_connected);EXPECT_TRUE(sup.status().le_connected);@@ -477,193 +526,6 @@ TEST(BearerSupervisor, TransientFailuresDoNotEscalateTheBackoff) {}}-// BlueZ implements an LE connect as an accept-list registration plus a-// background scan -- it waits for the phone to advertise rather than dialling-// it. Captured 2026-08-19: six Connect calls produced six "Add Device, action-// auto-connect" and not one LE Create Connection. So exactly one registration-// should be held open while LE is down, and repeating it is not progress.-TEST(BearerSupervisor, HoldsOneLeRegistrationRatherThanRepeatingIt) {- class ListeningBearer : public FakeBearer {- public:- ConnectResult connect_le(std::string&) override {- ++le_attempts;- outstanding = true; // BlueZ now holds it until the request completes- return ConnectResult::Requested;- }- } listening;-- BearerSupervisor sup(listening, true);- int64_t now = 0;- sup.tick(now);- sup.tick(++now);- now += BEARER_SETTLE_SECONDS;- sup.tick(now);- EXPECT_EQ(listening.le_attempts, 1);-- // Ticks throughout the dial window must not add a second one.- for (int i = 0; i < LE_DIAL_WINDOW_SECONDS - BEARER_SETTLE_SECONDS - 3; ++i)- sup.tick(++now);- EXPECT_EQ(listening.le_attempts, 1) << "re-registered on top of a live registration";- EXPECT_NE(sup.status().reason.find("Waiting for the iPhone to open the LE link"), std::string::npos);-- // When the request finally completes without a link, one fresh registration- // replaces it -- still only ever one at a time.- listening.outstanding = false;- sup.tick(++now);- EXPECT_EQ(listening.le_attempts, 2);-}--// InProgress means BlueZ already holds a registration. That is the state worth-// being in, so it must not be counted as a failure or earn a backoff -- treating-// it as one is what turned a healthy wait into an escalating retry.-TEST(BearerSupervisor, InProgressIsListeningNotFailing) {- class InProgressBearer : public FakeBearer {- public:- ConnectResult connect_le(std::string& err) override {- ++le_attempts;- err = "GDBus.Error:org.bluez.Error.InProgress: In Progress";- return ConnectResult::Failed;- }- } busy;-- BearerSupervisor sup(busy, true);- int64_t now = 0;- sup.tick(now);- sup.tick(++now);- now += BEARER_SETTLE_SECONDS;- sup.tick(now);-- EXPECT_EQ(sup.status().le_backoff, 0) << "an outstanding registration was treated as a refusal";- EXPECT_NE(sup.status().reason.find("Waiting for the iPhone"), std::string::npos);-}--// A registration BlueZ refuses outright is different: nothing is listening, and-// the status has to say so rather than implying the phone is being waited on.-TEST(BearerSupervisor, ARefusedRegistrationSaysNothingIsListening) {- FakeBearer ops;- ops.le_succeeds = false;- ops.le_error = "org.bluez.Error.AuthenticationFailed";- BearerSupervisor sup(ops, true);-- int64_t now = 0;- sup.tick(now);- sup.tick(++now);- now += BEARER_SETTLE_SECONDS;- while (ops.le_attempts < LE_ATTEMPTS_BEFORE_ADVICE) {- sup.tick(now);- now += BEARER_BACKOFF_MAX_SECONDS;- }- sup.tick(now);-- EXPECT_NE(sup.status().reason.find("Nothing is listening"), std::string::npos);- EXPECT_NE(sup.status().reason.find("systemctl restart bluetooth"), std::string::npos);- EXPECT_NE(sup.status().reason.find("Messages and contacts are unaffected"), std::string::npos);- EXPECT_GT(sup.status().le_backoff, BEARER_BACKOFF_MIN_SECONDS) << "a refusal must still back off";-}--// The two routes to an LE link cannot run together. Measured 2026-08-19 with the-// PreferredBearer race already removed: advert off -> connects first attempt, zero-// aborts; advert on -> four le-connection-abort-by-local and no link. So they-// alternate, and the phase has to be bounded by time rather than by failures ---// an outstanding registration suppresses new attempts, so failures stop accruing-// and a failure-counted phase would never end, leaving the advert off forever.-TEST(BearerSupervisor, AlternatesBetweenDiallingAndSoliciting) {- class ListeningBearer : public FakeBearer {- public:- ConnectResult connect_le(std::string&) override {- ++le_attempts;- outstanding = true; // BlueZ holds the registration, as it really does- return ConnectResult::Requested;- }- } ops;-- BearerSupervisor sup(ops, true);- int64_t now = 0;- sup.tick(now);- sup.tick(++now);- now += BEARER_SETTLE_SECONDS;- sup.tick(now);- EXPECT_TRUE(sup.status().le_dialling) << "the dial window should come first";- EXPECT_EQ(ops.le_attempts, 1);-- // The clock runs out while BlueZ is still connecting. Soliciting now would- // abort that connect, so the window stays open until the reply lands.- now += LE_DIAL_WINDOW_SECONDS;- sup.tick(now);- EXPECT_TRUE(sup.status().le_dialling) << "solicited on top of a dial that was still in flight";-- // connect_le() abandons the call at its own timeout, which is what ends it.- ops.outstanding = false;- sup.tick(++now);- EXPECT_FALSE(sup.status().le_dialling) << "deadlocked: an open registration froze the dial phase";-- // No connect may be issued anywhere in the solicitation window.- const int attempts = ops.le_attempts;- const int64_t cycle = LE_DIAL_WINDOW_SECONDS + LE_SOLICIT_WINDOW_SECONDS;- while (now < cycle - 2) {- sup.tick(++now);- ASSERT_FALSE(sup.status().le_dialling) << "left the solicitation window early, at t=" << now;- }- EXPECT_EQ(ops.le_attempts, attempts) << "dialled while the solicitation was broadcasting";-- // ...and then it comes back around to dialling.- now = cycle + 1;- sup.tick(now);- EXPECT_TRUE(sup.status().le_dialling) << "never returned to the dial route";-}--// A link that is up needs neither route, so nothing should be suppressed by it.-TEST(BearerSupervisor, NotDiallingOnceLeIsUp) {- FakeBearer ops;- BearerSupervisor sup(ops, true);-- sup.tick(0);- sup.tick(1);- sup.tick(1 + BEARER_SETTLE_SECONDS);- sup.tick(2 + BEARER_SETTLE_SECONDS);- ASSERT_TRUE(sup.status().le_connected);- EXPECT_FALSE(sup.status().le_dialling);-}--// A dead LE link has two very different causes. A timeout is the phone ignoring-// us, which only cycling Bluetooth on the phone clears; a refusal is BlueZ-// declining to register, which needs bluetoothd restarted. Sharing one message-// sent debugging to the wrong machine.-TEST(BearerSupervisor, TellsPhoneSilenceApartFromABlueZRefusal) {- FakeBearer silent;- silent.le_succeeds = false;- silent.le_error = "GDBus.Error:org.bluez.Error.Failed: Connection timed out";- BearerSupervisor a(silent, true);- int64_t now = 0;- a.tick(now);- a.tick(++now);- now += BEARER_SETTLE_SECONDS;- while (silent.le_attempts < LE_ATTEMPTS_BEFORE_ADVICE) {- a.tick(now);- now += BEARER_BACKOFF_MAX_SECONDS;- }- a.tick(now);- EXPECT_NE(a.status().reason.find("not answering on LE"), std::string::npos);- EXPECT_NE(a.status().reason.find("turn Bluetooth off and back on on the iPhone"), std::string::npos);- EXPECT_EQ(a.status().reason.find("systemctl"), std::string::npos) << "blamed the local stack for the phone";-- FakeBearer refused;- refused.le_succeeds = false;- refused.le_error = "org.bluez.Error.AuthenticationFailed";- BearerSupervisor b(refused, true);- now = 0;- b.tick(now);- b.tick(++now);- now += BEARER_SETTLE_SECONDS;- while (refused.le_attempts < LE_ATTEMPTS_BEFORE_ADVICE) {- b.tick(now);- now += BEARER_BACKOFF_MAX_SECONDS;- }- b.tick(now);- EXPECT_NE(b.status().reason.find("Nothing is listening"), std::string::npos);- EXPECT_EQ(b.status().reason.find("not answering"), std::string::npos);-}-// A refusal from the phone is a real answer, and repeating it every five seconds// helps nobody.TEST(BearerSupervisor, PersistentFailuresStillEscalate) {@@ -803,118 +665,3 @@ TEST(BearerSupervisor, RepeatedRefusalNamesTheRemedy) {sup.tick(++now);EXPECT_TRUE(sup.status().classic_connected);}--// An LE link that needed a few tries, then held, must not resume at the backoff-// those tries grew to. Inheriting it means the first drop after a healthy day-// costs five minutes of dead notification mirroring.-TEST(BearerSupervisor, ASuccessfulLeLinkClearsTheBackoffItGrew) {- FakeBearer ops;- ops.le_succeeds = false;- BearerSupervisor sup(ops, true);-- // Classic is observed connected on the tick after it is dialed, and the- // settle window runs from there.- sup.tick(0);- sup.tick(1);- int64_t now = 1 + BEARER_SETTLE_SECONDS;- for (int i = 0; i < 4; ++i) {- sup.tick(now);- now += sup.status().le_backoff;- }- ASSERT_GT(sup.status().le_backoff, BEARER_BACKOFF_MIN_SECONDS);-- // The phone accepts, and the link holds.- ops.le_succeeds = true;- ops.le = true;- sup.tick(now);- ASSERT_TRUE(sup.status().le_connected);- EXPECT_EQ(sup.status().le_backoff, 0) << "carried the old backoff into a healthy link";-- // It drops much later. The retry is prompt, not held over from before.- ops.le = false;- ops.le_succeeds = false;- now += 100000;- const int attempts = ops.le_attempts;- sup.tick(now);- EXPECT_EQ(ops.le_attempts, attempts + 1) << "sat out a backoff inherited from a previous outage";- EXPECT_EQ(sup.status().le_backoff, BEARER_BACKOFF_MIN_SECONDS);-}--// The advice threshold names the message, not the end of the retry. Letting it-// gate the loop meant one daemon lifetime got six LE attempts and then never-// dialled again -- the "worked all morning, then stopped for good" report.-TEST(BearerSupervisor, KeepsDiallingPastTheAdviceThreshold) {- FakeBearer ops;- ops.le_succeeds = false;- ops.le_error = "GDBus.Error:org.bluez.Error.Failed: Connection timed out";- BearerSupervisor sup(ops, true);-- int64_t now = 0;- sup.tick(now);- sup.tick(++now);- now += BEARER_SETTLE_SECONDS;-- // Well past the threshold, over many dial/solicit cycles.- const int64_t cycle = LE_DIAL_WINDOW_SECONDS + LE_SOLICIT_WINDOW_SECONDS;- for (int i = 0; i < 20; ++i) {- sup.tick(now);- now += cycle;- }- EXPECT_GT(ops.le_attempts, LE_ATTEMPTS_BEFORE_ADVICE) << "stopped dialling for good";- EXPECT_NE(sup.status().reason.find("not answering on LE"), std::string::npos);-}--// A dial that BlueZ has not answered yet must keep the solicitation off the air:-// raising an advert mid-connect is what produced le-connection-abort-by-local on-// every cycle, so the phone was never dialled and never solicited cleanly.-TEST(BearerSupervisor, HoldsTheSolicitationOffWhileADialIsInFlight) {- class ListeningBearer : public FakeBearer {- public:- ConnectResult connect_le(std::string&) override {- ++le_attempts;- outstanding = true;- return ConnectResult::Requested;- }- } ops;-- BearerSupervisor sup(ops, true);- int64_t now = 0;- sup.tick(now);- sup.tick(++now);- now += BEARER_SETTLE_SECONDS;- sup.tick(now);- ASSERT_TRUE(ops.outstanding);-- const int64_t cycle = LE_DIAL_WINDOW_SECONDS + LE_SOLICIT_WINDOW_SECONDS;- for (int64_t t = now; t < now + 3 * cycle; t += BEARER_POLL_SECONDS) {- sup.tick(t);- ASSERT_TRUE(sup.status().le_dialling) << "solicited over an outstanding dial at t=" << t;- }-}--// LE and BR/EDR back off to different ceilings on purpose. The LE failure this-// recovers from is usually cleared by the user cycling Bluetooth on the phone,-// and BR/EDR's five-minute ceiling meant a phone that had just been fixed still-// looked broken for minutes. A dial is cheap now that one is never issued while-// another is outstanding.-TEST(BearerSupervisor, LeBacksOffLessFarThanClassic) {- static_assert(LE_BACKOFF_MAX_SECONDS < BEARER_BACKOFF_MAX_SECONDS);-- FakeBearer ops;- ops.le_succeeds = false;- ops.le_error = "org.bluez.Error.AuthenticationFailed"; // not transient, so it grows- BearerSupervisor sup(ops, true);-- int64_t now = 0;- sup.tick(now);- sup.tick(++now);- now += BEARER_SETTLE_SECONDS;-- // Only the dial window issues attempts, so grow it one whole cycle at a time.- const int64_t cycle = LE_DIAL_WINDOW_SECONDS + LE_SOLICIT_WINDOW_SECONDS;- for (int i = 0; i < 20; ++i) {- sup.tick(now);- now += cycle;- }- EXPECT_EQ(sup.status().le_backoff, LE_BACKOFF_MAX_SECONDS) << "LE inherited the BR/EDR ceiling";-}