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: Wi-Fi check for setupwraith now stops when it cannot read the owners
vlaship6876d6c5ced2
diff --git a/tests/test_setupwraith_guard.py b/tests/test_setupwraith_guard.pyindex 54dd98320..ee84b788c 100644--- a/tests/test_setupwraith_guard.py+++ b/tests/test_setupwraith_guard.py@@ -16,7 +16,7 @@ LIST = f"# My TV\ncom.example.before\n{SETUP} # wizard\ncom.example.after\n"class SetupwraithGuardTest(unittest.TestCase):- def run_disable(self, wifi_owner, extra_env=None):+ def run_disable(self, wifi_owner, extra_env=None, dumpsys=None):with tempfile.TemporaryDirectory() as tmp:repo = Path(tmp) / "repo"tools = repo / "tools"@@ -25,10 +25,11 @@ class SetupwraithGuardTest(unittest.TestCase):client = tools / "venv" / "bin" / "python"client.parent.mkdir(parents=True)# Fake tv.py client: answers `dumpsys wifi` with the given owner, records --batch input.+ answer = dumpsys or f'echo " cuid=10031 cname={wifi_owner} allowAutojoin=true"'client.write_text('#!/bin/sh\n''case "$*" in\n'- f' *dumpsys*) echo " cuid=10031 cname={wifi_owner} allowAutojoin=true" ;;\n'+ f' *dumpsys*) {answer} ;;\n'' *) cat > "$CAPTURE" ;;\n''esac\n')client.chmod(0o755)@@ -53,6 +54,17 @@ class SetupwraithGuardTest(unittest.TestCase):f"pm disable-user --user 0 {SETUP}","pm disable-user --user 0 com.example.after"])+ def test_skipped_when_dumpsys_fails(self):+ # for example tv.py stopping in the middle (a console encoding error, a timeout)+ commands, stderr = self.run_disable(None, dumpsys='echo "partial output"; exit 1')+ self.assertNotIn(f"pm disable-user --user 0 {SETUP}", commands)+ self.assertIn("could not check", stderr)++ def test_skipped_when_no_network_listed(self):+ commands, stderr = self.run_disable(None, dumpsys='echo "Wi-Fi is off"')+ self.assertNotIn(f"pm disable-user --user 0 {SETUP}", commands)+ self.assertIn("could not check", stderr)+def test_force(self):commands, _ = self.run_disable(f"{SETUP}:10031", {"FORCE_SETUPWRAITH": "1"})self.assertIn(f"pm disable-user --user 0 {SETUP}", commands)diff --git a/tools/disable.ps1 b/tools/disable.ps1index 272e69d1e..7443d93eb 100644--- a/tools/disable.ps1+++ b/tools/disable.ps1@@ -28,7 +28,12 @@ if ($bad.Count -gt 0) {$setup = 'com.google.android.tungsten.setupwraith'if ($pkgs -contains $setup -and -not $env:FORCE_SETUPWRAITH) {$wifi = (& $py -I (Join-Path $repo 'tools\tv.py') 'dumpsys wifi') -join "`n"- if ($wifi -match 'cname=[^ ]*setupwraith') {+ # Be safe: if we cannot read the owners (tv.py failed, timed out, or showed no network at all),+ # do not disable setupwraith, so the TV cannot lose the network it is on.+ if ($LASTEXITCODE -ne 0 -or $wifi -notmatch 'cname=') {+ Write-Warning "Skipping ${setup}: could not check which app owns the saved Wi-Fi networks (dumpsys wifi failed or showed none). Try again, or set `$env:FORCE_SETUPWRAITH=1 if the TV uses Ethernet."+ $pkgs = @($pkgs | Where-Object { $_ -ne $setup })+ } elseif ($wifi -match 'cname=[^ ]*setupwraith') {Write-Warning "Skipping ${setup}: the saved Wi-Fi network belongs to it, and disabling it would delete that network and take the TV off Wi-Fi. Forget the network and join it again in Settings > Network & Internet, then run this again (or set `$env:FORCE_SETUPWRAITH=1 on Ethernet)."$pkgs = @($pkgs | Where-Object { $_ -ne $setup })}diff --git a/tools/disable.sh b/tools/disable.shindex 673156d7c..85fb6f63d 100755--- a/tools/disable.sh+++ b/tools/disable.sh@@ -30,9 +30,16 @@ fi# android.uid.system). FORCE_SETUPWRAITH=1 disables it anyway, e.g. on Ethernet.SETUP=com.google.android.tungsten.setupwraithif printf '%s\n' "$PKGS" | grep -x "$SETUP" >/dev/null && [ -z "${FORCE_SETUPWRAITH:-}" ]; then- WIFI="$("$PY" -I tools/tv.py "dumpsys wifi" || true)"+ # Be safe: if we cannot read the owners (tv.py failed, timed out, or showed no network at all),+ # do not disable setupwraith, so the TV cannot lose the network it is on.+ WIFI="$("$PY" -I tools/tv.py "dumpsys wifi")" || WIFI=""+ OWNERS="$(printf '%s\n' "$WIFI" | grep -o 'cname=[^ ]*' || true)"+ if [ -z "$OWNERS" ]; then+ echo "Skipping $SETUP: could not check which app owns the saved Wi-Fi networks (dumpsys wifi failed" >&2+ echo "or showed none). Try again, or set FORCE_SETUPWRAITH=1 if the TV uses Ethernet." >&2+ PKGS="$(printf '%s\n' "$PKGS" | grep -vx "$SETUP" || true)"# no grep -q here: with pipefail its early exit would SIGPIPE the grep before it and fail open- if printf '%s\n' "$WIFI" | grep -o 'cname=[^ ]*' | grep setupwraith >/dev/null; then+ elif printf '%s\n' "$OWNERS" | grep setupwraith >/dev/null; thenecho "Skipping $SETUP: the saved Wi-Fi network belongs to it, and disabling it would delete that" >&2echo "network and take the TV off Wi-Fi. On the TV, forget the network and join it again in" >&2echo "Settings > Network & Internet, then run this again (or set FORCE_SETUPWRAITH=1 on Ethernet)." >&2diff --git a/tools/tv.py b/tools/tv.pyindex 04ac527f3..9f08ba805 100644--- a/tools/tv.py+++ b/tools/tv.py@@ -15,6 +15,15 @@ from adb_shell.adb_device import AdbDeviceTcpfrom adb_shell.auth.keygen import keygenfrom adb_shell.auth.sign_pythonrsa import PythonRSASigner+# Windows consoles often use an old code page (cp1251, cp1252 and others) that cannot print every character+# in dumpsys output. Python then stops with an error in the middle. disable.ps1 reads this output to see if+# setupwraith owns the Wi-Fi network, so print a replacement character instead of stopping.+for _stream in (sys.stdout, sys.stderr):+ try:+ _stream.reconfigure(errors="replace")+ except (AttributeError, ValueError):+ pass+HOST = os.environ.get("TV_HOST")PORT = int(os.environ.get("TV_PORT", "5555"))if not HOST: