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.
Remember each TV's last known facts until Forget
jesse-agent-36212df9a0a367e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 43229a2..c6ae9ad 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,8 @@ until this file has a section for its version.## Unreleased+- **Improved:** An offline TV keeps its maker and Android version after the app restarts. [#63](../../pull/63)+## 0.4.0 — 2026-10-24- **Improved:** Each TV's page has four tabs: Overview, Apps, Files and Tweaks. [#60](../../pull/60)diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex 8578e27..6f21c1e 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -29,6 +29,7 @@ import app.tellyscope.adb.Protectedimport app.tellyscope.adb.ProtectedReasonimport app.tellyscope.adb.Remoteimport app.tellyscope.adb.RemoteKey+import app.tellyscope.adb.Statsimport app.tellyscope.adb.PairResultimport app.tellyscope.adb.pairOnFreshPortimport app.tellyscope.adb.Tweak@@ -109,6 +110,13 @@ class AdbDeviceSource(context: Context) : DeviceSource {})links.put(host, link)?.disconnect()watchers.put(host, scope.launch {+ // Save a fresh reading only when what's kept of it changed, not every 2 s.+ launch {+ link.stats.collect { st ->+ val kept = saved[host]?.lastKnown+ if (st != null && lastKnown(st, kept) != kept) remember(host)+ }+ }link.state.collect { st ->if (st == AdbState.ONLINE) {restoring -= host@@ -125,6 +133,8 @@ class AdbDeviceSource(context: Context) : DeviceSource {val link = links[host] ?: returnval hit = hits[host] ?: returnval old = saved[host]+ // Another TV on a saved address starts from nothing, not from the old one's facts.+ val kept = old?.lastKnown?.takeIf { old.historyKey == null || old.historyKey == keys[host] }saved[host] = SavedDevice(host = host,port = link.port,@@ -133,10 +143,26 @@ class AdbDeviceSource(context: Context) : DeviceSource {model = link.stats.value?.model ?: old?.model,lastSeen = link.lastSeenMillis ?: old?.lastSeen ?: System.currentTimeMillis(),historyKey = keys[host] ?: old?.historyKey,+ lastKnown = link.stats.value?.let { lastKnown(it, kept) } ?: kept,)persist()}+ /**+ * What is kept of a reading; a fact this reading missed keeps its [old] value. Storage is+ * rounded to 0.1 GB so a few KB written doesn't count as new.+ */+ private fun lastKnown(s: Stats, old: LastKnown?) = LastKnown(+ manufacturer = s.manufacturer ?: old?.manufacturer,+ brand = s.brand ?: old?.brand,+ android = s.androidVersion ?: old?.android,+ softwareMonth = s.softwareMonth ?: old?.softwareMonth,+ storageUsedGb = s.storage?.let { tenths(it.usedKb) } ?: old?.storageUsedGb,+ storageTotalGb = s.storage?.let { tenths(it.totalKb) } ?: old?.storageTotalGb,+ )++ private fun tenths(kb: Long) = Math.round(kb / 104_857.6) / 10.0+/** Reads the map at write time, so whichever save runs last writes the newest list. */private fun persist() {scope.launch(Dispatchers.IO) { synchronized(store) { store.save(saved.values.sortedBy { it.host }) } }@@ -582,11 +608,12 @@ class AdbDeviceSource(context: Context) : DeviceSource {AdbState.FOUND, null -> DeviceState.Found},model = stats?.model ?: saved[id]?.model,- manufacturer = stats?.manufacturer,- android = stats?.androidVersion,+ manufacturer = stats?.manufacturer ?: saved[id]?.lastKnown?.manufacturer,+ android = stats?.androidVersion ?: saved[id]?.lastKnown?.android,lastSeen = link?.lastSeenMillis ?: saved[id]?.lastSeen,nickname = names[keys[id] ?: id],- brand = stats?.brand,+ brand = stats?.brand ?: saved[id]?.lastKnown?.brand,+ lastKnown = saved[id]?.lastKnown,)}diff --git a/app/src/main/java/app/tellyscope/data/DeviceStore.kt b/app/src/main/java/app/tellyscope/data/DeviceStore.ktindex ed485e2..1e9929a 100644--- a/app/src/main/java/app/tellyscope/data/DeviceStore.kt+++ b/app/src/main/java/app/tellyscope/data/DeviceStore.kt@@ -3,6 +3,7 @@package app.tellyscope.dataimport java.io.File+import java.time.YearMonth/** What Tellyscope remembers about a TV between launches. */data class SavedDevice(@@ -14,6 +15,8 @@ data class SavedDevice(val lastSeen: Long?,/** [historyKey] once the TV has answered; null before that. */val historyKey: String? = null,+ /** Cleared only by Forget, which drops the whole line. */+ val lastKnown: LastKnown? = null,)/**@@ -42,12 +45,25 @@ class DeviceStore(private val file: File) {private fun format(d: SavedDevice) = listOf(VERSION, d.host, d.port.toString(), d.kind.name, clean(d.name), clean(d.model), d.lastSeen?.toString().orEmpty(),clean(d.historyKey),+ clean(d.lastKnown?.manufacturer), clean(d.lastKnown?.brand), clean(d.lastKnown?.android),+ d.lastKnown?.softwareMonth?.toString().orEmpty(),+ d.lastKnown?.storageUsedGb?.toString().orEmpty(), d.lastKnown?.storageTotalGb?.toString().orEmpty(),).joinToString("\t")private fun parse(line: String): SavedDevice? {val f = line.split('\t')- // 7 fields: written before the history key existed.- if (f.size !in 7..8 || f[0] != VERSION) return null+ // 7 fields: written before the history key existed; 8 before the last-known facts.+ if (f.size !in setOf(7, 8, 14) || f[0] != VERSION) return null+ val lastKnown = if (f.size == 14 && f.subList(8, 14).any { it.isNotEmpty() }) {+ LastKnown(+ manufacturer = f[8].ifEmpty { null },+ brand = f[9].ifEmpty { null },+ android = f[10].ifEmpty { null },+ softwareMonth = f[11].ifEmpty { null }?.let { runCatching { YearMonth.parse(it) }.getOrNull() ?: return null },+ storageUsedGb = f[12].ifEmpty { null }?.let { it.toDoubleOrNull() ?: return null },+ storageTotalGb = f[13].ifEmpty { null }?.let { it.toDoubleOrNull() ?: return null },+ )+ } else nullreturn SavedDevice(host = f[1].ifEmpty { return null },port = f[2].toIntOrNull() ?: return null,@@ -56,6 +72,7 @@ class DeviceStore(private val file: File) {model = f[5].ifEmpty { null },lastSeen = f[6].toLongOrNull(),historyKey = f.getOrNull(7)?.ifEmpty { null },+ lastKnown = lastKnown,)}diff --git a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.ktindex 6ffcff5..a00242d 100644--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt@@ -104,6 +104,7 @@ class FakeDeviceSource(manufacturer = "Amazon",android = "9",lastSeen = clock() - 14 * 60_000,+ lastKnown = LastKnown("Amazon", "Amazon", "9", YearMonth.of(2024, 3), 5.1, 5.4),),).takeIf { scenario == Scenario.Normal }.orEmpty().forEach { put(it.id, it) }}diff --git a/app/src/main/java/app/tellyscope/data/Model.kt b/app/src/main/java/app/tellyscope/data/Model.ktindex 35d0cdd..f7ba5a7 100644--- a/app/src/main/java/app/tellyscope/data/Model.kt+++ b/app/src/main/java/app/tellyscope/data/Model.kt@@ -49,6 +49,21 @@ data class Device(val nickname: String? = null,/** `ro.product.brand`, which can differ from [manufacturer]. */val brand: String? = null,+ /** What the TV last reported, kept until Forget; as of [lastSeen]. Null before it ever answered. */+ val lastKnown: LastKnown? = null,+)++/**+ * The slow-changing facts from a TV's last good reading, saved on the phone so an offline TV+ * (even after a restart) still shows them. Live numbers (CPU, RAM, temp, network) are never kept.+ */+data class LastKnown(+ val manufacturer: String? = null,+ val brand: String? = null,+ val android: String? = null,+ val softwareMonth: YearMonth? = null,+ val storageUsedGb: Double? = null,+ val storageTotalGb: Double? = null,)sealed interface ConnectResult {diff --git a/app/src/test/java/app/tellyscope/DeviceStoreTest.kt b/app/src/test/java/app/tellyscope/DeviceStoreTest.ktindex 0d24031..3d56e26 100644--- a/app/src/test/java/app/tellyscope/DeviceStoreTest.kt+++ b/app/src/test/java/app/tellyscope/DeviceStoreTest.kt@@ -3,12 +3,14 @@package app.tellyscopeimport app.tellyscope.data.DeviceStore+import app.tellyscope.data.LastKnownimport app.tellyscope.data.SavedDeviceimport app.tellyscope.data.ScanKindimport org.junit.Assert.assertEqualsimport org.junit.Ruleimport org.junit.Testimport org.junit.rules.TemporaryFolder+import java.time.YearMonthclass DeviceStoreTest {@get:Rule val tmp = TemporaryFolder()@@ -59,8 +61,33 @@ class DeviceStoreTest {val file = tmp.root.resolve("devices.tsv")DeviceStore(file).save(listOf(tv))// The older format had no eighth field at all.- file.writeText(file.readText().replace("\t\n", "\n"))+ file.writeText(file.readText().replace("\t".repeat(7) + "\n", "\n"))assertEquals(7, file.readLines().single().split('\t').size)assertEquals(listOf(tv), DeviceStore(file).load())}++ @Test fun keepsTheLastKnownFacts() {+ val file = tmp.root.resolve("devices.tsv")+ val known = tv.copy(lastKnown = LastKnown("XGIMI", "XGIMI", "11", YearMonth.of(2023, 5), 9.4, 12.0))+ DeviceStore(file).save(listOf(known, stick))+ assertEquals(listOf(known, stick), DeviceStore(file).load())+ }++ @Test fun readsFilesFromBeforeTheLastKnownFacts() {+ val file = tmp.root.resolve("devices.tsv")+ val keyed = tv.copy(historyKey = "sn:XK03H1234")+ DeviceStore(file).save(listOf(keyed))+ // The older format stopped at the history key.+ file.writeText(file.readText().replace("\t".repeat(6) + "\n", "\n"))+ assertEquals(8, file.readLines().single().split('\t').size)+ assertEquals(listOf(keyed), DeviceStore(file).load())+ }++ @Test fun aDamagedLastKnownFactCostsOnlyThatTv() {+ val file = tmp.root.resolve("devices.tsv")+ DeviceStore(file).save(listOf(stick))+ file.appendText("v1\t192.168.1.88\t5555\tClassic\t\t\t\t\tXGIMI\t\t11\tMay 2023\t\t\n")+ file.appendText("v1\t192.168.1.89\t5555\tClassic\t\t\t\t\tXGIMI\t\t11\t\tlots\t\n")+ assertEquals(listOf(stick), DeviceStore(file).load())+ }}diff --git a/app/src/test/java/app/tellyscope/LastKnownTest.kt b/app/src/test/java/app/tellyscope/LastKnownTest.ktnew file mode 100644index 0000000..74468ac--- /dev/null+++ b/app/src/test/java/app/tellyscope/LastKnownTest.kt@@ -0,0 +1,52 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope++import app.tellyscope.data.AdbDeviceSource+import app.tellyscope.data.DeviceState+import app.tellyscope.data.DeviceStore+import app.tellyscope.data.LastKnown+import app.tellyscope.data.SavedDevice+import app.tellyscope.data.ScanKind+import kotlinx.coroutines.delay+import kotlinx.coroutines.runBlocking+import kotlinx.coroutines.withTimeout+import org.junit.Assert.assertEquals+import org.junit.Test+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.RuntimeEnvironment+import org.robolectric.annotation.Config+import java.io.File+import java.time.YearMonth++/** What a TV last reported survives an app restart while it's off, and goes with Forget. */+@RunWith(RobolectricTestRunner::class)+@Config(sdk = [35])+class LastKnownTest {+ private val context = RuntimeEnvironment.getApplication()+ private val file = File(context.filesDir, "devices.tsv")+ private val facts = LastKnown("XGIMI", "XGIMI", "11", YearMonth.of(2023, 5), 9.4, 12.0)++ // Port 1 on loopback refuses at once: the TV is off for the whole test.+ private val tv = SavedDevice("127.0.0.1", 1, ScanKind.Classic, "xgimi-projector", "XGIMI Horizon Pro", 1_760_000_000_000, "sn:XK03H1234", facts)++ @Test fun offlineTvKeepsItsFactsAcrossARestartUntilForget() = runBlocking {+ // What the last launch saved.+ DeviceStore(file).save(listOf(tv))++ val source = AdbDeviceSource(context)+ val device = source.known().single()+ assertEquals(DeviceState.Offline, device.state)+ assertEquals(facts, device.lastKnown)+ assertEquals("XGIMI", device.manufacturer)+ assertEquals("XGIMI Horizon Pro", device.model)+ assertEquals("11", device.android)+ assertEquals(1_760_000_000_000, device.lastSeen)++ source.forget(device.id)+ // The file is written off the caller's thread.+ withTimeout(5_000) { while (DeviceStore(file).load().isNotEmpty()) delay(20) }+ assertEquals(emptyList<Any>(), AdbDeviceSource(context).known())+ }+}