From 7a88a2d4b971f367006733d54d5ca99500294fe0 Mon Sep 17 00:00:00 2001 From: mrambossek Date: Sun, 2 Aug 2026 15:27:32 +0200 Subject: [PATCH] app: make the relay come back by itself, and report within seconds Two faults found by watching it run. The heartbeat was the only cadence, so the first pass ran before mDNS discovery finished, saw nothing, and then sat silent for two minutes - precisely when someone has just switched the relay on and is watching for it to work. It now polls every five seconds until the first successful report, then settles. And nothing restarted the service after a reboot or an app update, which is the most common way it dies during development. A relay that has quietly stopped is worse than one never switched on: the endpoint it last published keeps looking authoritative while pointing at a port nothing is listening on. RelayBootReceiver handles BOOT_COMPLETED and MY_PACKAGE_REPLACED, debug builds only, and does nothing unless the relay was already on. Verified end to end: installing this build triggered the receiver and the phone reported its endpoint 7 seconds later, unattended. Co-Authored-By: Claude Opus 5 --- echolot-app/app/src/main/AndroidManifest.xml | 15 +++++++++ .../app/echo_lot/app/AdbRelayService.kt | 11 ++++++- .../app/echo_lot/app/RelayBootReceiver.kt | 33 +++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 echolot-app/app/src/main/kotlin/app/echo_lot/app/RelayBootReceiver.kt diff --git a/echolot-app/app/src/main/AndroidManifest.xml b/echolot-app/app/src/main/AndroidManifest.xml index 0030503..a63d39f 100644 --- a/echolot-app/app/src/main/AndroidManifest.xml +++ b/echolot-app/app/src/main/AndroidManifest.xml @@ -21,6 +21,8 @@ + + + + + + + + + + = Build.VERSION_CODES.O) ctx.startForegroundService(i) diff --git a/echolot-app/app/src/main/kotlin/app/echo_lot/app/RelayBootReceiver.kt b/echolot-app/app/src/main/kotlin/app/echo_lot/app/RelayBootReceiver.kt new file mode 100644 index 0000000..bb6c582 --- /dev/null +++ b/echolot-app/app/src/main/kotlin/app/echo_lot/app/RelayBootReceiver.kt @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2026 Echolot contributors +// SPDX-License-Identifier: GPL-3.0-or-later + +package app.echo_lot.app + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent + +/** + * Brings the relay back after a reboot or an app update, without anyone opening the app. + * + * The relay's whole purpose is to keep answering "where is this device" while the device sits on a + * shelf unattended. Starting it only from [MainActivity] meant it silently did not come back from + * either event — and a relay that has quietly stopped is worse than one that was never switched + * on, because the endpoint it last published keeps looking authoritative while pointing at a port + * nothing is listening on. + * + * `MY_PACKAGE_REPLACED` matters as much as boot here: installing a new build is the single most + * common way this service dies during development, which is exactly when it is being relied on. + */ +class RelayBootReceiver : BroadcastReceiver() { + override fun onReceive(ctx: Context, intent: Intent) { + if (!BuildConfig.DEBUG) return + when (intent.action) { + Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MY_PACKAGE_REPLACED -> { + if (Settings(ctx).adbRelayEnabled) { + runCatching { AdbRelayService.start(ctx) } + } + } + } + } +}