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
setupwraith: warn and guard against deleting Wi-Fi saved during setup
מקס חיים73feb98d855b
diff --git a/PROMPT.md b/PROMPT.mdindex 9faec58c9..685c55f55 100644--- a/PROMPT.md+++ b/PROMPT.md@@ -67,7 +67,10 @@ Launcherandroid.intent.category.HOME` and set the default with `cmd package set-home-activity`.- Before disabling the stock launcher, check which other apps claim HOME: on Google TV the setup wizard(`com.google.android.tungsten.setupwraith`) takes over even after the stock launcher is disabled, and- the matching `examples/` header says what to do.+ the matching `examples/` header says what to do. Before disabling setupwraith, run+ `dumpsys wifi | grep -o 'cname=[^ ]*'`: a Wi-Fi network saved during first setup belongs to it, and+ Android deletes that network the moment it is disabled, which takes the TV off Wi-Fi and ADB. If it+ does, ask me to forget the network and re-join it in Settings first.- On Android 11 and newer the launcher must declare `<queries>` for `android.intent.category.LEANBACK_LAUNCHER`,or package visibility silently hides every app and the grid comes up empty; target a recent SDK, someGoogle TV 14 sets refuse older targets at install.diff --git a/README.md b/README.mdindex 6d01fbc8c..55d70c9eb 100644--- a/README.md+++ b/README.md@@ -243,7 +243,7 @@ three that matter most:- **macOS blocks `adb connect`** ("No route to host") under Local Network privacy. `tools/tv.py` avoids the binary.- **Disable the stock launcher only after the new one is installed and running**, or Home lands on a factory test app. The install script orders this for you.-- **On Google TV the setup wizard** (`com.google.android.tungsten.setupwraith`) can take Home and crash-loop the system after the stock launcher is disabled. Disable it too, and list it in your `debloat.txt` so restore brings it back. Stuck already? `tools/tv.py 'pm enable --user 0 com.google.android.apps.tv.launcherx'`.+- **On Google TV the setup wizard** (`com.google.android.tungsten.setupwraith`) can take Home and crash-loop the system after the stock launcher is disabled. Disable it too, and list it in your `debloat.txt` so restore brings it back. But check `dumpsys wifi | grep -o 'cname=[^ ]*'` first: if the Wi-Fi network was saved during setup it belongs to setupwraith, and disabling it deletes the network (re-join it in Settings first; `tools/disable.sh` skips setupwraith until you do). Stuck already? `tools/tv.py 'pm enable --user 0 com.google.android.apps.tv.launcherx'`.## Questions people askdiff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex 3c11674d7..539b9e321 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -55,6 +55,15 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/`com.google.android.tungsten.setupwraith` package is what frees the slot. It is the first-runsetup wizard, so everyday use is unaffected, but re-enable it before a factory reset - list it inyour `debloat.txt` and `tools/restore.sh` does that for you.+- **The TV drops off Wi-Fi for good the moment setupwraith is disabled**, seen on Google TV 14 (Sony+ BRAVIA 9 II, Philips R8G, Skyworth SWTV-24NA-4K NF). A Wi-Fi network saved during the first-run+ wizard belongs to setupwraith, and Android deletes an app's saved networks when the app is disabled.+ The TV is fine but offline, so ADB and the phone remote stop working, and a restart doesn't bring+ the network back. Check before disabling it: `tools/tv.py "dumpsys wifi" | grep -o 'cname=[^ ]*'`.+ If it names setupwraith, forget the network and join it again in Settings > Network & Internet (it+ then belongs to `android.uid.system`), or use Ethernet. `tools/disable.sh` skips setupwraith while it+ owns the network (`FORCE_SETUPWRAITH=1` overrides). Already offline? Rejoin from the TV with its own+ remote or a USB keyboard, then turn Wireless debugging back on if it was in use.- **The TV drops off Wi-Fi every minute right after the install**, seen on Google TV 14 (XiaomiMiTV-MZTU0): the same setupwraith `.RecoveryActivity` took Home and system_server crash-loopedon it. The install script now starts the new launcher before disabling the stock one, sets thediff --git a/tests/test_setupwraith_guard.py b/tests/test_setupwraith_guard.pynew file mode 100644index 000000000..54dd98320--- /dev/null+++ b/tests/test_setupwraith_guard.py@@ -0,0 +1,62 @@+"""tools/disable.sh must not disable setupwraith while it owns the saved Wi-Fi network.++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]+SETUP = "com.google.android.tungsten.setupwraith"+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):+ 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 `dumpsys wifi` with the given owner, records --batch input.+ client.write_text(+ '#!/bin/sh\n'+ 'case "$*" in\n'+ f' *dumpsys*) echo " cuid=10031 cname={wifi_owner} allowAutojoin=true" ;;\n'+ ' *) 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), **(extra_env or {}))+ result = subprocess.run(["bash", str(tools / "disable.sh"), "debloat.txt"], cwd=repo,+ env=env, capture_output=True, text=True)+ self.assertEqual(result.returncode, 0, result.stderr)+ return capture.read_text().splitlines(), result.stderr++ def test_skipped_when_it_owns_wifi(self):+ commands, stderr = self.run_disable(f"{SETUP}:10031")+ self.assertNotIn(f"pm disable-user --user 0 {SETUP}", commands)+ self.assertEqual(commands[:2], ["pm disable-user --user 0 com.example.before",+ "pm disable-user --user 0 com.example.after"])+ self.assertIn("Skipping", stderr)++ def test_disabled_when_system_owns_wifi(self):+ commands, _ = self.run_disable("android.uid.system:1000")+ self.assertEqual(commands[:3], ["pm disable-user --user 0 com.example.before",+ f"pm disable-user --user 0 {SETUP}",+ "pm disable-user --user 0 com.example.after"])++ def test_force(self):+ commands, _ = self.run_disable(f"{SETUP}:10031", {"FORCE_SETUPWRAITH": "1"})+ self.assertIn(f"pm disable-user --user 0 {SETUP}", commands)+++if __name__ == "__main__":+ unittest.main()diff --git a/tools/disable.sh b/tools/disable.shindex cf6b22e20..b6fc67673 100755--- a/tools/disable.sh+++ b/tools/disable.sh@@ -13,7 +13,24 @@ PY=tools/venv/bin/python[ -x "$PY" ] || PY=tools/venv/Scripts/python.exeexport MSYS_NO_PATHCONV=1[ -x "$PY" ] || { echo "run: python3 -m venv tools/venv && tools/venv/bin/pip install -r tools/requirements.txt"; exit 1; }+PACKAGES="$(grep -vE '^\s*(#|$)' "$LIST" | sed -E 's/\s+#.*$//' | awk '{print $1}')"++# A Wi-Fi network saved during the first-run wizard belongs to setupwraith, and Android deletes it the+# moment setupwraith is disabled: the TV drops off Wi-Fi, and ADB and the phone remote go with it.+# Skip it until the network has been forgotten and re-joined in Settings (it then belongs to+# android.uid.system). FORCE_SETUPWRAITH=1 disables it anyway, e.g. on Ethernet.+SETUP=com.google.android.tungsten.setupwraith+if grep -qx "$SETUP" <<<"$PACKAGES" && [ -z "${FORCE_SETUPWRAITH:-}" ]; then+ WIFI="$("$PY" -I tools/tv.py "dumpsys wifi" || true)"+ if grep -o 'cname=[^ ]*' <<<"$WIFI" | grep -q setupwraith; then+ echo "Skipping $SETUP: the saved Wi-Fi network belongs to it, and disabling it would delete that" >&2+ echo "network and take the TV off Wi-Fi. On the TV, forget the network and join it again in" >&2+ echo "Settings > Network & Internet, then run this again (or set FORCE_SETUPWRAITH=1 on Ethernet)." >&2+ PACKAGES="$(grep -vx "$SETUP" <<<"$PACKAGES" || true)"+ fi+fi+{- grep -vE '^\s*(#|$)' "$LIST" | sed -E 's/\s+#.*$//' | awk '{print "pm disable-user --user 0 " $1}'+ awk 'NF {print "pm disable-user --user 0 " $1}' <<<"$PACKAGES"echo "pm list packages -d"} | "$PY" -I tools/tv.py --batch