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.
No default home and the TV's own launcher off: offer every launcher, lock only the last
jesse-agent-232668ebf48de5d
diff --git a/README.md b/README.mdindex 2015b6d..9eee6bd 100644--- a/README.md+++ b/README.md@@ -72,7 +72,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** tiles sit right under the vitals. Debloat shows a count while the TV's list still has apps on, or while apps Tellyscope turned off are back on, often after a TV update. When there's nothing left, it opens Apps instead. Below the tiles, one line says how many apps on the TV's list are off. If any came back on, a red line says so. Below that are the TV's Android version, when it last updated, and **Check for updates**, which opens the TV's own update screen. The Apps tab has an **Install app** button, and Files has **Upload files**.- **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, under three buttons: **Running** (what's using memory now), **Installed** (only the apps you put on the TV) and **Built-in** (what came with it). The buttons stay pinned under the bar as you scroll. Stop, disable or turn back on any app that isn't protected; each button says what it will do and asks first. Apps you installed yourself also offer **Uninstall**, which asks in a dialog that names the app and says it can't be undone. On Running and Built-in, the protected apps sit last under **System**, which folds away with a tap and stays folded until you open it again. **Search apps** sits under the buttons and pins with them. Tap it and the field moves to the top, the TV and the buttons step aside, and every matching app shows in one list. ← or Back brings them back.-- **Another home screen.** On a TV with the Play Store whose Home is still its own launcher, Apps shows a card that offers a better home screen, and Tweaks keeps **Choose one** after **Not now** puts the card away for that TV. Neither shows once a launcher you added is on the TV, whether or not it's Home. Tellyscope isn't affiliated with any of the launchers it recommends. Pick one of four recommended launchers (Projectivy, AT4K, Dispatch or the open-source FLauncher), and Tellyscope opens its Play Store page on the TV, waits for the install and then offers to make it Home. If the Store doesn't open, it says so and offers another launcher or a retry. With a second launcher such as Projectivy installed, its row in Apps offers **Set as default launcher**. 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. The one exception: a stock launcher that outranks the rest, e.g. Android TV Home, is turned off first and turned back on if Home still doesn't open the new one. One Undo in History turns the old launcher back on and makes it Home again. Later, the new launcher's row offers **Switch home back to** the one it replaced, or the TV's own if there was no switch: it's turned back on if it's off and made Home, and the added launcher stays, free to uninstall. For a launcher that keeps Home with its own accessibility service, such as Projectivy (the ones marked in [`launchers.json`](app/src/main/assets/launchers.json)), Set as default then asks separately whether to turn that service on, for TVs whose Home button opens their own launcher whatever the default is: **Turn it on** or **Switch without it**. Without it, the TV's page says Home may still open the TV's own launcher, with **Got it** and **Turn on**, and the launcher's row keeps **Turn on**. Undo and Switch home back turn it off again, and any other accessibility services stay as they were. The added launcher on Home also offers **Uninstall**: its confirm lists the steps, then Tellyscope switches Home back (turning the service off) and uninstalls it only if that worked. Only the launcher on Home is protected; another one you installed, such as FLauncher while Projectivy is Home, can be disabled or uninstalled. Installing a second launcher can leave the TV with no default home screen. Then only the TV's own launcher is protected, and each one you installed offers **Set as default launcher** and **Uninstall**. Settings and other apps that only answer Home as a fallback are never offered as launchers. On Google TV, the Apps row and the Live tab are part of the old launcher and go with it.+- **Another home screen.** On a TV with the Play Store whose Home is still its own launcher, Apps shows a card that offers a better home screen, and Tweaks keeps **Choose one** after **Not now** puts the card away for that TV. Neither shows once a launcher you added is on the TV, whether or not it's Home. Tellyscope isn't affiliated with any of the launchers it recommends. Pick one of four recommended launchers (Projectivy, AT4K, Dispatch or the open-source FLauncher), and Tellyscope opens its Play Store page on the TV, waits for the install and then offers to make it Home. If the Store doesn't open, it says so and offers another launcher or a retry. With a second launcher such as Projectivy installed, its row in Apps offers **Set as default launcher**. 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. The one exception: a stock launcher that outranks the rest, e.g. Android TV Home, is turned off first and turned back on if Home still doesn't open the new one. One Undo in History turns the old launcher back on and makes it Home again. Later, the new launcher's row offers **Switch home back to** the one it replaced, or the TV's own if there was no switch: it's turned back on if it's off and made Home, and the added launcher stays, free to uninstall. For a launcher that keeps Home with its own accessibility service, such as Projectivy (the ones marked in [`launchers.json`](app/src/main/assets/launchers.json)), Set as default then asks separately whether to turn that service on, for TVs whose Home button opens their own launcher whatever the default is: **Turn it on** or **Switch without it**. Without it, the TV's page says Home may still open the TV's own launcher, with **Got it** and **Turn on**, and the launcher's row keeps **Turn on**. Undo and Switch home back turn it off again, and any other accessibility services stay as they were. The added launcher on Home also offers **Uninstall**: its confirm lists the steps, then Tellyscope switches Home back (turning the service off) and uninstalls it only if that worked. Only the launcher on Home is protected; another one you installed, such as FLauncher while Projectivy is Home, can be disabled or uninstalled. Installing a second launcher can leave the TV with no default home screen. Then only the TV's own launcher is protected, and each one you installed offers **Set as default launcher** and **Uninstall**. If the TV's own launcher is off as well, Set as default turns nothing off, and only the last launcher left stays protected. Settings and other apps that only answer Home as a fallback are never offered as launchers. On Google TV, the Apps row and the Live tab are part of the old launcher and go with it.- **Debloat.** It finds your TV among 300+ tested clean-up lists (adapted from [cleanyourtv](https://github.com/Gathin23/cleanyourtv)) and opens on every app it will turn off, with the model on top. With no list for the model, it shows apps from the maker's other lists, none ticked. With none for the maker either, you tick the TV's own apps by hand; the ones it needs aren't shown. **Not this TV?** searches every list. Your pick is remembered, and the TV's page then says how many of the list's apps are still on. 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. If you'd rather not trust our lists, point the app at your own fork of them under **Advanced** in Settings (see [CONTRIBUTING](CONTRIBUTING.md#using-your-own-lists)).<img src="docs/screenshots/clean-home.jpg" alt="A TV home screen after debloating: the inputs and the user's own apps, with no ads or suggestions" width="100%">diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt b/adb/src/main/kotlin/app/tellyscope/adb/Actions.ktindex dc65aaa..73fa789 100644--- a/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt+++ b/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt@@ -13,19 +13,22 @@ 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. */+/**+ * What [Actions.makeHome] did. [from] and [to] are the old and new home activities, for Undo;+ * [from] is null when the TV had no default home and no launcher of its own to replace.+ */sealed interface HomeResult {- data class Switched(val from: String, val to: String) : HomeResult+ data class Switched(val from: String?, val to: String) : HomeResultdata class Refused(val reason: ProtectedReason) : HomeResultdata class Failed(val output: String) : HomeResult}-/** The launcher Home opens now, and the other launchers that could take its place. *//*** [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, and [default] is false.+ * is the TV's own launcher, the one the others would replace, or null when none is on; [default]+ * is false then.*/-data class HomeOptions(val current: String, val others: Set<String>, val default: Boolean = true)+data class HomeOptions(val current: String?, val others: Set<String>, val default: Boolean = true)class Actions(private val shell: AdbShell) {@@ -33,7 +36,7 @@ class Actions(private val shell: AdbShell) {require(PACKAGE.matches(pkg)) { "not a package name: $pkg" } // it goes into a shell lineif (action != Action.ENABLE && action != Action.OPEN) {// No launcher answer (no `cmd` before Android 7, or an error): we can't tell what's safe.- val home = homePackages().ifEmpty { return ActionResult.Refused(ProtectedReason.UNKNOWN_HOME) }+ val home = homePackages() ?: return ActionResult.Refused(ProtectedReason.UNKNOWN_HOME)// Only the name guard asks whether the user installed it; the live Home is refused unasked.val why = Protected.reason(pkg, home)?.let { if (it == ProtectedReason.HOME_SCREEN && pkg !in home) Protected.reason(pkg, home, userApp = pkg in userPackages()) else it }@@ -62,23 +65,30 @@ class Actions(private val shell: AdbShell) {/*** Launchers to protect: the default one, or with no default (then resolve-activity answers- * with the system chooser, package `android`) every built-in launcher. One the user installed- * isn't locked then: without it, Home still has the TV's own. Every launcher when the user's- * are all there is.+ * with the system chooser, package `android`) every built-in one. A launcher the user installed+ * isn't locked then, unless it's the only launcher left: the TV must keep one. Null when the+ * TV didn't answer, so nothing is known to be safe.*/- suspend fun homePackages(): Set<String> {+ suspend fun homePackages(): Set<String>? {val current = packagesIn(shell.shell(Commands.HOME_ACTIVITY).output) - "android"if (current.isNotEmpty()) return current- val all = packagesIn(shell.shell(Commands.HOME_ACTIVITIES).output) - "android"- if (all.isEmpty()) return all- return (all - userPackages()).ifEmpty { all }+ val homes = shell.shell(Commands.HOME_ACTIVITIES).output+ val all = packagesIn(homes) - "android"+ if (all.isEmpty()) return null+ val user = userPackages()+ val last = launchersIn(homes).keys.takeIf { it.size == 1 && it.single() in user }.orEmpty()+ return all - user + last}- /** Null when the TV didn't answer, or has no default home and no launcher of its own that is on. */+ /**+ * Null when the TV didn't answer or has no launcher. With no default home, the TV's own+ * launcher stands as [HomeOptions.current]; with none of its own on, every launcher is offered.+ */suspend fun homeOptions(): HomeOptions? {currentHome()?.substringBefore('/')?.let { return HomeOptions(it, launchers().keys - it) }- val stock = stockHome()?.substringBefore('/') ?: return null- return HomeOptions(stock, launchers().keys - stock, default = false)+ val launchers = launchers().keys.ifEmpty { return null }+ val stock = stockHome()?.substringBefore('/')+ return HomeOptions(stock, launchers - setOfNotNull(stock), default = false)}/**@@ -91,8 +101,8 @@ class Actions(private val shell: AdbShell) {*/suspend fun makeHome(pkg: String): HomeResult {require(PACKAGE.matches(pkg)) { "not a package name: $pkg" }- // With no default home, the TV's own launcher is the one being replaced.- val from = currentHome() ?: stockHome() ?: return HomeResult.Refused(ProtectedReason.UNKNOWN_HOME)+ // With no default home, the TV's own launcher is the one being replaced; with none on, nothing is.+ val from = currentHome() ?: stockHome() ?: return firstHome(pkg)val old = from.substringBefore('/')if (old == pkg) return HomeResult.Failed("it's already the home screen")val homes = shell.shell(Commands.HOME_ACTIVITIES).output@@ -198,6 +208,13 @@ class Actions(private val shell: AdbShell) {suspend fun currentHome(): String? =activitiesIn(shell.shell(Commands.HOME_ACTIVITY).output).singleOrNull()?.takeUnless { it.startsWith("android/") }+ /** No default home and no launcher of the TV's own on: sets [pkg] as Home, with nothing to turn off. */+ private suspend fun firstHome(pkg: String): HomeResult {+ val to = launchers()[pkg] ?: return HomeResult.Refused(ProtectedReason.UNKNOWN_HOME)+ if (!setHome(to)) return HomeResult.Failed("the TV still asks which home screen to use")+ return HomeResult.Switched(null, to)+ }+/** With no default home, the TV's own launcher that is on: the built-in one Home ranks highest. */private suspend fun stockHome(): String? {val homes = shell.shell(Commands.HOME_ACTIVITIES).outputdiff --git a/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.ktindex 66efc39..b487015 100644--- a/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt+++ b/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt@@ -59,15 +59,48 @@ class ActionsTest {assertEquals(ActionResult.Done(Action.ENABLE), Actions(sh).run(Action.DISABLE, "me.efesser.flauncher"))}- @Test fun noDefaultAndOnlyTheUsersLaunchersProtectsThemAll() = runTest {- // The TV's own launcher is off: one of the user's is all Home has left.- 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.spocky.projengmenu/.Main\nme.efesser.flauncher/.MainActivity\n"),- "pm list packages -3" to ok("package:com.spocky.projengmenu\npackage:me.efesser.flauncher\n"),- ))- assertEquals(setOf("com.spocky.projengmenu", "me.efesser.flauncher"), Actions(sh).homePackages())- assertEquals(null, Actions(sh).homeOptions())+ /** The TV's own launcher was turned off by hand, then a second launcher cleared the default. */+ private fun stockOff(vararg user: String): FakeShell {+ var home = "android/com.android.internal.app.ResolverActivity"+ val activities = mapOf("com.spocky.projengmenu" to "com.spocky.projengmenu/.ui.home.MainActivity", "me.efesser.flauncher" to "me.efesser.flauncher/.MainActivity")+ return FakeShell(mapOf(+ "cmd package query-activities" to ok(user.joinToString("") { activities.getValue(it) + "\n" }),+ "pm list packages -3" to ok(user.joinToString("") { "package:$it\n" }),+ "pm disable-user" to ok("Package me.efesser.flauncher new state: disabled-user\n"),+ )).apply {+ answer = { cmd ->+ when {+ cmd.startsWith("cmd package resolve-activity") -> ok("priority=0\n$home\n")+ cmd.startsWith("cmd package set-home-activity") -> {+ home = cmd.substringAfter("'").substringBefore("'")+ ok("Success\n")+ }+ else -> null+ }+ }+ }+ }++ @Test fun stockOffAndTwoOfTheUsersLaunchersLocksNeither() = runTest {+ val sh = stockOff("com.spocky.projengmenu", "me.efesser.flauncher")+ assertEquals(emptySet(), Actions(sh).homePackages())+ assertEquals(ActionResult.Done(Action.ENABLE), Actions(sh).run(Action.DISABLE, "me.efesser.flauncher"))+ assertEquals(HomeOptions(null, setOf("com.spocky.projengmenu", "me.efesser.flauncher"), default = false), Actions(sh).homeOptions())+ }++ @Test fun stockOffSetAsDefaultSetsHomeAndTurnsNothingOff() = runTest {+ val sh = stockOff("com.spocky.projengmenu", "me.efesser.flauncher")+ assertEquals(HomeResult.Switched(null, "com.spocky.projengmenu/.ui.home.MainActivity"), Actions(sh).makeHome("com.spocky.projengmenu"))+ assertTrue(sh.ran.none { it.startsWith("pm disable") || it.startsWith("pm enable") })+ assertEquals("com.spocky.projengmenu/.ui.home.MainActivity", Actions(sh).currentHome())+ }++ @Test fun stockOffAndOneOfTheUsersLaunchersKeepsItLocked() = runTest {+ // The only launcher left: without it the TV would have no home screen.+ val sh = stockOff("com.spocky.projengmenu")+ assertEquals(setOf("com.spocky.projengmenu"), Actions(sh).homePackages())+ assertEquals(ActionResult.Refused(ProtectedReason.HOME_SCREEN), Actions(sh).run(Action.DISABLE, "com.spocky.projengmenu"))+ assertEquals(ActionResult.Refused(ProtectedReason.HOME_SCREEN), Actions(sh).run(Action.UNINSTALL, "com.spocky.projengmenu"))}@Test fun unknownHomeRefusesStopAndDisable() = runTest {@@ -242,16 +275,6 @@ class ActionsTest {assertTrue("pm disable-user --user 0 com.google.android.tvlauncher 2>&1" in sh.ran)}- @Test fun noDefaultHomeAndNoLauncherOfItsOwnRefusesTheSwitch() = 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.spocky.projengmenu/.Main\nme.efesser.flauncher/.MainActivity\n"),- "pm list packages -3" to ok("package:com.spocky.projengmenu\npackage:me.efesser.flauncher\n"),- ))- assertEquals(HomeResult.Refused(ProtectedReason.UNKNOWN_HOME), Actions(sh).makeHome("com.spocky.projengmenu"))- assertTrue(sh.ran.none { it.startsWith("pm disable") || it.startsWith("pm enable") || "set-home" in it })- }-@Test fun makeHomeSwitchesChecksThenDisables() = runTest {val sh = twoLaunchers()assertEquals(diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex 56b765c..48bc6cc 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -397,7 +397,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {// for a built-in launcher that is off.protectedReason = when {p.name in disabled -> null- home.isNotEmpty() -> Protected.reason(p.name, home, userApp = p.name in userInstalled)+ home != null -> Protected.reason(p.name, home, userApp = p.name in userInstalled)else -> ProtectedReason.UNKNOWN_HOME}?.let(::reasonText),version = "",@@ -406,6 +406,8 @@ class AdbDeviceSource(context: Context) : DeviceSource {home = p.name == homeOptions?.takeIf { it.default }?.current,listedLauncher = launchers.any { it.pkg == p.name },homeInstead = homeOptions?.takeIf { p.name in it.others }?.current,+ homeFirst = homeOptions?.takeIf { it.current == null && p.name in it.others } != null,+ answersHome = homeOptions?.let { p.name == it.current || p.name in it.others } == true,homeBack = back?.takeIf { p.name == homeOptions?.current }?.let { names[it.pkg]?.label ?: AppNames.fallback(it.pkg) },homeService = p.name in serviceLaunchers,homeServiceOff = serviceOff && p.name == homeOptions?.current,@@ -530,12 +532,13 @@ class AdbDeviceSource(context: Context) : DeviceSource {deviceId = key,at = System.currentTimeMillis(),action = Action.Home,- packageName = r.from.substringBefore('/'),+ // With no launcher of the TV's own to replace, nothing was turned off and there's nothing to undo.+ packageName = r.from?.substringBefore('/') ?: packageName,label = label,- undo = Action.Enable,+ undo = Action.Enable.takeIf { r.from != null },undoing = undoing,// "service" only when this switch turned it on, so Undo turns off no more than that.- previous = mapOf("from" to r.from, "to" to r.to) + listOfNotNull(service?.takeIf { on == true }?.let { "service" to it }),+ previous = listOfNotNull(r.from?.let { "from" to it }, "to" to r.to, service?.takeIf { on == true }?.let { "service" to it }).toMap(),).also { if (on == false) throw IllegalStateException(serviceNotOn(label)) }}is HomeResult.Refused -> throw IllegalStateException(reasonText(r.reason))@@ -578,7 +581,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {undo = Action.Home,// The switch away from it is reversed now, so Restore leaves it alone.undoing = undoing ?: target.reverses,- previous = mapOf("from" to r.from, "to" to r.to) + listOfNotNull(service?.takeIf { off == true }?.let { "service" to it }),+ 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))) }}is HomeResult.Refused -> throw IllegalStateException(reasonText(r.reason))diff --git a/app/src/main/java/app/tellyscope/data/HistoryBook.kt b/app/src/main/java/app/tellyscope/data/HistoryBook.ktindex f0e640c..0ac3847 100644--- a/app/src/main/java/app/tellyscope/data/HistoryBook.kt+++ b/app/src/main/java/app/tellyscope/data/HistoryBook.kt@@ -89,7 +89,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.disables && it.undoneAt == null }+ .filter { it.deviceId == deviceId && it.packageName == packageName && it.disables && it.undoneAt == null }.maxOfOrNull { it.id }/**@@ -111,9 +111,9 @@ class HistoryBook(private val file: File? = null) {* old launcher); an uninstall clears it.*/fun leftDisabled(history: List<HistoryEntry>): List<String> =- history.filter { it.action.disables || it.action == Action.Enable || it.action == Action.Uninstall }+ history.filter { it.disables || it.action == Action.Enable || it.action == Action.Uninstall }.sortedBy { it.id }- .associate { it.packageName to it.action }+ .associate { it.packageName to it }.filterValues { it.disables }.keys.sorted()}@@ -189,7 +189,8 @@ fun homeBackTarget(current: String, history: List<HistoryEntry>, builtIns: List<return builtIns.firstOrNull { it != current }?.let { HomeBackTarget(it, null, null) }}-private val Action.disables get() = this == Action.Disable || this == Action.Home+/** A home switch disables the old launcher, unless there was none to replace: then it offers no undo. */+private val HistoryEntry.disables get() = action == Action.Disable || (action == Action.Home && undo != null)/*** Turns apps back on one at a time and stops at the first refusal, saying how far it got so thediff --git a/app/src/main/java/app/tellyscope/data/Model.kt b/app/src/main/java/app/tellyscope/data/Model.ktindex a380186..3025193 100644--- a/app/src/main/java/app/tellyscope/data/Model.kt+++ b/app/src/main/java/app/tellyscope/data/Model.kt@@ -130,6 +130,10 @@ data class AppInfo(val listedLauncher: Boolean = false,/** Another launcher that can replace the current home screen, [homeInstead]: "Set as default launcher" is offered. */val homeInstead: String? = null,+ /** No default home and no launcher of the TV's own on: "Set as default launcher" is offered with nothing to replace. */+ val homeFirst: Boolean = false,+ /** A launcher: it answers the Home button (an off app answers nothing). */+ val answersHome: Boolean = false,/** On the home screen the user added: the name of the launcher "Switch home back" returns to. */val homeBack: String? = null,/** A launcher that keeps Home with its accessibility service: the switch turns it on, the way back off. */diff --git a/app/src/main/java/app/tellyscope/ui/AppsTabs.kt b/app/src/main/java/app/tellyscope/ui/AppsTabs.ktindex 2389028..1dfb7cf 100644--- a/app/src/main/java/app/tellyscope/ui/AppsTabs.kt+++ b/app/src/main/java/app/tellyscope/ui/AppsTabs.kt@@ -30,7 +30,7 @@ data class AppsSplit(val apps: List<AppInfo>, val system: List<AppInfo>)/** Locked, as [AppRow] shows it: protected, and not offered as the new home screen or the way back. */private fun locked(app: AppInfo, all: List<AppInfo>) =app.protectedReason != null && (app.homeInstead == null || !app.enabled || homeLabel(all, app) == null) &&- (app.homeBack == null || !app.enabled)+ (app.homeBack == null || !app.enabled) && !(app.homeFirst && app.enabled)/*** Splits the TV's apps for [tab]. Running: apps using RAM now. Installed: the user's own apps,diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.ktindex ea7d24f..480d1b2 100644--- a/app/src/main/java/app/tellyscope/ui/Copy.kt+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt@@ -103,6 +103,12 @@ object Copy {if (service) append("\n\nNext, you choose whether to turn on its accessibility service.")}+ /** No default home and no launcher of the TV's own on: nothing is turned off, so there's no Undo either. */+ fun explainFirstHome(app: String, pkg: String, service: Boolean = false) = buildString {+ append("Makes $app ($pkg) open when you press Home. The TV has no default home screen now, and nothing else is turned off.")+ if (service) append("\n\nNext, you choose whether to turn on its accessibility service.")+ }+/** The separate yes for a launcher's accessibility service: what it does, what it can see, how it goes. */fun serviceTitle(app: String) = "Turn on $app's accessibility service?"diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.ktindex 168969a..cebfd4d 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt@@ -404,8 +404,10 @@ internal fun AppRow(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 }+ // No default home and no launcher of the TV's own on: Set as default replaces nothing.+ val first = app.homeFirst && app.enabledval back = app.homeBack?.takeIf { app.enabled }- val changeable = app.protectedReason == null || home != null || back != null+ val changeable = app.protectedReason == null || home != null || first || back != nullval ram = procs.filter { it.packageName == app.packageName }.sumOf { it.ramMb }val status = when {!app.enabled -> "Disabled"@@ -429,15 +431,15 @@ internal fun AppRow(}val asked = pending?.takeIf { it.first == app.packageName }?.second// A launcher switch whose target went away meanwhile (turned off in Debloat, say) has nothing left to explain.- val orphaned = (asked == Action.Home && home == null) || (asked == Action.HomeBack && back == null)+ val orphaned = (asked == Action.Home && home == null && !first) || (asked == Action.HomeBack && back == null)if (orphaned) LaunchedEffect(app.packageName) { actions.cancel() }val proposed = asked.takeUnless { orphaned }// The service gets its own yes after the switch's; dismissing it goes back to the switch's.var askService by remember(app.packageName, proposed) { mutableStateOf(false) }var turningOn by rememberSaveable(app.packageName) { mutableStateOf(false) }- if (askService && proposed == Action.Home && home != null) {+ if (askService && proposed == Action.Home && (home != null || first)) {ServiceDialog(- app.label, homeLabel!!,+ app.label, homeLabel ?: Copy.TV_OWN_LAUNCHER,onTurnOn = { actions.confirmHome(true) },dismissLabel = Copy.SWITCH_WITHOUT, onOther = { actions.confirmHome(false) }, onDismiss = { askService = false },)@@ -460,7 +462,7 @@ internal fun AppRow(else FilledTonalButton(onClick = { actions.propose(app.packageName, Action.Enable) }, enabled = !locked) { Text(Copy.button(Action.Enable)) }if (app.removable) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Uninstall) }, enabled = !locked) { Text(Copy.button(Action.Uninstall)) }}- if (home != null) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Home) }, enabled = !locked) { Text(Copy.MAKE_HOME) }+ if (home != null || first) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Home) }, enabled = !locked) { Text(Copy.MAKE_HOME) }if (back != null && app.homeServiceOff) FilledTonalButton(onClick = { turningOn = true }, enabled = !locked) { Text(Copy.TURN_ON) }if (back != null) OutlinedButton(onClick = { actions.propose(app.packageName, Action.HomeBack) }, enabled = !locked) { Text(Copy.homeBack(back)) }if (back != null && app.removable) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Uninstall) }, enabled = !locked) { Text(Copy.button(Action.Uninstall)) }@@ -470,6 +472,7 @@ internal fun AppRow(Text(when {proposed == Action.Home && home != null -> Copy.explainHome(app.label, app.packageName, homeLabel!!, home, app.homeService)+ proposed == Action.Home && first -> Copy.explainFirstHome(app.label, app.packageName, app.homeService)proposed == Action.HomeBack && back != null -> Copy.explainHomeBack(app.label, back, app.homeService && !app.homeServiceOff)app.listKeep && proposed != Action.Enable -> Copy.explain(proposed, app.label, app.packageName) + "\n\n" + Copy.KEEP_WARNINGelse -> Copy.explain(proposed, app.label, app.packageName)@@ -477,7 +480,7 @@ internal fun AppRow(style = MaterialTheme.typography.bodyMedium,)Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- val asks = proposed == Action.Home && home != null && app.homeService+ val asks = proposed == Action.Home && (home != null || first) && app.homeServiceButton(onClick = if (asks) ({ askService = true }) else actions.confirm, enabled = !locked) { Text(Copy.confirm(proposed)) }TextButton(onClick = actions.cancel) { Text("Cancel") }}diff --git a/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.kt b/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.ktindex 7f62750..2de3e39 100644--- a/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.kt+++ b/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.kt@@ -73,7 +73,7 @@ const val PLAY_STORE = "com.android.vending"internal fun hasPlayStore(apps: List<AppInfo>) = apps.any { it.packageName == PLAY_STORE && it.enabled }/** A launcher someone added is on the TV, Home or not: one on `launchers.json`, or one they installed that answers Home. */-internal fun hasAddedLauncher(apps: List<AppInfo>) = apps.any { it.listedLauncher || (it.removable && (it.home || it.homeInstead != null)) }+internal fun hasAddedLauncher(apps: List<AppInfo>) = apps.any { it.listedLauncher || (it.removable && it.answersHome) }internal fun offerChoose(apps: List<AppInfo>) = hasPlayStore(apps) && !hasAddedLauncher(apps)diff --git a/app/src/test/java/app/tellyscope/HistoryBookTest.kt b/app/src/test/java/app/tellyscope/HistoryBookTest.ktindex 5199bc1..1e7dfd7 100644--- a/app/src/test/java/app/tellyscope/HistoryBookTest.kt+++ b/app/src/test/java/app/tellyscope/HistoryBookTest.kt@@ -133,6 +133,14 @@ class HistoryBookTest {assertEquals(emptyList<String>(), source.restoreAll(id).map { it.packageName })}+ @Test fun aHomeSwitchThatReplacedNothingLeavesNothingToRestore() {+ val book = HistoryBook()+ book.record("tv", 0L, Action.Home, "com.google.android.tvlauncher", "Projectivy Launcher", undo = Action.Enable)+ book.record("tv", 1L, Action.Home, "me.efesser.flauncher", "FLauncher", undo = null)+ assertEquals(listOf("com.google.android.tvlauncher"), HistoryBook.leftDisabled(book.entries("tv")))+ assertNull(book.openDisable("tv", "me.efesser.flauncher"))+ }+@Test fun restoreAllTurnsOnOnlyWhatTellyscopeDisabled() = runTest {// The fake TV starts with TV Recommendations already disabled.val source = FakeDeviceSource()diff --git a/app/src/test/java/app/tellyscope/HomeServiceTest.kt b/app/src/test/java/app/tellyscope/HomeServiceTest.ktindex 6171868..2a33256 100644--- a/app/src/test/java/app/tellyscope/HomeServiceTest.kt+++ b/app/src/test/java/app/tellyscope/HomeServiceTest.kt@@ -72,6 +72,15 @@ class HomeServiceTest {assertEquals(pkg to Action.Uninstall, proposed)}+ @Test fun withNoLauncherOfTheTvsOwnOnSetAsDefaultSaysNothingIsTurnedOff() {+ var confirmed = false+ val first = projectivy.copy(homeInstead = null, homeFirst = true, homeService = false, removable = true)+ compose.setContent { AppRow(first, emptyList(), pkg to Action.Home, busy = false, actions = DeviceActions(confirm = { confirmed = true })) }+ compose.onNodeWithText(Copy.explainFirstHome("Projectivy Launcher", pkg)).assertExists()+ compose.onNodeWithText(Copy.confirm(Action.Home)).performClick()+ assertTrue(confirmed)+ }+private val onHome = projectivy.copy(homeInstead = null, homeBack = "Google TV Home", homeServiceOff = true, homeServiceNote = true, protectedReason = "this is your home screen")@Test fun theLauncherOnHomeOffersUninstallAndItsConfirmListsTheSteps() {diff --git a/app/src/test/java/app/tellyscope/LauncherFlowTest.kt b/app/src/test/java/app/tellyscope/LauncherFlowTest.ktindex 3953d26..5098362 100644--- a/app/src/test/java/app/tellyscope/LauncherFlowTest.kt+++ b/app/src/test/java/app/tellyscope/LauncherFlowTest.kt@@ -237,13 +237,16 @@ class LauncherScreenTest {@Test fun anAddedLauncherThatIsNotHomeStillHidesTheCardAndTheTweaksRow() {// Installing a second launcher clears the default: nothing is Home, and both are on.val noDefault = stock.copy(home = false, protectedReason = "this is your home screen")- val projectivy = AppInfo(PROJECTIVY, "Projectivy Launcher", null, false, true, null, "1.0", removable = true, listedLauncher = true, homeInstead = TV_HOME)- val flauncher = AppInfo("me.efesser.flauncher", "FLauncher", null, false, true, null, "1.0", removable = true, listedLauncher = true, homeInstead = TV_HOME)+ val projectivy = AppInfo(PROJECTIVY, "Projectivy Launcher", null, false, true, null, "1.0", removable = true, listedLauncher = true, homeInstead = TV_HOME, answersHome = true)+ val flauncher = AppInfo("me.efesser.flauncher", "FLauncher", null, false, true, null, "1.0", removable = true, listedLauncher = true, homeInstead = TV_HOME, answersHome = true)assertFalse(offerChoose(listOf(store, noDefault, projectivy, flauncher)))assertFalse(offerLauncher(listOf(store, noDefault, projectivy, flauncher), hidden = false))// One the user installed that isn't on launchers.json counts once it answers Home.- val other = AppInfo("com.example.home", "Home", null, false, true, null, "1.0", removable = true, homeInstead = TV_HOME)+ val other = AppInfo("com.example.home", "Home", null, false, true, null, "1.0", removable = true, answersHome = true)assertFalse(offerChoose(listOf(store, stock, other)))+ // The TV's own launcher off too: nothing to replace, and still no card.+ val off = stock.copy(enabled = false, home = false, protectedReason = null)+ assertFalse(offerChoose(listOf(store, off, other.copy(homeFirst = true))))// An app that doesn't answer Home is no launcher.val app = AppInfo("org.mine.jellyfin", "Jellyfin", null, false, true, null, "1.0", removable = true)assertTrue(offerChoose(listOf(store, stock, app)))