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.
Reset TV: keep Home's move when its service stays on, and review fixes
jesse-agent-23261127bdd9e84
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex d0c1ed1..cf354a3 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -688,7 +688,10 @@ class AdbDeviceSource(context: Context) : DeviceSource {val home = plan.home?.let { h ->onProgress(ResetProgress(ResetPart.Home, 0, 1))try {- resetHome(Actions(shell), h)+ val (moved, stuck) = resetHome(Actions(shell), h)+ // Home moved but the service stayed on: Undo still needs the move.+ if (stuck != null) failed += ResetFailure(ResetPart.Home, ResetApp(h.from, h.fromLabel), stuck)+ moved} catch (e: CancellationException) {throw e} catch (e: Exception) {@@ -708,20 +711,23 @@ class AdbDeviceSource(context: Context) : DeviceSource {/*** Home back to [home]'s TV's own launcher, the added one's accessibility service off with it:- * it would keep sending Home there. Returns what Undo needs; throws when Home didn't move. A- * service that stayed on throws too, but by then Home has moved, so that's recorded first.+ * it would keep sending Home there. Returns what Undo needs, and why the service stayed on if+ * it did; throws when Home didn't move. On Try again Home may have moved already: then only+ * the service is left to do, and the entry already holds the move.*/- private suspend fun resetHome(actions: Actions, home: ResetHome): Map<String, String?> =- when (val r = actions.homeBack(home.to)) {- is HomeResult.Switched -> {- val service = home.from.takeIf { it in serviceLaunchers }?.let { actions.homeService(it) }?.takeIf { actions.serviceOn(it) }- val off = service?.let { actions.setService(it, false) }- if (off == false) throw IllegalStateException(serviceNotOff(home.fromLabel))- listOfNotNull(ResetRecord.FROM to r.from, ResetRecord.TO to r.to, service?.let { ResetRecord.SERVICE to it }).toMap()- }+ private suspend fun resetHome(actions: Actions, home: ResetHome): Pair<Map<String, String?>, String?> {+ val moved: Map<String, String?> = if (actions.currentHome()?.substringBefore('/') == home.to) emptyMap()+ else when (val r = actions.homeBack(home.to)) {+ is HomeResult.Switched -> listOfNotNull(ResetRecord.FROM to r.from, ResetRecord.TO to r.to).toMap()is HomeResult.Refused -> throw IllegalStateException(reasonText(r.reason))is HomeResult.Failed -> throw IllegalStateException(r.output.ifEmpty { "the TV refused" })}+ val service = home.from.takeIf { it in serviceLaunchers }?.let { actions.homeService(it) }?.takeIf { actions.serviceOn(it) }+ ?: return moved to null+ // Recorded only once it's off: Undo turns back on what Reset turned off, nothing more.+ return if (actions.setService(service, false)) moved + (ResetRecord.SERVICE to service) to null+ else moved to serviceNotOff(home.fromLabel)+ }/*** Undo of a reset: Home back to the launcher it replaced, its service on again, then the apps@@ -762,8 +768,11 @@ class AdbDeviceSource(context: Context) : DeviceSource {}val on = each(ResetRecord.list(p, ResetRecord.ON), tv::turnOff)val back = each(ResetRecord.list(p, ResetRecord.BACK), tv::remove)- if (errors.isEmpty()) {- return book.record(key, System.currentTimeMillis(), Action.Change, RESET, "Put back what Reset TV changed", undo = null, undoing = id)+ // Only the service left on: every change is back, so the reset is undone, with a warning.+ if (errors.isEmpty() || (on.isEmpty() && back.isEmpty() && !homeLeft)) {+ val undone = book.record(key, System.currentTimeMillis(), Action.Change, RESET, "Put back what Reset TV changed", undo = null, undoing = id)+ if (errors.isEmpty()) return undone+ throw IllegalStateException("put back every change, but ${errors.first()}")}val left = mapOf(ResetRecord.ON to on.joinToString(","), ResetRecord.BACK to back.joinToString(",")) +if (homeLeft) emptyMap() else mapOf(ResetRecord.FROM to null, ResetRecord.TO to null, ResetRecord.SERVICE to null)diff --git a/app/src/main/java/app/tellyscope/ui/ResetScreen.kt b/app/src/main/java/app/tellyscope/ui/ResetScreen.ktindex d3ac7b8..92fc494 100644--- a/app/src/main/java/app/tellyscope/ui/ResetScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/ResetScreen.kt@@ -259,6 +259,7 @@ private fun AppList(apps: List<ResetApp>) {private const val SHOWN = 7/** After a run: a cookie badge, what changed, and per part what worked, with the first failure's reason. */+@OptIn(ExperimentalMaterial3ExpressiveApi::class)@Composableprivate fun Result(plan: ResetPlan, failed: List<ResetFailure>) {val c = MaterialTheme.colorScheme@@ -295,9 +296,10 @@ private fun Result(plan: ResetPlan, failed: List<ResetFailure>) {val line = when (part) {ResetPart.TurnOn -> Copy.turnedOn(on, plan.turnOn.size)ResetPart.BringBack -> Copy.broughtBack(back, plan.bringBack.size)- ResetPart.Home -> plan.home!!.let { if (miss.isEmpty()) Copy.isHome(it.toLabel) else Copy.stillHome(it.fromLabel) }+ // A miss with an app is only the service: Home did move.+ ResetPart.Home -> plan.home!!.let { if (miss.all { m -> m.app != null }) Copy.isHome(it.toLabel) else Copy.stillHome(it.fromLabel) }}- val why = miss.firstOrNull()?.let { f -> (f.app?.let { "${it.label}: " } ?: "") + f.reason.replaceFirstChar(Char::uppercase).trimEnd('.') + "." }+ val why = miss.firstOrNull()?.let { f -> (f.app?.takeIf { f.part != ResetPart.Home }?.let { "${it.label}: " } ?: "") + f.reason.replaceFirstChar(Char::uppercase).trimEnd('.') + "." }Surface(color = c.surfaceContainerLow, shape = groupShape(i, rows.size), modifier = Modifier.fillMaxWidth().padding(bottom = 2.dp)) {Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {if (miss.isEmpty()) Icon(HistoryIcons.TurnedOn, contentDescription = null, tint = c.primary)diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.ktindex 3355b34..cd1e755 100644--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt@@ -975,6 +975,8 @@ class TellyscopeViewModel(// Anything else (a dropped socket) still must not crash the app.updateDevice(id) { it.copy(busy = null) }undoing?.let(undoInFlight::remove) // a failed Undo can be tried again+ // A reset's Undo can get partway, so History shows where it ended.+ if (undoing != null) runCatching { source.history(id) }.getOrNull()?.let { h -> updateDevice(id) { it.copy(history = h) } }_notice.value = e.message?.replaceFirstChar(Char::uppercase) ?: "That didn't work."return@launch}@@ -1570,6 +1572,8 @@ class TellyscopeViewModel(/** Opens Reset TV and reads what it would change. */fun openReset() {val id = _state.value.selectedId ?: return+ // Back during a run only closed the screen; opening it again shows that run.+ if (_state.value.device.busy == RESETTING && _state.value.device.reset != null) returnupdateDevice(id) { it.copy(reset = ResetUi()) }viewModelScope.launch {val ui = try {@@ -1592,6 +1596,7 @@ class TellyscopeViewModel(val todo = if (!retry) plan else ResetPlan(turnOn = ui.failed.filter { it.part == ResetPart.TurnOn }.mapNotNull { it.app },bringBack = ui.failed.filter { it.part == ResetPart.BringBack }.mapNotNull { it.app },+ // A Home failure with an app is its service, still on: Try again does just that.home = plan.home?.takeIf { ui.failed.any { it.part == ResetPart.Home } },)updateDevice(id) { it.copy(busy = RESETTING, reset = ui.copy(running = todo, progress = null, failed = emptyList())) }@@ -1620,7 +1625,7 @@ class TellyscopeViewModel(fun closeReset() {val id = _state.value.selectedId ?: return- updateDevice(id) { it.copy(reset = null) }+ updateDevice(id) { if (it.busy == RESETTING) it else it.copy(reset = null) }}/** History opened: its newest change is seen, so ⋮ loses its dot until the next one. */