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.

Let users point the debloat lists at their own fork

jesse-agent-3628e1c8f3f21e3
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index f544404..663c5df 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -24,6 +24,10 @@ The per-TV lists behind **Suggested for this TV** live in the [tellyscope-device
- Say which TV models you tested on, and what changed after disabling it.
- If disabling it broke anything (launcher, updates, remote, input, HDMI-CEC), put it in the list's keep entries, or propose it for the built-in protected list (`adb/src/main/kotlin/app/tellyscope/adb/Protected.kt`) here.
+### Using your own lists
+
+You don't have to trust ours. Fork tellyscope-devices, edit the lists in your fork, and keep `index.json` on schema 1 with each file's sha256 updated. Then in the app open **Debloat**, tap **Change** next to "Lists from …", and paste the raw address of the folder that holds `index.json`, for example `https://raw.githubusercontent.com/<you>/tellyscope-devices/main/`. Only HTTPS is accepted, and a source that doesn't serve a schema 1 index is refused without changing anything. Switching drops the cached lists. While your source is in use, the review step says where the list came from. The built-in protected list still wins over any list, and **Reset to default** goes back to tellyscope-devices.
+
## README screenshots
They come from the screenshot tests, so they always show the current UI with sample data. To refresh them, render the tests, then put them in phone frames (needs Python 3 with Pillow):
diff --git a/README.md b/README.md
index 75c0743..c17761a 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ Tellyscope needs a phone on Android 8.0 or newer, on the same Wi-Fi as the TV, a
## Is it safe?
-- **Small and private.** Under 3 MB. No ads, no tracking, no accounts. Its only internet request fetches the debloat lists from this project's GitHub; everything else stays on your Wi-Fi.
+- **Small and private.** Under 3 MB. No ads, no tracking, no accounts. Its only internet request fetches the debloat lists from this project's GitHub, or from your own fork if you point it there; everything else stays on your Wi-Fi.
- **Reversible.** Tellyscope disables apps; it never uninstalls them, so nothing is deleted. Every change goes into History with an Undo, and **Restore everything** turns back on all it turned off.
- **Protected list.** Apps the TV needs to start, update, stay on Wi-Fi, show its home screen or take input can't be stopped or disabled. There is no override.
- **You see it first.** Debloat shows every app it will turn off, and the confirm names each one before anything runs.
@@ -72,7 +72,7 @@ Tellyscope is a phone app that talks to your Android TV, Google TV or Fire TV ov
- **Advanced.** Every number in one place: memory, storage, CPU, temperature, uptime and screen state, CPU and RAM by app, processes, network and data used, and the TV's address.
- **Apps.** Every app on the TV with its real name and icon. Stop, disable or turn back on any app that isn't protected; each button says what it will do and asks first.
- **Another home screen.** With a second launcher such as Projectivy installed, its row in Apps offers **Make it your home screen**. Tellyscope makes it Home, checks that Home really opens it, and only then disables the old launcher, so the TV can't switch back by itself. One Undo in History turns the old launcher back on and makes it Home again. On Google TV, the Apps row and the Live tab are part of the old launcher and go with it.
-- **Debloat.** Tellyscope matches your TV to a tested clean-up list (adapted from [cleanyourtv](https://github.com/Gathin23/cleanyourtv)) and says how many of its apps are still on. **Debloat** first asks which TV it is, with the match already chosen, then shows every app it will turn off. Apps are pre-ticked only when the TV runs the Android version the list was tested on; untick anything you use, and you confirm before anything is disabled.
+- **Debloat.** Tellyscope matches your TV to a tested clean-up list (adapted from [cleanyourtv](https://github.com/Gathin23/cleanyourtv)) and says how many of its apps are still on. **Debloat** first asks which TV it is, with the match already chosen, then shows every app it will turn off. Apps are pre-ticked only when the TV runs the Android version the list was tested on; untick anything you use, and you confirm before anything is disabled. If you'd rather not trust our lists, point Debloat at your own fork of them (see [CONTRIBUTING](CONTRIBUTING.md#using-your-own-lists)).
- **History.** Every change is listed with an Undo, and **Restore everything** turns back on what Tellyscope turned off. Undoing a **Turn on** asks first, since it disables the app again. History is kept per TV, across restarts.
- **Install apps.** Pick an APK, several split APKs or an `.apks`/`.xapk`/`.apkm` bundle on your phone. Before installing, Tellyscope shows the app's name, version and size and says whether it's new, an update, a reinstall or an older version. It won't install an older version over a newer one unless you tick the box. If the TV refuses, you get the reason in plain words.
- **Files.** Send a file from your phone into the TV's Download or Movies folder, or save one from there to your phone. A file with the same name gets a " (1)" instead of being overwritten, and a cancelled copy leaves nothing half-written behind.
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index 4518ab2..19e97b4 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -174,6 +174,8 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
onDisable = vm::disableSuggested,
back = { debloat = false },
snackbar = snackbar,
+ source = state.listSource,
+ onSource = vm::setListSource,
)
} else {
DeviceScreen(
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
index 04b7068..8eb694c 100644
--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
@@ -412,6 +412,17 @@ class AdbDeviceSource(context: Context) : DeviceSource {
keep.remove(key)
}
+ override suspend fun listSource(): String? = lists.custom()
+
+ override suspend fun setListSource(url: String?) {
+ when (lists.setSource(url)) {
+ SourceResult.Ok -> keep.clear() // the old source's keep entries
+ SourceResult.NotHttps -> throw IllegalStateException("the address has to start with https://")
+ SourceResult.Unreachable -> throw IllegalStateException("couldn't reach that address. Check it and the phone's internet")
+ SourceResult.NotAList -> throw IllegalStateException(NOT_A_LIST)
+ }
+ }
+
private class Resolved(val index: ListIndex?, val entry: ListEntry?, val list: DeviceList?, val sdk: Int?)
/** This TV's list (picked, else matched), with its keep entries recorded for [apps] and [act]. */
diff --git a/app/src/main/java/app/tellyscope/data/DeviceLists.kt b/app/src/main/java/app/tellyscope/data/DeviceLists.kt
index f4bc46f..f41067b 100644
--- a/app/src/main/java/app/tellyscope/data/DeviceLists.kt
+++ b/app/src/main/java/app/tellyscope/data/DeviceLists.kt
@@ -168,6 +168,40 @@ class DeviceLists(
private val lock = Mutex()
private var index: ListIndex? = null
private val picks = File(dir, "picks.tsv")
+ private val sourceFile = File(dir, "source.txt")
+
+ /** The folder holding `index.json`: one the user set, else [LISTS_BASE]. */
+ val base: String get() = custom() ?: LISTS_BASE
+
+ /** The user's own source, or null for tellyscope-devices. */
+ @Synchronized
+ fun custom(): String? = sourceFile.takeIf { it.exists() }?.readText()?.trim()?.ifEmpty { null }
+
+ /**
+ * Points the lists at [url], or back at [LISTS_BASE] with null. The new source must answer
+ * with a schema 1 index first; otherwise nothing changes. The cached lists are dropped, so
+ * nothing from the old source lingers; picks stay, and a pick the new source lacks falls
+ * back to matching.
+ */
+ suspend fun setSource(url: String?): SourceResult = lock.withLock {
+ val next = if (url == null) LISTS_BASE else normalize(url) ?: return@withLock SourceResult.NotHttps
+ val text = attempt { fetch(next + "index.json") }?.decodeToString()
+ // Going back to the default always works, offline too: its lists load once online.
+ if (text == null && url != null) return@withLock SourceResult.Unreachable
+ val parsed = text?.let(::parseIndex)
+ if (text != null && parsed == null) return@withLock SourceResult.NotAList
+ withContext(Dispatchers.IO) {
+ File(dir, "index.json").delete()
+ File(dir, "devices").deleteRecursively()
+ dir.mkdirs()
+ if (text != null) File(dir, "index.json").writeText(text)
+ synchronized(this@DeviceLists) {
+ if (next == LISTS_BASE) sourceFile.delete() else sourceFile.writeText(next)
+ }
+ }
+ index = parsed
+ SourceResult.Ok
+ }
/**
* Fetched once per process; later calls reuse it. Offline, the cached copy is returned and the
@@ -177,7 +211,7 @@ class DeviceLists(
index ?: withContext(Dispatchers.IO) {
dir.mkdirs()
val cache = File(dir, "index.json")
- val text = attempt { fetch(LISTS_BASE + "index.json") }?.decodeToString()
+ val text = attempt { fetch(base + "index.json") }?.decodeToString()
text?.let(::parseIndex)?.also { cache.writeText(text); index = it }
?: cache.takeIf { it.exists() }?.readText()?.let(::parseIndex)
}
@@ -187,7 +221,7 @@ class DeviceLists(
suspend fun list(entry: ListEntry): DeviceList? = withContext(Dispatchers.IO) {
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 }
+ ?: attempt { fetch(base + entry.file) }?.takeIf { sha256(it) == entry.sha256 }
?.also { cache.parentFile?.mkdirs(); cache.writeBytes(it) }
bytes?.let { parseList(it.decodeToString(), entry.id) }
}
@@ -224,6 +258,32 @@ class DeviceLists(
}
}
+enum class SourceResult { Ok, NotHttps, Unreachable, NotAList }
+
+const val NOT_A_LIST = "this source isn't a Tellyscope list"
+
+/**
+ * An `https://` folder address ending in `/`, or null for anything else. A pasted `index.json`
+ * address is cut back to its folder.
+ */
+fun normalize(url: String): String? {
+ val u = url.trim().removeSuffix("index.json")
+ val parsed = try {
+ java.net.URI(u)
+ } catch (_: java.net.URISyntaxException) {
+ return null
+ }
+ if (!parsed.scheme.equals("https", ignoreCase = true) || parsed.host.isNullOrEmpty() || parsed.query != null || parsed.fragment != null) return null
+ return if (u.endsWith("/")) u else "$u/"
+}
+
+/** How a source reads on screen: `github.com/owner/repo` for raw GitHub addresses, else host and path. */
+fun sourceName(base: String): String {
+ val rest = base.substringAfter("://").trimEnd('/')
+ val raw = "raw.githubusercontent.com/"
+ return if (rest.startsWith(raw)) "github.com/" + rest.removePrefix(raw).split('/').take(2).joinToString("/") else rest
+}
+
private const val MAX_BYTES = 2 shl 20 // 2 MiB; the index is ~60 KB
/** Plain GET with short timeouts, so a slow network falls back to the cache rather than hanging. */
diff --git a/app/src/main/java/app/tellyscope/data/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
index 5c1ce0d..88b08c3 100644
--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
@@ -92,6 +92,16 @@ interface DeviceSource {
/** "Pick your TV": use list [listId] for this TV from now on. */
suspend fun pickList(deviceId: String, listId: String)
+ /** Where the debloat lists come from, as the user set it; null for tellyscope-devices. */
+ suspend fun listSource(): String?
+
+ /**
+ * Reads the lists from [url] (the folder holding `index.json`) from now on, or from
+ * tellyscope-devices again with null. Throws with the reason, changing nothing, when it
+ * isn't HTTPS, can't be reached or isn't a Tellyscope list.
+ */
+ suspend fun setListSource(url: String?)
+
/** One remote key. False when the TV answered with an error; throws when it's gone. */
suspend fun press(deviceId: String, key: RemoteKey): Boolean
diff --git a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
index a9acb21..6ffcff5 100644
--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
@@ -289,6 +289,14 @@ class FakeDeviceSource(
override suspend fun pickList(deviceId: String, listId: String) = Unit
+ private var listSource: String? = null
+
+ override suspend fun listSource() = listSource
+
+ override suspend fun setListSource(url: String?) {
+ listSource = url?.let { normalize(it) ?: throw IllegalStateException("the address has to start with https://") }
+ }
+
override suspend fun press(deviceId: String, key: RemoteKey): Boolean {
delay(60)
return true
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index 5ed0c46..0b84964 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -10,6 +10,7 @@ import app.tellyscope.data.AppNames
import app.tellyscope.data.DeviceState
import app.tellyscope.data.Snapshot
import app.tellyscope.data.TvSettings
+import app.tellyscope.data.sourceName
import java.text.SimpleDateFormat
import java.time.YearMonth
import java.time.format.DateTimeFormatter
@@ -67,6 +68,10 @@ object Copy {
Action.Home -> "Made $app your home screen"
}
+ /** Where the lists come from, for the Debloat screen and the snackbar after a change. */
+ fun listSource(custom: String?) =
+ if (custom == null) "Lists from tellyscope-devices, built from cleanyourtv" else "Lists from ${sourceName(custom)}"
+
fun makeHome(app: String) = "Make $app your home screen"
/**
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
index 34ab8ab..1e5a4d1 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
@@ -220,7 +220,9 @@ fun DeviceScreen(
item {
ActionTiles(
actions,
- canDebloat = ui.lists is Suggestions.Pick || ui.lists is Suggestions.Ready,
+ // A source of the user's own that stopped answering must still be reachable to reset.
+ canDebloat = ui.lists is Suggestions.Pick || ui.lists is Suggestions.Ready ||
+ (ui.lists == Suggestions.Unavailable && state.listSource != null),
disabling = ui.busy == DISABLING,
)
}
diff --git a/app/src/main/java/app/tellyscope/ui/ListsCard.kt b/app/src/main/java/app/tellyscope/ui/ListsCard.kt
index 8a89772..2f4d091 100644
--- a/app/src/main/java/app/tellyscope/ui/ListsCard.kt
+++ b/app/src/main/java/app/tellyscope/ui/ListsCard.kt
@@ -49,6 +49,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import app.tellyscope.data.Suggested
import app.tellyscope.data.Suggestions
+import app.tellyscope.data.sourceName
/** Body of the "Suggested for this TV" section: one line on what the list offers; the Debloat tile is the way in. */
@Composable
@@ -91,8 +92,13 @@ fun DebloatScreen(
onDisable: (List<String>) -> Unit,
back: () -> Unit,
snackbar: SnackbarHostState = remember { SnackbarHostState() },
+ /** The user's own list source, null for the default. */
+ source: String? = null,
+ onSource: (String?) -> Unit = {},
) {
val ready = lists as? Suggestions.Ready
+ var editing by rememberSaveable { mutableStateOf(false) }
+ if (editing) SourceDialog(source, onSave = { editing = false; onSource(it) }, onDismiss = { editing = false })
val devices = when (lists) {
is Suggestions.Pick -> lists.devices
is Suggestions.Ready -> lists.devices
@@ -168,6 +174,15 @@ fun DebloatScreen(
singleLine = true,
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
)
+ Row(verticalAlignment = Alignment.CenterVertically) {
+ Text(
+ Copy.listSource(source),
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ modifier = Modifier.weight(1f),
+ )
+ TextButton(onClick = { editing = true }) { Text("Change") }
+ }
// Empty while a picked list reloads, if they came back to change it.
if (devices.isEmpty()) Muted("Loading the lists…")
else if (shown.isEmpty()) Muted("No list matches \"${q.trim()}\".")
@@ -203,6 +218,12 @@ fun DebloatScreen(
"From the list for ${showing.list.name}. Untick anything you use. Nothing is deleted: each app is hidden, and History can turn it back on.",
style = MaterialTheme.typography.bodyMedium,
)
+ // Nobody should debloat from a list they didn't mean to use.
+ if (source != null) Text(
+ "This list comes from ${sourceName(source)}, not tellyscope-devices.",
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.error,
+ )
if (!showing.sdkMatches) Muted(
showing.list.testedOs?.let { "Tested on $it, not this TV's Android version, so nothing is ticked. Tick only what you know you don't use." }
?: "This list doesn't say which Android it was tested on, so nothing is ticked. Tick only what you know you don't use.",
@@ -259,6 +280,29 @@ internal fun DisableDialog(apps: List<Suggested>, onDisable: () -> Unit, onDismi
)
}
+/** Edits the list source: an HTTPS folder holding `index.json`, or back to the default. */
+@Composable
+private fun SourceDialog(source: String?, onSave: (String?) -> Unit, onDismiss: () -> Unit) {
+ var url by rememberSaveable { mutableStateOf(source.orEmpty()) }
+ AlertDialog(
+ onDismissRequest = onDismiss,
+ title = { Text("Where the lists come from") },
+ text = {
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ Text(
+ "To use your own lists, fork tellyscope-devices, edit it, and paste the address of the folder that holds index.json, " +
+ "like https://raw.githubusercontent.com/you/tellyscope-devices/main/. Protected apps stay protected whatever a list says.",
+ style = MaterialTheme.typography.bodyMedium,
+ )
+ OutlinedTextField(url, { url = it }, placeholder = { Text("https://…") }, singleLine = true, modifier = Modifier.fillMaxWidth())
+ if (source != null) TextButton(onClick = { onSave(null) }) { Text("Reset to default") }
+ }
+ },
+ confirmButton = { Button(onClick = { onSave(url) }, enabled = url.isNotBlank()) { Text("Use these lists") } },
+ dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },
+ )
+}
+
/** About and licences; [commit] is the cleanyourtv commit the downloaded lists were built from. */
@Composable
fun AboutDialog(commit: String?, onDismiss: () -> Unit) {
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index fa17897..e9f25b1 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -121,6 +121,8 @@ data class UiState(
val now: Long = System.currentTimeMillis(),
/** TVs asked to restart, by id. */
val restarting: Map<String, Restart> = emptyMap(),
+ /** The user's own debloat-list source; null for tellyscope-devices. */
+ val listSource: String? = null,
) {
val selected: Device? get() = devices.firstOrNull { it.id == selectedId }
}
@@ -182,7 +184,8 @@ class TellyscopeViewModel(
viewModelScope.launch {
// Remembered TVs open straight to their page (offline until they answer).
val known = source.known()
- _state.update { it.copy(devices = known) }
+ val lists = runCatching { source.listSource() }.getOrNull()
+ _state.update { it.copy(devices = known, listSource = lists) }
if (_state.value.selectedId == null) known.firstOrNull()?.let { select(it.id) }
}
viewModelScope.launch {
@@ -355,7 +358,8 @@ class TellyscopeViewModel(
viewModelScope.launch {
source.forget(id)
val known = source.known()
- _state.update { it.copy(devices = known) }
+ val lists = runCatching { source.listSource() }.getOrNull()
+ _state.update { it.copy(devices = known, listSource = lists) }
// Next TV, online ones first; none left means back to the scan screen.
select((known.firstOrNull { it.state == DeviceState.Online } ?: known.firstOrNull())?.id)
}
@@ -737,6 +741,29 @@ class TellyscopeViewModel(
}
}
+ /**
+ * Reads the debloat lists from [url] from now on, or from tellyscope-devices with null, then
+ * reloads this TV's list. A refused source changes nothing and says why.
+ */
+ fun setListSource(url: String?) {
+ val id = _state.value.selectedId
+ listsJob?.cancel()
+ listsJob = viewModelScope.launch {
+ try {
+ source.setListSource(url)
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Exception) {
+ _notice.value = e.message?.replaceFirstChar(Char::uppercase) ?: "That didn't work."
+ return@launch
+ }
+ val now = source.listSource()
+ _state.update { it.copy(listSource = now, device = it.device.copy(lists = null)) }
+ _notice.value = Copy.listSource(now)
+ if (id != null) loadLists(id)
+ }
+ }
+
/** Disables the ticked suggestions one by one, each recorded in History with its own undo. */
fun disableSuggested(packages: List<String>) {
val id = _state.value.selectedId ?: return
diff --git a/app/src/test/java/app/tellyscope/DeviceListsTest.kt b/app/src/test/java/app/tellyscope/DeviceListsTest.kt
index c6f49bd..cfea303 100644
--- a/app/src/test/java/app/tellyscope/DeviceListsTest.kt
+++ b/app/src/test/java/app/tellyscope/DeviceListsTest.kt
@@ -12,6 +12,9 @@ import app.tellyscope.data.ListGroup
import app.tellyscope.data.ListPackage
import app.tellyscope.data.keepRefuses
import app.tellyscope.data.matches
+import app.tellyscope.data.SourceResult
+import app.tellyscope.data.normalize
+import app.tellyscope.data.sourceName
import app.tellyscope.data.depth
import app.tellyscope.data.parseIndex
import app.tellyscope.data.parseList
@@ -168,4 +171,68 @@ class DeviceListsTest {
// Brackets inside strings don't count.
assertEquals(2, depth("""{"a":["[[[{{{\"]"]}"""))
}
+
+ private val fork = "https://raw.githubusercontent.com/someone/my-lists/main/"
+
+ @Test fun aForkThatServesSchemaOneBecomesTheSourceAndDropsTheOldCache() = runTest {
+ val served = mapOf(
+ LISTS_BASE + "index.json" to index(), LISTS_BASE + "devices/acme-55.json" to device,
+ fork + "index.json" to index(sha = "f".repeat(64)),
+ )
+ val fetched = mutableListOf<String>()
+ val fetch: suspend (String) -> ByteArray = { url -> fetched += url; served[url] ?: throw IOException("404 $url") }
+ val lists = DeviceLists(tmp.root, fetch)
+ assertNotNull(lists.list(lists.index()!!.devices.first()))
+ assertTrue(tmp.root.resolve("devices/acme-55.json").exists())
+
+ assertEquals(SourceResult.Ok, lists.setSource(fork.removeSuffix("/") + "/index.json"))
+ assertEquals(fork, lists.custom())
+ assertFalse(tmp.root.resolve("devices").exists())
+ // Survives a restart, and every later fetch goes to the fork.
+ val again = DeviceLists(tmp.root, fetch)
+ assertEquals(fork, again.base)
+ fetched.clear()
+ assertNull(again.list(again.index()!!.devices.first())) // the fork's checksum doesn't match
+ assertTrue(fetched.isNotEmpty() && fetched.all { it.startsWith(fork) })
+
+ assertEquals(SourceResult.Ok, again.setSource(null))
+ assertNull(again.custom())
+ assertEquals(LISTS_BASE, again.base)
+ }
+
+ @Test fun aSourceThatIsntATellyscopeListChangesNothing() = runTest {
+ val lists = DeviceLists(tmp.root, served("index.json" to index()))
+ lists.index()
+ val other: suspend (String) -> ByteArray = { url ->
+ when (url) {
+ fork + "index.json" -> """{"schema": 2, "devices": []}""".toByteArray()
+ LISTS_BASE + "index.json" -> index()
+ else -> throw IOException("404 $url")
+ }
+ }
+ val l = DeviceLists(tmp.root, other)
+ assertEquals(SourceResult.NotAList, l.setSource(fork))
+ assertEquals(SourceResult.NotHttps, l.setSource("http://example.com/lists/"))
+ assertEquals(SourceResult.Unreachable, l.setSource("https://example.com/nothing/"))
+ assertNull(l.custom())
+ assertTrue(tmp.root.resolve("index.json").exists())
+ }
+
+ @Test fun resetToDefaultWorksOffline() = runTest {
+ val lists = DeviceLists(tmp.root) { url -> if (url == fork + "index.json") index() else throw IOException("offline") }
+ assertEquals(SourceResult.Ok, lists.setSource(fork))
+ assertEquals(SourceResult.Ok, lists.setSource(null))
+ assertNull(lists.custom())
+ assertNull(lists.index()) // nothing from the fork is left to fall back on
+ }
+
+ @Test fun sourceAddressesAreHttpsFoldersAndReadShort() {
+ assertEquals("https://example.com/lists/", normalize(" https://example.com/lists "))
+ assertEquals("https://example.com/lists/", normalize("https://example.com/lists/index.json"))
+ assertNull(normalize("http://example.com/lists/"))
+ assertNull(normalize("file:///sdcard/lists/"))
+ assertNull(normalize("https://example.com/lists/?x=1"))
+ assertEquals("github.com/someone/my-lists", sourceName(fork))
+ assertEquals("example.com/lists", sourceName("https://example.com/lists/"))
+ }
}