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: adb-closed.py answers a malformed address with exit 2, not "still open"
xbshengcc5b0e1038a2
diff --git a/tests/test_adb_closed.py b/tests/test_adb_closed.pyindex 8ea7e4d43..9024b9256 100644--- a/tests/test_adb_closed.py+++ b/tests/test_adb_closed.py@@ -95,6 +95,27 @@ class AdbClosedTest(unittest.TestCase):self.assertEqual(result.returncode, 1, result.stderr)self.assertIn(f"127.0.0.1:{port} is still open", result.stderr)+ def test_a_name_that_is_not_a_hostname_is_not_an_open_port(self):+ # getaddrinfo runs the name through the idna codec, which raises UnicodeError on an empty or+ # over-long label (a doubled dot, a 70-character label) rather than the gaierror an unresolvable+ # name gives. Uncaught, that was a traceback that ended in exit 1 - the code this tool reserves+ # for "the port is still open" - so a typo in the address read as an open port at the closing+ # step the prompt sends an assistant to.+ for address in ("192.168.1..50", ".", "192.168.1.50..", "a" * 70 + ".com", "192.168.1..50:5555"):+ with self.subTest(address=address):+ result = check(address)+ self.assertEqual(result.returncode, 2, result.stderr)+ self.assertIn("not a hostname", result.stderr)+ self.assertNotIn("Traceback", result.stderr)+ self.assertNotIn("still open", result.stderr)+ self.assertEqual(result.stdout, "")++ def test_a_refused_check_names_the_address_it_was_given(self):+ # Whatever the reason, the message has to name the address the owner typed: the one reading+ # "could not check" is the one who can see the typo.+ result = check("192.168.1..50")+ self.assertIn("could not check 192.168.1..50:5555", result.stderr)+def test_bad_arguments(self):self.assertEqual(check("127.0.0.1", "not-a-port").returncode, 2)self.assertEqual(check("127.0.0.1:not-a-port").returncode, 2)diff --git a/tools/adb-closed.py b/tools/adb-closed.pyindex 4ebfd147f..273efad86 100644--- a/tools/adb-closed.py+++ b/tools/adb-closed.py@@ -4,7 +4,8 @@adb-closed.py <tv ip[:port]> [port] port defaults to TV_PORT or 5555; the IP to TV_HOSTExits 0 when the port refuses the connection or does not answer, 1 when it is still open, and 2-when the check itself could not run (a name that does not resolve, no route to the TV).+when the check itself could not run (a name that does not resolve or is not a hostname, no route to+the TV)."""import osimport socket@@ -65,6 +66,13 @@ def main():print(f"{host}:{port} did not answer in {TIMEOUT_S:.0f} s: closed, unless the TV is off or not at ""this address.")return 0+ except UnicodeError:+ # getaddrinfo runs the name through the idna codec, which raises UnicodeError on an empty or+ # over-long label (192.168.1..50, a 70-character label) instead of the gaierror an unresolvable+ # name gives. Left uncaught it printed a traceback and exited 1 - the code this tool reserves for+ # "the port is still open" - so a typo in the address read as an open port at the closing step.+ sys.stderr.write(f"could not check {host}:{port}: not a hostname. Check the address.\n")+ return 2except OSError as e:sys.stderr.write(f"could not check {host}:{port} ({e}). Is the TV on and on this network?\n")return 2