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.

Take the switch back's Undo away once the launcher is uninstalled

jesse-agent-2320d1ff4eb683f
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
index 15256ef..32ec7c4 100644
--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
@@ -548,7 +548,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {
* service off with it, as Switch home back does. Any step that fails stops it before the uninstall.
*/
private suspend fun uninstallHome(deviceId: String, pkg: String): HistoryEntry =
- uninstallAfterHomeBack({ homeBack(deviceId, pkg, null) }, { actNow(deviceId, Action.Uninstall, pkg, null) })
+ uninstallAfterHomeBack({ homeBack(deviceId, pkg, null) }, { actNow(deviceId, Action.Uninstall, pkg, null) }, book::dropUndo)
/**
* Makes Home again the launcher that [added], now Home, replaced: the one the last switch saved,
@@ -948,10 +948,11 @@ internal suspend fun applyTweak(
/**
* Runs [switchBack] (Home to the TV's own, the launcher's service off), and [uninstall] only once
- * it worked. A failure says which step stopped it.
+ * it worked. A failure says which step stopped it. Once it's gone, the switch's Undo, which would
+ * make it Home again, can't work: [dropUndo] takes it away.
*/
-internal suspend fun uninstallAfterHomeBack(switchBack: suspend () -> Unit, uninstall: suspend () -> HistoryEntry): HistoryEntry {
- try {
+internal suspend fun uninstallAfterHomeBack(switchBack: suspend () -> HistoryEntry, uninstall: suspend () -> HistoryEntry, dropUndo: (Long) -> Unit): HistoryEntry {
+ val back = try {
switchBack()
} catch (e: CancellationException) {
throw e
@@ -960,5 +961,5 @@ internal suspend fun uninstallAfterHomeBack(switchBack: suspend () -> Unit, unin
// "switched back, but …": Home moved, its service didn't turn off.
throw IllegalStateException(if (why.startsWith("switched back")) "$why. Nothing was uninstalled" else "Home didn't switch back: $why. Nothing was uninstalled")
}
- return uninstall()
+ return uninstall().also { dropUndo(back.id) }
}
diff --git a/app/src/main/java/app/tellyscope/data/HistoryBook.kt b/app/src/main/java/app/tellyscope/data/HistoryBook.kt
index fa6eb64..f0e640c 100644
--- a/app/src/main/java/app/tellyscope/data/HistoryBook.kt
+++ b/app/src/main/java/app/tellyscope/data/HistoryBook.kt
@@ -60,6 +60,14 @@ class HistoryBook(private val file: File? = null) {
return entry
}
+ /** Takes entry [id]'s Undo away, for a change a later one made impossible to undo. */
+ @Synchronized
+ fun dropUndo(id: Long) {
+ val i = entries.indexOfFirst { it.id == id }.takeIf { it >= 0 } ?: return
+ entries[i] = entries[i].copy(undo = null)
+ save()
+ }
+
/** Adds [extra] to entry [id]'s saved state, for a later step of the same change. */
@Synchronized
fun amend(id: Long, extra: Map<String, String?>) {
diff --git a/app/src/test/java/app/tellyscope/UninstallHomeTest.kt b/app/src/test/java/app/tellyscope/UninstallHomeTest.kt
index 808395b..a73b6a5 100644
--- a/app/src/test/java/app/tellyscope/UninstallHomeTest.kt
+++ b/app/src/test/java/app/tellyscope/UninstallHomeTest.kt
@@ -3,10 +3,12 @@
package app.tellyscope
import app.tellyscope.data.Action
+import app.tellyscope.data.HistoryBook
import app.tellyscope.data.HistoryEntry
import app.tellyscope.data.uninstallAfterHomeBack
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
@@ -15,26 +17,41 @@ class UninstallHomeTest {
private val steps = mutableListOf<String>()
private val removed = HistoryEntry(1, "tv", 0L, Action.Uninstall, "com.spocky.projengmenu", "Projectivy Launcher", null, null)
+ private val switched = HistoryEntry(0, "tv", 0L, Action.HomeBack, "com.spocky.projengmenu", "Google TV Home", Action.Home, null)
+ private val dropped = mutableListOf<Long>()
+
private suspend fun uninstall(): HistoryEntry {
steps += "uninstall"
return removed
}
@Test fun homeGoesBackBeforeTheUninstall() = runTest {
- assertEquals(removed, uninstallAfterHomeBack({ steps += "home back" }, ::uninstall))
+ assertEquals(removed, uninstallAfterHomeBack({ steps += "home back"; switched }, ::uninstall) { dropped += it })
assertEquals(listOf("home back", "uninstall"), steps)
+ assertEquals(listOf(0L), dropped)
+ }
+
+ @Test fun theSwitchBacksUndoGoesWithTheLauncher() = runTest {
+ val book = HistoryBook()
+ uninstallAfterHomeBack(
+ { book.record("tv", 0L, Action.HomeBack, "com.spocky.projengmenu", "Google TV Home", undo = Action.Home) },
+ { book.record("tv", 1L, Action.Uninstall, "com.spocky.projengmenu", "Projectivy Launcher", undo = null) },
+ book::dropUndo,
+ )
+ val back = book.entries("tv").single { it.action == Action.HomeBack }
+ assertNull(back.undo)
}
@Test fun aSwitchThatFailsUninstallsNothingAndSaysSo() = runTest {
- val e = runCatching { uninstallAfterHomeBack({ throw IllegalStateException("the TV kept the home screen it has") }, ::uninstall) }.exceptionOrNull()
+ val e = runCatching { uninstallAfterHomeBack({ throw IllegalStateException("the TV kept the home screen it has") }, ::uninstall) { dropped += it } }.exceptionOrNull()
assertEquals("Home didn't switch back: the TV kept the home screen it has. Nothing was uninstalled", e?.message)
- assertTrue(steps.isEmpty())
+ assertTrue(steps.isEmpty() && dropped.isEmpty())
}
@Test fun aServiceStillOnUninstallsNothing() = runTest {
val why = "switched back, but Projectivy Launcher's accessibility service is still on. Turn it off in the TV's Settings → Accessibility"
- val e = runCatching { uninstallAfterHomeBack({ throw IllegalStateException(why) }, ::uninstall) }.exceptionOrNull()
+ val e = runCatching { uninstallAfterHomeBack({ throw IllegalStateException(why) }, ::uninstall) { dropped += it } }.exceptionOrNull()
assertEquals("$why. Nothing was uninstalled", e?.message)
- assertTrue(steps.isEmpty())
+ assertTrue(steps.isEmpty() && dropped.isEmpty())
}
}