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.
Switch the home screen to another installed launcher
jesse-agent-362deb03bb878b4
diff --git a/README.md b/README.mdindex 72b9999..75c0743 100644--- a/README.md+++ b/README.md@@ -71,6 +71,7 @@ Tellyscope is a phone app that talks to your Android TV, Google TV or Fire TV ov- **The main jobs up front.** Big **Install app**, **Debloat** and **Send file** buttons right under the vitals.- **Advanced.** Every number in one place: memory, storage, CPU, temperature, uptime and screen state, CPU and RAM by app, processes, network and data used, and the TV's address.- **Apps.** Every app on the TV with its real name and icon. Stop, disable or turn back on any app that isn't protected; each button says what it will do and asks first.+- **Another home screen.** With a second launcher such as Projectivy installed, its row in Apps offers **Make it your home screen**. Tellyscope makes it Home, checks that Home really opens it, and only then disables the old launcher, so the TV can't switch back by itself. One Undo in History turns the old launcher back on and makes it Home again. On Google TV, the Apps row and the Live tab are part of the old launcher and go with it.- **Debloat.** Tellyscope matches your TV to a tested clean-up list (adapted from [cleanyourtv](https://github.com/Gathin23/cleanyourtv)) and says how many of its apps are still on. **Debloat** first asks which TV it is, with the match already chosen, then shows every app it will turn off. Apps are pre-ticked only when the TV runs the Android version the list was tested on; untick anything you use, and you confirm before anything is disabled.- **History.** Every change is listed with an Undo, and **Restore everything** turns back on what Tellyscope turned off. Undoing a **Turn on** asks first, since it disables the app again. History is kept per TV, across restarts.- **Install apps.** Pick an APK, several split APKs or an `.apks`/`.xapk`/`.apkm` bundle on your phone. Before installing, Tellyscope shows the app's name, version and size and says whether it's new, an update, a reinstall or an older version. It won't install an older version over a newer one unless you tick the box. If the TV refuses, you get the reason in plain words.@@ -91,7 +92,7 @@ Debloating a TV can break it if done carelessly. Tellyscope is built around thes1. **Disable only, never uninstall.** Tellyscope uses `pm disable-user`, which is reversible from the app or with `pm enable`. It never runs `pm uninstall`, not even for the current user.2. **Record before changing.** Before the first change on a TV, Tellyscope notes which apps were already off, so **Restore everything** turns back on only what Tellyscope turned off. Every change goes into the TV's history with an Undo. The history lives on the phone and is deleted if you uninstall Tellyscope; a disabled app still shows in the Apps list with **Turn on**.-3. **Protected list.** Packages the TV needs to boot, install its updates, stay on Wi-Fi, show web pages, show the home screen or accept input are on a protected list. Tellyscope refuses to stop or disable them, and there is no override in the app. If the TV doesn't say which app is its home screen, Tellyscope refuses to stop or disable anything. A TV's suggested list can protect more apps, never fewer.+3. **Protected list.** Packages the TV needs to boot, install its updates, stay on Wi-Fi, show web pages, show the home screen or accept input are on a protected list. Tellyscope refuses to stop or disable them, and there is no override in the app. If the TV doesn't say which app is its home screen, Tellyscope refuses to stop or disable anything. The one exception is switching home screens: the old launcher is disabled only after another launcher has become Home and Home has been checked to open it, and the current home screen itself never can be. A TV's suggested list can protect more apps, never fewer.4. **No root, no exploits.** Only what ADB allows on a stock TV.5. **Nothing left on the TV.** To show real app names and icons, Tellyscope copies a small helper to `/data/local/tmp`, runs it once and deletes it. The helper only reads through PackageManager: no writes, no permissions, no network.diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt b/adb/src/main/kotlin/app/tellyscope/adb/Actions.ktindex 8d3d5c8..a60219f 100644--- a/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt+++ b/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt@@ -13,6 +13,16 @@ sealed interface ActionResult {data class Failed(val output: String) : ActionResult}+/** What [Actions.makeHome] did. [from] and [to] are the old and new home activities, for Undo. */+sealed interface HomeResult {+ data class Switched(val from: String, val to: String) : HomeResult+ data class Refused(val reason: ProtectedReason) : HomeResult+ data class Failed(val output: String) : HomeResult+}++/** The launcher Home opens now, and the other launchers that could take its place. */+data class HomeOptions(val current: String, val others: Set<String>)+class Actions(private val shell: AdbShell) {suspend fun run(action: Action, pkg: String): ActionResult {@@ -51,8 +61,58 @@ class Actions(private val shell: AdbShell) {return current.ifEmpty { packagesIn(shell.shell(Commands.HOME_ACTIVITIES).output) - "android" }}- private fun packagesIn(brief: String): Set<String> =- brief.lineSequence().map(String::trim).filter { '/' in it && ' ' !in it }.map { it.substringBefore('/') }.toSet()+ /** Null when the TV has no default home (it asks each time) or didn't answer. */+ suspend fun homeOptions(): HomeOptions? {+ val current = currentHome()?.substringBefore('/') ?: return null+ return HomeOptions(current, launchers().keys - current)+ }++ /**+ * Makes [pkg] the home screen in place of the current one, then disables the old launcher so+ * the TV can't switch back by itself. Home is checked to open [pkg] before anything is+ * disabled; if it doesn't, the old home is set back and nothing is turned off.+ */+ suspend fun makeHome(pkg: String): HomeResult {+ require(PACKAGE.matches(pkg)) { "not a package name: $pkg" }+ val from = currentHome() ?: return HomeResult.Refused(ProtectedReason.UNKNOWN_HOME)+ val old = from.substringBefore('/')+ if (old == pkg) return HomeResult.Failed("it's already the home screen")+ val to = launchers()[pkg] ?: return HomeResult.Failed("it has no home screen")+ // The old launcher is protected as the home screen and by name; once it isn't Home, that+ // guard has done its job. Any other reason still stands.+ Protected.reason(old)?.takeIf { it != ProtectedReason.HOME_SCREEN }?.let { return HomeResult.Refused(it) }+ if (!setHome(to)) {+ setHome(from)+ return HomeResult.Failed("the TV kept its own home screen, so nothing was turned off")+ }+ val off = exec("pm disable-user --user 0 $old", undo = null) { "disabled-user" in it }+ if (off is ActionResult.Failed) {+ setHome(from)+ return HomeResult.Failed(off.output)+ }+ return HomeResult.Switched(from, to)+ }++ /** Makes [activity] (`package/class`) the default home, then checks that Home opens it. */+ suspend fun setHome(activity: String): Boolean {+ require(ACTIVITY.matches(activity)) { "not an activity: $activity" }+ shell.shell("${Commands.SET_HOME} '$activity' 2>&1") // a nested class has a $+ return currentHome()?.substringBefore('/') == activity.substringBefore('/')+ }++ /** The activity Home opens, or null when Android would ask (its chooser lives in `android`). */+ private suspend fun currentHome(): String? =+ activitiesIn(shell.shell(Commands.HOME_ACTIVITY).output).singleOrNull()?.takeUnless { it.startsWith("android/") }++ /** Every enabled launcher, package to its home activity. */+ private suspend fun launchers(): Map<String, String> =+ activitiesIn(shell.shell(Commands.HOME_ACTIVITIES).output).filterNot { it.startsWith("android/") }+ .associateBy { it.substringBefore('/') }++ private fun packagesIn(brief: String): Set<String> = activitiesIn(brief).map { it.substringBefore('/') }.toSet()++ private fun activitiesIn(brief: String): List<String> =+ brief.lineSequence().map(String::trim).filter { '/' in it && ' ' !in it }.distinct().toList()/** TV apps register under LEANBACK_LAUNCHER only; phone-style apps under LAUNCHER. Try both. */private suspend fun open(pkg: String): ActionResult {@@ -74,5 +134,6 @@ class Actions(private val shell: AdbShell) {internal companion object {val PACKAGE = Regex("[A-Za-z][A-Za-z0-9_]*(\\.[A-Za-z0-9_]+)+|android")+ val ACTIVITY = Regex("(${PACKAGE.pattern})/[A-Za-z0-9_.$]+")}}diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt b/adb/src/main/kotlin/app/tellyscope/adb/Commands.ktindex 4f6b223..987bad7 100644--- a/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt+++ b/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt@@ -38,6 +38,7 @@ internal object Commands {/** Apps the user installed: the only ones Tellyscope may uninstall. */const val USER_PACKAGES = "pm list packages -3"const val HOME_ACTIVITY = "cmd package resolve-activity --brief -a android.intent.action.MAIN -c android.intent.category.HOME"+ const val SET_HOME = "cmd package set-home-activity --user 0"const val HOME_ACTIVITIES = "cmd package query-activities --brief -a android.intent.action.MAIN -c android.intent.category.HOME"private fun List<String>.batch() = joinToString("; echo $SEP; ") { "$it 2>/dev/null" }diff --git a/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.ktindex 4e9c595..3217cb6 100644--- a/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt+++ b/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt@@ -116,4 +116,82 @@ class ActionsTest {assertFailsWith<IllegalArgumentException> { Actions(sh).run(Action.STOP, "\$(reboot)") }assertTrue(sh.ran.isEmpty())}++ /** A TV with the stock launcher and Projectivy; set-home-activity moves Home only if [accepts]. */+ private fun twoLaunchers(accepts: Boolean = true): FakeShell {+ var home = "com.google.android.tvlauncher/.MainActivity"+ return FakeShell(mapOf(+ "cmd package query-activities" to ok("com.google.android.tvlauncher/.MainActivity\ncom.spocky.projengmenu/.ui.home.MainActivity\n"),+ "pm disable-user" to ok("Package com.google.android.tvlauncher new state: disabled-user\n"),+ )).apply {+ answer = { cmd ->+ when {+ cmd.startsWith("cmd package resolve-activity") -> ok("priority=0 preferredOrder=0\n$home\n")+ cmd.startsWith("cmd package set-home-activity") -> {+ if (accepts) home = cmd.substringAfter("'").substringBefore("'")+ ok("Success\n")+ }+ else -> null+ }+ }+ }+ }++ @Test fun offersOtherLaunchersOnly() = runTest {+ assertEquals(HomeOptions("com.google.android.tvlauncher", setOf("com.spocky.projengmenu")), Actions(twoLaunchers()).homeOptions())+ }++ @Test fun noSecondLauncherNothingOffered() = runTest {+ val sh = FakeShell(mapOf(home, "cmd package query-activities" to ok("com.google.android.tvlauncher/.MainActivity\n")))+ assertEquals(emptySet(), Actions(sh).homeOptions()?.others)+ }++ @Test fun noDefaultHomeNothingOffered() = runTest {+ val sh = FakeShell(mapOf(+ "cmd package resolve-activity" to ok("priority=0\nandroid/com.android.internal.app.ResolverActivity\n"),+ "cmd package query-activities" to ok("com.google.android.tvlauncher/.MainActivity\ncom.spocky.projengmenu/.Main\n"),+ ))+ assertEquals(null, Actions(sh).homeOptions())+ assertEquals(HomeResult.Refused(ProtectedReason.UNKNOWN_HOME), Actions(sh).makeHome("com.spocky.projengmenu"))+ assertTrue(sh.ran.none { it.startsWith("pm ") || "set-home" in it })+ }++ @Test fun makeHomeSwitchesChecksThenDisables() = runTest {+ val sh = twoLaunchers()+ assertEquals(+ HomeResult.Switched("com.google.android.tvlauncher/.MainActivity", "com.spocky.projengmenu/.ui.home.MainActivity"),+ Actions(sh).makeHome("com.spocky.projengmenu"),+ )+ val set = sh.ran.indexOf("cmd package set-home-activity --user 0 'com.spocky.projengmenu/.ui.home.MainActivity' 2>&1")+ val off = sh.ran.indexOf("pm disable-user --user 0 com.google.android.tvlauncher 2>&1")+ assertTrue(set >= 0 && off > set)+ }++ @Test fun homeCheckFailsNothingDisabled() = runTest {+ val sh = twoLaunchers(accepts = false)+ assertTrue(Actions(sh).makeHome("com.spocky.projengmenu") is HomeResult.Failed)+ assertTrue(sh.ran.none { it.startsWith("pm ") })+ // The old home is set back, in case the TV took the new one half-way.+ assertEquals("cmd package set-home-activity --user 0 'com.google.android.tvlauncher/.MainActivity' 2>&1", sh.ran.last { "set-home" in it })+ }++ @Test fun failedDisablePutsHomeBack() = runTest {+ val sh = twoLaunchers()+ sh.answer.let { prev -> sh.answer = { if (it.startsWith("pm disable-user")) ok("Error: refused\n") else prev(it) } }+ assertTrue(Actions(sh).makeHome("com.spocky.projengmenu") is HomeResult.Failed)+ assertEquals("com.google.android.tvlauncher", Actions(sh).homeOptions()?.current)+ }++ @Test fun newHomeIsProtectedAfterTheSwitch() = runTest {+ val sh = twoLaunchers()+ Actions(sh).makeHome("com.spocky.projengmenu")+ assertEquals(ActionResult.Refused(ProtectedReason.HOME_SCREEN), Actions(sh).run(Action.DISABLE, "com.spocky.projengmenu"))+ }++ @Test fun makeHomeOnlyForInstalledLaunchers() = runTest {+ val sh = twoLaunchers()+ assertTrue(Actions(sh).makeHome("com.netflix.ninja") is HomeResult.Failed)+ assertTrue(Actions(sh).makeHome("com.google.android.tvlauncher") is HomeResult.Failed)+ assertTrue(sh.ran.none { it.startsWith("pm ") || "set-home" in it })+ }}diff --git a/adb/src/test/kotlin/app/tellyscope/adb/FakeShell.kt b/adb/src/test/kotlin/app/tellyscope/adb/FakeShell.ktindex 586435a..2ce3971 100644--- a/adb/src/test/kotlin/app/tellyscope/adb/FakeShell.kt+++ b/adb/src/test/kotlin/app/tellyscope/adb/FakeShell.kt@@ -19,10 +19,13 @@ class FakeShell(var rebooted = false/** Thrown by [reboot], like Kadb does when adbd refuses the service. */var rebootFails: Exception? = null+ /** Checked before [answers], for a TV whose answer changes after a command. */+ var answer: (String) -> ShellResult? = { null }override suspend fun shell(command: String): ShellResult {failWith?.let { throw it }ran += command+ answer(command)?.let { return it }return answers.entries.firstOrNull { command.startsWith(it.key) }?.value ?: ShellResult("", 0)}diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex 3ea0b2d..04b7068 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -8,6 +8,7 @@ import android.net.NetworkCapabilitiesimport app.tellyscope.adb.ActionResultimport app.tellyscope.adb.ApkInfoimport app.tellyscope.adb.Files+import app.tellyscope.adb.HomeResultimport app.tellyscope.adb.InstallResultimport app.tellyscope.adb.Progressimport app.tellyscope.adb.Sideload@@ -252,6 +253,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {override suspend fun apps(deviceId: String): List<AppInfo> {val shell = session(deviceId)val home = Actions(shell).homePackages()+ val homeOptions = Actions(shell).homeOptions()val system = Parsers.packages(shell.shell("pm list packages -s").output).map { it.name }.toSet()val disabled = Parsers.packages(shell.shell("pm list packages -d").output).map { it.name }.toSet()val userInstalled = Parsers.packages(shell.shell("pm list packages -3").output).map { it.name }.toSet()@@ -283,6 +285,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {version = "",icon = name.icon,removable = p.name in userInstalled && p.name !in keep,+ homeInstead = homeOptions?.takeIf { p.name in it.others && it.current !in keep }?.current,)}.sortedBy { it.label.lowercase() }}@@ -333,19 +336,48 @@ class AdbDeviceSource(context: Context) : DeviceSource {throw IllegalStateException(KEEP_REASON)}}+ if (action == Action.Home) return makeHome(deviceId, packageName, undoing)val r = Actions(shell).run(AdbAction.valueOf(action.name.uppercase()), packageName)return when (r) {- is ActionResult.Done -> book.record(+ is ActionResult.Done -> {+ // Undoing a home switch: the old launcher is on again, now make it Home again too.+ val switch = undoing?.let { id -> book.entries(key).firstOrNull { it.id == id && it.action == Action.Home } }+ val back = switch?.previous?.get("from")?.let { Actions(shell).setHome(it) }+ book.record(+ deviceId = key,+ at = System.currentTimeMillis(),+ action = action,+ packageName = packageName,+ label = labels[packageName] ?: AppNames.fallback(packageName),+ // Disabling the home screen is refused anyway; offer no undo that can't work.+ undo = if (switch != null) null else r.undo?.let { Action.valueOf(it.name.lowercase().replaceFirstChar(Char::uppercase)) },+ undoing = undoing,+ ).also { if (back == false) throw IllegalStateException(homeNotBack(it.label)) }+ }+ is ActionResult.Refused -> throw IllegalStateException(reasonText(r.reason))+ is ActionResult.Failed -> throw IllegalStateException(r.output.ifEmpty { "the TV refused" })+ }+ }++ private suspend fun makeHome(deviceId: String, packageName: String, undoing: Long?): HistoryEntry {+ val key = key(deviceId)+ val old = Actions(session(deviceId)).homeOptions()?.current+ if (old != null && keepRefuses(Action.Disable, old, keep[key] ?: resolve(deviceId).list?.keep.orEmpty())) {+ throw IllegalStateException(KEEP_REASON)+ }+ return when (val r = Actions(session(deviceId)).makeHome(packageName)) {+ is HomeResult.Switched -> book.record(deviceId = key,at = System.currentTimeMillis(),- action = action,- packageName = packageName,+ action = Action.Home,+ packageName = r.from.substringBefore('/'),label = labels[packageName] ?: AppNames.fallback(packageName),- undo = r.undo?.let { Action.valueOf(it.name.lowercase().replaceFirstChar(Char::uppercase)) },+ undo = Action.Enable,undoing = undoing,+ previous = mapOf("from" to r.from, "to" to r.to),)- is ActionResult.Refused -> throw IllegalStateException(reasonText(r.reason))- is ActionResult.Failed -> throw IllegalStateException(r.output.ifEmpty { "the TV refused" })+ is HomeResult.Refused -> throw IllegalStateException(reasonText(r.reason))+ is HomeResult.Failed -> throw IllegalStateException(r.output.ifEmpty { "the TV refused" })}}@@ -528,6 +560,9 @@ class AdbDeviceSource(context: Context) : DeviceSource {else -> "closing"}+ private fun homeNotBack(app: String) =+ "turned $app back on, but the TV kept the other home screen. Press Home on the remote to pick $app"+/** Copy from the protected-apps table in the UX copy doc. */private fun reasonText(r: ProtectedReason) = when (r) {ProtectedReason.HOME_SCREEN -> "this is your home screen"diff --git a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.ktindex a0e1c75..a9acb21 100644--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt@@ -202,12 +202,13 @@ class FakeDeviceSource(Action.Disable -> list[i] = app.copy(enabled = false)Action.Enable -> list[i] = app.copy(enabled = true)Action.Uninstall -> list.removeAt(i)- Action.Stop, Action.Open, Action.Change, Action.ClearCaches -> Unit+ Action.Stop, Action.Open, Action.Change, Action.ClearCaches, Action.Home -> Unit}val undo = when (action) {Action.Stop -> Action.OpenAction.Disable -> Action.EnableAction.Enable -> Action.Disable+ Action.Home -> Action.EnableAction.Open, Action.Uninstall, Action.Change, Action.ClearCaches -> null}return book.record(deviceId, clock(), action, packageName, app.label, undo, undoing)diff --git a/app/src/main/java/app/tellyscope/data/HistoryBook.kt b/app/src/main/java/app/tellyscope/data/HistoryBook.ktindex b2715a6..ad89e2c 100644--- a/app/src/main/java/app/tellyscope/data/HistoryBook.kt+++ b/app/src/main/java/app/tellyscope/data/HistoryBook.kt@@ -69,7 +69,7 @@ class HistoryBook(private val file: File? = null) {/** The newest disable of [packageName] that nothing has undone yet: what Restore reverses. */@Synchronizedfun openDisable(deviceId: String, packageName: String): Long? = entries- .filter { it.deviceId == deviceId && it.packageName == packageName && it.action == Action.Disable && it.undoneAt == null }+ .filter { it.deviceId == deviceId && it.packageName == packageName && it.action.disables && it.undoneAt == null }.maxOfOrNull { it.id }/**@@ -86,12 +86,15 @@ class HistoryBook(private val file: File? = null) {}companion object {- /** Packages whose last disable/enable in [history] was a disable; an uninstall clears it. */+ /**+ * Packages whose last disable/enable in [history] was a disable (a home switch disables the+ * old launcher); an uninstall clears it.+ */fun leftDisabled(history: List<HistoryEntry>): List<String> =- history.filter { it.action == Action.Disable || it.action == Action.Enable || it.action == Action.Uninstall }+ history.filter { it.action.disables || it.action == Action.Enable || it.action == Action.Uninstall }.sortedBy { it.id }.associate { it.packageName to it.action }- .filterValues { it == Action.Disable }+ .filterValues { it.disables }.keys.sorted()}@@ -151,6 +154,8 @@ class HistoryBook(private val file: File? = null) {private const val VERSION = "v1"+private val Action.disables get() = this == Action.Disable || this == Action.Home+/*** Turns apps back on one at a time and stops at the first refusal, saying how far it got so the* user knows what already changed. [enable] records each step.diff --git a/app/src/main/java/app/tellyscope/data/Model.kt b/app/src/main/java/app/tellyscope/data/Model.ktindex 3e4a0a5..1c033c1 100644--- a/app/src/main/java/app/tellyscope/data/Model.kt+++ b/app/src/main/java/app/tellyscope/data/Model.kt@@ -100,6 +100,8 @@ data class AppInfo(val icon: ByteArray? = null,/** Installed by the user (`pm list packages -3`), so Uninstall is offered. Never for apps that came with the TV. */val removable: Boolean = false,+ /** Another launcher that can replace the current home screen, [homeInstead]: "Make it your home screen" is offered. */+ val homeInstead: String? = null,)data class Socket(val app: String, val remote: String, val state: String)@@ -118,9 +120,12 @@ data class NetworkInfo(/*** [Change] sets one [app.tellyscope.adb.Tweak]: its entry's packageName is the tweak's name and- * [HistoryEntry.previous] holds what Undo writes back. [ClearCaches] has no undo.+ * [HistoryEntry.previous] holds what Undo writes back. [ClearCaches] has no undo. [Home] makes a+ * launcher the home screen and disables the old one: its entry's packageName is the old launcher,+ * the label the new one's, and [HistoryEntry.previous] holds both home activities ("from", "to").+ * Its undo is [Enable], which also makes the old launcher Home again.*/-enum class Action { Stop, Disable, Enable, Open, Uninstall, Change, ClearCaches }+enum class Action { Stop, Disable, Enable, Open, Uninstall, Change, ClearCaches, Home }data class HistoryEntry(val id: Long,diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.ktindex 68dfcfe..5ed0c46 100644--- a/app/src/main/java/app/tellyscope/ui/Copy.kt+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt@@ -27,7 +27,7 @@ object Copy {Action.Enable -> "Turn on"Action.Open -> "Open"Action.Uninstall -> "Uninstall"- Action.Change, Action.ClearCaches -> error("$action isn't an app action")+ Action.Change, Action.ClearCaches, Action.Home -> error("$action has its own button")}fun confirm(action: Action) = when (action) {@@ -36,6 +36,7 @@ object Copy {Action.Enable -> "Yes, turn it on"Action.Open -> "Yes, open it"Action.Uninstall -> "Yes, uninstall it"+ Action.Home -> "Yes, switch home screen"Action.Change, Action.ClearCaches -> error("$action isn't an app action")}@@ -50,7 +51,7 @@ object Copy {Action.Enable -> "Turns $who back on."Action.Open -> "Opens $who on the TV."Action.Uninstall -> "Removes $who and everything saved in it. This can't be undone; to get it back, install it again."- Action.Change, Action.ClearCaches -> error("$action isn't an app action")+ Action.Change, Action.ClearCaches, Action.Home -> error("$action isn't a one-app action")}}@@ -63,8 +64,23 @@ object Copy {// A setting's label is the whole sentence: "Private DNS set to …".Action.Change -> appAction.ClearCaches -> "Cleared $app"+ Action.Home -> "Made $app your home screen"}+ fun makeHome(app: String) = "Make $app your home screen"++ /**+ * The home switch touches two apps, so it names both. The old launcher is disabled, not just+ * replaced: otherwise many TVs switch back to it by themselves.+ */+ fun explainHome(app: String, pkg: String, current: String, currentPkg: String) = buildString {+ append("Makes $app ($pkg) open when you press Home, then disables $current ($currentPkg) so the TV can't switch back by itself. ")+ append("Undo in History turns $current back on and makes it Home again.")+ if (currentPkg in GOOGLE_HOMES) append("\n\nSome Google TV features, like the Apps row and the Live tab, are part of $current and go away with it.")+ }++ private val GOOGLE_HOMES = setOf("com.google.android.tvlauncher", "com.google.android.apps.tv.launcherx")+/*** Force-stop has no true undo, and undoing a Turn on disables the app; the button says what it* actually does.diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.ktindex a824fe8..34ab8ab 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt@@ -244,7 +244,7 @@ fun DeviceScreen() {if (changeable.isEmpty()) EmptyLine(q)changeable.forEach { app ->- AppRow(app, snap?.procs.orEmpty(), ui.pending, ui.busy == app.packageName, actions)+ AppRow(app, snap?.procs.orEmpty(), ui.pending, ui.busy == app.packageName, actions, homeLabel(ui.apps, app))}}if (ui.apps.any { it.protectedReason != null } && (q.isEmpty() || locked.isNotEmpty())) section(@@ -254,7 +254,7 @@ fun DeviceScreen(forceOpen = q.isNotEmpty(),) {locked.forEach { app ->- AppRow(app, snap?.procs.orEmpty(), ui.pending, ui.busy == app.packageName, actions)+ AppRow(app, snap?.procs.orEmpty(), ui.pending, ui.busy == app.packageName, actions, homeLabel(ui.apps, app))}}if (!offline && q.isEmpty()) section("files", "Files on the TV", ui.files.list?.size ?: 0) {@@ -694,6 +694,10 @@ fun AppIcon(app: AppInfo, modifier: Modifier = Modifier) {}}+/** The name of the home screen [app] would replace, or null when it isn't offered as one. */+private fun homeLabel(apps: List<AppInfo>, app: AppInfo): String? =+ app.homeInstead?.let { pkg -> apps.firstOrNull { it.packageName == pkg }?.label }+/** Uninstall has no undo, so it asks in a dialog that names the app, not inline. */@Composablefun UninstallDialog(app: AppInfo, onUninstall: () -> Unit, onDismiss: () -> Unit) {@@ -719,15 +723,20 @@ private fun AppRow(pending: Pair<String, Action>?,busy: Boolean,actions: DeviceActions,+ /** The current home screen's name, when this app can replace it. */+ homeLabel: String? = null,) {var open by rememberSaveable(app.packageName) { mutableStateOf(false) }+ // A launcher can be protected by its name and still be offered as the new home screen.+ val home = app.homeInstead?.takeIf { app.enabled && homeLabel != null }+ val changeable = app.protectedReason == null || home != nullval ram = procs.filter { it.packageName == app.packageName }.sumOf { it.ramMb }val status = when {!app.enabled -> "Disabled"ram > 0 -> "Running"else -> "Not running"}- Column(Modifier.fillMaxWidth().clip(MaterialTheme.shapes.large).clickable(enabled = app.protectedReason == null) { open = !open }.padding(vertical = 8.dp)) {+ Column(Modifier.fillMaxWidth().clip(MaterialTheme.shapes.large).clickable(enabled = changeable) { open = !open }.padding(vertical = 8.dp)) {Row(verticalAlignment = Alignment.CenterVertically) {AppIcon(app, Modifier.alpha(if (app.enabled) 1f else 0.4f))Spacer(Modifier.width(12.dp))@@ -745,21 +754,26 @@ private fun AppRow(if (busy) androidx.compose.material3.LoadingIndicator(Modifier.size(32.dp))}val proposed = pending?.takeIf { it.first == app.packageName }?.second- AnimatedVisibility((open || proposed != null) && app.protectedReason == null) {+ AnimatedVisibility((open || proposed != null) && changeable) {Column(Modifier.padding(start = 52.dp, top = 8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {// The label is whatever the app calls itself; the package id is what an action touches.Text(app.packageName, style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)if (proposed == null) {- Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {+ if (app.protectedReason == null) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {if (app.enabled && ram > 0) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Stop) }) { Text(Copy.button(Action.Stop)) }if (app.enabled) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Disable) }) { Text(Copy.button(Action.Disable)) }else FilledTonalButton(onClick = { actions.propose(app.packageName, Action.Enable) }) { Text(Copy.button(Action.Enable)) }if (app.removable) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Uninstall) }) { Text(Copy.button(Action.Uninstall)) }}+ if (home != null) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Home) }) { Text(Copy.makeHome(app.label)) }} else if (proposed == Action.Uninstall) {UninstallDialog(app, onUninstall = actions.confirm, onDismiss = actions.cancel)} else {- Text(Copy.explain(proposed, app.label, app.packageName), style = MaterialTheme.typography.bodyMedium)+ Text(+ if (proposed == Action.Home && home != null) Copy.explainHome(app.label, app.packageName, homeLabel!!, home)+ else Copy.explain(proposed, app.label, app.packageName),+ style = MaterialTheme.typography.bodyMedium,+ )Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {Button(onClick = actions.confirm) { Text(Copy.confirm(proposed)) }TextButton(onClick = actions.cancel) { Text("Cancel") }diff --git a/app/src/test/java/app/tellyscope/HistoryBookTest.kt b/app/src/test/java/app/tellyscope/HistoryBookTest.ktindex 86248de..fae4816 100644--- a/app/src/test/java/app/tellyscope/HistoryBookTest.kt+++ b/app/src/test/java/app/tellyscope/HistoryBookTest.kt@@ -48,6 +48,19 @@ class HistoryBookTest {assertTrue(again.first().id > disabled.id)}+ @Test fun aHomeSwitchSurvivesARestartAndRestoreTurnsTheOldLauncherOn() {+ val file = tmp.root.resolve("history.tsv")+ val previous = mapOf("from" to "com.google.android.tvlauncher/.MainActivity", "to" to "com.spocky.projengmenu/.Main")+ val switch = HistoryBook(file).record(tv, 1_000, Action.Home, "com.google.android.tvlauncher", "Projectivy Launcher", Action.Enable, previous = previous)+ val after = HistoryBook(file)+ assertEquals(listOf(switch), after.entries(tv))+ assertEquals(listOf("com.google.android.tvlauncher"), after.restorable(tv))+ assertEquals(switch.id, after.openDisable(tv, "com.google.android.tvlauncher"))++ after.record(tv, 2_000, Action.Enable, "com.google.android.tvlauncher", "Android TV Home", undo = null, undoing = switch.id)+ assertTrue(after.restorable(tv).isEmpty())+ }+@Test fun baselineIsWrittenOnlyOnce() {val book = HistoryBook(tmp.root.resolve("history.tsv"))book.setBaseline(tv, setOf("com.old.off"))