Skip to content

Debloat your Android TV, install apps, browse and transfer files on it, all from your phone. Just 3 MB, no tracking, no root, no PC.

Off Wi-Fi: TVs go offline the moment the phone drops Wi-Fi

jesse-agent-232efa99252c2ed
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 99e7c68..d867395 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,7 +12,7 @@ until this file has a section for its version.
## Unreleased
-- **Fixed:** Off Wi-Fi, the TV screen says the phone isn't on Wi-Fi instead of "TV offline". [#333](../../pull/333)
+- **Fixed:** Off Wi-Fi, the TV screen says the phone isn't on Wi-Fi instead of "TV offline", and it changes the moment Wi-Fi drops, not after reopening the app. [#333](../../pull/333)
- **Fixed:** With the TV offline, Installed and Built-in say why they're empty instead of "Nothing here yet." [#333](../../pull/333)
## 0.15.0 — 2026-11-03
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/DeviceLink.kt b/adb/src/main/kotlin/app/tellyscope/adb/DeviceLink.kt
index b73539b..f3c1d14 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/DeviceLink.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/DeviceLink.kt
@@ -85,6 +85,21 @@ class DeviceLink(
_state.value = DeviceState.NOT_ALLOWED
}
+ /**
+ * The phone left the network, so an online TV is out of reach now, though a read on the old
+ * connection can take its socket timeout to fail. Offline at once; the loop retries as usual.
+ */
+ fun lanLost() {
+ if (_state.value != DeviceState.ONLINE) return
+ job?.cancel()
+ current.getAndSet(null)?.close()
+ _state.value = _state.value.on(DeviceEvent.Lost)
+ job = scope.launch {
+ delay(retryEvery)
+ loop()
+ }
+ }
+
fun disconnect() {
job?.cancel()
job = null
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/DeviceLinkTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/DeviceLinkTest.kt
index 74c0f06..98c21b7 100644
--- a/adb/src/test/kotlin/app/tellyscope/adb/DeviceLinkTest.kt
+++ b/adb/src/test/kotlin/app/tellyscope/adb/DeviceLinkTest.kt
@@ -103,6 +103,42 @@ class DeviceLinkTest {
assertEquals(2, sessions.size)
}
+ @Test fun lanLostGoesOfflineAtOnce() = runTest {
+ // The read on the old connection never fails, as on a phone that just lost Wi-Fi.
+ val sessions = mutableListOf<FakeShell>()
+ var reachable = true
+ val link = DeviceLink(
+ "tv", 5555, backgroundScope,
+ monitorFor = { _, _ -> fakeMonitor(failFirst = false) },
+ open = { _, _ ->
+ if (reachable) ConnectResult.Online(FakeShell().also { sessions += it }) else ConnectResult.Unreachable("no route")
+ },
+ )
+ link.connect(); runCurrent()
+ assertEquals(DeviceState.ONLINE, link.state.value)
+
+ reachable = false
+ link.lanLost(); runCurrent()
+ assertEquals(DeviceState.OFFLINE, link.state.value)
+ assertEquals(reading, link.stats.value)
+ assertTrue(sessions[0].closed)
+
+ reachable = true
+ advanceTimeBy(5_001)
+ assertEquals(DeviceState.ONLINE, link.state.value)
+ assertEquals(2, sessions.size)
+ }
+
+ @Test fun lanLostLeavesAnOfflineLinkAlone() = runTest {
+ var calls = 0
+ val link = DeviceLink("tv", 5555, backgroundScope, open = { _, _ -> calls++; ConnectResult.NotAllowed })
+ link.connect(); runCurrent()
+ link.lanLost()
+ advanceTimeBy(60_000)
+ assertEquals(DeviceState.NOT_ALLOWED, link.state.value)
+ assertEquals(1, calls)
+ }
+
@Test fun needsPairingStopsRetrying() = runTest {
var calls = 0
val link = DeviceLink("tv", 37011, backgroundScope, open = { _, _ -> calls++; ConnectResult.NeedsPairing })
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
index c621874..a40ac32 100644
--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
@@ -295,6 +295,8 @@ class AdbDeviceSource(
}
}
+ override fun lanLost() = links.values.forEach(DeviceLink::lanLost)
+
override fun lanUp(): Flow<Unit> = callbackFlow {
val cm = appContext.getSystemService(ConnectivityManager::class.java) ?: run { close(); return@callbackFlow }
val callback = object : ConnectivityManager.NetworkCallback() {
diff --git a/app/src/main/java/app/tellyscope/data/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
index 0e5895d..236c692 100644
--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
@@ -38,6 +38,9 @@ interface DeviceSource {
/** Whether the phone is on Wi-Fi or Ethernet right now, VPN or not. */
fun onLan(): Boolean = true
+ /** The phone just left Wi-Fi: every online TV goes offline now rather than when a read times out. */
+ fun lanLost() {}
+
/** Classic connect. Suspends while the TV shows the Allow prompt; the caller owns the timeout. */
suspend fun connect(hit: ScanHit): ConnectResult
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index c68cdbe..35c5898 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -552,8 +552,12 @@ class TellyscopeViewModel(
while (true) {
delay(1_000)
_now.value = clock()
- _state.update { it.copy(offWifi = !source.onLan()) }
- if (++tick % 3 == 0) refreshDevices()
+ val offWifi = !source.onLan()
+ val lost = offWifi && !_state.value.offWifi
+ _state.update { it.copy(offWifi = offWifi) }
+ // Just off Wi-Fi: the TVs show offline now, not after the old connection's read times out.
+ if (lost) source.lanLost()
+ if (++tick % 3 == 0 || lost) refreshDevices()
}
}
}