Skip to content

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

examples: the Dcolor GD2 and Lumio Vision 7 Apply lines keep the setupwraith Wi-Fi guard

Mazin Kanugafbaea6875f83
diff --git a/examples/dcolor-gd2/debloat.txt b/examples/dcolor-gd2/debloat.txt
index ab17418f0..356af4294 100644
--- a/examples/dcolor-gd2/debloat.txt
+++ b/examples/dcolor-gd2/debloat.txt
@@ -2,14 +2,16 @@
# Build: Dcolor/GD2/YHT:14/URO4.260304.027/15200246:user/release-keys
# Home it shipped with: Google TV (com.google.android.apps.tv.launcherx). 128 system apps, 39 disabled here.
#
-# Apply: FORCE_SETUPWRAITH=1 tools/disable.sh examples/dcolor-gd2/debloat.txt
+# Apply: tools/disable.sh examples/dcolor-gd2/debloat.txt
# Restore: tools/restore.sh examples/dcolor-gd2/debloat.txt com.google.android.apps.tv.launcherx
# Launcher: INPUT_KEY_SERVICE=1 launcher/build-and-install.sh
#
# Stock launcher: com.google.android.apps.tv.launcherx. Disable it only after the new launcher is Home;
# disable.sh skips it until another app answers HOME, so run this list again once the launcher is installed.
# setupwraith: the first-run wizard also claims HOME on Google TV. disable.sh skips it while it owns the
-# saved Wi-Fi network (FORCE_SETUPWRAITH=1 overrides). Re-enable it before a factory reset; restore.sh does.
+# saved Wi-Fi network (`dumpsys wifi | grep -o 'cname=[^ ]*'`): forget the network the box is on and join it
+# again in Settings, then run this list again. FORCE_SETUPWRAITH=1 only on Ethernet, or if disable.sh still
+# skips it after that re-join. Re-enable it before a factory reset; restore.sh does.
# Disabling setupwraith gives Home back but costs casting (Chromecast built-in); re-enable it to cast.
#
# Left on on purpose: com.android.vending (Play Store), com.google.android.gms, com.google.android.youtube.tv,
diff --git a/examples/lumio-vision-7/README.md b/examples/lumio-vision-7/README.md
index 7f8727b34..363dccfd2 100644
--- a/examples/lumio-vision-7/README.md
+++ b/examples/lumio-vision-7/README.md
@@ -23,9 +23,20 @@ whole package goes.
setupwraith owned one saved Wi-Fi network here, but the **active** network was system-owned
(`OwnerUid 1000`), so disabling setupwraith did **not** drop Wi-Fi or ADB. `tools/disable.sh`'s guard is
-deliberately conservative, so it needs `FORCE_SETUPWRAITH=1` (already in the Apply line). If your unit's
-active Wi-Fi is owned by setupwraith instead, forget and re-join the network in Settings first so it
-becomes system-owned.
+deliberately conservative: it skips setupwraith whenever setupwraith owns a saved network, used or not,
+so this unit needed `FORCE_SETUPWRAITH=1`. The Apply line leaves it out, so first check which network
+your unit is on and who owns it:
+
+```sh
+tools/tv.py "dumpsys wifi | grep -oE 'Currently Connected: [a-z]*|cname=[^ ]*'"
+```
+
+Each saved network prints its `Currently Connected:` flag and then its owner, and `dumpsys` lists them
+more than once. A plain `grep -o 'cname=[^ ]*'` prints only the owners, so it looks the same whichever
+network is in use. If the `cname=` after `Currently Connected: true` is
+`com.google.android.tungsten.setupwraith`, forget and re-join that network in Settings first so it
+becomes system-owned, then check again. Add `FORCE_SETUPWRAITH=1` only on Ethernet, or once the entry you
+are connected to is `android.uid.system`, as it was here.
**Trade-off:** disabling setupwraith can break Chromecast (the Cast receiver `mediashell` reads device
info from it). Re-enable setupwraith (`pm enable com.google.android.tungsten.setupwraith`) to get casting
diff --git a/examples/lumio-vision-7/debloat.txt b/examples/lumio-vision-7/debloat.txt
index 2d8479ab2..828a102e7 100644
--- a/examples/lumio-vision-7/debloat.txt
+++ b/examples/lumio-vision-7/debloat.txt
@@ -2,7 +2,7 @@
# Google TV 14 (Android 14, SDK 34), build UKRA.251202.032
# First Lumio list. Contributed by Subramanya GB.
#
-# Apply: TV_HOST=<tv ip> FORCE_SETUPWRAITH=1 tools/disable.sh examples/lumio-vision-7/debloat.txt
+# Apply: TV_HOST=<tv ip> tools/disable.sh examples/lumio-vision-7/debloat.txt
# Undo: TV_HOST=<tv ip> tools/restore.sh examples/lumio-vision-7/debloat.txt com.google.android.apps.tv.launcherx
# Everything is DISABLED, not uninstalled. Comment out any line you want to keep.
#
@@ -10,9 +10,11 @@
# new launcher is confirmed Home). On this build setupwraith re-claims Home (.RecoveryActivity/.MainActivity)
# the moment launcherx is off, and the shell cannot disable that component alone (SecurityException), so
# setupwraith has to be disabled too (listed below). The active Wi-Fi here was system-owned (OwnerUid 1000),
-# so disabling setupwraith did NOT drop Wi-Fi - but disable.sh's guard is conservative, hence
-# FORCE_SETUPWRAITH=1. Disabling setupwraith may break Chromecast (mediashell reads device info from it);
-# re-enable setupwraith to get casting back.
+# so disabling setupwraith did NOT drop Wi-Fi - but setupwraith owned another saved network, so disable.sh's
+# guard skipped it and this unit needed FORCE_SETUPWRAITH=1. Check yours first with the README's
+# "Currently Connected" check (the cname list alone does not say which network is in use): if setupwraith
+# owns the network in use, forget and re-join it in Settings. Disabling setupwraith may break Chromecast
+# (mediashell reads device info from it); re-enable setupwraith to get casting back.
# Live TV / tuner app: com.realtek.tv (set as live_tv_package in config.xml, and hidden from the grid).
# Netflix (com.netflix.ninja) shipped already disabled on this unit.
# Remote app buttons (for config.xml app_keys): YouTube 190, Netflix 191, Prime Video 195, TL;DR 200.
@@ -42,7 +44,7 @@ com.google.android.youtube.tvmusic
# Voice assistant (optional): ~100 MB RAM in the background. Comment out to keep voice search / the mic button.
com.google.android.katniss
-# Required for a third-party launcher to hold Home on this build (see header; needs FORCE_SETUPWRAITH=1)
+# Required for a third-party launcher to hold Home on this build (see header: check the Wi-Fi owner first)
com.google.android.tungsten.setupwraith
# Owner's personal swap, NOT bloat - left commented so the list keeps YouTube by default:
diff --git a/tests/test_apply_override_caveat.py b/tests/test_apply_override_caveat.py
new file mode 100644
index 000000000..b78e2bb6c
--- /dev/null
+++ b/tests/test_apply_override_caveat.py
@@ -0,0 +1,125 @@
+"""A list's Apply command that sets FORCE_SETUPWRAITH=1 says, in the same block, when that is safe.
+
+`tools/disable.sh` and `disable.ps1` skip setupwraith while it owns a saved Wi-Fi network, because Android
+deletes an app's saved networks when the app is disabled: the TV drops off Wi-Fi, and ADB and the phone remote
+go with it. Their own messages offer the override only "on Ethernet" (on Wi-Fi they say to forget the network
+and join it again), and AGENTS.md allows `FORCE_SETUPWRAITH=1` only in the situation those messages describe.
+
+The Apply line is the command an owner of that model copies. One that carries the override with no condition
+switches the guard off for every other unit, including the ones whose network in use belongs to setupwraith.
+So when an Apply block (the `# Apply:` line and the indented lines under it) sets the override, the same block
+has to say when it is safe: Ethernet, the owner check (`cname`, `dumpsys wifi`), or forgetting and re-joining
+the network. A note further down the header does not count; it is not what gets pasted.
+
+Run from the repository root: python3 -m unittest discover -s tests -v
+"""
+import re
+import unittest
+from pathlib import Path
+
+
+ROOT = Path(__file__).resolve().parents[1]
+
+# `FORCE_SETUPWRAITH=1` for disable.sh, `$env:FORCE_SETUPWRAITH=1` or `="1"` for disable.ps1.
+OVERRIDE = re.compile(r"\bFORCE_SETUPWRAITH\s*=\s*[\"']?1\b")
+CONDITION = re.compile(r"(?i)\bethernet\b|\bcname\b|dumpsys wifi|\bre-?join|join (?:it|the network) again")
+# `# Apply:`, `# Apply (bash):`, `# Apply (PowerShell):`.
+APPLY = re.compile(r"#\s*Apply\b[^:]*:")
+# A line under it that carries on the same command: a comment indented past the labels, e.g.
+# `# FORCE_SETUPWRAITH=1 only on Ethernet ...`. `# Undo:` or a bare `#` ends the block.
+CONTINUATION = re.compile(r"#\s{3,}\S")
+
+
+def apply_blocks(text):
+ """(line number, lines) for every Apply block of a list: the label line and its continuation lines."""
+ lines = text.splitlines()
+ blocks = []
+ for index, line in enumerate(lines):
+ if not APPLY.match(line):
+ continue
+ block = [line]
+ for following in lines[index + 1:]:
+ if not CONTINUATION.match(following):
+ break
+ block.append(following)
+ blocks.append((index + 1, block))
+ return blocks
+
+
+def override_problems(text):
+ """Why an Apply block in this list switches the Wi-Fi guard off without a condition, one sentence each."""
+ problems = []
+ for number, block in apply_blocks(text):
+ joined = " ".join(block)
+ if OVERRIDE.search(joined) and not CONDITION.search(joined):
+ problems.append(
+ f"line {number}: the Apply command sets FORCE_SETUPWRAITH=1 but does not say when that is "
+ f"safe (on Ethernet, after checking the Wi-Fi owner, or after re-joining the network)")
+ return problems
+
+
+class ApplyOverrideCaveatTest(unittest.TestCase):
+ def test_every_apply_override_says_when_it_is_safe(self):
+ lists = blocks = overrides = 0
+ failures = []
+ for path in sorted((ROOT / "examples").glob("*/debloat*.txt")):
+ lists += 1
+ text = path.read_text(encoding="utf-8")
+ found = apply_blocks(text)
+ blocks += len(found)
+ overrides += sum(1 for _, block in found if OVERRIDE.search(" ".join(block)))
+ for problem in override_problems(text):
+ failures.append(f"{path.relative_to(ROOT).as_posix()}: {problem}")
+ self.assertGreaterEqual(lists, 250, "the sweep read too few lists to be meaningful")
+ self.assertGreaterEqual(blocks, 250, "the sweep found too few Apply lines")
+ self.assertGreaterEqual(overrides, 2, "the sweep found no Apply block with the override, so it reads nothing")
+ self.assertEqual([], failures, "\n".join(failures))
+
+ def test_an_override_with_no_condition_is_reported(self):
+ text = (
+ "# Apply: TV_HOST=<tv ip> FORCE_SETUPWRAITH=1 tools/disable.sh examples/x/debloat.txt\n"
+ "# Undo: TV_HOST=<tv ip> tools/restore.sh examples/x/debloat.txt com.google.android.apps.tv.launcherx\n"
+ )
+ problems = override_problems(text)
+ self.assertEqual(1, len(problems))
+ self.assertIn("line 1", problems[0])
+
+ def test_an_ethernet_condition_under_the_apply_line_is_quiet(self):
+ text = (
+ "# Apply: FORCE_SETUPWRAITH=1 TV_HOST=<tv ip> tools/disable.sh examples/x/debloat.txt\n"
+ "# FORCE_SETUPWRAITH=1 only on Ethernet with no saved Wi-Fi: disable.sh otherwise skips setupwraith\n"
+ "# Undo: TV_HOST=<tv ip> tools/restore.sh examples/x/debloat.txt com.google.android.apps.tv.launcherx\n"
+ )
+ self.assertEqual([], override_problems(text))
+
+ def test_a_rejoin_first_condition_is_quiet(self):
+ text = (
+ "# Apply: TV_HOST=<tv ip> tools/disable.sh examples/x/debloat.txt\n"
+ "# (forget and re-join Wi-Fi first, see setupwraith below; then FORCE_SETUPWRAITH=1)\n"
+ )
+ self.assertEqual([], override_problems(text))
+
+ def test_the_powershell_form_counts_as_the_override(self):
+ text = (
+ "# Apply (PowerShell): $env:FORCE_SETUPWRAITH=\"1\"; tools\\disable.ps1 -TvHost <tv ip> examples\\x\\debloat.txt\n"
+ )
+ self.assertEqual(1, len(override_problems(text)))
+
+ def test_a_condition_outside_the_block_does_not_count(self):
+ # The Undo line ends the block, and the setupwraith note further down is not what gets pasted.
+ text = (
+ "# Apply: FORCE_SETUPWRAITH=1 tools/disable.sh examples/x/debloat.txt\n"
+ "# Restore: tools/restore.sh examples/x/debloat.txt com.google.android.apps.tv.launcherx\n"
+ "#\n"
+ "# setupwraith: disable.sh skips it while it owns the saved Wi-Fi network; on Ethernet that is fine.\n"
+ )
+ self.assertEqual([(1, [text.splitlines()[0]])], apply_blocks(text))
+ self.assertEqual(1, len(override_problems(text)))
+
+ def test_an_apply_line_without_the_override_needs_nothing(self):
+ text = "# Apply: TV_HOST=<tv ip> tools/disable.sh examples/x/debloat.txt\n"
+ self.assertEqual([], override_problems(text))
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/test_lumio_connected_wifi_check.py b/tests/test_lumio_connected_wifi_check.py
new file mode 100644
index 000000000..eb34037ac
--- /dev/null
+++ b/tests/test_lumio_connected_wifi_check.py
@@ -0,0 +1,129 @@
+"""The Lumio Vision 7 notes give a Wi-Fi check that shows which saved network is in use.
+
+On the contributor's unit setupwraith owned one saved network, but the network in use was system-owned, so
+`FORCE_SETUPWRAITH=1` was safe there. The README and the list header tell other units to add the override only
+once the network they are connected to is system-owned. `dumpsys wifi | grep -o 'cname=[^ ]*'` cannot tell them:
+it prints one bare owner per saved network, with no SSID and no connected flag, so a unit whose network in use
+belongs to setupwraith prints the same two lines as the contributor's. The check has to pair each entry's
+`Currently Connected:` flag with its owner (examples/xgimi-mogo-4/README.md reads the same flag).
+
+The README's command is run here, as grep would run it, against a `dumpsys wifi` excerpt shaped like the one a
+Chromecast with Google TV 4K (Google TV 14) prints, with made-up network names.
+
+Run from the repository root: python3 -m unittest discover -s tests -v
+"""
+from pathlib import Path
+import re
+import sys
+import unittest
+
+sys.path.insert(0, str(Path(__file__).resolve().parent))
+from test_apply_override_caveat import OVERRIDE, apply_blocks # noqa: E402
+
+
+ROOT = Path(__file__).resolve().parents[1]
+FOLDER = ROOT / "examples" / "lumio-vision-7"
+README = (FOLDER / "README.md").read_text(encoding="utf-8")
+LIST = (FOLDER / "debloat.txt").read_text(encoding="utf-8")
+SETUP = "com.google.android.tungsten.setupwraith"
+SYSTEM = "android.uid.system:1000"
+
+# `tools/tv.py "dumpsys wifi | grep -o 'PATTERN'"` or `grep -oE`.
+CHECK = re.compile(r'tools/tv\.py "dumpsys wifi \| grep -oE? \'([^\']+)\'"')
+
+
+def network(number, name, connected, owner, uid):
+ """One saved network as WifiConfigManager dumps it: the ID line first, the creator further down."""
+ mark = "* " if connected else ""
+ return (
+ f'{mark}ID: {number} SSID: "{name}" PROVIDER-NAME: null BSSID: null FQDN: HOME-PROVIDER-NETWORK: false '
+ f"PRIO: 0 HIDDEN: false PMF: false CarrierId: -1 SubscriptionId: -1 SubscriptionGroup: null "
+ f"Currently Connected: {'true' if connected else 'false'} User Selected: false\n"
+ " NetworkSelectionStatus NETWORK_SELECTION_ENABLED\n"
+ " KeyMgmt: WPA_PSK Protocols: WPA RSN\n"
+ f" cuid={uid} cname={owner} luid={uid} lname={owner}\n"
+ )
+
+
+def dumpsys(home_connected):
+ """A system-owned home network and a setupwraith-owned one; `home_connected` says which is in use."""
+ return (
+ "WifiConfigManager - Configured networks Begin ----\n"
+ + network(0, "Home", home_connected, SYSTEM, 1000)
+ + network(1, "Hotspot", not home_connected, SETUP, 10031)
+ + "WifiConfigManager - Configured networks End ----\n"
+ )
+
+
+def grep_o(pattern, text):
+ """What `grep -o` (or `grep -oE`) prints: every match, line by line, in order."""
+ return [m.group(0) for line in text.splitlines() for m in re.finditer(pattern, line)]
+
+
+def owner_in_use(output):
+ """The `cname=` that follows `Currently Connected: true` in the check's output, or None."""
+ for flag, owner in zip(output, output[1:]):
+ if flag == "Currently Connected: true" and owner.startswith("cname="):
+ return owner[len("cname="):]
+ return None
+
+
+def setupwraith_section():
+ parts = re.split(r"(?m)^## ", README)
+ matches = [p for p in parts[1:] if "setupwraith" in p.split("\n", 1)[0]]
+ assert len(matches) == 1, f"expected one README section about setupwraith, found {len(matches)}"
+ return matches[0]
+
+
+def header():
+ return "\n".join(line for line in LIST.splitlines() if line.startswith("#"))
+
+
+class LumioConnectedWifiCheckTest(unittest.TestCase):
+ def setUp(self):
+ self.patterns = CHECK.findall(setupwraith_section())
+
+ def test_the_readme_gives_a_wifi_check(self):
+ self.assertTrue(self.patterns, "the setupwraith section gives no `tools/tv.py \"dumpsys wifi | grep ...\"` check")
+
+ def test_the_bare_owner_list_cannot_tell_which_network_is_in_use(self):
+ # Why the check needs more than the owners: both units print the same lines.
+ bare = "cname=[^ ]*"
+ self.assertEqual(grep_o(bare, dumpsys(True)), grep_o(bare, dumpsys(False)))
+
+ def test_every_check_in_the_readme_names_the_owner_of_the_network_in_use(self):
+ for pattern in self.patterns:
+ with self.subTest(pattern=pattern):
+ self.assertEqual(SYSTEM, owner_in_use(grep_o(pattern, dumpsys(True))),
+ "on the contributor's unit the check must show the system-owned network in use")
+ self.assertEqual(SETUP, owner_in_use(grep_o(pattern, dumpsys(False))),
+ "on a unit on setupwraith's network the check must show setupwraith in use")
+
+ def test_the_check_prints_no_network_names(self):
+ # Owners post their output in issues; the check should not carry the SSIDs along.
+ for pattern in self.patterns:
+ with self.subTest(pattern=pattern):
+ output = "\n".join(grep_o(pattern, dumpsys(True)))
+ self.assertNotIn("Home", output)
+ self.assertNotIn("Hotspot", output)
+
+ def test_the_override_stays_tied_to_ethernet_or_a_system_owned_connection(self):
+ text = re.sub(r"\s+", " ", setupwraith_section())
+ self.assertIn("only on Ethernet", text)
+ self.assertIn("`android.uid.system`", text)
+ self.assertIn("Currently Connected: true", text)
+
+ def test_the_header_points_to_the_connected_network_check(self):
+ text = re.sub(r"#\s*", " ", header())
+ text = re.sub(r"\s+", " ", text)
+ self.assertIn("Currently Connected", text)
+ self.assertIn("network in use", text)
+
+ def test_the_apply_line_still_leaves_the_override_out(self):
+ blocks = apply_blocks(LIST)
+ self.assertEqual(1, len(blocks))
+ self.assertIsNone(OVERRIDE.search(" ".join(blocks[0][1])))
+
+
+if __name__ == "__main__":
+ unittest.main()