Probe for 10s and log its outcome before locking

The phone's beacon app pauses advertising for stretches while in range,
which is what the 3s probe could not bridge. Give the controller a 10s
window to find the phone, and log probe outcomes at INFO/WARN so the
journal explains every lock decision.
This commit is contained in:
Bastian Mäuser committed 2026-11-05 14:57:48 +01:00
1 parent 43a79d8a43
commit c25ccde58e
2 files changed
+12 -8

No files matched your search

+2 -2
View File
@@ -39,7 +39,7 @@ The daemon adapts it to a small state machine:
Locking goes through `loginctl lock-session` (works with GNOME, KDE, Sway, Locking goes through `loginctl lock-session` (works with GNOME, KDE, Sway,
...), configurable via `lock_command`. Before locking, the daemon attempts a ...), configurable via `lock_command`. Before locking, the daemon attempts a
short (3s) LE connection to the paired phone: a phone in range accepts it, short (10s) LE connection to the paired phone: a phone in range accepts it,
which cancels the lock — silence in the advertisement stream alone is not which cancels the lock — silence in the advertisement stream alone is not
proof of absence. proof of absence.
@@ -122,7 +122,7 @@ See `config.toml.example`; every knob is documented there. Highlights:
identical RSSI values (its property cache suppresses unchanged values), so identical RSSI values (its property cache suppresses unchanged values), so
a stationary phone can go quiet in the event stream while in range. Two a stationary phone can go quiet in the event stream while in range. Two
countermeasures: the radio escalates duty while updates are stalled (see countermeasures: the radio escalates duty while updates are stalled (see
Present above), and the lock decision is gated on a 3s LE connect probe. Present above), and the lock decision is gated on a 10s LE connect probe.
`--dry-run` on your hardware remains the arbiter. The AdvertisementMonitor `--dry-run` on your hardware remains the arbiter. The AdvertisementMonitor
roadmap removes this class of problem. roadmap removes this class of problem.
- While the screen is locked the daemon keeps low-duty scanning to notice - While the screen is locked the daemon keeps low-duty scanning to notice
+10 -6
View File
@@ -176,9 +176,10 @@ struct Target {
} }
/// How long to wait for the connect probe before concluding the phone is /// How long to wait for the connect probe before concluding the phone is
/// gone. LE connection setup with the phone in range completes well within /// gone. The controller scans for the phone's advertisements for this whole
/// this; aborting cancels BlueZ's connection attempt. /// window, so slow or intermittent advertising still gets caught; aborting
const PROBE_TIMEOUT: Duration = Duration::from_secs(3); /// cancels BlueZ's connection attempt.
const PROBE_TIMEOUT: Duration = Duration::from_secs(10);
/// Attempt a short LE connection to the paired phone. Returns true if the /// Attempt a short LE connection to the paired phone. Returns true if the
/// device accepted the connection (it is in range); the connection is closed /// device accepted the connection (it is in range); the connection is closed
@@ -190,7 +191,7 @@ async fn probe_reachable(conn: &Connection, target: Option<&Target>) -> bool {
let proxy = match Proxy::new(conn, BLUEZ, target.path.clone(), DEVICE_IFACE).await { let proxy = match Proxy::new(conn, BLUEZ, target.path.clone(), DEVICE_IFACE).await {
Ok(p) => p, Ok(p) => p,
Err(e) => { Err(e) => {
debug!("probe: proxy setup failed: {e:#}"); warn!("probe: proxy setup failed: {e:#}");
return false; return false;
} }
}; };
@@ -207,11 +208,14 @@ async fn probe_reachable(conn: &Connection, target: Option<&Target>) -> bool {
true true
} }
Ok(Err(e)) => { Ok(Err(e)) => {
debug!("probe: connect rejected: {e:#}"); info!("probe: connect rejected: {e:#}");
false false
} }
Err(_) => { Err(_) => {
debug!("probe: timed out"); warn!(
"probe: no connection within {}s, treating phone as out of range",
PROBE_TIMEOUT.as_secs()
);
// Cancel the pending connection attempt so BlueZ does not keep // Cancel the pending connection attempt so BlueZ does not keep
// paging for the device in the background. // paging for the device in the background.
let _ = tokio::time::timeout( let _ = tokio::time::timeout(