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
tools: drop a UTF-8 BOM and CRLF from lists before parsing
xbshengc73e32f3e707
diff --git a/tests/test_debloat_paths.py b/tests/test_debloat_paths.pyindex d67b4c990..c466adcb5 100644--- a/tests/test_debloat_paths.py+++ b/tests/test_debloat_paths.py@@ -26,6 +26,45 @@ class DebloatPathsTest(unittest.TestCase):with self.subTest(script=script):self.check_injected_line(script)+ def test_windows_bom_and_crlf_are_normalised(self):+ # Notepad saves a BOM and CRLF; the list must still yield clean package names (#208).+ for script in ("disable.sh", "restore.sh"):+ with self.subTest(script=script):+ self.check_windows_list(script)++ def check_windows_list(self, script):+ with tempfile.TemporaryDirectory() as tmp:+ base = Path(tmp)+ tools = base / "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)++ package_list = base / "debloat.txt"+ package_list.write_bytes(+ b"\xef\xbb\xbf# My TV, saved in Notepad\r\n"+ b"com.example.one\r\n"+ b"com.example.two # a note\r\n"+ )+ capture = base / "commands.txt"+ result = subprocess.run(+ ["bash", str(tools / script), str(package_list)], cwd=base,+ env=dict(os.environ, CAPTURE=str(capture)),+ capture_output=True, text=True,+ )+ self.assertEqual(result.returncode, 0, result.stderr)+ sent = capture.read_bytes()+ self.assertNotIn(b"\xef\xbb\xbf", sent, "BOM reached the TV")+ self.assertNotIn(b"\r", sent, "CR reached the TV")+ operation = "pm disable-user --user 0" if script == "disable.sh" else "pm enable"+ self.assertEqual(sent.decode().splitlines()[:2], [+ f"{operation} com.example.one",+ f"{operation} com.example.two",+ ])+def check_injected_line(self, script):with tempfile.TemporaryDirectory() as tmp:base = Path(tmp)diff --git a/tools/disable.sh b/tools/disable.shindex d0e05bded..9714e2fec 100755--- a/tools/disable.sh+++ b/tools/disable.sh@@ -15,7 +15,10 @@ export MSYS_NO_PATHCONV=1[ -x "$PY" ] || { echo "run: python3 -m venv tools/venv && tools/venv/bin/pip install -r tools/requirements.txt"; exit 1; }# Lists come from contributors, and the package name is pasted into a shell command on the TV.# Refuse the whole list unless every entry is a bare package name (#165).-PKGS=$(grep -vE '^\s*(#|$)' "$LIST" | sed -E 's/\s+#.*$//' | awk '{print $1}')+# Normalise first: Notepad on Windows saves a BOM and CRLF, and without this the first "# TV" line+# arrives as a package name and every entry keeps a trailing \r (#208).+PKGS=$(awk 'NR==1{sub(/^\357\273\277/,"")} {sub(/\r$/,""); print}' "$LIST" \+ | grep -vE '^\s*(#|$)' | sed -E 's/\s+#.*$//' | awk '{print $1}')BAD=$(printf '%s\n' "$PKGS" | grep -vE '^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)+$' || true)if [ -n "$BAD" ]; then{ echo "refusing $LIST: not a package name:"; printf '%s\n' "$BAD" | sed 's/^/ /'; } >&2diff --git a/tools/restore.sh b/tools/restore.shindex 12ebdd272..4b1e44f63 100755--- a/tools/restore.sh+++ b/tools/restore.sh@@ -14,8 +14,9 @@ PY=tools/venv/bin/python[ -x "$PY" ] || PY=tools/venv/Scripts/python.exeexport MSYS_NO_PATHCONV=1# Same check as disable.sh: the list is contributor-supplied and each entry becomes a shell-# command on the TV (#165).-PKGS=$(grep -vE '^\s*(#|$)' "$LIST" | sed -E 's/\s+#.*$//' | awk '{print $1}')+# command on the TV. A BOM and CRLF from a Windows editor are dropped first (#165, #208).+PKGS=$(awk 'NR==1{sub(/^\357\273\277/,"")} {sub(/\r$/,""); print}' "$LIST" \+ | grep -vE '^\s*(#|$)' | sed -E 's/\s+#.*$//' | awk '{print $1}')BAD=$(printf '%s\n' "$PKGS" | grep -vE '^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)+$' || true)if [ -n "$BAD" ]; then{ echo "refusing $LIST: not a package name:"; printf '%s\n' "$BAD" | sed 's/^/ /'; } >&2