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.

Cache device files under lists/devices

jesse-agent-362b503451416ee
diff --git a/app/src/main/java/app/tellyscope/data/DeviceLists.kt b/app/src/main/java/app/tellyscope/data/DeviceLists.kt
index 61ff4c0..54393db 100644
--- a/app/src/main/java/app/tellyscope/data/DeviceLists.kt
+++ b/app/src/main/java/app/tellyscope/data/DeviceLists.kt
@@ -185,10 +185,10 @@ class DeviceLists(
/** The device file for [entry], from cache or the network. Null when the bytes don't match its sha256. */
suspend fun list(entry: ListEntry): DeviceList? = withContext(Dispatchers.IO) {
- val cache = File(dir, entry.file.substringAfter('/'))
+ val cache = File(dir, entry.file) // lists/devices/<id>.json, apart from index.json
val bytes = cache.takeIf { it.exists() }?.readBytes()?.takeIf { sha256(it) == entry.sha256 }
?: attempt { fetch(LISTS_BASE + entry.file) }?.takeIf { sha256(it) == entry.sha256 }
- ?.also { dir.mkdirs(); cache.writeBytes(it) }
+ ?.also { cache.parentFile?.mkdirs(); cache.writeBytes(it) }
bytes?.let { parseList(it.decodeToString(), entry.id) }
}
diff --git a/app/src/test/java/app/tellyscope/DeviceListsTest.kt b/app/src/test/java/app/tellyscope/DeviceListsTest.kt
index b38b0cd..d58afcb 100644
--- a/app/src/test/java/app/tellyscope/DeviceListsTest.kt
+++ b/app/src/test/java/app/tellyscope/DeviceListsTest.kt
@@ -83,7 +83,7 @@ class DeviceListsTest {
val lists = DeviceLists(tmp.root, served("index.json" to index(sha = "f".repeat(64)), "devices/acme-55.json" to device))
val entry = lists.index()!!.devices.first()
assertNull(lists.list(entry))
- assertFalse(tmp.root.resolve("acme-55.json").exists())
+ assertFalse(tmp.root.resolve("devices/acme-55.json").exists())
val good = DeviceLists(tmp.newFolder(), served("index.json" to index(), "devices/acme-55.json" to device))
assertEquals("Acme 55", good.list(good.index()!!.devices.first())?.name)