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).
1.9 KiB
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:
- BlueZ dedupes identical RSSI values, so a stationary phone goes
silent in the desktop's event stream. This app rotates the advertised
ServiceDatacounter every 10 s (AdvertisingSet.setAdvertisingData), which makes BlueZ emitPropertiesChangedeven when the RSSI repeats. The desktop daemon treats anyDevice1property update as a sighting. - Beacon apps get frozen by Android doze / battery optimization,
pausing advertising for stretches. This app advertises from a
foreground service (
connectedDevicetype) 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):
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
- Open "Proximity Beacon", grant the advertising/notification prompts.
- Tap "Exempt from battery optimization" (the point of the app).
- Tap "Start beacon"; keep the notification. Point the daemon's
device_macat 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.