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
fix: resolve debloat list paths before changing directories
alfibia4933f3b342e
diff --git a/.gitignore b/.gitignoreindex b2a165599..a2a8c877d 100644--- a/.gitignore+++ b/.gitignore@@ -1,6 +1,6 @@tools/venv/tools/adbkey/-tools/__pycache__/+__pycache__/launcher/.gradle/launcher/build/launcher/app/build/diff --git a/README.md b/README.mdindex d49efe57e..70d346ec5 100644--- a/README.md+++ b/README.md@@ -147,6 +147,9 @@ tools/theme.sh themes/aurora # push a theme; --r| [`tools/theme.sh`](tools/theme.sh) | Push a folder from [`themes/`](themes/) to the launcher and restart Home. || [`launcher/build-and-install.sh`](launcher/build-and-install.sh) | Builds a shrunk release (about 250 KB), installs it, switches Home, and rolls back if Home does not land on it. |+Debloat list paths passed to `disable.sh` and `restore.sh` are relative to the directory you run+from, so your own lists can live outside the repository. Absolute paths also work.+Every script has a PowerShell twin next to it. On Windows with Android Studio installed nothingelse is needed:diff --git a/tests/test_debloat_paths.py b/tests/test_debloat_paths.pynew file mode 100644index 000000000..acb1a8280--- /dev/null+++ b/tests/test_debloat_paths.py@@ -0,0 +1,68 @@+"""Exercise the shell helpers without connecting to a TV.++Run from the repository root: python3 -m unittest discover -s tests -v+"""+import os+from pathlib import Path+import shutil+import subprocess+import tempfile+import unittest+++ROOT = Path(__file__).resolve().parents[1]+++class DebloatPathsTest(unittest.TestCase):+ def test_list_paths(self):+ for script in ("disable.sh", "restore.sh"):+ for path_kind in ("caller-relative", "absolute", "repo-relative"):+ with self.subTest(script=script, path_kind=path_kind):+ self.check_list_path(script, path_kind)++ def check_list_path(self, script, path_kind):+ with tempfile.TemporaryDirectory() as tmp:+ base = Path(tmp)+ repo = base / "repo checkout"+ tools = repo / "tools"+ tools.mkdir(parents=True)+ shutil.copy2(ROOT / "tools" / script, tools / script)+ client = tools / "venv" / "bin" / "python"+ client.parent.mkdir(parents=True)+ client.write_text('#!/bin/sh\ncat > "$CAPTURE"\n')+ client.chmod(0o755)++ caller = base / "caller folder"+ caller.mkdir()+ cwd = repo if path_kind == "repo-relative" else caller+ relative = Path("my TV lists") / "debloat.txt"+ package_list = cwd / relative+ package_list.parent.mkdir()+ package_list.write_text("# My TV\ncom.example.keep_order_one # note\n\ncom.example.keep_order_two\n")+ if cwd != repo:+ # An incorrect resolution must not silently operate on this other list.+ decoy = repo / relative+ decoy.parent.mkdir()+ decoy.write_text("com.example.wrong_tv\n")+ argument = str(package_list) if path_kind == "absolute" else str(relative)+ capture = base / "commands.txt"+ env = dict(os.environ, CAPTURE=str(capture))+ result = subprocess.run(+ ["bash", str(tools / script), argument], cwd=cwd, env=env,+ capture_output=True, text=True,+ )+ self.assertEqual(result.returncode, 0, result.stderr)+ commands = capture.read_text().splitlines()+ operation = "pm disable-user --user 0" if script == "disable.sh" else "pm enable"+ self.assertEqual(commands[:2], [+ f"{operation} com.example.keep_order_one",+ f"{operation} com.example.keep_order_two",+ ])+ self.assertNotIn("wrong_tv", "\n".join(commands))+ self.assertEqual(commands[-1], "pm list packages -d")+ if script == "restore.sh":+ self.assertIn("pm enable com.google.android.tvlauncher", commands)+++if __name__ == "__main__":+ unittest.main()diff --git a/tools/disable.sh b/tools/disable.shindex e5aefc02a..cf6b22e20 100755--- a/tools/disable.sh+++ b/tools/disable.sh@@ -4,8 +4,11 @@## Usage: TV_HOST=192.168.1.50 tools/disable.sh examples/xiaomi-mi-tv-4a/debloat.txtset -euo pipefail-cd "$(dirname "$0")/.."LIST="${1:?usage: disable.sh <debloat list>}"+# Resolve the list against the caller's directory before moving into the repo.+LIST_DIR="$(cd "$(dirname "$LIST")" && pwd)"+LIST="$LIST_DIR/$(basename "$LIST")"+cd "$(dirname "$0")/.."PY=tools/venv/bin/python[ -x "$PY" ] || PY=tools/venv/Scripts/python.exeexport MSYS_NO_PATHCONV=1diff --git a/tools/restore.sh b/tools/restore.shindex 7c086d9ef..eb32e1b04 100755--- a/tools/restore.sh+++ b/tools/restore.sh@@ -4,8 +4,11 @@## Usage: TV_HOST=192.168.1.50 tools/restore.sh examples/xiaomi-mi-tv-4a/debloat.txt [stock.launcher.package]set -euo pipefail-cd "$(dirname "$0")/.."LIST="${1:?usage: restore.sh <debloat list> [stock launcher package]}"+# Resolve the list against the caller's directory before moving into the repo.+LIST_DIR="$(cd "$(dirname "$LIST")" && pwd)"+LIST="$LIST_DIR/$(basename "$LIST")"+cd "$(dirname "$0")/.."STOCK="${2:-com.google.android.tvlauncher}"PY=tools/venv/bin/python[ -x "$PY" ] || PY=tools/venv/Scripts/python.exe