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.
Ask separately before turning on a launcher's accessibility service
jesse-agent-2322ebe96138685
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 46b4bd7..fffb23c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,7 @@ until this file has a section for its version.## Unreleased+- **Improved:** Setting a launcher as default asks separately before turning on its accessibility service, and the TV's page offers to turn it on later.- **Fixed:** A TV that removes this phone's access logs you out instead of re-asking. [#149](../../pull/149)- **New:** A connection left open after Remove offers Check again and Restart the TV. [#148](../../pull/148)diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 05774c2..3597fc8 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -30,7 +30,7 @@ You don't have to trust ours. Fork tellyscope-devices, edit the lists in your fo## Launchers-[`app/src/main/assets/launchers.json`](app/src/main/assets/launchers.json) lists the third-party launchers Tellyscope knows. Set `"accessibility": true` only for a launcher that keeps Home with its own accessibility service: Set as default turns that service on, and an accessibility service can read the screen. Check the APK's manifest for a service with `BIND_ACCESSIBILITY_SERVICE`, and put the version you checked in `"checked"`. The list ships with the app and is never fetched, so a custom list source can't add to it.+[`app/src/main/assets/launchers.json`](app/src/main/assets/launchers.json) lists the third-party launchers Tellyscope knows. Set `"accessibility": true` only for a launcher that keeps Home with its own accessibility service: Set as default offers to turn that service on, and an accessibility service can read the screen. Check the APK's manifest for a service with `BIND_ACCESSIBILITY_SERVICE`, and put the version you checked in `"checked"`. The list ships with the app and is never fetched, so a custom list source can't add to it.## README screenshotsdiff --git a/NOTICE b/NOTICEindex 180069b..656495c 100644--- a/NOTICE+++ b/NOTICE@@ -36,7 +36,8 @@ of "shield", "gpp_good", "gpp_maybe", "lock_reset", "smartphone", "lan","laptop", "desktop_windows" and "help_outline"; the Connected devices cardthose of "bluetooth", "headphones", "keyboard", "mouse", "sports_esports","usb", "speaker" and "settings_input_hdmi". The logged-out page and the-logged-out badge on a TV's chip use that of "logout".+logged-out badge on a TV's chip use that of "logout"; the dialog that asks+about a launcher's accessibility service that of "accessibility_new".--------------------------------------------------------------------------------Store badges in docs/badges/ (README only, not in the app)diff --git a/README.md b/README.mdindex ba7fc5d..685dac3 100644--- a/README.md+++ b/README.md@@ -80,7 +80,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.** 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 also turns that service on, after the confirm says so, for TVs whose Home button opens their own launcher whatever the default is. Undo and Switch home back turn it off again, and any other accessibility services stay as they were. 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.** 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. 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/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.ktindex f7c252c..f444ece 100644--- a/app/src/main/java/app/tellyscope/MainActivity.kt+++ b/app/src/main/java/app/tellyscope/MainActivity.kt@@ -336,7 +336,10 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {query = vm::query,propose = vm::propose,confirm = vm::confirm,+ confirmHome = vm::confirmHome,cancel = vm::cancel,+ homeServiceOn = vm::homeServiceOn,+ dismissServiceNote = vm::dismissServiceNote,undo = vm::undo,reconnect = { state.selectedId?.let(vm::reconnect) },forget = vm::forget,diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex d8eabd5..86e9723 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -371,6 +371,12 @@ class AdbDeviceSource(context: Context) : DeviceSource {// On a launcher the user added, offer the way back to the one it replaced.val back = homeOptions?.current?.takeIf { it !in system }?.let { homeBackTarget(it, book.entries(key(deviceId)), builtIns(system, disabled, homeOptions)) }+ // 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+ // The card stays until Got it, which notes it on the switch; the next switch shows it again.+ val note = serviceOff && back?.reverses?.let { id -> book.entries(key(deviceId)).firstOrNull { it.id == id } }+ ?.let { it.previous?.get("note") != "dismissed" } == truereturn listed.map { p ->val name = names.getValue(p.name)labels[p.name] = name.label@@ -395,6 +401,8 @@ class AdbDeviceSource(context: Context) : DeviceSource {homeInstead = homeOptions?.takeIf { p.name in it.others }?.current,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,+ homeServiceNote = note && p.name == homeOptions?.current,listKeep = p.name in keep,launchable = p.name in launchable,tvHome = p.name in tvHome,@@ -440,13 +448,39 @@ class AdbDeviceSource(context: Context) : DeviceSource {override suspend fun act(deviceId: String, action: Action, packageName: String, undoing: Long?): HistoryEntry =busy(deviceId) { actNow(deviceId, action, packageName, undoing) }- private suspend fun actNow(deviceId: String, action: Action, packageName: String, undoing: Long?): HistoryEntry {+ override suspend fun makeHome(deviceId: String, packageName: String, service: Boolean): HistoryEntry =+ busy(deviceId) { actNow(deviceId, Action.Home, packageName, null, service) }++ override suspend fun homeServiceOn(deviceId: String, packageName: String): Unit = busy(deviceId) {+ val actions = Actions(session(deviceId))+ val label = labels[packageName] ?: AppNames.fallback(packageName)+ val service = packageName.takeIf { it in serviceLaunchers }?.let { actions.homeService(it) }+ ?: throw IllegalStateException("$label has no accessibility service")+ if (!actions.setService(service, true)) throw IllegalStateException(serviceNotOn(label))+ // Undo of the switch to it turns it off again, as if the switch had turned it on.+ openSwitch(deviceId, packageName)?.let { book.amend(it, mapOf("service" to service)) }+ Unit+ }++ override suspend fun dismissServiceNote(deviceId: String, packageName: String) {+ openSwitch(deviceId, packageName)?.let { book.amend(it, mapOf("note" to "dismissed")) }+ }++ /** The newest switch to [pkg] that nothing has undone: the change a later step belongs to. */+ private suspend fun openSwitch(deviceId: String, pkg: String): Long? = book.entries(key(deviceId))+ .firstOrNull { it.action == Action.Home && it.undoneAt == null && it.previous?.get("to")?.substringBefore('/') == pkg }?.id++ private suspend fun actNow(deviceId: String, action: Action, packageName: String, undoing: Long?, service: Boolean = true): HistoryEntry {val shell = session(deviceId)// Before the first change on a TV, note what was already off: Restore must leave those alone.val key = key(deviceId)if (!book.hasBaseline(key)) book.setBaseline(key, disabledPackages(deviceId))// The list's keep entries only warn, in the confirm; Actions.run holds the hard locks.- if (action == Action.Home) return makeHome(deviceId, packageName, undoing)+ if (action == Action.Home) {+ // Undoing a switch back turns the service on again only if that switch turned it off.+ val again = undoing?.let { id -> book.entries(key).firstOrNull { it.id == id } }?.let { it.previous?.get("service") != null }+ return switchHome(deviceId, packageName, undoing, again ?: service)+ }if (action == Action.HomeBack) return homeBack(deviceId, packageName, undoing)val r = Actions(shell).run(AdbAction.valueOf(action.name.uppercase()), packageName)return when (r) {@@ -472,13 +506,14 @@ class AdbDeviceSource(context: Context) : DeviceSource {}}- private suspend fun makeHome(deviceId: String, packageName: String, undoing: Long?): HistoryEntry {+ /** [withService] false leaves the new launcher's accessibility service as it is: the user said no. */+ private suspend fun switchHome(deviceId: String, packageName: String, undoing: Long?, withService: Boolean): HistoryEntry {val key = key(deviceId)val actions = Actions(session(deviceId))return when (val r = actions.makeHome(packageName)) {is HomeResult.Switched -> {// Where the TV sends Home to its own launcher, the new one holds it with this service.- val service = packageName.takeIf { it in serviceLaunchers }?.let { actions.homeService(it) }?.takeUnless { actions.serviceOn(it) }+ val service = packageName.takeIf { withService && it in serviceLaunchers }?.let { actions.homeService(it) }?.takeUnless { actions.serviceOn(it) }val on = service?.let { actions.setService(it, true) }val label = labels[packageName] ?: AppNames.fallback(packageName)book.record(@@ -525,7 +560,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),+ previous = mapOf("from" to r.from, "to" to r.to) + listOfNotNull(service?.takeIf { off == true }?.let { "service" to it }),).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/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.ktindex df86787..dc5d2d3 100644--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt@@ -73,6 +73,15 @@ interface DeviceSource {*/suspend fun act(deviceId: String, action: Action, packageName: String, undoing: Long? = null): HistoryEntry+ /** [Action.Home], leaving the launcher's accessibility service off when [service] is false. */+ suspend fun makeHome(deviceId: String, packageName: String, service: Boolean): HistoryEntry = act(deviceId, Action.Home, packageName)++ /** Turns on the accessibility service of [packageName], the launcher on Home; Undo of the switch turns it off again. */+ suspend fun homeServiceOn(deviceId: String, packageName: String) {}++ /** Puts away the TV page's card about [packageName]'s service being off, until the next switch. */+ suspend fun dismissServiceNote(deviceId: String, packageName: String) {}+/** Everything Tellyscope changed on this TV, newest first. Survives app restarts. */suspend fun history(deviceId: String): List<HistoryEntry>diff --git a/app/src/main/java/app/tellyscope/data/HistoryBook.kt b/app/src/main/java/app/tellyscope/data/HistoryBook.ktindex be983d8..fa6eb64 100644--- a/app/src/main/java/app/tellyscope/data/HistoryBook.kt+++ b/app/src/main/java/app/tellyscope/data/HistoryBook.kt@@ -60,6 +60,14 @@ class HistoryBook(private val file: File? = null) {return entry}+ /** Adds [extra] to entry [id]'s saved state, for a later step of the same change. */+ @Synchronized+ fun amend(id: Long, extra: Map<String, String?>) {+ val i = entries.indexOfFirst { it.id == id }.takeIf { it >= 0 } ?: return+ entries[i] = entries[i].copy(previous = entries[i].previous.orEmpty() + extra)+ save()+ }+/*** Apps Tellyscope left disabled on this TV: the last disable/enable it ran was a disable, and* the app wasn't already off before Tellyscope's first change. Restore turns on only these.diff --git a/app/src/main/java/app/tellyscope/data/Model.kt b/app/src/main/java/app/tellyscope/data/Model.ktindex c0ce4b8..ffe874f 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 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,+ /** The launcher on Home, with its accessibility service off: Home may still open the TV's own. The row offers Turn on. */+ val homeServiceOff: Boolean = false,+ /** [homeServiceOff], and the TV page's card about it hasn't been put away with Got it since the switch. */+ val homeServiceNote: Boolean = false,/** This TV's list says to keep it: Stop, Disable and Uninstall still run, after a warning. */val listKeep: Boolean = false,/** Has an icon on a launcher, so the Remote's dock can open it. */diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.ktindex 87009d9..a33a1f4 100644--- a/app/src/main/java/app/tellyscope/ui/Copy.kt+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt@@ -99,13 +99,32 @@ object Copy {fun explainHome(app: String, pkg: String, current: String, currentPkg: String, service: Boolean = false) = buildString {append("Makes $app ($pkg) open when you press Home, then disables $current ($currentPkg) so the TV can't switch back by itself. ")append("Undo in History turns $current back on and makes it Home again.")- if (service) {- append("\n\nIt also turns on $app's accessibility service, so the Home button opens $app on TVs that would open their own launcher. ")- append("An accessibility service can see what's on screen. Undo and Switch home back turn it off.")- }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.")}+ /** 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?"++ 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."++ const val TURN_IT_ON = "Turn it on"+ const val SWITCH_WITHOUT = "Switch without it"+ const val NOT_NOW = "Not now"+ const val TURN_ON = "Turn on"+ const val GOT_IT = "Got it"+ const val SERVICE_OFF = "Accessibility service off"++ /** The TV page's card while the launcher on Home has its service off; [other] is the launcher Home may still open. */+ fun serviceOffTitle(other: String?) = "Home may open ${other ?: TV_OWN_LAUNCHER}"++ const val TV_OWN_LAUNCHER = "the TV's own launcher"++ fun serviceOffText(app: String) = "$app's accessibility service is off, so the TV can take Home back."+private val GOOGLE_HOMES = setOf("com.google.android.tvlauncher", "com.google.android.apps.tv.launcherx")/**diff --git a/app/src/main/java/app/tellyscope/ui/DeviceIcons.kt b/app/src/main/java/app/tellyscope/ui/DeviceIcons.ktindex 0132924..43b9428 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceIcons.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceIcons.kt@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-3.0-only-// Tv, Stick, WifiOff and Logout are the Material Icons "tv", "settings_input_hdmi", "wifi_off" and "logout" (Apache-2.0), see NOTICE.+// Tv, Stick, WifiOff, Logout and Accessibility are the Material Icons "tv", "settings_input_hdmi", "wifi_off", "logout" and+// "accessibility_new" (Apache-2.0), see NOTICE.package app.tellyscope.ui@@ -41,12 +42,16 @@ object DeviceIcons {private const val LOGOUT ="M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z"+ private const val ACCESSIBILITY =+ "M20.5 6c-2.61.7-5.67 1-8.5 1s-5.89-.3-8.5-1L3 8c1.86.5 4 .83 6 1v13h2v-6h2v6h2V9c2-.17 4.14-.5 6-1l-.5-2zM12 6c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z"+val Tv = icon("Tv", TV)val FireTv = icon("FireTv", FIRE_TV)val Stick = icon("Stick", STICK)val Projector = icon("Projector", PROJECTOR)val WifiOff = icon("WifiOff", WIFI_OFF)val Logout = icon("Logout", LOGOUT)+ val Accessibility = icon("Accessibility", ACCESSIBILITY)fun of(kind: DeviceKind) = when (kind) {DeviceKind.Tv -> Tvdiff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.ktindex 5ae6e0e..7d4d4af 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt@@ -73,7 +73,13 @@ data class DeviceActions(val query: (String) -> Unit = {},val propose: (String, Action) -> Unit = { _, _ -> },val confirm: () -> Unit = {},+ /** The confirmed switch to a launcher with an accessibility service, with the service or without it. */+ val confirmHome: (service: Boolean) -> Unit = {},val cancel: () -> Unit = {},+ /** Turns on the accessibility service of the launcher on Home, after a switch left it off. */+ val homeServiceOn: (String) -> Unit = {},+ /** Got it on the TV page's card about that service being off. */+ val dismissServiceNote: (String) -> Unit = {},val undo: (HistoryEntry) -> Unit = {},val reconnect: () -> Unit = {},val forget: (String) -> Unit = {},@@ -409,6 +415,7 @@ internal fun AppRow(style = MaterialTheme.typography.bodySmall,color = MaterialTheme.colorScheme.onSurfaceVariant,)+ if (app.homeServiceOff) Text(Copy.SERVICE_OFF, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)}if (busy) androidx.compose.material3.LoadingIndicator(Modifier.size(32.dp))}@@ -417,6 +424,23 @@ internal fun AppRow(val orphaned = (asked == Action.Home && home == null) || (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) {+ ServiceDialog(+ app.label, homeLabel!!,+ 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 },+ )+ }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.@@ -429,6 +453,7 @@ internal fun AppRow(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 (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)) }} else if (proposed == Action.Uninstall) {UninstallDialog(app, onUninstall = actions.confirm, onDismiss = actions.cancel, enabled = !locked)@@ -436,14 +461,15 @@ internal fun AppRow(Text(when {proposed == Action.Home && home != null -> Copy.explainHome(app.label, app.packageName, homeLabel!!, home, app.homeService)- proposed == Action.HomeBack && back != null -> Copy.explainHomeBack(app.label, back, 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)},style = MaterialTheme.typography.bodyMedium,)Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- Button(onClick = actions.confirm, enabled = !locked) { Text(Copy.confirm(proposed)) }+ val asks = proposed == Action.Home && home != null && app.homeService+ Button(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/DeviceTabs.kt b/app/src/main/java/app/tellyscope/ui/DeviceTabs.ktindex e848e30..8fbb1e6 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt@@ -266,6 +266,10 @@ fun DeviceTabsScreen(} else if (offline) {item { OfflineCard(device, state.now, actions.reconnect) }}+ // A switch that left the launcher's service off: Home may go back to the TV's own.+ ui.apps.firstOrNull { it.homeServiceNote }?.takeIf { !offline }?.let { a ->+ item(key = "serviceOff") { ServiceOffCard(a, onTurnOn = { actions.homeServiceOn(a.packageName) }, onDismiss = { actions.dismissServiceNote(a.packageName) }) }+ }// Another computer connected needs acting on now, so it sits with the cards above the stats.ui.access?.takeIf { it.warning && !offline }?.let { a -> item(key = "accessWarning") { AccessWarning(a, actions.access, onWho = actions.whoHasAccess) } }// Away, storage is the last one seen, this session's or the saved one after a restart.diff --git a/app/src/main/java/app/tellyscope/ui/HomeServiceUi.kt b/app/src/main/java/app/tellyscope/ui/HomeServiceUi.ktnew file mode 100644index 0000000..3548e4d--- /dev/null+++ b/app/src/main/java/app/tellyscope/ui/HomeServiceUi.kt@@ -0,0 +1,96 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+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.foundation.shape.CircleShape+import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.filled.Home+import androidx.compose.material3.AlertDialog+import androidx.compose.material3.Card+import androidx.compose.material3.CardDefaults+import androidx.compose.material3.FilledTonalButton+import androidx.compose.material3.Icon+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Text+import androidx.compose.material3.TextButton+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+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.platform.testTag+import androidx.compose.ui.unit.dp+import app.tellyscope.data.AppInfo++/**+ * The separate yes for a launcher's accessibility service, which can see the screen, so it is+ * never turned on as a side effect of a switch. [other] is the launcher Home may open without it;+ * [dismissLabel] is "Switch without it" during a switch, "Not now" after one.+ */+@Composable+fun ServiceDialog(app: String, other: String, onTurnOn: () -> Unit, dismissLabel: String, onOther: () -> Unit, onDismiss: () -> Unit) {+ AlertDialog(+ onDismissRequest = onDismiss,+ icon = { Icon(DeviceIcons.Accessibility, contentDescription = null) },+ title = { Text(Copy.serviceTitle(app)) },+ text = { Text(Copy.explainService(app, other)) },+ confirmButton = { TextButton(onClick = onTurnOn) { Text(Copy.TURN_IT_ON) } },+ dismissButton = { TextButton(onClick = onOther) { Text(dismissLabel) } },+ )+}++/**+ * On the TV page after a switch left [app]'s service off: Home may still open the TV's own+ * launcher. Got it puts it away until the next switch; Turn on asks the same separate yes.+ */+@Composable+fun ServiceOffCard(app: AppInfo, onTurnOn: () -> Unit, onDismiss: () -> Unit) {+ val c = MaterialTheme.colorScheme+ var asking by rememberSaveable { mutableStateOf(false) }+ if (asking) {+ ServiceDialog(+ app.label, app.homeBack ?: Copy.TV_OWN_LAUNCHER,+ onTurnOn = { asking = false; onTurnOn() },+ dismissLabel = Copy.NOT_NOW, onOther = { asking = false }, onDismiss = { asking = false },+ )+ }+ Card(+ colors = CardDefaults.cardColors(containerColor = c.surfaceContainer),+ shape = MaterialTheme.shapes.large,+ modifier = Modifier.fillMaxWidth().testTag("serviceOff"),+ ) {+ Column(Modifier.padding(start = 16.dp, end = 16.dp, top = 16.dp, bottom = 12.dp)) {+ Row {+ Box(Modifier.size(40.dp).background(c.tertiaryContainer, CircleShape), contentAlignment = Alignment.Center) {+ Icon(Icons.Default.Home, contentDescription = null, tint = c.onTertiaryContainer, modifier = Modifier.size(24.dp))+ }+ Spacer(Modifier.width(16.dp))+ Column(Modifier.weight(1f)) {+ Text(Copy.serviceOffTitle(app.homeBack), style = MaterialTheme.typography.titleMedium)+ Text(+ Copy.serviceOffText(app.label),+ style = MaterialTheme.typography.bodyMedium,+ color = c.onSurfaceVariant,+ modifier = Modifier.padding(top = 4.dp),+ )+ }+ }+ Row(Modifier.fillMaxWidth().padding(top = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End)) {+ TextButton(onClick = onDismiss) { Text(Copy.GOT_IT) }+ FilledTonalButton(onClick = { asking = true }) { Text(Copy.TURN_ON) }+ }+ }+ }+}diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.ktindex 415ee3b..504d708 100644--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt@@ -560,6 +560,47 @@ class TellyscopeViewModel(run(pkg, action)}+ /** A pending switch to a launcher with an accessibility service, answered in the dialog that asks about it. */+ fun confirmHome(service: Boolean) {+ val (pkg, action) = _state.value.device.pending?.takeIf { it.second == Action.Home } ?: return+ run(pkg, action) { id -> source.makeHome(id, pkg, service) }+ }++ /** Turns on the accessibility service of [pkg], the launcher on Home, after a switch left it off. */+ fun homeServiceOn(pkg: String) {+ val id = _state.value.selectedId ?: return+ updateDevice(id) { it.copy(busy = pkg) }+ viewModelScope.launch {+ val apps = try {+ source.homeServiceOn(id, pkg)+ source.apps(id)+ } catch (e: CancellationException) {+ throw e+ } catch (e: Exception) {+ updateDevice(id) { it.copy(busy = null) }+ _notice.value = e.message?.replaceFirstChar(Char::uppercase) ?: "That didn't work."+ return@launch+ }+ val history = source.history(id)+ updateDevice(id) { it.copy(apps = apps, busy = null, history = history) }+ }+ }++ /** Got it on the TV page's card about [pkg]'s service being off: it stays away until the next switch. */+ fun dismissServiceNote(pkg: String) {+ val id = _state.value.selectedId ?: return+ updateDevice(id) { d -> d.copy(apps = d.apps.map { if (it.packageName == pkg) it.copy(homeServiceNote = false) else it }) }+ viewModelScope.launch {+ try {+ source.dismissServiceNote(id, pkg)+ } catch (e: CancellationException) {+ throw e+ } catch (_: Exception) {+ // Only the card's memory: at worst it shows again next time.+ }+ }+ }+/*** Undoes [entry] on the TV it happened on. The snackbar passes [deviceId] because the user may* have switched TVs since; History only lists the selected TV's entries.@@ -653,13 +694,19 @@ class TellyscopeViewModel(private fun updateDevice(id: String, f: (DeviceUi) -> DeviceUi) =_state.update { s -> if (s.selectedId == id) s.copy(device = f(s.device)) else s }- private fun run(pkg: String, action: Action, undoing: Long? = null, id: String? = _state.value.selectedId) {+ private fun run(+ pkg: String,+ action: Action,+ undoing: Long? = null,+ id: String? = _state.value.selectedId,+ act: suspend (String) -> HistoryEntry = { source.act(it, action, pkg, undoing) },+ ) {if (id == null) returnupdateDevice(id) { it.copy(pending = null, busy = pkg) }viewModelScope.launch {// The source throws with the user-facing reason when the TV refuses.val (entry, apps) = try {- source.act(id, action, pkg, undoing) to source.apps(id)+ act(id) to source.apps(id)} catch (e: CancellationException) {throw e} catch (e: Exception) {diff --git a/app/src/test/java/app/tellyscope/HistoryBookTest.kt b/app/src/test/java/app/tellyscope/HistoryBookTest.ktindex eb06013..5199bc1 100644--- a/app/src/test/java/app/tellyscope/HistoryBookTest.kt+++ b/app/src/test/java/app/tellyscope/HistoryBookTest.kt@@ -29,6 +29,17 @@ class HistoryBookTest {assertEquals(listOf(change), HistoryBook(file).entries(tv))}+ @Test fun aLaterStepOfASwitchIsKeptOnItsEntry() {+ val file = tmp.root.resolve("history.tsv")+ val switch = HistoryBook(file).record(tv, 1_000, Action.Home, "com.google.android.tvlauncher", "Projectivy", Action.Enable,+ previous = mapOf("from" to "com.google.android.tvlauncher/.Main", "to" to "com.spocky.projengmenu/.Home"))+ HistoryBook(file).apply { amend(switch.id, mapOf("service" to "com.spocky.projengmenu/.Service")); amend(switch.id, mapOf("note" to "dismissed")) }+ val previous = HistoryBook(file).entries(tv).single().previous+ assertEquals("com.spocky.projengmenu/.Service", previous?.get("service"))+ assertEquals("dismissed", previous?.get("note"))+ assertEquals("com.google.android.tvlauncher/.Main", previous?.get("from"))+ }+@Test fun historyAndUndoSurviveARestart() {val file = tmp.root.resolve("history.tsv")val before = HistoryBook(file)diff --git a/app/src/test/java/app/tellyscope/HomeServiceTest.kt b/app/src/test/java/app/tellyscope/HomeServiceTest.ktnew file mode 100644index 0000000..09490ac--- /dev/null+++ b/app/src/test/java/app/tellyscope/HomeServiceTest.kt@@ -0,0 +1,91 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope++import androidx.compose.ui.test.junit4.v2.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import app.tellyscope.data.Action+import app.tellyscope.data.AppInfo+import app.tellyscope.ui.AppRow+import app.tellyscope.ui.Copy+import app.tellyscope.ui.DeviceActions+import app.tellyscope.ui.ServiceOffCard+import org.junit.Assert.assertEquals+import org.junit.Assert.assertFalse+import org.junit.Assert.assertTrue+import org.junit.Rule+import org.junit.Test+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config++/** A launcher's accessibility service is 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)++ @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()+ compose.onNodeWithText(Copy.serviceTitle("Projectivy Launcher")).assertExists()+ compose.onNodeWithText(Copy.SWITCH_WITHOUT).performClick()+ assertEquals(listOf(false), answers)+ }++ @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()+ 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()+ compose.onNodeWithText(Copy.serviceTitle("Projectivy Launcher")).assertDoesNotExist()+ 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 theRowSaysTheServiceIsOffAndOffersTurnOn() {+ var on: String? = null+ compose.setContent { AppRow(onHome, emptyList(), null, busy = false, 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)+ compose.onNodeWithText(Copy.TURN_ON).performClick()+ compose.onNodeWithText(Copy.TURN_IT_ON).performClick()+ assertEquals(pkg, on)+ }++ @Test fun theCardsGotItAndTurnOn() {+ var dismissed = false+ var on = false+ compose.setContent { ServiceOffCard(onHome, onTurnOn = { on = true }, onDismiss = { dismissed = true }) }+ compose.onNodeWithText(Copy.serviceOffTitle("Google TV Home")).assertExists()+ compose.onNodeWithText(Copy.TURN_ON).performClick()+ assertFalse(on)+ compose.onNodeWithText(Copy.TURN_IT_ON).performClick()+ assertTrue(on)+ compose.onNodeWithText(Copy.GOT_IT).performClick()+ assertTrue(dismissed)+ }+}