Skip to content

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.

Disable first only when the old launcher outranks the new one

jesse-agent-2326da6d6610b1a
diff --git a/README.md b/README.md
index d7ce70f..c2424f4 100644
--- a/README.md
+++ b/README.md
@@ -85,7 +85,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. Under **Suggested for this TV**, one line says how many of the list's apps 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 and disables the old launcher, so the TV can't switch back by itself. Home is checked to open the new launcher before the old one goes off; Android TV Home outranks other launchers until it's off, so there Tellyscope checks again just after. If Home still doesn't open the new launcher, the old one is turned back on and made Home. 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. 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. 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 230+ 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)).
- **History.** Every change is listed with an Undo, and **Restore everything** turns back on what Tellyscope turned off. Undoing a **Turn on** asks first, since it disables the app again. History is kept per TV, across restarts.
- **Install apps.** Pick an APK, several split APKs or an `.apks`/`.xapk`/`.apkm` bundle on your phone. Before installing, Tellyscope shows the app's name, version and size and says whether it's new, an update, a reinstall or an older version. It won't install an older version over a newer one unless you tick the box. If the TV refuses, you get the reason in plain words.
@@ -108,7 +108,7 @@ Debloating a TV can break it if done carelessly. Tellyscope is built around thes
1. **Disable what came with the TV, never uninstall it.** Tellyscope uses `pm disable-user`, which is reversible from the app or with `pm enable`. Uninstall is offered only for apps `pm list packages -3` lists as installed by the user, and runs plain `pm uninstall` after a confirm that says it can't be undone. Tellyscope never runs `pm uninstall --user 0`, the form that removes a TV's own apps.
2. **Record before changing.** Before the first change on a TV, Tellyscope notes which apps were already off, so **Restore everything** turns back on only what Tellyscope turned off. Every change goes into the TV's history with an Undo. The history lives on the phone and is deleted if you uninstall Tellyscope; a disabled app still shows in the Apps list with **Turn on**.
-3. **Protected list.** Packages the TV needs to boot, install its updates, stay on Wi-Fi, show web pages, show the home screen or accept input are on a protected list. Tellyscope refuses to stop or disable them, and there is no override in the app. A TV's list can add keeps: those only warn in the confirm, and can be overridden. If the TV doesn't say which app is its home screen, Tellyscope refuses to stop or disable anything. The one exception is switching home screens: the old launcher is disabled only after another launcher is set as Home, and if Home then doesn't open the new launcher, the old one is turned back on and made Home again. The current home screen itself never can be. A TV's suggested list never protects fewer apps; its keeps add a warning, not a lock.
+3. **Protected list.** Packages the TV needs to boot, install its updates, stay on Wi-Fi, show web pages, show the home screen or accept input are on a protected list. Tellyscope refuses to stop or disable them, and there is no override in the app. A TV's list can add keeps: those only warn in the confirm, and can be overridden. If the TV doesn't say which app is its home screen, Tellyscope refuses to stop or disable anything. The one exception is switching home screens: the old launcher is disabled only after another launcher has become Home and Home has been checked to open it, and the current home screen itself never can be. 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. A TV's suggested list never protects fewer apps; its keeps add a warning, not a lock.
4. **No root, no exploits.** Only what ADB allows on a stock TV.
5. **Nothing left on the TV.** To show real app names and icons, Tellyscope copies a small helper to `/data/local/tmp`, runs it once and deletes it. The helper only reads through PackageManager: no writes, no permissions, no network.
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt b/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt
index df844ec..9b09d3f 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Actions.kt
@@ -70,20 +70,27 @@ class Actions(private val shell: AdbShell) {
/**
* Makes [pkg] the home screen in place of the current one, then disables the old launcher so
* the TV can't switch back by itself. Home is checked to open [pkg] before anything is
- * disabled. Android skips the default when one launcher has a higher Home priority than the
- * rest, and Android TV Home has one, so if that check fails the old launcher is turned off
- * and Home checked again. If Home still doesn't open [pkg], the old one goes back on and Home.
+ * disabled; if it doesn't, the old home is set back and nothing is turned off. The one
+ * exception: Android skips the default while a launcher with a higher Home priority is on, as
+ * Android TV Home is. Such an old launcher is turned off first, and turned back on and made
+ * Home again if Home still doesn't open [pkg].
*/
suspend fun makeHome(pkg: String): HomeResult {
require(PACKAGE.matches(pkg)) { "not a package name: $pkg" }
val from = currentHome() ?: return HomeResult.Refused(ProtectedReason.UNKNOWN_HOME)
val old = from.substringBefore('/')
if (old == pkg) return HomeResult.Failed("it's already the home screen")
- val to = launchers()[pkg] ?: return HomeResult.Failed("it has no home screen")
+ val homes = shell.shell(Commands.HOME_ACTIVITIES).output
+ val to = launchersIn(homes)[pkg] ?: return HomeResult.Failed("it has no home screen")
// The old launcher is protected as the home screen and by name; once it isn't Home, that
// guard has done its job. Any other reason still stands.
Protected.reason(old)?.takeIf { it != ProtectedReason.HOME_SCREEN }?.let { return HomeResult.Refused(it) }
val checked = setHome(to)
+ val priority = prioritiesIn(homes)
+ if (!checked && (priority[from] ?: 0) <= (priority[to] ?: 0)) {
+ setHome(from)
+ return HomeResult.Failed("the TV kept its own home screen, so nothing was turned off")
+ }
val off = exec("pm disable-user --user 0 $old", undo = null) { "disabled-user" in it }
if (off is ActionResult.Failed) {
setHome(from)
@@ -93,8 +100,8 @@ class Actions(private val shell: AdbShell) {
val on = exec("pm enable --user 0 $old", undo = null) { "enabled" in it }
setHome(from)
return HomeResult.Failed(
- if (on is ActionResult.Failed) "Home didn't open it, and the old home screen didn't turn back on: ${on.output}"
- else "the TV kept its own home screen, so nothing was changed",
+ if (on is ActionResult.Failed) "Home didn't open it, and the old home screen didn't turn back on: ${on.output}. Turn it back on from Apps → Built-in"
+ else "Home still didn't open it, so the old home screen was turned back on",
)
}
@@ -133,11 +140,27 @@ class Actions(private val shell: AdbShell) {
* Every enabled launcher, package to its home activity. Apps protected for another reason
* aren't launchers, though they may answer Home: TV Settings has a fallback home screen.
*/
- private suspend fun launchers(): Map<String, String> =
- activitiesIn(shell.shell(Commands.HOME_ACTIVITIES).output).filterNot { it.startsWith("android/") }
+ private suspend fun launchers(): Map<String, String> = launchersIn(shell.shell(Commands.HOME_ACTIVITIES).output)
+
+ private fun launchersIn(brief: String): Map<String, String> =
+ activitiesIn(brief).filterNot { it.startsWith("android/") }
.associateBy { it.substringBefore('/') }
.filterKeys { Protected.reason(it).let { r -> r == null || r == ProtectedReason.HOME_SCREEN } }
+ /** Each activity's Home priority, from the `priority=` line `--brief` prints above it. */
+ private fun prioritiesIn(brief: String): Map<String, Int> {
+ val priorities = mutableMapOf<String, Int>()
+ var last: Int? = null
+ for (line in brief.lineSequence().map(String::trim)) {
+ if (line.startsWith("priority=")) last = line.removePrefix("priority=").substringBefore(' ').toIntOrNull()
+ else if ('/' in line && ' ' !in line) {
+ last?.let { priorities[line] = it }
+ last = null
+ }
+ }
+ return priorities
+ }
+
private fun packagesIn(brief: String): Set<String> = activitiesIn(brief).map { it.substringBefore('/') }.toSet()
private fun activitiesIn(brief: String): List<String> =
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt
index b84ceed..23ba785 100644
--- a/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt
+++ b/adb/src/test/kotlin/app/tellyscope/adb/ActionsTest.kt
@@ -126,7 +126,11 @@ class ActionsTest {
var home = "com.google.android.tvlauncher/.MainActivity"
var oldOn = true
return FakeShell(mapOf(
- "cmd package query-activities" to ok("com.google.android.tvlauncher/.MainActivity\ncom.spocky.projengmenu/.ui.home.MainActivity\n"),
+ "cmd package query-activities" to ok(
+ if (outranks) "2 activities found:\n Activity #0:\n priority=2 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=true\n com.google.android.tvlauncher/.MainActivity\n" +
+ " Activity #1:\n priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=true\n com.spocky.projengmenu/.ui.home.MainActivity\n"
+ else "com.google.android.tvlauncher/.MainActivity\ncom.spocky.projengmenu/.ui.home.MainActivity\n",
+ ),
"pm disable-user" to ok("Package com.google.android.tvlauncher new state: disabled-user\n"),
"pm enable" to ok("Package com.google.android.tvlauncher new state: enabled\n"),
)).apply {
@@ -194,10 +198,18 @@ class ActionsTest {
assertTrue(sh.ran.none { it.startsWith("pm enable") })
}
- @Test fun homeCheckFailsOldLauncherBackOnAndHome() = runTest {
+ @Test fun homeCheckFailsNothingDisabled() = runTest {
val sh = twoLaunchers(accepts = false)
+ assertEquals(HomeResult.Failed("the TV kept its own home screen, so nothing was turned off"), Actions(sh).makeHome("com.spocky.projengmenu"))
+ assertTrue(sh.ran.none { it.startsWith("pm ") })
+ // The old home is set back, in case the TV took the new one half-way.
+ assertEquals("cmd package set-home-activity --user 0 'com.google.android.tvlauncher/.MainActivity' 2>&1", sh.ran.last { "set-home" in it })
+ }
+
+ @Test fun outrankingHomeCheckFailsOldLauncherBackOnAndHome() = runTest {
+ val sh = twoLaunchers(accepts = false, outranks = true)
val r = Actions(sh).makeHome("com.spocky.projengmenu")
- assertEquals(HomeResult.Failed("the TV kept its own home screen, so nothing was changed"), r)
+ assertEquals(HomeResult.Failed("Home still didn't open it, so the old home screen was turned back on"), r)
val off = sh.ran.indexOf("pm disable-user --user 0 com.google.android.tvlauncher 2>&1")
val on = sh.ran.indexOf("pm enable --user 0 com.google.android.tvlauncher 2>&1")
assertTrue(off >= 0 && on > off)
@@ -206,6 +218,13 @@ class ActionsTest {
assertEquals("com.google.android.tvlauncher", Actions(sh).homeOptions()?.current)
}
+ @Test fun failedTurnBackOnSaysWhereToDoIt() = runTest {
+ val sh = twoLaunchers(accepts = false, outranks = true)
+ sh.answer.let { prev -> sh.answer = { if (it.startsWith("pm enable")) ok("Error: refused\n") else prev(it) } }
+ val r = Actions(sh).makeHome("com.spocky.projengmenu") as HomeResult.Failed
+ assertTrue(r.output.endsWith("Turn it back on from Apps → Built-in"), r.output)
+ }
+
@Test fun failedDisablePutsHomeBack() = runTest {
val sh = twoLaunchers()
sh.answer.let { prev -> sh.answer = { if (it.startsWith("pm disable-user")) ok("Error: refused\n") else prev(it) } }