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.
Home screen card in Tweaks; Apps launcher rows link to it
jesse-agent-2323af97a81960a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9f0e435..a494b80 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,7 @@ until this file has a section for its version.## Unreleased+- **New:** A Home screen card in Tweaks switches launchers; only the TV's own turns off.- **Fixed:** Undo in History turns off a new home screen's accessibility service, as promised. [#185](../../pull/185)- **Fixed:** Restore everything always ends on your TV's own home screen. [#184](../../pull/184)- **Fixed:** The Remote's backspace no longer closes the TV app once the box is empty. [#183](../../pull/183)diff --git a/README.md b/README.mdindex 13d2ded..7be762b 100644--- a/README.md+++ b/README.md@@ -31,8 +31,8 @@ Debloat your Android TV, install apps, and browse and transfer files on it, all</tr><tr><td><img src="docs/screenshots/send.png" alt="Sending a video from the phone to the TV's Movies folder"></td>- <td><img src="docs/screenshots/tweaks.png" alt="TV tweaks: ad-blocking Private DNS on, faster animations, clear caches, screenshot, and Another home screen to install a launcher"></td>- <td><img src="docs/screenshots/home.png" alt="Making Projectivy Launcher the home screen: the confirm names both launchers"></td>+ <td><img src="docs/screenshots/tweaks.png" alt="Tweaks: the Home screen card with Google TV Home as Current and Get another launcher, then ad-blocking Private DNS on, faster animations and clear caches"></td>+ <td><img src="docs/screenshots/home.png" alt="Make Projectivy Launcher the home screen: the confirm says Google TV Home, the TV's built-in launcher, is the only one ever turned off"></td><td><img src="docs/screenshots/advanced.png" alt="Advanced: CPU and RAM by app, the TV's network connection, and the apps' open connections"></td></tr><tr>@@ -43,7 +43,7 @@ Debloat your Android TV, install apps, and browse and transfer files on it, all</tr></table>-<sub>Rendered from the app's screenshot tests with sample data. The Install dialog and the Tweaks launcher row are drawn to match the app, and Advanced joins parts of its longer page.</sub>+<sub>Rendered from the app's screenshot tests with sample data. The Install dialog is drawn to match the app, and Advanced joins parts of its longer page.</sub>## What it does@@ -54,7 +54,7 @@ Tellyscope talks to your Android TV, Google TV, NVIDIA Shield or Fire TV over Wi- **Debloat.** Matches your TV to one of 300+ tested lists (adapted from [cleanyourtv](https://github.com/Gathin23/cleanyourtv)) and shows every app it will turn off before it does. Untick anything you use. No list for your model? Pick from the maker's lists, or by hand.- **Apps.** See what's running and what's on the TV. Turn off apps you don't want, turn them back on any time, and uninstall the ones you added yourself.- **Install apps.** From an APK, split APKs or an `.apks`/`.xapk`/`.apkm` bundle on your phone. It says first whether it's new, an update or an older version.-- **A better home screen.** On TVs with the Play Store, pick a recommended launcher (Projectivy, AT4K, Dispatch or FLauncher), install it and make it Home. Switch back or remove it any time. A launcher's accessibility service turns on only if you say yes.+- **A better home screen.** On TVs with the Play Store, pick a recommended launcher (Projectivy, AT4K, Dispatch or FLauncher), install it and make it Home. Switch between launchers, or back to the TV's own, from the Home screen card in Tweaks; only the TV's own is ever turned off. A launcher's accessibility service turns on only if you say yes.- **Send files.** To and from the TV's Download and Movies folders.- **Remote.** D-pad, Back, Home, Menu, mute and volume, typing on the TV, a dock of up to four apps, restart the TV, and **Screen off** for music with the picture off (Android 13 or older).- **Tweaks.** Block ads with Private DNS, faster animations, clear caches, take a screenshot.diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex bedb1e1..9004642 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -384,8 +384,9 @@ class AdbDeviceSource(context: Context) : DeviceSource {val names = appNames.names(key(deviceId), listed, LabelHelper(session, helperDex)::describe)val keep = keep[key(deviceId)].orEmpty()// On a launcher the user added, offer the way back to the one it replaced.+ val own = homeOptions?.let { builtIns(system, disabled, it) }.orEmpty()val back = homeOptions?.current?.takeIf { it !in system }- ?.let { homeBackTarget(it, book.entries(key(deviceId)), builtIns(system, disabled, homeOptions)) }+ ?.let { homeBackTarget(it, book.entries(key(deviceId)), own) }// Its service off, the TV's own launcher may still answer Home: the row offers Turn on.val serviceOff = back != null && homeOptions?.current?.takeIf { it in serviceLaunchers }?.let { Actions(shell).homeService(it) }?.let { !Actions(shell).serviceOn(it) } == true@@ -418,6 +419,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {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,+ builtInLauncher = p.name in system && (p.name == homeOptions?.current || p.name in own),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,@@ -556,25 +558,29 @@ class AdbDeviceSource(context: Context) : DeviceSource {/*** Uninstall of the launcher on Home: Home goes back to the TV's own first, its accessibility- * service off with it, as Switch home back does. Any step that fails stops it before the uninstall.+ * service off with it, as going 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) }, book::dropUndo)/**- * Makes Home again the launcher that [added], now Home, replaced: the one the last switch saved,- * else the TV's own. [added] stays on; the entry's undo makes it Home again.+ * Leaves the launcher the user added, now Home, for one of the TV's own. [pkg] is either that+ * added launcher, going back to the one it replaced (the one the last switch saved, else the+ * TV's own), or the TV's own launcher to go to, from the Home screen card. The added launcher+ * stays on; the entry's undo makes it Home again.*/- private suspend fun homeBack(deviceId: String, added: String, undoing: Long?): HistoryEntry {+ private suspend fun homeBack(deviceId: String, pkg: String, undoing: Long?): HistoryEntry {fireHomes -= deviceIdval key = key(deviceId)val shell = session(deviceId)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 options = Actions(shell).homeOptions()- val target = options?.current?.takeIf { it == added && it !in system }- ?.let { homeBackTarget(it, book.entries(key), builtIns(system, disabled, options)) }- ?: throw IllegalStateException("there's no home screen to switch back to")+ val nothing = "there's no home screen to switch back to"+ val options = Actions(shell).homeOptions() ?: throw IllegalStateException(nothing)+ val added = options.current?.takeIf { it !in system } ?: throw IllegalStateException(nothing)+ val own = builtIns(system, disabled, options)+ val target = (if (pkg == added) homeBackTarget(added, book.entries(key), own) else pkg.takeIf { it in own }?.let { builtInTarget(it, book.entries(key)) })+ ?: throw IllegalStateException(nothing)return when (val r = Actions(shell).homeBack(target.pkg, target.activity)) {is HomeResult.Switched -> {// Off with Home: it would keep sending Home to [added]. Undo, a switch, turns it on again.diff --git a/app/src/main/java/app/tellyscope/data/HistoryBook.kt b/app/src/main/java/app/tellyscope/data/HistoryBook.ktindex 14ea408..9e641be 100644--- a/app/src/main/java/app/tellyscope/data/HistoryBook.kt+++ b/app/src/main/java/app/tellyscope/data/HistoryBook.kt@@ -178,7 +178,7 @@ class HistoryBook(private val file: File? = null) {private const val VERSION = "v1"-/** Where "Switch home back" goes: a launcher, its home activity if known, and the switch it reverses. */+/** Where going back from a launcher the user added goes: a launcher, its home activity if known, and the switch it reverses. */data class HomeBackTarget(val pkg: String, val activity: String?, val reverses: Long?)/**@@ -193,6 +193,17 @@ fun homeBackTarget(current: String, history: List<HistoryEntry>, builtIns: List<return builtIns.firstOrNull { it != current }?.let { HomeBackTarget(it, null, null) }}+/**+ * Going back to [pkg], one of the TV's own launchers, from the Home screen card: the newest+ * switch away from it gives its home activity and is the one reversed, so Restore leaves it alone.+ */+fun builtInTarget(pkg: String, history: List<HistoryEntry>): HomeBackTarget {+ val switch = history+ .filter { it.action == Action.Home && it.undoneAt == null && it.previous?.get("from")?.substringBefore('/') == pkg }+ .maxByOrNull { it.id }+ return HomeBackTarget(pkg, switch?.previous?.get("from"), switch?.id)+}+/*** A home switch disables the old launcher, unless there was none to replace (then it offers no* undo, or one for its service only) or the old one was a launcher the user added, which staysdiff --git a/app/src/main/java/app/tellyscope/data/Launchers.kt b/app/src/main/java/app/tellyscope/data/Launchers.ktindex 9355445..5b968a9 100644--- a/app/src/main/java/app/tellyscope/data/Launchers.kt+++ b/app/src/main/java/app/tellyscope/data/Launchers.kt@@ -7,8 +7,8 @@ import org.json.JSONObject/*** A third-party launcher Tellyscope knows, from `assets/launchers.json`. [accessibility]: it keeps* Home with its own accessibility service, for TVs whose Home button opens their own launcher- * whatever the default is, so Set as default turns that service on and Undo / Switch home back- * turn it off. [checked] is the version whose manifest was read.+ * whatever the default is, so Make Home turns that service on, and Undo or a switch away from it+ * turns it off. [checked] is the version whose manifest was read.*/data class KnownLauncher(val pkg: String, val name: String, val accessibility: Boolean, val checked: String?)diff --git a/app/src/main/java/app/tellyscope/data/Model.kt b/app/src/main/java/app/tellyscope/data/Model.ktindex 3025193..5ecb513 100644--- a/app/src/main/java/app/tellyscope/data/Model.kt+++ b/app/src/main/java/app/tellyscope/data/Model.kt@@ -128,13 +128,15 @@ data class AppInfo(val home: Boolean = false,/** On the bundled `launchers.json`: a launcher people add, never a TV's own. */val listedLauncher: Boolean = false,- /** Another launcher that can replace the current home screen, [homeInstead]: "Set as default launcher" is offered. */+ /** Another launcher that can replace the current home screen, [homeInstead]: Make Home 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. */+ /** No default home and no launcher of the TV's own on: Make Home 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. */+ /** A launcher the TV came with, on or off: the Home screen card lists it, and it's the only kind a switch turns off. */+ val builtInLauncher: Boolean = false,+ /** On the home screen the user added: the name of the launcher going back from it returns to. */val homeBack: String? = null,/** A launcher that keeps Home with its accessibility service: the switch turns it on, the way back off. */val homeService: Boolean = false,diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.ktindex fff569b..81da6b1 100644--- a/app/src/main/java/app/tellyscope/ui/Copy.kt+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt@@ -77,20 +77,54 @@ object Copy {/** Said in the confirm before Stop, Disable or Uninstall of an app the TV's list keeps. */const val KEEP_WARNING = "This TV's list says to keep this."- fun homeBack(launcher: String) = "Switch home back to $launcher"-- /** The way back keeps the added launcher, so it can be made Home again or uninstalled. */- fun explainHomeBack(added: String, back: String, service: Boolean) = buildString {- append("Makes $back open when you press Home again, turning it back on if it's off. $added stays on")- append(if (service) ", with its accessibility service turned off. " else ". ")- append("Undo in History makes $added Home again.")- }-/** Where the lists come from, for the Debloat screen and the snackbar after a change. */fun listSource(custom: String?) =if (custom == null) "Lists from tellyscope-devices, built from cleanyourtv" else "Lists from ${sourceName(custom)}"- const val MAKE_HOME = "Set as default launcher"+ /** The Home screen card at the top of Tweaks: every launcher on the TV, and which one Home opens. */+ const val HOME_SCREEN = "Home screen"++ fun opensOnHome(app: String) = "$app opens when you press Home."++ const val NO_DEFAULT = "No default: pick one below."+ const val ADDED = "Added"++ fun builtIn(off: Boolean) = "Built into the TV" + if (off) " · turned off" else ""++ const val CURRENT = "Current"+ const val KEEPS_HOME = "Keeps Home with its accessibility service"+ const val MAKE_HOME = "Make Home"+ const val GET_LAUNCHER = "Get another launcher"+ const val GET_LAUNCHER_TEXT = "Install one from the Play Store, like Projectivy or FLauncher. Switch back any time."++ /** The Apps tab's launcher rows: switching lives in the card, this opens it. */+ const val HOME_SETTINGS = "Home screen settings"++ fun makeHomeTitle(app: String) = "Make $app the home screen?"++ /** A launcher the user added in place of the TV's own, which is turned off: otherwise many TVs switch back by themselves. */+ fun explainReplace(app: String, current: String, currentPkg: String, service: Boolean) = buildString {+ append("Home opens $app. To stop the TV switching back by itself, Tellyscope turns off $current, the TV's built-in launcher.")+ append("\n\nThat's the only launcher it ever turns off. Launchers you added stay on, so you can switch between them any time.")+ append("\n\nUndo in History turns $current back on.")+ 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.")+ if (service) append("\n\nNext, you choose whether to turn on its accessibility service.")+ }++ /**+ * Away from [current], a launcher the user added: it stays on, only its accessibility service+ * goes off when it has one on, since that would take Home straight back. [off]: [app] is the+ * TV's own launcher, turned off by an earlier switch.+ */+ fun explainLeave(app: String, off: Boolean, current: String, currentService: Boolean, service: Boolean) = buildString {+ append(if (off) "Tellyscope turns $app back on and makes it open when you press Home." else "Tellyscope makes $app open when you press Home.")+ append("\n\n")+ if (currentService) append("It also turns off $current's accessibility service, which would otherwise take Home straight back. ")+ append("$current stays installed and on, so you can make it Home again any time.")+ append("\n\nUndo in History makes $current Home again")+ append(if (currentService) " and turns its service back on." else ".")+ if (service) append("\n\nNext, you choose whether to turn on its accessibility service.")+ }/*** The home switch touches two apps, so it names both. The old launcher is disabled, not just@@ -115,7 +149,7 @@ object Copy {fun explainService(app: String, other: String) ="It keeps the Home button opening $app. Without it, this TV's Home button may still open $other.\n\n" +"An accessibility service can see what's on screen. Turn it on only if you trust $app.\n\n" +- "Undo in History or Switch home back turns it off."+ "Undo in History, or making another launcher Home, turns it off."const val TURN_IT_ON = "Turn it on"const val SWITCH_WITHOUT = "Switch without it"@@ -158,7 +192,7 @@ object Copy {fun isInstalled(name: String) = "$name is installed."- fun launcherLater(name: String) = "$name is installed. To use it later, open its row and choose $MAKE_HOME."+ fun launcherLater(name: String) = "$name is installed. To use it later, choose $MAKE_HOME on it in Tweaks, under $HOME_SCREEN."fun launcherInstalled(name: String) = "$name is installed. Press Home on the remote to pick it."@@ -178,8 +212,6 @@ object Copy {"The Play Store closed on the TV before it was installed. If the Store said it isn't available for this TV, choose another launcher."/** The Tweaks row that reopens it after Not now on the card. */- const val ANOTHER_HOME = "Another home screen"- const val ANOTHER_HOME_TEXT = "Install a launcher from the Play Store, like Projectivy or FLauncher. Switch back any time."fun serviceOffText(app: String) = "$app's accessibility service is off, so the TV can take Home back."diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.ktindex 77d1d03..32d8b10 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt@@ -19,6 +19,7 @@ import androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.widthimport androidx.compose.foundation.shape.CircleShapeimport androidx.compose.material.icons.Icons+import androidx.compose.material.icons.automirrored.filled.ArrowForwardimport androidx.compose.material.icons.filled.Checkimport androidx.compose.material.icons.filled.CheckCircleimport androidx.compose.material.icons.filled.Delete@@ -39,7 +40,6 @@ import androidx.compose.material3.OutlinedTextFieldimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composable-import androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.remember@@ -400,18 +400,15 @@ internal 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,/** Something else is running on this TV: every button waits for it, like the tweaks do. */locked: Boolean = false,+ /** Opens the Home screen card in Tweaks, where launchers are switched. */+ toHomeScreen: () -> Unit = {},) {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.enabled- val back = app.homeBack?.takeIf { app.enabled }- val changeable = app.protectedReason == null || home != null || first || back != null+ // A launcher can be protected and still open, for the way to the Home screen card.+ val launcher = app.answersHome || app.builtInLauncher+ val changeable = app.protectedReason == null || launcherval ram = procs.filter { it.packageName == app.packageName }.sumOf { it.ramMb }val status = when {!app.enabled -> "Disabled"@@ -433,59 +430,39 @@ internal fun AppRow(}if (busy) androidx.compose.material3.LoadingIndicator(Modifier.size(32.dp))}- 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 && !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 || first)) {- ServiceDialog(- app.label, homeLabel ?: Copy.TV_OWN_LAUNCHER,- onTurnOn = { actions.confirmHome(true) },- dismissLabel = Copy.SWITCH_WITHOUT, onOther = { actions.confirmHome(false) }, onDismiss = { askService = false },- )- }- if (turningOn && app.homeServiceOff) {- ServiceDialog(- app.label, back ?: Copy.TV_OWN_LAUNCHER,- onTurnOn = { turningOn = false; actions.homeServiceOn(app.packageName) },- dismissLabel = Copy.NOT_NOW, onOther = { turningOn = false }, onDismiss = { turningOn = false },- )- }+ // Home switches are asked for in the Home screen card, not here.+ val proposed = pending?.takeIf { it.first == app.packageName }?.second?.takeUnless { it == Action.Home || it == Action.HomeBack }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) {- if (app.protectedReason == null) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- if (app.enabled && ram > 0) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Stop) }, enabled = !locked) { Text(Copy.button(Action.Stop)) }- if (app.enabled) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Disable) }, enabled = !locked) { Text(Copy.button(Action.Disable)) }- 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 (app.protectedReason == null) {+ Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {+ if (app.enabled && ram > 0) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Stop) }, enabled = !locked) { Text(Copy.button(Action.Stop)) }+ if (app.enabled) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Disable) }, enabled = !locked) { Text(Copy.button(Action.Disable)) }+ 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)) }+ }+ } else if (launcher && app.removable) {+ // The launcher on Home: protected, but Uninstall still goes, Home moving first.+ OutlinedButton(onClick = { actions.propose(app.packageName, Action.Uninstall) }, enabled = !locked) { Text(Copy.button(Action.Uninstall)) }+ }+ if (launcher) TextButton(onClick = toHomeScreen) {+ Text(Copy.HOME_SETTINGS)+ Spacer(Modifier.width(8.dp))+ Icon(Icons.AutoMirrored.Filled.ArrowForward, contentDescription = null, Modifier.size(18.dp))}- 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)) }} else if (proposed == Action.Uninstall) {UninstallDialog(app, onUninstall = actions.confirm, onDismiss = actions.cancel, enabled = !locked)} else {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_WARNING- else -> Copy.explain(proposed, app.label, app.packageName)- },+ if (app.listKeep && proposed != Action.Enable) Copy.explain(proposed, app.label, app.packageName) + "\n\n" + Copy.KEEP_WARNING+ else Copy.explain(proposed, app.label, app.packageName),style = MaterialTheme.typography.bodyMedium,)Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- val asks = proposed == Action.Home && (home != null || first) && app.homeService- Button(onClick = if (asks) ({ askService = true }) else actions.confirm, enabled = !locked) { Text(Copy.confirm(proposed)) }+ Button(onClick = actions.confirm, enabled = !locked) { Text(Copy.confirm(proposed)) }TextButton(onClick = actions.cancel) { Text("Cancel") }}}diff --git a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt b/app/src/main/java/app/tellyscope/ui/DeviceTabs.ktindex 3849a01..4832a77 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt@@ -176,7 +176,7 @@ fun DeviceTabsScreen(}}// The tabs share one list, so each opens at the top with its hero, not where the last one was left.- // "See changes" lands on Tweaks scrolled to Recent changes, the list's third item, after the hero.+ // "See changes" lands on Tweaks scrolled to Recent changes, the item after the hero and the cards above it.var toChanges by remember { mutableStateOf(false) }var shown by rememberSaveable { mutableStateOf(tab) }var gate by rememberSaveable { mutableStateOf(false) }@@ -206,7 +206,8 @@ fun DeviceTabsScreen(LaunchedEffect(tab) {if (tab == shown) return@LaunchedEffectshown = tab- list.scrollToItem(if (tab == TvTab.Tweaks && toChanges) 2 else 0)+ val hub = !offline && homeLaunchers(ui.apps).isNotEmpty()+ list.scrollToItem(if (tab == TvTab.Tweaks && toChanges) (if (hub) 3 else 2) else 0)toChanges = false}// Opening search starts the results from the top; closing it brings the TV back into view.@@ -336,7 +337,7 @@ fun DeviceTabsScreen(}TvTab.Apps -> {fun rows(apps: List<AppInfo>) = items(apps, key = { it.packageName }) { app ->- AppRow(app, procs, ui.pending, ui.busy == app.packageName, actions, homeLabel(ui.apps, app), locked = ui.busy != null)+ AppRow(app, procs, ui.pending, ui.busy == app.packageName, actions, locked = ui.busy != null, toHomeScreen = { if (searching) closeSearch(); tab = TvTab.Tweaks })}// Until the first read lands, an empty list means "not yet", not "none".val loading = ui.appsLoading && !offline@@ -396,7 +397,10 @@ fun DeviceTabsScreen(}TvTab.Tweaks -> {if (offline) item { Muted("Connect to the TV to change its settings.") }- else item { Panel(Copy.TWEAKS) { TweaksBlock(ui, actions) } }+ else {+ if (homeLaunchers(ui.apps).isNotEmpty()) item { Panel(Copy.HOME_SCREEN) { HomeScreenBlock(ui, actions) } }+ item { Panel(Copy.TWEAKS) { TweaksBlock(ui, actions) } }+ }item {Panel("Recent changes") {HistoryList(ui.history, state.clock(), actions.undo, restoring = ui.busy == RESTORING, onRestoreAll = actions.restoreAll, busy = ui.busy != null)diff --git a/app/src/main/java/app/tellyscope/ui/HomeScreenCard.kt b/app/src/main/java/app/tellyscope/ui/HomeScreenCard.ktnew file mode 100644index 0000000..f4fbdb2--- /dev/null+++ b/app/src/main/java/app/tellyscope/ui/HomeScreenCard.kt@@ -0,0 +1,212 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.material3.AlertDialog+import androidx.compose.material3.Button+import androidx.compose.material3.FilledTonalButton+import androidx.compose.material3.Icon+import androidx.compose.material3.LinearProgressIndicator+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Surface+import androidx.compose.material3.Text+import androidx.compose.material3.TextButton+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.saveable.rememberSaveable+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.alpha+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.PathFillType+import androidx.compose.ui.graphics.SolidColor+import androidx.compose.ui.graphics.vector.ImageVector+import androidx.compose.ui.graphics.vector.PathParser+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import app.tellyscope.data.Action+import app.tellyscope.data.AppInfo++/** The launchers the Home screen card lists: the one on Home, then the ones the user added, then the TV's own. */+internal fun homeLaunchers(apps: List<AppInfo>): List<AppInfo> =+ apps.filter { it.answersHome || it.builtInLauncher }+ .sortedWith(compareBy({ !it.home }, { it.system }, { it.label.lowercase() }))++/**+ * What Make Home on [app] does, or null when it isn't offered. [current] is the launcher on Home,+ * null when the TV has no default. Leaving a launcher the user added for the TV's own goes back+ * ([Action.HomeBack]): that turns it back on if an earlier switch turned it off.+ */+internal fun homeMove(app: AppInfo, current: AppInfo?): Action? = when {+ app.home -> null+ app.builtInLauncher && current != null && !current.system -> Action.HomeBack+ !app.enabled -> null+ app.homeInstead != null || app.homeFirst -> Action.Home+ // No default: the TV's own launcher can be made the default too.+ current == null && app.answersHome -> Action.Home+ else -> null+}++/**+ * The Home screen card at the top of Tweaks: every launcher on the TV, which one Home opens, and+ * the one place to change it. Make Home asks first; only the TV's own launcher is ever turned off.+ */+@Composable+fun HomeScreenBlock(ui: DeviceUi, actions: DeviceActions) {+ val launchers = homeLaunchers(ui.apps)+ val current = launchers.firstOrNull { it.home }+ val locked = ui.busy != null+ if (launchers.any { it.packageName == ui.busy }) LinearProgressIndicator(Modifier.fillMaxWidth())+ if (current != null) {+ Text(Copy.opensOnHome(current.label), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ } else {+ NoDefaultBanner()+ }+ Column(Modifier.padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {+ launchers.forEach { app ->+ LauncherRow(+ app, homeMove(app, current), locked,+ onMove = { actions.propose(app.packageName, it) },+ onUninstall = { actions.propose(app.packageName, Action.Uninstall) },+ onServiceOn = { actions.homeServiceOn(app.packageName) },+ )+ }+ }+ // Only before a launcher was added: after that, the rows above are the way to switch.+ if (launchers.none { !it.system } && hasPlayStore(ui.apps)) {+ Column(Modifier.fillMaxWidth().padding(top = 16.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {+ Text(Copy.GET_LAUNCHER, style = MaterialTheme.typography.bodyLarge)+ Text(Copy.GET_LAUNCHER_TEXT, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ FilledTonalButton(onClick = actions.installLauncher, enabled = !locked) { Text(Copy.GET_LAUNCHER) }+ }+ }+ val (pkg, action) = ui.pending ?: return+ val app = launchers.firstOrNull { it.packageName == pkg }+ when (action) {+ Action.Uninstall -> if (app != null) UninstallDialog(app, onUninstall = actions.confirm, onDismiss = actions.cancel, enabled = !locked)+ Action.Home, Action.HomeBack -> if (app != null && homeMove(app, current) == action) {+ MakeHomeDialog(app, action, current, ui.apps, locked, actions)+ } else {+ // A switch whose target changed meanwhile (turned off in Debloat, say) has nothing left to ask.+ LaunchedEffect(pkg, action) { actions.cancel() }+ }+ else -> Unit+ }+}++/** Material 3 has no banner; a tonal surface stands in, as for the other notes. */+@Composable+private fun NoDefaultBanner() {+ Surface(color = MaterialTheme.colorScheme.secondaryContainer, shape = MaterialTheme.shapes.medium, modifier = Modifier.fillMaxWidth()) {+ Row(Modifier.padding(horizontal = 12.dp, vertical = 8.dp), verticalAlignment = Alignment.CenterVertically) {+ Icon(HubIcons.InfoOutline, contentDescription = null, Modifier.size(20.dp), tint = MaterialTheme.colorScheme.onSecondaryContainer)+ Spacer(Modifier.width(8.dp))+ Text(Copy.NO_DEFAULT, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSecondaryContainer)+ }+ }+}++@Composable+private fun LauncherRow(app: AppInfo, move: Action?, locked: Boolean, onMove: (Action) -> Unit, onUninstall: () -> Unit, onServiceOn: () -> Unit) {+ var turningOn by rememberSaveable(app.packageName) { mutableStateOf(false) }+ if (turningOn && app.homeServiceOff) {+ ServiceDialog(+ app.label, app.homeBack ?: Copy.TV_OWN_LAUNCHER,+ onTurnOn = { turningOn = false; onServiceOn() },+ dismissLabel = Copy.NOT_NOW, onOther = { turningOn = false }, onDismiss = { turningOn = false },+ )+ }+ Column {+ Row {+ AppIcon(app, Modifier.alpha(if (app.enabled) 1f else 0.4f))+ Spacer(Modifier.width(12.dp))+ Column(Modifier.weight(1f)) {+ Text(app.label, style = MaterialTheme.typography.bodyLarge, maxLines = 1, overflow = TextOverflow.Ellipsis)+ Text(+ if (app.system) Copy.builtIn(off = !app.enabled) else Copy.ADDED,+ style = MaterialTheme.typography.bodyMedium,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ if (app.homeService) {+ Row(verticalAlignment = Alignment.CenterVertically) {+ Icon(DeviceIcons.Accessibility, contentDescription = null, Modifier.size(14.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant)+ Spacer(Modifier.width(4.dp))+ Text(if (app.homeServiceOff) Copy.SERVICE_OFF else Copy.KEEPS_HOME, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)+ }+ }+ }+ if (app.home) {+ Row(Modifier.padding(start = 8.dp), verticalAlignment = Alignment.CenterVertically) {+ Icon(HubIcons.CheckCircleOutline, contentDescription = null, Modifier.size(18.dp), tint = MaterialTheme.colorScheme.primary)+ Spacer(Modifier.width(4.dp))+ Text(Copy.CURRENT, style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.primary)+ }+ }+ }+ // One action row for every launcher, so Uninstall lines up whether or not Make Home sits beside it.+ val serviceOn = app.home && app.homeServiceOff+ if (move != null || serviceOn || app.removable) {+ Row(Modifier.padding(start = 52.dp, top = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {+ if (move != null) FilledTonalButton(onClick = { onMove(move) }, enabled = !locked) { Text(Copy.MAKE_HOME) }+ if (serviceOn) FilledTonalButton(onClick = { turningOn = true }, enabled = !locked) { Text(Copy.TURN_ON) }+ if (app.removable) TextButton(onClick = onUninstall, enabled = !locked) { Text(Copy.button(Action.Uninstall)) }+ }+ }+ }+}++/**+ * Make Home's confirm: what changes, what stays, and what Undo does. A launcher with an+ * accessibility service gets its own yes for that next, never as a side effect of this one.+ */+@Composable+private fun MakeHomeDialog(app: AppInfo, action: Action, current: AppInfo?, apps: List<AppInfo>, locked: Boolean, actions: DeviceActions) {+ val replaced = homeLabel(apps, app)+ val asks = action == Action.Home && app.homeService+ var askService by remember(app.packageName) { mutableStateOf(false) }+ if (askService) {+ ServiceDialog(+ app.label, current?.label ?: replaced ?: Copy.TV_OWN_LAUNCHER,+ onTurnOn = { actions.confirmHome(true) },+ dismissLabel = Copy.SWITCH_WITHOUT, onOther = { actions.confirmHome(false) }, onDismiss = { askService = false },+ )+ return+ }+ val currentService = current != null && current.homeService && !current.homeServiceOff+ val text = when {+ action == Action.HomeBack && current != null -> Copy.explainLeave(app.label, off = !app.enabled, current.label, currentService, service = false)+ current != null && !current.system -> Copy.explainLeave(app.label, off = false, current.label, currentService, app.homeService)+ replaced != null && app.homeInstead != null -> Copy.explainReplace(app.label, replaced, app.homeInstead, app.homeService)+ else -> Copy.explainFirstHome(app.label, app.packageName, app.homeService)+ }+ AlertDialog(+ onDismissRequest = actions.cancel,+ title = { Text(Copy.makeHomeTitle(app.label)) },+ text = { Text(text) },+ confirmButton = { Button(onClick = if (asks) ({ askService = true }) else actions.confirm, enabled = !locked) { Text(Copy.MAKE_HOME) } },+ dismissButton = { TextButton(onClick = actions.cancel) { Text("Cancel") } },+ )+}++private object HubIcons {+ // Absolute commands only: Compose's path parser misplaces a relative move after a close.+ private const val RING = "M12 2A10 10 0 1 0 12 22A10 10 0 1 0 12 2ZM12 4A8 8 0 1 1 12 20A8 8 0 1 1 12 4Z"+ val InfoOutline = icon("InfoOutline", RING + "M11 11H13V17H11ZM11 7H13V9H11Z")+ val CheckCircleOutline = icon("CheckCircleOutline", RING + "M16.59 7.58L10 14.17L6.41 10.59L5 12L10 17L18 9Z")++ private fun icon(name: String, path: String) = ImageVector.Builder(name, 24.dp, 24.dp, 24f, 24f)+ .addPath(PathParser().parsePathString(path).toNodes(), pathFillType = PathFillType.EvenOdd, fill = SolidColor(Color.Black))+ .build()+}diff --git a/app/src/main/java/app/tellyscope/ui/TweaksBlock.kt b/app/src/main/java/app/tellyscope/ui/TweaksBlock.ktindex 0a71313..be4c7a0 100644--- a/app/src/main/java/app/tellyscope/ui/TweaksBlock.kt+++ b/app/src/main/java/app/tellyscope/ui/TweaksBlock.kt@@ -57,7 +57,6 @@ fun TweaksBlock(ui: DeviceUi, actions: DeviceActions) {}ButtonRow(Copy.CACHES_TITLE, Copy.CACHES_TEXT, Copy.CACHES_BUTTON, enabled = ui.busy == null, actions.clearCaches)ButtonRow(Copy.SCREENSHOT_TITLE, Copy.SCREENSHOT_TEXT, Copy.SCREENSHOT_BUTTON, enabled = ui.busy == null, actions.screenshot)- if (hasPlayStore(ui.apps)) ButtonRow(Copy.ANOTHER_HOME, Copy.ANOTHER_HOME_TEXT, Copy.CHOOSE_ONE, enabled = ui.busy == null, actions.installLauncher)if (askDns) DnsDialog(onDismiss = { askDns = false }) { host -> askDns = false; actions.setDns(host) }}diff --git a/app/src/test/java/app/tellyscope/BusyGatingTest.kt b/app/src/test/java/app/tellyscope/BusyGatingTest.ktindex b7e91f0..f39d7a2 100644--- a/app/src/test/java/app/tellyscope/BusyGatingTest.kt+++ b/app/src/test/java/app/tellyscope/BusyGatingTest.kt@@ -92,22 +92,4 @@ class BusyGatingTest {compose.setContent { DebloatScreen(lists, {}, {}, {}) }compose.onNodeWithText("Disable 1 app").assertIsEnabled()}-- @Test fun launcherSwitchWithItsTargetGoneIsCancelled() {- // "Set as default launcher" was asked, then the launcher was turned off in Debloat.- var cancels = 0- val off = app.copy(enabled = false, homeInstead = "com.stock.home")- compose.setContent { AppRow(off, emptyList(), pkg to Action.Home, busy = false, actions = DeviceActions(cancel = { cancels++ }), homeLabel = "Stock") }- compose.waitForIdle()- assertEquals(1, cancels)- compose.onNodeWithText(Copy.confirm(Action.Home)).assertDoesNotExist()- }-- @Test fun switchBackWithItsTargetGoneIsCancelled() {- var cancels = 0- val off = app.copy(enabled = false, homeBack = "Stock")- compose.setContent { AppRow(off, emptyList(), pkg to Action.HomeBack, busy = false, actions = DeviceActions(cancel = { cancels++ })) }- compose.waitForIdle()- assertEquals(1, cancels)- }}diff --git a/app/src/test/java/app/tellyscope/HomeBackTest.kt b/app/src/test/java/app/tellyscope/HomeBackTest.ktindex 168e884..5c0ea7c 100644--- a/app/src/test/java/app/tellyscope/HomeBackTest.kt+++ b/app/src/test/java/app/tellyscope/HomeBackTest.kt@@ -5,6 +5,7 @@ package app.tellyscopeimport app.tellyscope.data.Actionimport app.tellyscope.data.HistoryEntryimport app.tellyscope.data.HomeBackTarget+import app.tellyscope.data.builtInTargetimport app.tellyscope.data.homeBackTargetimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertNull@@ -39,4 +40,15 @@ class HomeBackTest {assertNull(homeBackTarget(added, emptyList(), emptyList()))assertNull(homeBackTarget(added, emptyList(), listOf(added)))}++ @Test fun theCardGoesBackToTheBuiltInItNames() {+ // Stock → Projectivy → FLauncher: Make Home on the stock launcher reverses the switch that turned it off.+ val history = listOf(+ switch(1, "$stock/.MainActivity", "$added/.Home"),+ switch(2, "$added/.Home", "me.efesser.flauncher/.Main"),+ )+ assertEquals(HomeBackTarget(stock, "$stock/.MainActivity", 1), builtInTarget(stock, history))+ // Turned off on the TV itself, or by a switch since undone: nothing to reverse.+ assertEquals(HomeBackTarget(stock, null, null), builtInTarget(stock, listOf(switch(3, "$stock/.MainActivity", "$added/.Home", undoneAt = 4))))+ }}diff --git a/app/src/test/java/app/tellyscope/HomeServiceTest.kt b/app/src/test/java/app/tellyscope/HomeServiceTest.ktindex 2a33256..29b1804 100644--- a/app/src/test/java/app/tellyscope/HomeServiceTest.kt+++ b/app/src/test/java/app/tellyscope/HomeServiceTest.kt@@ -2,6 +2,11 @@package app.tellyscope+import androidx.compose.foundation.layout.Column+import androidx.compose.ui.test.SemanticsNodeInteraction+import androidx.compose.ui.test.hasAnyAncestor+import androidx.compose.ui.test.hasText+import androidx.compose.ui.test.isDialogimport androidx.compose.ui.test.junit4.v2.createComposeRuleimport androidx.compose.ui.test.onNodeWithTextimport androidx.compose.ui.test.performClick@@ -10,10 +15,14 @@ import app.tellyscope.data.AppInfoimport app.tellyscope.ui.AppRowimport app.tellyscope.ui.Copyimport app.tellyscope.ui.DeviceActions+import app.tellyscope.ui.DeviceUi+import app.tellyscope.ui.HomeScreenBlockimport app.tellyscope.ui.ServiceOffCardimport app.tellyscope.ui.UninstallDialog+import app.tellyscope.ui.homeMoveimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertFalse+import org.junit.Assert.assertNullimport org.junit.Assert.assertTrueimport org.junit.Ruleimport org.junit.Test@@ -21,21 +30,43 @@ import org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config-/** A launcher's accessibility service is its own yes, never a side effect of the switch. */+/**+ * The Home screen card: every launcher, Make Home with a confirm, and a launcher's accessibility+ * service as its own yes, never a side effect of the switch.+ */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35])class HomeServiceTest {@get:Rule val compose = createComposeRule()private val pkg = "com.spocky.projengmenu"- private val projectivy = AppInfo(pkg, "Projectivy Launcher", null, false, true, null, "1.0", homeInstead = "com.google.android.tvlauncher", homeService = true)+ private val stockPkg = "com.google.android.tvlauncher"+ private val stock = AppInfo(+ stockPkg, "Google TV Home", null, true, true, "this is your home screen", "1.0",+ home = true, answersHome = true, builtInLauncher = true,+ )+ private val projectivy = AppInfo(+ pkg, "Projectivy Launcher", null, false, true, null, "1.0",+ removable = true, answersHome = true, homeInstead = stockPkg, homeService = true,+ )+ private val flauncher = AppInfo("me.efesser.flauncher", "FLauncher", null, false, true, null, "1.0", removable = true, answersHome = true)++ /** Projectivy on Home, the stock launcher turned off by the switch to it. */+ private val onHome = projectivy.copy(+ homeInstead = null, home = true, homeBack = "Google TV Home", protectedReason = "this is your home screen",+ )+ private val stockOff = stock.copy(enabled = false, home = false, answersHome = false, protectedReason = null)++ private fun card(vararg apps: AppInfo, pending: Pair<String, Action>? = null, actions: DeviceActions = DeviceActions()) =+ compose.setContent { Column { HomeScreenBlock(DeviceUi(apps = apps.toList(), pending = pending), actions) } }++ private fun inDialog(text: String): SemanticsNodeInteraction = compose.onNode(hasText(text) and hasAnyAncestor(isDialog()))@Test fun theSwitchAsksAboutTheServiceSeparately() {val answers = mutableListOf<Boolean>()- compose.setContent {- AppRow(projectivy, emptyList(), pkg to Action.Home, busy = false, actions = DeviceActions(confirmHome = { answers += it }), homeLabel = "Google TV Home")- }- compose.onNodeWithText(Copy.confirm(Action.Home)).performClick()+ card(stock, projectivy, pending = pkg to Action.Home, actions = DeviceActions(confirmHome = { answers += it }))+ inDialog(Copy.makeHomeTitle("Projectivy Launcher")).assertExists()+ inDialog(Copy.MAKE_HOME).performClick()compose.onNodeWithText(Copy.serviceTitle("Projectivy Launcher")).assertExists()compose.onNodeWithText(Copy.SWITCH_WITHOUT).performClick()assertEquals(listOf(false), answers)@@ -43,85 +74,153 @@ class HomeServiceTest {@Test fun turnItOnSwitchesWithTheService() {val answers = mutableListOf<Boolean>()- compose.setContent {- AppRow(projectivy, emptyList(), pkg to Action.Home, busy = false, actions = DeviceActions(confirmHome = { answers += it }), homeLabel = "Google TV Home")- }- compose.onNodeWithText(Copy.confirm(Action.Home)).performClick()+ card(stock, projectivy, pending = pkg to Action.Home, actions = DeviceActions(confirmHome = { answers += it }))+ inDialog(Copy.MAKE_HOME).performClick()compose.onNodeWithText(Copy.TURN_IT_ON).performClick()assertEquals(listOf(true), answers)}@Test fun aLauncherWithoutAServiceSwitchesStraightAway() {var confirmed = false- compose.setContent {- AppRow(projectivy.copy(homeService = false), emptyList(), pkg to Action.Home, busy = false, actions = DeviceActions(confirm = { confirmed = true }), homeLabel = "Google TV Home")- }- compose.onNodeWithText(Copy.confirm(Action.Home)).performClick()+ card(stock, projectivy.copy(homeService = false), pending = pkg to Action.Home, actions = DeviceActions(confirm = { confirmed = true }))+ inDialog(Copy.explainReplace("Projectivy Launcher", "Google TV Home", stockPkg, service = false)).assertExists()+ inDialog(Copy.MAKE_HOME).performClick()compose.onNodeWithText(Copy.serviceTitle("Projectivy Launcher")).assertDoesNotExist()assertTrue(confirmed)}- @Test fun withNoDefaultHomeTheUsersLauncherOffersSetAsDefaultAndAPlainUninstall() {- var proposed: Pair<String, Action>? = null- compose.setContent {- AppRow(projectivy.copy(removable = true), emptyList(), null, busy = false, actions = DeviceActions(propose = { p, a -> proposed = p to a }), homeLabel = "Google TV Home")- }- compose.onNodeWithText("Projectivy Launcher").performClick()- compose.onNodeWithText(Copy.MAKE_HOME).assertExists()+ @Test fun theStockHomeIsCurrentAndAnAddedLauncherOffersMakeHomeAndUninstall() {+ val proposed = mutableListOf<Pair<String, Action>>()+ card(stock, projectivy, actions = DeviceActions(propose = { p, a -> proposed += p to a }))+ compose.onNodeWithText(Copy.opensOnHome("Google TV Home")).assertExists()+ compose.onNodeWithText(Copy.CURRENT).assertExists()+ compose.onNodeWithText(Copy.KEEPS_HOME).assertExists()+ compose.onNodeWithText(Copy.MAKE_HOME).performClick()compose.onNodeWithText(Copy.button(Action.Uninstall)).performClick()- assertEquals(pkg to Action.Uninstall, proposed)+ assertEquals(listOf(pkg to Action.Home, pkg to Action.Uninstall), proposed)+ // A launcher was added, so the card no longer offers to get one.+ compose.onNodeWithText(Copy.GET_LAUNCHER_TEXT).assertDoesNotExist()+ }++ @Test fun withNothingAddedTheCardOffersAnotherLauncher() {+ var installs = 0+ val store = AppInfo("com.android.vending", "Google Play Store", null, true, true, null, "1.0")+ card(stock, store, actions = DeviceActions(installLauncher = { installs++ }))+ compose.onNodeWithText(Copy.GET_LAUNCHER_TEXT).assertExists()+ compose.onNode(hasText(Copy.GET_LAUNCHER) and androidx.compose.ui.test.hasClickAction()).performClick()+ assertEquals(1, installs)}@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()+ val first = projectivy.copy(homeInstead = null, homeFirst = true, homeService = false)+ card(first, pending = pkg to Action.Home, actions = DeviceActions(confirm = { confirmed = true }))+ compose.onNodeWithText(Copy.NO_DEFAULT).assertExists()+ inDialog(Copy.explainFirstHome("Projectivy Launcher", pkg)).assertExists()+ inDialog(Copy.MAKE_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 withNoDefaultTheTvsOwnCanBeMadeTheDefault() {+ // Android asks which home to use: the stock launcher is on, but nothing is the default.+ val asking = stock.copy(home = false)+ assertEquals(Action.Home, homeMove(asking, current = null))+ assertEquals(Action.Home, homeMove(projectivy, current = null))+ }- @Test fun theLauncherOnHomeOffersUninstallAndItsConfirmListsTheSteps() {- var proposed: Pair<String, Action>? = null- compose.setContent { AppRow(onHome.copy(removable = true), emptyList(), null, busy = false, actions = DeviceActions(propose = { p, a -> proposed = p to a })) }- compose.onNodeWithText("Projectivy Launcher").performClick()- compose.onNodeWithText(Copy.button(Action.Uninstall)).performClick()- assertEquals(pkg to Action.Uninstall, proposed)+ @Test fun fromAnAddedLauncherTheTvsOwnGoesBackAndTurnsBackOn() {+ val proposed = mutableListOf<Pair<String, Action>>()+ card(onHome, stockOff, actions = DeviceActions(propose = { p, a -> proposed += p to a }))+ compose.onNodeWithText(Copy.builtIn(off = true)).assertExists()+ compose.onNodeWithText(Copy.MAKE_HOME).performClick()+ assertEquals(listOf(stockPkg to Action.HomeBack), proposed)}- @Test fun theHomeUninstallConfirmSaysWhatHappensFirst() {- compose.setContent { UninstallDialog(onHome.copy(removable = true), onUninstall = {}, onDismiss = {}) }- compose.onNodeWithText(Copy.uninstallHome("Projectivy Launcher", "Google TV Home", service = true)).assertExists()- assertTrue("Turns off Projectivy Launcher's accessibility service" in Copy.uninstallHome("Projectivy Launcher", "Google TV Home", service = true))- assertFalse("accessibility" in Copy.uninstallHome("FLauncher", "Google TV Home", service = false))+ @Test fun makingTheTvsOwnHomeSaysTheAddedOnesServiceGoesOff() {+ var confirmed = false+ card(onHome, stockOff, pending = stockPkg to Action.HomeBack, actions = DeviceActions(confirm = { confirmed = true }))+ val text = Copy.explainLeave("Google TV Home", off = true, "Projectivy Launcher", currentService = true, service = false)+ inDialog(text).assertExists()+ assertTrue("turns off Projectivy Launcher's accessibility service" in text)+ assertTrue("turns Google TV Home back on" in text)+ inDialog(Copy.MAKE_HOME).performClick()+ assertTrue(confirmed)}- @Test fun aLauncherOnHomeTheTvCameWithOffersNoUninstall() {- compose.setContent { AppRow(onHome, emptyList(), null, busy = false, actions = DeviceActions()) }- compose.onNodeWithText("Projectivy Launcher").performClick()- compose.onNodeWithText(Copy.button(Action.Uninstall)).assertDoesNotExist()+ @Test fun betweenAddedLaunchersNeitherIsTurnedOff() {+ val f = flauncher.copy(homeInstead = pkg)+ assertEquals(Action.Home, homeMove(f, onHome))+ card(onHome, f, stockOff, pending = f.packageName to Action.Home)+ val text = Copy.explainLeave("FLauncher", off = false, "Projectivy Launcher", currentService = true, service = false)+ inDialog(text).assertExists()+ assertTrue("Projectivy Launcher stays installed and on" in text)+ assertFalse("turns off FLauncher" in text)+ }++ @Test fun aSwitchWhoseTargetChangedIsCancelled() {+ // Make Home was asked, then the launcher was turned off in Debloat.+ var cancels = 0+ card(stock, projectivy.copy(enabled = false), pending = pkg to Action.Home, actions = DeviceActions(cancel = { cancels++ }))+ compose.waitForIdle()+ assertEquals(1, cancels)+ inDialog(Copy.MAKE_HOME).assertDoesNotExist()}- @Test fun theRowSaysTheServiceIsOffAndOffersTurnOn() {+ @Test fun theHomeRowSaysTheServiceIsOffAndOffersTurnOn() {var on: String? = null- compose.setContent { AppRow(onHome, emptyList(), null, busy = false, actions = DeviceActions(homeServiceOn = { on = it })) }+ card(onHome.copy(homeServiceOff = true), stockOff, actions = DeviceActions(homeServiceOn = { on = it }))compose.onNodeWithText(Copy.SERVICE_OFF).assertExists()- compose.onNodeWithText("Projectivy Launcher").performClick()compose.onNodeWithText(Copy.TURN_ON).performClick()// Not now leaves it off; Turn it on asks the TV.compose.onNodeWithText(Copy.NOT_NOW).performClick()- assertEquals(null, on)+ assertNull(on)compose.onNodeWithText(Copy.TURN_ON).performClick()compose.onNodeWithText(Copy.TURN_IT_ON).performClick()assertEquals(pkg, on)}+ @Test fun uninstallOnTheHomeOneListsTheSteps() {+ card(onHome, stockOff, pending = pkg to Action.Uninstall)+ inDialog(Copy.uninstallHome("Projectivy Launcher", "Google TV Home", service = true)).assertExists()+ }++ @Test fun theHomeUninstallConfirmSaysWhatHappensFirst() {+ compose.setContent { UninstallDialog(onHome, onUninstall = {}, onDismiss = {}) }+ compose.onNodeWithText(Copy.uninstallHome("Projectivy Launcher", "Google TV Home", service = true)).assertExists()+ assertTrue("Turns off Projectivy Launcher's accessibility service" in Copy.uninstallHome("Projectivy Launcher", "Google TV Home", service = true))+ assertFalse("accessibility" in Copy.uninstallHome("FLauncher", "Google TV Home", service = false))+ }++ @Test fun anAppsRowForALauncherLinksToTheCardInsteadOfSwitching() {+ var opened = 0+ compose.setContent { AppRow(projectivy, emptyList(), null, busy = false, actions = DeviceActions(), toHomeScreen = { opened++ }) }+ compose.onNodeWithText("Projectivy Launcher").performClick()+ compose.onNodeWithText(Copy.MAKE_HOME).assertDoesNotExist()+ compose.onNodeWithText(Copy.HOME_SETTINGS).performClick()+ assertEquals(1, opened)+ }++ @Test fun theLauncherOnHomeKeepsUninstallInApps() {+ var proposed: Pair<String, Action>? = null+ compose.setContent { AppRow(onHome, emptyList(), null, busy = false, actions = DeviceActions(propose = { p, a -> proposed = p to a })) }+ compose.onNodeWithText("Projectivy Launcher").performClick()+ compose.onNodeWithText(Copy.HOME_SETTINGS).assertExists()+ compose.onNodeWithText(Copy.button(Action.Uninstall)).performClick()+ assertEquals(pkg to Action.Uninstall, proposed)+ }++ @Test fun aLauncherOnHomeTheTvCameWithOffersNoUninstall() {+ compose.setContent { AppRow(stock, emptyList(), null, busy = false, actions = DeviceActions()) }+ compose.onNodeWithText("Google TV Home").performClick()+ compose.onNodeWithText(Copy.HOME_SETTINGS).assertExists()+ compose.onNodeWithText(Copy.button(Action.Uninstall)).assertDoesNotExist()+ }+@Test fun theCardsGotItAndTurnOn() {var dismissed = falsevar on = false- compose.setContent { ServiceOffCard(onHome, onTurnOn = { on = true }, onDismiss = { dismissed = true }) }+ val off = onHome.copy(homeServiceOff = true, homeServiceNote = true)+ compose.setContent { ServiceOffCard(off, onTurnOn = { on = true }, onDismiss = { dismissed = true }) }compose.onNodeWithText(Copy.serviceOffTitle("Google TV Home")).assertExists()compose.onNodeWithText(Copy.TURN_ON).performClick()assertFalse(on)diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.ktindex b3f8014..538905f 100644--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt@@ -23,7 +23,6 @@ import androidx.compose.ui.test.onAllNodesWithTextimport androidx.activity.OnBackPressedDispatcherimport androidx.activity.compose.LocalOnBackPressedDispatcherOwnerimport androidx.compose.ui.test.onFirst-import androidx.compose.ui.test.assertCountEqualsimport androidx.compose.ui.test.onRootimport androidx.compose.ui.test.performClickimport androidx.compose.ui.test.performScrollToNode@@ -1386,55 +1385,75 @@ class ScreenshotTest {compose.onNodeWithText("wallpaper-mountains.jpg").assertExists()}+ // The Tweaks tab opens on the Home screen card: Google TV's own launcher is Home, nothing added yet.@Test fun readme_tweaks() {val tweaks = TvTweaks(dnsHost = TvSettings.ADGUARD, animationScale = null)- shot("29_readme_tweaks") { DeviceTabsScreen(deviceState { copy(tweaks = tweaks) }, DeviceActions(), startTab = TvTab.Tweaks) }- compose.onNodeWithText(Copy.dnsState(TvSettings.ADGUARD)).assertExists()+ shot("29_readme_tweaks") { DeviceTabsScreen(deviceState { copy(tweaks = tweaks, apps = listOf(stockHome, playStore) + apps) }, DeviceActions(), startTab = TvTab.Tweaks) }+ compose.onNodeWithText(Copy.GET_LAUNCHER_TEXT).assertExists()}- // The list scrolls to the confirm, as a user would.+ private val stockHome = AppInfo(+ "com.google.android.tvlauncher", "Google TV Home", 0xFF1A73E8, true, true, "this is your home screen", "1.0.4",+ home = true, answersHome = true, builtInLauncher = true,+ )+ private val playStore = AppInfo("com.android.vending", "Google Play Store", 0xFF01875F, true, true, null, "40.1")+ private val flauncher = AppInfo("me.efesser.flauncher", "FLauncher", 0xFF3F6FD8, false, true, null, "0.18", removable = true, answersHome = true)++ /** Projectivy, installed by the user, as a launcher: [home] it's on Home, the stock launcher off; else it offers to replace it. */+ private fun projectivy(a: AppInfo, home: Boolean) = a.copy(+ protectedReason = "this is your home screen".takeIf { home }, system = false, removable = true, answersHome = true, homeService = true,+ home = home, homeInstead = stockHome.packageName.takeUnless { home }, homeBack = stockHome.label.takeIf { home },+ )++ private fun homeState(home: Boolean, pending: Pair<String, Action>? = null) = deviceState {+ val stock = if (home) stockHome.copy(enabled = false, home = false, answersHome = false, protectedReason = null) else stockHome+ val f = flauncher.copy(homeInstead = if (home) "com.spocky.projengmenu" else stock.packageName)+ copy(apps = listOf(stock, f) + apps.map { if (it.packageName == "com.spocky.projengmenu") projectivy(it, home) else it }, pending = pending)+ }++ // Make Home on Projectivy: the confirm says the TV's own launcher is the only one turned off.@Test fun readme_home() {- // Google TV's own launcher is Home; Projectivy, installed by the user, offers to replace it.- val stock = AppInfo("com.google.android.tvlauncher", "Google TV Home", 0xFF1A73E8, true, true, "this is your home screen", "1.0.4")- val state = deviceState {- val projectivy = { a: AppInfo -> a.copy(protectedReason = null, system = false, removable = true, homeInstead = stock.packageName) }- copy(apps = listOf(stock) + apps.map { if (it.packageName == "com.spocky.projengmenu") projectivy(it) else it }, pending = "com.spocky.projengmenu" to Action.Home)- }- shot("30_readme_home", before = { compose.onNode(hasScrollAction()).performScrollToNode(hasText("Yes, switch home screen")); Unit }) { DeviceTabsScreen(state, DeviceActions(), startTab = TvTab.Apps) }- compose.onNodeWithText("Yes, switch home screen").assertExists()+ shot("30_readme_home", screen = true) { DeviceTabsScreen(homeState(home = false, pending = "com.spocky.projengmenu" to Action.Home), DeviceActions(), startTab = TvTab.Tweaks) }+ compose.onNodeWithText(Copy.makeHomeTitle("Projectivy Launcher")).assertExists()}- // Projectivy is Home now, made so on the TV itself; its row offers the way back to Google TV Home, which is off.- private fun homeBackState(confirming: Boolean = false) = deviceState {- val stock = AppInfo("com.google.android.tvlauncher", "Google TV Home", 0xFF1A73E8, true, false, null, "1.0.4")- val projectivy = { a: AppInfo -> a.copy(protectedReason = "this is your home screen", system = false, removable = true, homeBack = stock.label) }- copy(- apps = listOf(stock) + apps.map { if (it.packageName == "com.spocky.projengmenu") projectivy(it) else it },- pending = ("com.spocky.projengmenu" to Action.HomeBack).takeIf { confirming },- )+ private fun homeCard(dark: Boolean) {+ shot("78_tweaks_home_card", dark) { DeviceTabsScreen(homeState(home = true), DeviceActions(), startTab = TvTab.Tweaks) }+ compose.onNodeWithText(Copy.builtIn(off = true)).assertExists()+ }+ @Test fun tweaks_homeCard() = homeCard(false)+ @Test fun tweaks_homeCard_dark() = homeCard(true)++ // No default: Android would ask which home screen to use, so the card says to pick one.+ @Test fun tweaks_homeCardNoDefault() {+ val state = homeState(home = false).let { s -> s.copy(device = s.device.copy(apps = s.device.apps.map { if (it.packageName == stockHome.packageName) it.copy(home = false) else it })) }+ shot("78_tweaks_home_card_no_default") { DeviceTabsScreen(state, DeviceActions(), startTab = TvTab.Tweaks) }+ compose.onNodeWithText(Copy.NO_DEFAULT).assertExists()}++ // Back to Google TV Home from Projectivy: turned back on, and Projectivy's service goes off with Home.private fun homeBack(dark: Boolean) {- val back = { compose.onNode(hasScrollAction()).performScrollToNode(hasText(Copy.confirm(Action.HomeBack))); Unit }- shot("78_apps_home_back", dark, before = back) { DeviceTabsScreen(homeBackState(confirming = true), DeviceActions(), startTab = TvTab.Apps) }- compose.onNodeWithText(Copy.explainHomeBack("Projectivy Launcher", "Google TV Home", service = false)).assertExists()+ shot("78_tweaks_home_back", dark, screen = true) {+ DeviceTabsScreen(homeState(home = true, pending = stockHome.packageName to Action.HomeBack), DeviceActions(), startTab = TvTab.Tweaks)+ }+ compose.onNodeWithText(Copy.explainLeave("Google TV Home", off = true, "Projectivy Launcher", currentService = true, service = false)).assertExists()}- @Test fun apps_homeBack() = homeBack(false)- @Test fun apps_homeBack_dark() = homeBack(true)+ @Test fun tweaks_homeBack() = homeBack(false)+ @Test fun tweaks_homeBack_dark() = homeBack(true)- @Test fun apps_homeBackIsOfferedOnTheAddedLauncher() {- val proposed = mutableListOf<Pair<String, Action>>()+ // On Apps, a launcher's row links to the card rather than switching itself.+ @Test fun apps_launcherRowLinksToTheCard() {compose.mainClock.autoAdvance = false- compose.setContent { TellyscopeTheme(dynamic = false) { DeviceTabsScreen(homeBackState(), DeviceActions(propose = { pkg, a -> proposed += pkg to a }), startTab = TvTab.Apps) } }+ compose.setContent { TellyscopeTheme(dynamic = false) { DeviceTabsScreen(homeState(home = true), DeviceActions(), startTab = TvTab.Apps) } }compose.mainClock.advanceTimeBy(1_000)compose.onNode(hasScrollAction()).performScrollToNode(hasText("Projectivy Launcher"))compose.onNodeWithText("Projectivy Launcher").performClick()compose.mainClock.advanceTimeBy(1_000)- compose.onNode(hasScrollAction()).performScrollToNode(hasText(Copy.homeBack("Google TV Home")))- compose.onNodeWithText(Copy.homeBack("Google TV Home")).performClick()+ compose.onNode(hasScrollAction()).performScrollToNode(hasText(Copy.HOME_SETTINGS))+ compose.onNodeWithText(Copy.HOME_SETTINGS).performClick()compose.mainClock.advanceTimeBy(1_000)- assertEquals(listOf("com.spocky.projengmenu" to Action.HomeBack), proposed)- // Still the home screen, so nothing that would turn it off.- compose.onAllNodesWithText("Disable").assertCountEquals(0)+ // The Tweaks tab, on the card.+ compose.onNodeWithText(Copy.opensOnHome("Projectivy Launcher")).assertExists()}// A keep from the TV's list only warns; a hard lock still offers nothing.