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.

Update check: every 6 hours, every 5 minutes on alpha builds, and on return to the app

jesse-agent-362208c62456abb
diff --git a/README.md b/README.md
index e67e126..42613e4 100644
--- a/README.md
+++ b/README.md
@@ -66,7 +66,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. It makes two internet requests: one fetches the debloat lists from this project's GitHub, or from your own fork if you point it there; the other asks GitHub once a day whether a newer version is out, and you can turn it off in Settings. Everything else stays on your Wi-Fi. Turning on Private DNS changes where the *TV* looks up addresses, not what the app sends.
+- **Small and private.** Under 3 MB. No ads, no tracking, no accounts. It makes two internet requests: one fetches the debloat lists from this project's GitHub, or from your own fork if you point it there; the other asks GitHub every 6 hours whether a newer version is out, and you can turn it off in Settings. Everything else stays on your Wi-Fi. Turning on Private DNS changes where the *TV* looks up addresses, not what the app sends.
- **Reversible.** Apps that came with the TV are only ever disabled, never uninstalled, so nothing is deleted. Apps you installed yourself can also be uninstalled, after a confirm that says it can't be undone. Every change goes into History, all but Uninstall 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. They sit in their own **Can't be changed** section under Apps. 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.
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index e3b4b6d..e73ffe7 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -153,6 +153,9 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
UpdateDialog(u, onGet = { vm.updateLater(); runCatching { browser.openUri(u.url) } }, onLater = vm::updateLater, onSkip = vm::skipUpdate)
}
+ // On every return to the app, not just a cold start; the check itself enforces the interval.
+ LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { vm.checkForUpdate() }
+
Snackbars(snackbar, vm.done, vm.notice, vm::doneShown, vm::noticeShown) { vm.undo(it.entry, it.deviceId) }
// A newly connected TV becomes the selection; leave the add flow then, not on tap.
@@ -191,6 +194,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
state.listSource,
onListSource = vm::setListSource,
checkUpdates = state.checkUpdates,
+ alphaBuild = state.alphaBuild,
onCheckUpdates = vm::setCheckUpdates,
back = { settings = false },
snackbar = snackbar,
diff --git a/app/src/main/java/app/tellyscope/data/UpdateCheck.kt b/app/src/main/java/app/tellyscope/data/UpdateCheck.kt
index c69cdc0..df70f2d 100644
--- a/app/src/main/java/app/tellyscope/data/UpdateCheck.kt
+++ b/app/src/main/java/app/tellyscope/data/UpdateCheck.kt
@@ -13,13 +13,15 @@ import java.util.Properties
const val RELEASES = "https://github.com/man15h/tellyscope/releases"
private const val RELEASES_API = "https://api.github.com/repos/man15h/tellyscope/releases?per_page=20"
-private const val DAY_MS = 24 * 60 * 60 * 1000L
+/** How long a check counts for: release builds ask every 6 hours, alpha builds every 5 minutes for testing. */
+private const val RELEASE_INTERVAL_MS = 6 * 60 * 60 * 1000L
+private const val ALPHA_INTERVAL_MS = 5 * 60 * 1000L
/** A newer Tellyscope than the one running. */
data class Update(val version: String, val notes: String, val url: String)
/**
- * Asks GitHub, at most once a day, whether a newer release is out. No auth and no download: it
+ * Asks GitHub, at most every 6 hours (5 minutes on alpha builds), whether a newer release is out. No auth and no download: it
* only reads the release list. Off switch, last check and a skipped version live in [file].
* Release builds look at full releases only; alpha builds at `-alpha` pre-releases too.
*/
@@ -27,7 +29,7 @@ class UpdateCheck(
private val file: File,
/** The running versionName, alpha suffix included. */
private val current: String,
- private val alpha: Boolean,
+ val alpha: Boolean,
private val clock: () -> Long = System::currentTimeMillis,
private val fetch: suspend (String) -> ByteArray = ::download,
) {
@@ -39,13 +41,14 @@ class UpdateCheck(
@Synchronized
fun skip(version: String) = save { setProperty("skip", version) }
- /** The newest release past [current], unless it was skipped. Null when off, checked today, or on any failure. */
+ /** The newest release past [current], unless it was skipped. Null when off, checked recently, or on any failure. */
suspend fun check(): Update? = withContext(Dispatchers.IO) {
val p = props()
if (p.getProperty("off") == "true") return@withContext null
val last = p.getProperty("checked")?.toLongOrNull()
val now = clock()
- if (last != null && now - last in 0 until DAY_MS) return@withContext null
+ val interval = if (alpha) ALPHA_INTERVAL_MS else RELEASE_INTERVAL_MS
+ if (last != null && now - last in 0 until interval) return@withContext null
val text = try {
fetch(RELEASES_API).decodeToString()
} catch (e: CancellationException) {
diff --git a/app/src/main/java/app/tellyscope/ui/SettingsScreen.kt b/app/src/main/java/app/tellyscope/ui/SettingsScreen.kt
index 28f06e0..40f2bb0 100644
--- a/app/src/main/java/app/tellyscope/ui/SettingsScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/SettingsScreen.kt
@@ -49,6 +49,8 @@ fun SettingsScreen(
onListSource: (String?) -> Unit,
/** Null hides the switch: this build doesn't check (screenshots). */
checkUpdates: Boolean?,
+ /** Alpha builds check every 5 minutes, release builds every 6 hours. */
+ alphaBuild: Boolean,
onCheckUpdates: (Boolean) -> Unit,
back: () -> Unit,
snackbar: SnackbarHostState = remember { SnackbarHostState() },
@@ -93,7 +95,8 @@ fun SettingsScreen(
Column(Modifier.weight(1f)) {
Text("Check for updates", style = MaterialTheme.typography.titleSmall)
Text(
- "Once a day, ask GitHub whether a newer Tellyscope is out. Nothing is downloaded.",
+ (if (alphaBuild) "Every 5 minutes on alpha builds" else "Every 6 hours") +
+ ", ask GitHub whether a newer Tellyscope is out. Nothing is downloaded.",
style = MaterialTheme.typography.bodyMedium,
)
}
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index 0ccd060..4f3854b 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -128,6 +128,8 @@ data class UiState(
val listSource: String? = null,
/** The once-a-day look at GitHub for a newer release; null when this build has none (screenshots, tests). */
val checkUpdates: Boolean? = null,
+ /** An alpha build, which checks every 5 minutes rather than every 6 hours. */
+ val alphaBuild: Boolean = false,
/** A newer release to offer; cleared once the user answers. */
val update: Update? = null,
) {
@@ -185,6 +187,7 @@ class TellyscopeViewModel(
private var mediumJob: Job? = null
private var listsJob: Job? = null
private var requestJob: Job? = null
+ private var updateJob: Job? = null
/** The fingerprint the user waved away on the phone; its prompt stays hidden while the TV shows it. */
private var dismissedRequest: String? = null
@@ -205,12 +208,7 @@ class TellyscopeViewModel(
}
}
updates?.let { u ->
- viewModelScope.launch(Dispatchers.IO) {
- _state.update { it.copy(checkUpdates = u.enabled) }
- // Null on any failure: no offer looks the same as no newer release.
- val found = u.check()
- _state.update { it.copy(update = found) }
- }
+ viewModelScope.launch(Dispatchers.IO) { _state.update { it.copy(checkUpdates = u.enabled, alphaBuild = u.alpha) } }
}
rescan()
}
@@ -780,7 +778,20 @@ class TellyscopeViewModel(
}
}
- /** "Get it" or "Later": the offer goes away until tomorrow's check. */
+ /**
+ * Each time the app comes to the front: offers a newer release if the interval since the last
+ * check has passed. One check at a time; an offer on screen stays until it is answered.
+ */
+ fun checkForUpdate() {
+ val u = updates ?: return
+ if (updateJob?.isActive == true || _state.value.update != null) return
+ updateJob = viewModelScope.launch(Dispatchers.IO) {
+ // Null on any failure: no offer looks the same as no newer release.
+ u.check()?.let { found -> _state.update { it.copy(update = found) } }
+ }
+ }
+
+ /** "Get it" or "Later": the offer goes away until the next check. */
fun updateLater() {
_state.update { it.copy(update = null) }
}
diff --git a/app/src/test/java/app/tellyscope/UpdateCheckTest.kt b/app/src/test/java/app/tellyscope/UpdateCheckTest.kt
index 0cac1b1..f9c3084 100644
--- a/app/src/test/java/app/tellyscope/UpdateCheckTest.kt
+++ b/app/src/test/java/app/tellyscope/UpdateCheckTest.kt
@@ -27,7 +27,9 @@ import java.io.IOException
class UpdateCheckTest {
@get:Rule val tmp = TemporaryFolder()
- private val day = 24 * 60 * 60 * 1000L
+ private val minute = 60 * 1000L
+ private val hour = 60 * minute
+ private val day = 24 * hour
private fun release(tag: String, pre: Boolean = tag.contains("-alpha"), notes: String = "Notes for $tag") =
"""{"tag_name":"$tag","prerelease":$pre,"draft":false,"body":"$notes"}"""
@@ -73,19 +75,31 @@ class UpdateCheckTest {
assertNull(check.check())
}
- @Test fun `asks at most once a day`() = runTest {
+ @Test fun `a release build asks again after 6 hours, not before`() = runTest {
var now = 1_000_000L
var calls = 0
val check = UpdateCheck(tmp.newFile(), "0.1.0", alpha = false, clock = { now }) { calls++; releases(release("v0.2.0")).toByteArray() }
assertEquals("0.2.0", check.check()?.version)
- now += day - 1
+ now += 6 * hour - minute
assertNull(check.check())
assertEquals(1, calls)
- now += 1
+ now += minute
assertEquals("0.2.0", check.check()?.version)
assertEquals(2, calls)
}
+ @Test fun `an alpha build asks again after 5 minutes`() = runTest {
+ var now = 1_000_000L
+ var calls = 0
+ val check = UpdateCheck(tmp.newFile(), "0.2.0-alpha.2", alpha = true, clock = { now }) { calls++; releases(release("v0.2.0-alpha.3")).toByteArray() }
+ assertEquals("0.2.0-alpha.3", check.check()?.version)
+ now += 5 * minute - 1
+ assertNull(check.check())
+ now += 1
+ assertEquals("0.2.0-alpha.3", check.check()?.version)
+ assertEquals(2, calls)
+ }
+
@Test fun `a failed request is silent and tried again next time`() = runTest {
var fail = true
val check = UpdateCheck(tmp.newFile(), "0.1.0", alpha = false) {