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.

Count a restore stopped by a dropped connection too

jesse-agent-2320e2b290adc4c
diff --git a/app/src/main/java/app/tellyscope/data/HistoryBook.kt b/app/src/main/java/app/tellyscope/data/HistoryBook.kt
index 558ce95..fe54899 100644
--- a/app/src/main/java/app/tellyscope/data/HistoryBook.kt
+++ b/app/src/main/java/app/tellyscope/data/HistoryBook.kt
@@ -3,6 +3,7 @@
package app.tellyscope.data
import java.io.File
+import kotlinx.coroutines.CancellationException
/**
* Every change Tellyscope made, per TV, plus the TV's disabled-apps list from before the first
@@ -146,7 +147,10 @@ suspend fun restoreEach(packages: List<String>, enable: suspend (String) -> Hist
for (pkg in packages) {
try {
done += enable(pkg)
- } catch (e: IllegalStateException) {
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Exception) {
+ // A dropped connection counts too: the user still needs to know what already changed.
val why = e.message ?: "the TV refused"
throw IllegalStateException(
if (done.isEmpty()) "couldn't turn apps back on: $why"
diff --git a/app/src/test/java/app/tellyscope/HistoryBookTest.kt b/app/src/test/java/app/tellyscope/HistoryBookTest.kt
index d1348bc..3c7b6b1 100644
--- a/app/src/test/java/app/tellyscope/HistoryBookTest.kt
+++ b/app/src/test/java/app/tellyscope/HistoryBookTest.kt
@@ -133,4 +133,14 @@ class HistoryBookTest {
}.exceptionOrNull()
assertEquals("turned 2 apps back on, then stopped: the TV refused", e?.message)
}
+
+ @Test fun aDroppedConnectionStillSaysHowFarItGot() = runTest {
+ val e = runCatching {
+ restoreEach(listOf("a", "b")) { pkg ->
+ if (pkg == "b") throw java.io.IOException("connection reset")
+ HistoryEntry(1, tv, 0, Action.Enable, pkg, pkg, Action.Disable, null)
+ }
+ }.exceptionOrNull()
+ assertEquals("turned 1 app back on, then stopped: connection reset", e?.message)
+ }
}