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.
Keep raw TV output out of the hand-off failure line
jesse-agent-8219ecb6fabbc47
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt b/adb/src/main/kotlin/app/tellyscope/adb/Actions.ktindex cb78a47..234cb12 100644--- a/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt+++ b/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt@@ -26,6 +26,9 @@ sealed interface HomeResult {data class Failed(val output: String, val details: String = output) : HomeResult}+/** A step of [Actions.handOff] that didn't take: [reason] is one plain line, [output] what the TV printed. */+data class HandOffFailed(val reason: String, val output: String)+/*** [current] is Home; [others] are the launchers that can take over. With no default home, [current]* is the TV's own launcher, the one the others would replace, or null when none is on; [default]@@ -235,14 +238,14 @@ class Actions(private val shell: AdbShell) {* service change: a service still on can pull Home straight back. Home has moved either way,* so a step that fails is only reported: what went wrong, or null when both took.*/- suspend fun handOff(old: String?, to: String): String? {+ suspend fun handOff(old: String?, to: String): HandOffFailed? {require(old == null || PACKAGE.matches(old)) { "not a package name: $old" }require(ACTIVITY.matches(to)) { "not an activity: $to" }val stop = old?.takeIf { it != to.substringBefore('/') }?.let { exec("am force-stop $it", undo = null) }val open = shell.shell("${Commands.OPEN_HOME} '$to' 2>&1")return when {- open.exitCode != 0 || "Error" in open.output -> "it didn't open (${open.output.trim()}), so press Home on the remote to go there"- stop is ActionResult.Failed -> "the old home screen didn't close (${stop.output})"+ open.exitCode != 0 || "Error" in open.output -> HandOffFailed("it didn't open, so press Home on the remote to go there", open.output.trim())+ stop is ActionResult.Failed -> HandOffFailed("the old home screen didn't close", stop.output)else -> null}}diff --git a/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.ktindex 7a9a278..49e7f31 100644--- a/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt+++ b/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt@@ -514,13 +514,15 @@ class ActionsTest {@Test fun handOffSaysWhenTheNewHomeDidNotOpen() = runTest {val sh = FakeShell(mapOf("am start" to ok("Error: Activity not started\n")))- val left = Actions(sh).handOff("com.spocky.projengmenu", "me.efesser.flauncher/.MainActivity")- assertTrue(left.orEmpty().startsWith("it didn't open"), left)+ assertEquals(+ HandOffFailed("it didn't open, so press Home on the remote to go there", "Error: Activity not started"),+ Actions(sh).handOff("com.spocky.projengmenu", "me.efesser.flauncher/.MainActivity"),+ )}@Test fun handOffSaysWhenTheOldHomeDidNotStop() = runTest {val sh = FakeShell(mapOf("am force-stop" to ShellResult("Error: denied\n", 1)))- assertEquals("the old home screen didn't close (Error: denied)", Actions(sh).handOff("com.spocky.projengmenu", "me.efesser.flauncher/.MainActivity"))+ assertEquals(HandOffFailed("the old home screen didn't close", "Error: denied"), Actions(sh).handOff("com.spocky.projengmenu", "me.efesser.flauncher/.MainActivity"))assertTrue(openFlauncher in sh.ran)}}diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex f238472..7ac0c4d 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -609,7 +609,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {previous = listOfNotNull(r.from?.let { "from" to it }, "to" to r.to, service?.takeIf { off == true }?.let { "service" to it }).toMap(),).also {if (off == false) throw IllegalStateException(serviceNotOff(labels[added] ?: AppNames.fallback(added)))- left?.let { throw IllegalStateException(notShown(labels[target.pkg] ?: AppNames.fallback(target.pkg), it)) }+ left?.let { throw ActionFailed(notShown(labels[target.pkg] ?: AppNames.fallback(target.pkg), it.reason), it.output) }}}is HomeResult.Refused -> throw IllegalStateException(reasonText(r.reason))@@ -741,7 +741,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {val service = home.from.takeIf { it in serviceLaunchers }?.let { actions.homeService(it) }?.takeIf { actions.serviceOn(it) }val off = service?.let { actions.setService(it, false) }// Last, on Try again too: with its service still on, the added launcher could take Home straight back.- val left = actions.currentHome()?.let { actions.handOff(home.from, it) }?.let { notShown(home.toLabel, it) }+ val left = actions.currentHome()?.let { actions.handOff(home.from, it) }?.let { notShown(home.toLabel, it.reason) }// Recorded only once it's off: Undo turns back on what Reset turned off, nothing more.val recorded = service?.takeIf { off == true }?.let { moved + (ResetRecord.SERVICE to it) } ?: movedreturn recorded to if (off == false) serviceNotOff(home.fromLabel) else left@@ -1137,7 +1137,7 @@ internal suspend fun switchHome().also {if (on == false) throw IllegalStateException(serviceNotOn(label(pkg)))if (off == false) throw IllegalStateException(serviceNotOff(label(was!!)))- left?.let { throw IllegalStateException(notShown(label(pkg), it)) }+ left?.let { throw ActionFailed(notShown(label(pkg), it.reason), it.output) }}}is HomeResult.Refused -> throw IllegalStateException(reason(r.reason))@@ -1161,7 +1161,7 @@ internal const val RESET = "reset"private fun serviceNotOn(app: String) ="$app is Home now, but its accessibility service didn't turn on, so the TV's Home button may still open its own launcher"-/** Home moved, but the old launcher didn't close or [app] didn't open: [why], from [Actions.handOff]. */+/** Home moved, but the old launcher didn't close or [app] didn't open: [why] is [HandOffFailed.reason]. */private fun notShown(app: String, why: String) = "$app is Home now, but $why"private fun serviceNotOff(app: String) =diff --git a/app/src/test/java/app/tellyscope/HomeSwitchTest.kt b/app/src/test/java/app/tellyscope/HomeSwitchTest.ktindex d984979..7e159cf 100644--- a/app/src/test/java/app/tellyscope/HomeSwitchTest.kt+++ b/app/src/test/java/app/tellyscope/HomeSwitchTest.kt@@ -9,6 +9,7 @@ import app.tellyscope.adb.AdbSessionimport app.tellyscope.adb.RemoteEntryimport app.tellyscope.adb.ShellResultimport app.tellyscope.data.Action+import app.tellyscope.data.ActionFailedimport app.tellyscope.data.HistoryBookimport app.tellyscope.data.HistoryEntryimport app.tellyscope.data.switchHome@@ -141,7 +142,9 @@ class HomeSwitchTest {@Test fun aHomeThatDoesNotOpenStillSwitchesAndIsRecordedBeforeItSays() = runTest {val tv = LauncherTv(TV_HOME).apply { opens = false }val e = runCatching { switch(tv, FLAUNCHER) }.exceptionOrNull()- assertTrue(e?.message.orEmpty(), e is IllegalStateException && e.message!!.startsWith("$FLAUNCHER is Home now, but it didn't open"))+ assertTrue(e?.message.orEmpty(), e is ActionFailed)+ assertEquals("$FLAUNCHER is Home now, but it didn't open, so press Home on the remote to go there", e!!.message)+ assertEquals("Error: Activity not started", (e as ActionFailed).details)assertEquals(FLAUNCHER, tv.home)assertEquals(TV_HOME, book.entries("tv").single().packageName)}