Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

docs: what is left when 5555 is closed and there is no Wireless debugging (#1489)

xbsheng7b10b5d95179
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index 7268bfe3d..9146db458 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -34,6 +34,19 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/
close up, switch Wireless debugging off on its own: on a Chromecast with Google TV 4K (`sabrina`)
turning USB debugging off left the Wireless debugging port accepting connections, and
`tools/adb-closed.py` only checks 5555. `adb mdns services` lists that port while it is open.
+- **Port 5555 stays closed and there is no Wireless debugging entry either**, so the pair-once recipe
+ above has nothing to pair with: a [Philips 58PUS8505/62 The One, Android TV 12,
+ `STT2.230526.001`](https://github.com/Gathin23/cleanyourtv/issues/1489) reported USB debugging on, no
+ Wireless debugging screen, `adb connect <tv ip>:5555` refused, and a USB cable to the computer that got
+ no connection either. Two routes are left, and the firmware has to offer one of them. The first is the
+ port-scan bullet further down this section: some firmware runs `adbd` on a port of its own, so scan and
+ try each open one with `TV_PORT=<port> tools/tv.py --probe`. The second is the cable, when `adb devices` lists the set
+ while USB debugging is on: `adb tcpip 5555` with the stock `adb` then opens the port, the cable comes
+ out, and `tools/tv.py` reaches the TV over the network. The cable is only a way to open the port, never
+ a way to run these tools: `tools/tv.py` connects with `AdbDeviceTcp(HOST, PORT)` - `<tv ip>:5555`, or
+ `TV_PORT` for another port - and carries no USB transport, so no script here talks to a TV over USB. A
+ set that neither enumerates over USB nor runs `adbd` on any TCP port has no way in, and this repo does
+ not try to get around that.
- **USB devices go dead while USB debugging is on**, seen on the Xiaomi Mi Box S and the Xiaomi TV
Box S 3rd gen ([MiTV-AFMU0, Google TV 14](https://github.com/Gathin23/cleanyourtv/issues/737)):
their firmware switches the USB port to ADB device mode, which cuts the power to a USB speaker or
diff --git a/tests/test_connecting_no_wireless_note.py b/tests/test_connecting_no_wireless_note.py
new file mode 100644
index 000000000..4d3dc8caf
--- /dev/null
+++ b/tests/test_connecting_no_wireless_note.py
@@ -0,0 +1,157 @@
+"""The Connecting page tells an owner what is left when 5555 is closed and there is no Wireless debugging.
+
+`docs/TROUBLESHOOTING.md` answers "USB debugging never opens port 5555" with one recipe: pair once through
+Wireless debugging, `adb connect`, `adb tcpip 5555`. That recipe needs a pairing code on screen, so a set
+whose Developer options show USB debugging and nothing else had no answer on the page at all - #1489 is a
+Philips 58PUS8505/62 The One (Android TV 12, `STT2.230526.001`) with USB debugging on, no Wireless
+debugging entry, `adb connect <tv ip>:5555` refused and a USB cable that got no connection either.
+
+The two routes that remain are the port scan the same section already documents (`TV_PORT`) and the
+cable, when the set enumerates: `adb tcpip 5555` with the stock `adb` opens the port the tools use. That
+last part rests on the tools being TCP-only, which is read out of `tools/tv.py` here rather than asserted
+in prose: if `tv.py` ever grows a USB transport, this pair fails and the bullet has to be rewritten.
+"""
+import re
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parent.parent
+PAGE = ROOT / "docs" / "TROUBLESHOOTING.md"
+TVPY = ROOT / "tools" / "tv.py"
+SECTION = "## Connecting"
+
+
+def connecting(text=None):
+ """The Connecting section's text, or an empty string when the heading is gone."""
+ text = PAGE.read_text(encoding="utf-8") if text is None else text
+ start = text.find(SECTION)
+ if start == -1:
+ return ""
+ rest = text[start + len(SECTION):]
+ end = re.search(r"^## ", rest, re.M)
+ return rest if end is None else rest[:end.start()]
+
+
+def bullets(text=None):
+ """The section's bullets, continuation lines joined: one string per bullet."""
+ out = []
+ for line in connecting(text).splitlines():
+ if line.startswith("- "):
+ out.append(line[2:].strip())
+ elif out and line.startswith(" ") and line.strip():
+ out[-1] = out[-1] + " " + line.strip()
+ elif not line.strip():
+ continue
+ return out
+
+
+def connect_body(text=None):
+ """The body of tools/tv.py's connect(), which is where the transport is chosen."""
+ text = TVPY.read_text(encoding="utf-8") if text is None else text
+ m = re.search(r"^def connect\(.*?(?=^def |\Z)", text, re.M | re.S)
+ return m.group(0) if m else ""
+
+
+def bullet_naming(*needles, text=None):
+ """The first bullet that names every needle, or None."""
+ for b in bullets(text):
+ if all(n in b for n in needles):
+ return b
+ return None
+
+
+def cable_bullet(text=None):
+ """The bullet that offers the cable route: `adb tcpip 5555` next to the `adb devices` check.
+
+ The pair-once bullet names `adb tcpip 5555` as well, so the `adb devices` check is what tells the
+ two apart.
+ """
+ return bullet_naming("adb tcpip 5555", "adb devices", text=text)
+
+
+class ToolsAreTcpOnly(unittest.TestCase):
+ def test_connect_opens_a_tcp_connection_to_host_and_port(self):
+ body = connect_body()
+ self.assertIn("AdbDeviceTcp(HOST, PORT", body,
+ "tv.py no longer connects with AdbDeviceTcp(HOST, PORT): the page's "
+ "'<tv ip>:5555' needs checking")
+ self.assertIn("TV_PORT", TVPY.read_text(encoding="utf-8"),
+ "tv.py no longer honours TV_PORT, which the bullets hand out")
+ self.assertRegex(TVPY.read_text(encoding="utf-8"), r"TV_PORT\"\)\s*or\s*\"5555\"",
+ "the default port in tv.py is no longer 5555")
+
+ def test_there_is_no_usb_transport_to_document(self):
+ src = TVPY.read_text(encoding="utf-8")
+ self.assertNotIn("AdbDeviceUsb", src,
+ "tv.py now has a USB transport: the Connecting bullet that says the tools "
+ "speak TCP only, and the cable is just a way to open the port, needs rewriting")
+
+
+class ThePageAnswersIt(unittest.TestCase):
+ def test_the_pair_once_recipe_is_still_there_and_before_the_new_bullet(self):
+ pair = bullet_naming("adb pair")
+ self.assertIsNotNone(pair, "the pair-once recipe left the Connecting section; the new bullet "
+ "refers to it as 'the recipe above'")
+ self.assertIn("Wireless debugging", pair)
+
+ def test_a_closed_5555_with_no_wireless_debugging_is_answered(self):
+ bullet = cable_bullet()
+ self.assertIsNotNone(
+ bullet,
+ "nothing in Connecting tells an owner whose set has no Wireless debugging entry how to reach "
+ "it: the pair-once recipe needs a code on screen, so the page ends there (#1489)")
+ assert bullet is not None
+ self.assertIn("adb devices", bullet, "the cable route needs the check that the set enumerates")
+ self.assertIn("TV_PORT", bullet, "the port scan is the other route left, and it needs TV_PORT")
+ self.assertIn("5555", bullet)
+ self.assertIn("1489", bullet, "the bullet should link the report it comes from")
+ self.assertIn("USB", bullet)
+
+ def test_the_new_bullet_comes_after_the_pair_once_recipe(self):
+ cable = cable_bullet()
+ self.assertIsNotNone(cable, "no cable bullet in the Connecting section")
+ sections = bullets()
+ pair_at = [i for i, b in enumerate(sections) if "adb pair" in b]
+ cable_at = [i for i, b in enumerate(sections) if b == cable]
+ self.assertTrue(pair_at, "no bullet names `adb pair` any more: %r" % (sections,))
+ self.assertTrue(cable_at, "the cable bullet did not read back out of the section")
+ self.assertLess(pair_at[0], cable_at[0],
+ "'the recipe above' has to be above the bullet that says it cannot be followed")
+
+ def test_the_bullet_does_not_promise_the_tools_run_over_usb(self):
+ bullet = cable_bullet()
+ assert bullet is not None
+ self.assertIn("over USB", bullet,
+ "the bullet has to say the cable is not a transport for these tools, or an owner "
+ "will keep a cable plugged in and expect tools/tv.py to use it")
+
+
+class TheReader(unittest.TestCase):
+ def test_a_wrapped_bullet_is_joined(self):
+ page = "## Connecting\n\n- **A** one\n two three\n- **B** four\n\n## Working\n"
+ self.assertEqual(bullets(page), ["**A** one two three", "**B** four"])
+
+ def test_a_bullet_in_another_section_is_not_read(self):
+ page = "## Connecting\n- **A** one\n\n## Working\n- **B** adb tcpip 5555\n"
+ self.assertIsNone(bullet_naming("adb tcpip 5555", text=page))
+
+ def test_the_section_stops_at_the_next_heading(self):
+ page = "## Connecting\n- **A** one\n## Working on the TV\nmore\n"
+ self.assertEqual(len(bullets(page)), 1)
+
+ def test_a_page_without_the_section_reads_as_nothing(self):
+ self.assertEqual(bullets("# Troubleshooting\n\n## Working\n- x\n"), [])
+ self.assertIsNone(bullet_naming("adb tcpip 5555", text="# Nothing here\n"))
+
+ def test_naming_every_needle_is_required(self):
+ page = "## Connecting\n- **A** adb tcpip\n- **B** adb tcpip 5555 TV_PORT\n"
+ self.assertEqual(bullet_naming("adb tcpip", "TV_PORT", text=page), "**B** adb tcpip 5555 TV_PORT")
+
+ def test_the_real_page_reads_as_a_section_of_bullets(self):
+ self.assertGreaterEqual(len(bullets()), 10,
+ "the Connecting section parsed as %d bullets: the reader is broken, not "
+ "the page" % len(bullets()))
+
+
+if __name__ == "__main__":
+ unittest.main()