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: say so when the TV reports ro.adb.secure=0
James Coatesbe264d20aeb0
diff --git a/tests/test_adb_exposure.py b/tests/test_adb_exposure.pynew file mode 100644index 000000000..99491ebde--- /dev/null+++ b/tests/test_adb_exposure.py@@ -0,0 +1,71 @@+"""tools/disable.sh says so when the TV's network ADB accepts any device (ro.adb.secure=0).++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]+LIST = "# My TV\ncom.example.one\ncom.example.two\n"+++class AdbSecureWarningTest(unittest.TestCase):+ def run_disable(self, getprop):+ 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")+ client = tools / "venv" / "bin" / "python"+ client.parent.mkdir(parents=True)+ # Fake tv.py client: answers getprop as given, takes the record, records --batch input.+ client.write_text(+ '#!/bin/sh\n'+ 'case "$*" in\n'+ f' *getprop*) {getprop} ;;\n'+ ' *recovery.py*) exit 0 ;;\n'+ ' *--batch*) cat > "$CAPTURE" ;;\n'+ 'esac\n')+ client.chmod(0o755)+ (repo / "debloat.txt").write_text(LIST)+ capture = Path(tmp) / "commands.txt"+ env = dict(os.environ, CAPTURE=str(capture))+ result = subprocess.run(["bash", str(tools / "disable.sh"), "debloat.txt"], cwd=repo,+ env=env, capture_output=True, text=True,+ stdin=subprocess.DEVNULL, timeout=60)+ self.assertEqual(result.returncode, 0, result.stderr)+ # The note never changes what is sent.+ self.assertEqual(capture.read_text().splitlines(), [+ "pm disable-user --user 0 com.example.one",+ "pm disable-user --user 0 com.example.two",+ "pm list packages -d",+ ])+ return result.stderr++ def test_warns_when_adb_is_not_secure(self):+ stderr = self.run_disable('echo 0')+ self.assertIn("ro.adb.secure=0", stderr)+ self.assertIn("Isn't ADB access a security hole?", stderr)++ def test_warns_with_crlf_output(self):+ stderr = self.run_disable(r"printf '0\r\n'")+ self.assertIn("ro.adb.secure=0", stderr)++ def test_quiet_when_adb_is_secure(self):+ self.assertNotIn("ro.adb.secure", self.run_disable('echo 1'))++ def test_quiet_when_the_property_is_missing(self):+ self.assertNotIn("ro.adb.secure", self.run_disable('echo'))++ def test_quiet_when_the_read_fails(self):+ # A failed read skips the note; it does not stop the list or guess.+ self.assertNotIn("ro.adb.secure", self.run_disable('echo 0; exit 1'))+++if __name__ == "__main__":+ unittest.main()diff --git a/tools/disable.ps1 b/tools/disable.ps1index 50b8b3a81..b07f325a7 100644--- a/tools/disable.ps1+++ b/tools/disable.ps1@@ -38,6 +38,14 @@ if ($pkgs -contains $setup -and -not $env:FORCE_SETUPWRAITH) {$pkgs = @($pkgs | Where-Object { $_ -ne $setup })}}+# Same as disable.sh: on firmware with ro.adb.secure=0, port 5555 gives a shell to any device on the+# network without the "Allow" prompt. Read it now and say so once the list is done; a failed read only+# skips the note. Windows PowerShell turns redirected stderr into an error that 'Stop' would throw.+$ErrorActionPreference = 'Continue'+$adbSecure = ((& $py -I (Join-Path $repo 'tools\tv.py') 'getprop ro.adb.secure' 2>$null) -join '').Trim()+if ($LASTEXITCODE -ne 0) { $adbSecure = '' }+$ErrorActionPreference = 'Stop'+# Same as disable.sh: the state undo needs is recorded before the first command reaches the TV, and# a failed save leaves the TV untouched (#239).& $py -I (Join-Path $repo 'tools\recovery.py') --save $List@@ -45,3 +53,7 @@ if ($LASTEXITCODE -ne 0) { throw 'no recovery record was written, so nothing was$cmds = @($pkgs | ForEach-Object { "pm disable-user --user 0 $_" }) + 'pm list packages -d'$cmds | & $py -I (Join-Path $repo 'tools\tv.py') --batch++if ($adbSecure -eq '0') {+ Write-Warning "This TV reports ro.adb.secure=0, so network ADB on port 5555 accepts any device on your network without the `"Allow`" prompt. When you are done, turn USB debugging and Network/ADB debugging off on the TV and reboot it (README: `"Isn't ADB access a security hole?`")."+}diff --git a/tools/disable.sh b/tools/disable.shindex 054295e23..b56495e3b 100755--- a/tools/disable.sh+++ b/tools/disable.sh@@ -49,6 +49,10 @@ if printf '%s\n' "$PKGS" | grep -x "$SETUP" >/dev/null && [ -z "${FORCE_SETUPWRAfifi+# On firmware with ro.adb.secure=0, port 5555 gives a shell to any device on the network without the+# "Allow" prompt. Read it now and say so once the list is done; a failed read only skips the note.+ADB_SECURE="$("$PY" -I tools/tv.py "getprop ro.adb.secure" 2>/dev/null | tr -d '[:space:]')" || ADB_SECURE=""+# The state undo needs goes to disk before the first command reaches the TV, and a failed save stops# here with the TV untouched: a record written afterwards would describe a TV that is already broken,# and a retry must not overwrite the one taken before the first change (#239).@@ -58,3 +62,9 @@ fi[ -n "$PKGS" ] && printf '%s\n' "$PKGS" | sed 's/^/pm disable-user --user 0 /'echo "pm list packages -d"} | "$PY" -I tools/tv.py --batch++if [ "$ADB_SECURE" = "0" ]; then+ echo "Warning: this TV reports ro.adb.secure=0, so network ADB on port 5555 accepts any device on" >&2+ echo "your network without the \"Allow\" prompt. When you are done, turn USB debugging and" >&2+ echo "Network/ADB debugging off on the TV and reboot it (README: \"Isn't ADB access a security hole?\")." >&2+fidiff --git a/tools/tv.py b/tools/tv.pyindex 9f08ba805..7a5d6d701 100644--- a/tools/tv.py+++ b/tools/tv.py@@ -60,7 +60,8 @@ def main():dev = connect()if not args or args == ["--probe"]:for p in ("ro.product.model", "ro.product.device", "ro.build.version.release",- "ro.build.version.sdk", "ro.build.display.id", "ro.product.manufacturer"):+ "ro.build.version.sdk", "ro.build.display.id", "ro.product.manufacturer",+ "ro.adb.secure", "service.adb.tcp.port"):print(f"{p} = {dev.shell(f'getprop {p}').strip()}")elif args[0] == "--push" and len(args) == 3:dev.push(args[1], args[2], transport_timeout_s=300.0, read_timeout_s=300.0)