Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
disable: refuse lists that disable Android's core packages (#884)
Gathin2322dc48fe21b1
diff --git a/AGENTS.md b/AGENTS.mdindex 9dfcba96c..3fcd1f826 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -22,6 +22,12 @@ this file repeats their rules in the form an agent needs, and links to them for- **Leave alone what the TV needs to work:** the TV app and input services behind HDMI and the tuner,the input/source menu, remote and Bluetooth pairing, the on-screen keyboard, Play Store and PlayServices. When a package name says nothing, read `dumpsys package <name>`, then ask.+- **Never disable Android's core packages:** the permission controller, package installer, ext+ services/shared and module metadata (`com.android.*` and `com.google.android.*`),+ `com.google.android.overlay.modules*`, `com.android.providers.*` (calendar, contacts, user dictionary+ and blocked numbers aside), `com.android.systemui`, `com.android.shell`, `com.android.phone`,+ `com.android.settings`, `com.android.tv.settings`, `android`. Without them Android may not boot (#884);+ `tools/disable.sh`, `disable.ps1` and `check.py --fix` refuse such a list, with no override.- **Never start a factory or test package** (`com.cvte.tv.hkcfac`, `mediatek.factorymenu.ui` and the like),not even to look. On some boards that flips a factory-mode flag the shell cannot undo.- **Keep the Home guard.** The stock launcher is disabled only after the new launcher is installed anddiff --git a/PROMPT.md b/PROMPT.mdindex 92a079892..c95601eb5 100644--- a/PROMPT.md+++ b/PROMPT.md@@ -68,6 +68,13 @@ Debloatkeyboard, Google Play Store and Play Services. Manufacturer package names often don't say what apackage does: check its activities and services with `dumpsys package` first, and ask me if it'sstill unclear.+- Never disable Android's own core packages, or the TV may not boot again: the permission controller,+ the package installer, ext services and ext shared, module metadata (each as `com.android.*` or+ `com.google.android.*`), `com.google.android.overlay.modules*`, `com.android.providers.*` (calendar,+ contacts, user dictionary and blocked numbers aside), `com.android.systemui`, `com.android.shell`,+ `com.android.phone`, `com.android.settings`, `com.android.tv.settings` and `android`. An original Mi TV+ Stick never booted again after a list took the first six+ ([#884](https://github.com/Gathin23/cleanyourtv/issues/884)); `tools/disable.sh` refuses such a list.- Before touching streaming apps, voice assistant, Chromecast, Miracast or the update service, ask mewhich ones I use with a checklist question and disable only what I don't tick.- Run `pm` commands one per shell call, chained commands may silently stop after the first.diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex 23189a29b..09c4e033d 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -211,6 +211,18 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/test app does not count as something else: on a Xiaomi Mi TV 4A`com.duokan.factorytest/.FactoryLauncher` answers HOME, so the guard leaves it out, along with anypackage named `*factorytest*`, `*factory_test*` or `*factorymode*`.+- **The TV no longer boots after a list that disabled Android's core packages** (original Mi TV+ Stick, [#884](https://github.com/Gathin23/cleanyourtv/issues/884)). An agent's list took+ `com.google.android.permissioncontroller`, `com.google.android.packageinstaller`,+ `com.google.android.ext.services`, `com.google.android.ext.shared`,+ `com.google.android.modulemetadata` and the `com.google.android.overlay.modules.*` overlays, plus+ the stock launcher and setupwraith, and the stick never came back. Those are part of Android+ itself, not bloat. `tools/disable.sh`, `disable.ps1` and `check.py --fix` now refuse any list that+ names them (or `com.android.providers.*` other than calendar, contacts, user dictionary and+ blocked numbers, `com.android.systemui`, `com.android.shell`, `com.android.phone`,+ `com.android.settings`, `com.android.tv.settings` or `android`), with no switch to override it.+ If a set is already stuck and still answers ADB, `pm enable` each of those packages and reboot;+ if ADB is gone too, a factory reset from the recovery menu is usually the only way back.- **The TV stays on the boot logo after a list, and disabling the only Home app is enough to doit**, seen on a KitKat-era set ([COOP COTV-0001](https://github.com/Gathin23/cleanyourtv/issues/795):Realtek `rtd298x`, Android 4.4.2, SDK 19). 17 packages were disabled over Ethernet ADB, eachdiff --git a/tests/test_core_packages.py b/tests/test_core_packages.pynew file mode 100644index 000000000..4b1913837--- /dev/null+++ b/tests/test_core_packages.py@@ -0,0 +1,118 @@+"""No list may disable the core Android packages the system needs to boot (#884).++An agent applied a list to an original Mi TV Stick that disabled the permission controller, the package+installer, ext services/shared, module metadata and the mainline overlays, and the stick never booted+again. tools/disable.sh, tools/disable.ps1 and tools/check.py --fix refuse such a list before the TV is+touched, with no switch to override it, and no list in examples/ may name one of these packages.+The pattern lives in three places (bash, PowerShell, Python); this test keeps them identical.+"""+import os+from pathlib import Path+import re+import shutil+import subprocess+import sys+import tempfile+import unittest++ROOT = Path(__file__).resolve().parent.parent+sys.path.insert(0, str(ROOT / "tools"))+import recovery # noqa: E402++# The packages named in #884, plus the rest of the block.+CORE = [+ "com.google.android.permissioncontroller", "com.android.permissioncontroller",+ "com.google.android.packageinstaller", "com.android.packageinstaller",+ "com.google.android.ext.services", "com.android.ext.services",+ "com.google.android.ext.shared", "com.android.ext.shared",+ "com.google.android.modulemetadata", "com.android.modulemetadata",+ "com.google.android.overlay.modules.ext.services", "com.google.android.overlay.modules.permissioncontroller",+ "com.android.systemui", "com.android.shell", "com.android.phone",+ "com.android.settings", "com.android.tv.settings",+ "com.android.providers.settings", "com.android.providers.tv", "com.android.providers.media",+ "com.android.providers.downloads",+]+# Look alike but are fine: what tested lists disable, and names that only share a prefix.+NOT_CORE = [+ "com.android.providers.calendar", "com.android.providers.contacts",+ "com.android.providers.userdictionary", "com.android.providers.blockednumber",+ "com.android.settings.intelligence", "com.android.tv.settings.overlay", "com.android.phone.extra",+ "com.google.android.tungsten.setupwraith", "com.google.android.apps.tv.launcherx",+ "com.android.shell2", "com.example.android.ext.services",+]+++def script_pattern(path, regex):+ match = re.search(regex, path.read_text(encoding="utf-8"), re.M)+ if not match:+ raise AssertionError(f"no core-package pattern found in {path}")+ return match.group(1)+++class CorePackagesTest(unittest.TestCase):+ def test_the_three_copies_of_the_pattern_agree(self):+ sh_re = script_pattern(ROOT / "tools" / "disable.sh", r"^CORE_RE='([^']+)'$")+ sh_ok = script_pattern(ROOT / "tools" / "disable.sh", r"^CORE_OK='([^']+)'$")+ ps_re = script_pattern(ROOT / "tools" / "disable.ps1", r"^\$coreRe = '([^']+)'$")+ ps_ok = script_pattern(ROOT / "tools" / "disable.ps1", r"^\$coreOk = '([^']+)'$")+ self.assertEqual(sh_re, recovery.CORE_RE.pattern)+ self.assertEqual(ps_re, recovery.CORE_RE.pattern)+ self.assertEqual(sh_ok, recovery.CORE_OK.pattern)+ self.assertEqual(ps_ok, recovery.CORE_OK.pattern)++ def test_core_packages_are_blocked(self):+ self.assertEqual(CORE, recovery.core_packages(CORE))++ def test_look_alikes_are_not(self):+ self.assertEqual([], recovery.core_packages(NOT_CORE))++ def test_no_list_in_examples_disables_a_core_package(self):+ found = []+ for path in sorted((ROOT / "examples").glob("*/debloat*.txt")):+ for name in recovery.core_packages(recovery.read_list(path)):+ found.append(f"{path.relative_to(ROOT)}: {name}")+ self.assertEqual([], found, "core Android packages must stay enabled (#884)")++ def test_disable_sh_refuses_before_touching_the_tv(self):+ with tempfile.TemporaryDirectory() as tmp:+ repo = Path(tmp) / "repo"+ tools = repo / "tools"+ tools.mkdir(parents=True)+ shutil.copy2(ROOT / "tools" / "disable.sh", tools / "disable.sh")+ touched = Path(tmp) / "touched"+ # Any call to the TV leaves a mark; the refusal has to come first.+ (tools / "tv.py").write_text(f"open({str(touched)!r}, 'a').write('x')\n")+ python = tools / "venv" / "bin" / "python"+ python.parent.mkdir(parents=True)+ python.write_text(f'#!/bin/sh\nexec "{sys.executable}" "$@"\n')+ python.chmod(0o755)+ listing = Path(tmp) / "debloat.txt"+ listing.write_text("com.example.ads\ncom.google.android.permissioncontroller # no\n"+ "com.google.android.overlay.modules.ext.services\n")+ env = dict(os.environ, TV_HOST="192.168.1.50", FORCE_HOME="1", FORCE_SETUPWRAITH="1",+ TVINPUT_ALLOW="1")+ result = subprocess.run(["bash", str(tools / "disable.sh"), str(listing)], cwd=repo, env=env,+ capture_output=True, text=True, stdin=subprocess.DEVNULL, timeout=60)+ self.assertEqual(1, result.returncode, result.stdout + result.stderr)+ self.assertIn("#884", result.stderr)+ self.assertIn("com.google.android.permissioncontroller", result.stderr)+ self.assertIn("com.google.android.overlay.modules.ext.services", result.stderr)+ self.assertNotIn("com.example.ads", result.stderr)+ self.assertFalse(touched.exists(), "the TV was contacted before the refusal")++ def test_check_py_refuses_before_connecting(self):+ with tempfile.TemporaryDirectory() as tmp:+ listing = Path(tmp) / "debloat.txt"+ listing.write_text("com.example.ads\ncom.android.packageinstaller\n")+ # A host nothing answers on: reaching connect() would print "could not reach the TV".+ env = dict(os.environ, TV_HOST="192.0.2.1")+ result = subprocess.run([sys.executable, "-I", str(ROOT / "tools" / "check.py"), "--fix",+ str(listing)], env=env, capture_output=True, text=True,+ stdin=subprocess.DEVNULL, timeout=60)+ self.assertEqual(2, result.returncode, result.stdout + result.stderr)+ self.assertIn("#884", result.stderr)+ self.assertNotIn("could not reach", result.stderr)+++if __name__ == "__main__":+ unittest.main()diff --git a/tools/check.py b/tools/check.pyindex b63e131e1..970387879 100644--- a/tools/check.py+++ b/tools/check.py@@ -247,6 +247,13 @@ def main():# read_list validates every name before anything is sent to the TV: its entries end up in the# TV's shell, and a list edited by hand since then is not to be trusted.listed = recovery.read_list(list_path)+ core = recovery.core_packages(listed)+ if core:+ # The same refusal as disable.sh: --fix would disable these again (#884).+ sys.stderr.write(f"refusing {list_path}: it disables core Android packages, and without them "+ f"the TV may not boot again (#884): {', '.join(core)}. Take these lines out "+ f"of the list and run it again. Nothing was checked or changed.\n")+ return 2try:dev = recovery.connect()diff --git a/tools/disable.ps1 b/tools/disable.ps1index 796890736..2ca24a716 100644--- a/tools/disable.ps1+++ b/tools/disable.ps1@@ -23,6 +23,15 @@ $bad = @($pkgs | Where-Object { $_ -notmatch '^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0if ($bad.Count -gt 0) {throw "refusing $List, not a package name: $($bad -join ', ')"}+# Core Android packages, the same block as disable.sh: with one of these disabled Android itself can stop+# booting (#884, an original Mi TV Stick). No switch overrides it. Keep both patterns in step with+# disable.sh and recovery.py (tests/test_core_packages.py).+$coreRe = '^(android|com\.android\.systemui|com\.android\.shell|com\.android\.phone|com\.android\.settings|com\.android\.tv\.settings|com\.(google\.)?android\.(permissioncontroller|packageinstaller|ext\.services|ext\.shared|modulemetadata)|com\.google\.android\.overlay\.modules.*|com\.android\.providers\..*)$'+$coreOk = '^com\.android\.providers\.(calendar|contacts|userdictionary|blockednumber)$'+$core = @($pkgs | Where-Object { $_ -cmatch $coreRe -and $_ -cnotmatch $coreOk })+if ($core.Count -gt 0) {+ throw "refusing ${List}: it disables core Android packages, and without them the TV may not boot again (#884): $($core -join ', '). Take these lines out of the list (or comment them) and run it again. Nothing was changed on the TV."+}# A Wi-Fi network saved during the first-run wizard belongs to setupwraith, and Android deletes it when# setupwraith is disabled. Skip it while it owns the saved network; `$env:FORCE_SETUPWRAITH=1` overrides.$setup = 'com.google.android.tungsten.setupwraith'diff --git a/tools/disable.sh b/tools/disable.shindex 7a978817a..d06076ca3 100755--- a/tools/disable.sh+++ b/tools/disable.sh@@ -26,6 +26,20 @@ if [ -n "$BAD" ]; then{ echo "refusing $LIST: not a package name:"; printf '%s\n' "$BAD" | sed 's/^/ /'; } >&2exit 1fi+# Core Android packages: with one of these disabled, Android itself can stop booting. An original Mi TV+# Stick never came back after a list took the permission controller, package installer, ext services,+# module metadata and the mainline overlays (#884). No switch overrides this. The content providers+# below CORE_OK are the exception: tested lists turn them off and no TV feature uses them.+# Keep CORE_RE and CORE_OK the same in disable.ps1 and recovery.py (tests/test_core_packages.py).+CORE_RE='^(android|com\.android\.systemui|com\.android\.shell|com\.android\.phone|com\.android\.settings|com\.android\.tv\.settings|com\.(google\.)?android\.(permissioncontroller|packageinstaller|ext\.services|ext\.shared|modulemetadata)|com\.google\.android\.overlay\.modules.*|com\.android\.providers\..*)$'+CORE_OK='^com\.android\.providers\.(calendar|contacts|userdictionary|blockednumber)$'+CORE=$(printf '%s\n' "$PKGS" | grep -E "$CORE_RE" | grep -vE "$CORE_OK" || true)+if [ -n "$CORE" ]; then+ { echo "refusing $LIST: it disables core Android packages, and without them the TV may not boot again (#884):"+ printf '%s\n' "$CORE" | sed 's/^/ /'+ echo "Take these lines out of the list (or comment them) and run it again. Nothing was changed on the TV."; } >&2+ exit 1+fi# A Wi-Fi network saved during the first-run wizard belongs to setupwraith, and Android deletes it the# moment setupwraith is disabled: the TV drops off Wi-Fi, and ADB and the phone remote go with it.# Skip it until the network has been forgotten and re-joined in Settings (it then belongs todiff --git a/tools/recovery.py b/tools/recovery.pyindex 2500157f3..11d4eb8eb 100644--- a/tools/recovery.py+++ b/tools/recovery.py@@ -32,6 +32,18 @@ SETTINGS = ("window_animation_scale", "transition_animation_scale", "animator_du# would leave the stock launcher off, so restore goes back to the stock one instead.CUSTOM_LAUNCHER = "com.gathin.tvhome"VERSION = 1+# Core Android packages no list may disable: with one of these off, Android itself can stop booting+# (#884: an original Mi TV Stick that lost its permission controller, package installer, ext services,+# module metadata and mainline overlays never came back). The content providers in CORE_OK are the+# exception, since tested lists turn them off and no TV feature uses them. disable.sh and disable.ps1+# carry the same two patterns (tests/test_core_packages.py keeps the three in step).+CORE_RE = re.compile(r"^(android|com\.android\.systemui|com\.android\.shell|com\.android\.phone|com\.android\.settings|com\.android\.tv\.settings|com\.(google\.)?android\.(permissioncontroller|packageinstaller|ext\.services|ext\.shared|modulemetadata)|com\.google\.android\.overlay\.modules.*|com\.android\.providers\..*)$")+CORE_OK = re.compile(r"^com\.android\.providers\.(calendar|contacts|userdictionary|blockednumber)$")+++def core_packages(names):+ """The names in a list that must never be disabled, in list order."""+ return [n for n in names if CORE_RE.match(n) and not CORE_OK.match(n)]def read_list(path):