Add Android companion beacon app (v1)

Kotlin/Compose foreground service advertising a connectable legacy
advertisement at ~1 Hz with a counter that rotates in ServiceData every
10s: changed payload values make BlueZ emit PropertiesChanged even when
the RSSI repeats, keeping the daemon's freshness clock fed for a
stationary phone. Running from a foreground service with a battery
optimization exemption defeats the advertising pauses that caused the
false locks. Replaces third-party beacon apps; the daemon needs no
changes. Verified with a real Gradle build (AGP 8.13.2, Kotlin 2.3.21,
compileSdk 36).
This commit is contained in:
Bastian Mäuser committed 2026-11-05 15:15:03 +01:00
1 parent aef8e2af17
commit 44510411fc
19 files changed
+917

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
# Proximity Beacon (companion Android app)
A minimal beacon app that replaces third-party iBeacon apps. It exists to
fix the two phone-side reliability problems documented in
`docs/HANDOFF.md` and AGENTS.md:
1. **BlueZ dedupes identical RSSI values**, so a stationary phone goes
silent in the desktop's event stream. This app rotates the advertised
`ServiceData` counter every 10 s (`AdvertisingSet.setAdvertisingData`),
which makes BlueZ emit `PropertiesChanged` even when the RSSI repeats.
The desktop daemon treats any `Device1` property update as a sighting.
2. **Beacon apps get frozen by Android doze / battery optimization**,
pausing advertising for stretches. This app advertises from a
foreground service (`connectedDevice` type) with a persistent
notification, and offers a one-tap battery-optimization exemption.
The advertisement is legacy, connectable and scannable at ~1 Hz
(`INTERVAL_HIGH`): connectable so the desktop's pre-lock connect probe
can attach, ~1 Hz to match the daemon's duty-cycle assumptions.
Payload: 16-bit service UUID `0xFCA7` (unassigned) + 8-byte rotating
counter. No stable identifier — privacy comes from the phone's rotating
private address, which only the bonded desktop can resolve.
## Build
Requires JDK 17+ (Android Studio's bundled JDK works):
```sh
cd android
./gradlew assembleDebug
# -> app/build/outputs/apk/debug/app-debug.apk
```
Install: `adb install app/build/outputs/apk/debug/app-debug.apk`, or copy
the APK to the phone and open it.
## Use
1. Open "Proximity Beacon", grant the advertising/notification prompts.
2. Tap "Exempt from battery optimization" (the point of the app).
3. Tap "Start beacon"; keep the notification. Point the daemon's
`device_mac` at this phone as before.
If the beacon is running, the desktop journal should show sightings every
few seconds even when the phone lies still — watch with
`journalctl --user -u btle-proximity -f` while testing.