Skip to content

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

Safety: keep the stock launcher that owns Home while setupwraith stays enabled (#1573)

Gathin236ffa7fa5df7c
diff --git a/README.md b/README.md
index 5b256d907..92a40a7ab 100644
--- a/README.md
+++ b/README.md
@@ -567,7 +567,9 @@ in `KNOWN_STOCK_LAUNCHERS`: `com.google.android.tvlauncher`, `com.google.android
contains the app that owns Home and no other app on the TV answers HOME, it skips that entry, says
why, and disables the rest of the list. The setup wizard, the settings apps, a vendor `FallbackHome`
and factory-test apps (Xiaomi's `com.duokan.factorytest`) answer HOME too and don't count. So a list applied before the launcher handover cannot leave
-the TV with nothing to start. Run the same list again once `launcher/build-and-install.sh` has made
+the TV with nothing to start. On Google TV it also keeps the owner while setupwraith answers HOME and
+stays enabled (not listed, or kept for the Wi-Fi network): setupwraith answers ahead of an installed
+launcher that is not Home yet, so it would take Home. Run the same list again once `launcher/build-and-install.sh` has made
the new launcher Home and the entry is applied; `FORCE_HOME=1` (`$env:FORCE_HOME`) disables it anyway.
</details>
diff --git a/tests/test_drift_check.py b/tests/test_drift_check.py
index 924a160fa..922102a99 100644
--- a/tests/test_drift_check.py
+++ b/tests/test_drift_check.py
@@ -81,7 +81,10 @@ def apply(command):
if name not in state["disabled"] and name not in state.get("pinned", []):
state["disabled"].append(name)
elif command.startswith("cmd package set-home-activity --user 0 "):
- state["home"] = command.split()[-1]
+ # Some firmware answers the switch and keeps Home where it was (the Chromecast with Google TV
+ # 4K list records it); home_locked plays that firmware.
+ if not state.get("home_locked"):
+ state["home"] = command.split()[-1]
save()
diff --git a/tests/test_home_guard.py b/tests/test_home_guard.py
index b14b981fe..fa7b74ead 100644
--- a/tests/test_home_guard.py
+++ b/tests/test_home_guard.py
@@ -66,6 +66,9 @@ def answer(command):
return (state["home"] or "") + "\n"
if command.startswith("dumpsys activity"):
return state.get("home_process", "")
+ # The Wi-Fi guard asks which app owns the saved networks (tests/test_setupwraith_home_guard.py).
+ if command.startswith("dumpsys wifi"):
+ return state.get("wifi", "")
if command.startswith("settings get global "):
return "null\n"
return ""
diff --git a/tests/test_setupwraith_home_guard.py b/tests/test_setupwraith_home_guard.py
new file mode 100644
index 000000000..118962a3d
--- /dev/null
+++ b/tests/test_setupwraith_home_guard.py
@@ -0,0 +1,192 @@
+"""The scripts do not disable the stock launcher that owns Home while setupwraith stays enabled (#1573).
+
+On Google TV, setupwraith's `.RecoveryActivity` answers HOME ahead of an installed launcher: on a
+Chromecast with Google TV 4K (Google TV 14, UTTC.250917.004) launcherx answers at priority 2,
+setupwraith at 1 and com.gathin.tvhome at 0. With launcherx disabled and setupwraith left on, Home goes
+to the RecoveryActivity, the black screen system_server crash-loops on (docs/TROUBLESHOOTING.md).
+
+disable.sh and disable.ps1 reached that state: the Wi-Fi guard kept setupwraith because it owned the
+saved network, and the Home guard let launcherx go because com.gathin.tvhome was installed, although it
+was not Home (build-and-install.sh rolls back when set-home-activity does not take, which that
+Chromecast's list records). Now, when Home's owner is listed and setupwraith answers HOME and stays
+enabled, the owner is skipped too, with FORCE_HOME=1 as the override, as for the rest of the Home
+guard. A launcher that already owns Home is not touched by this (examples/prismplus-q65-ultra-r10g
+disables launcherx and keeps setupwraith on once com.gathin.tvhome is Home).
+
+check.py --fix had the same gap: when set-home-activity did not take it went on to disable the packages
+that came back, launcherx included, although its own comment says a Home that cannot be fixed stops
+the run first. It now stops there. It also refuses a launcher argument that the list disables or that
+is no launcher: `--fix <list> com.google.android.tungsten.setupwraith` set Home to the
+RecoveryActivity and called it fixed.
+
+The disable cases borrow the fake TV of tests/test_home_guard.py and the check.py cases the one of
+tests/test_drift_check.py. The PowerShell cases need `pwsh` on PATH and skip without it; CI's Ubuntu
+runner has it.
+
+Run from the repository root: python3 -m unittest discover -s tests -v
+"""
+import sys
+import unittest
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parent))
+import test_drift_check as drift # noqa: E402
+import test_home_guard as guard # noqa: E402
+
+SETUP = "com.google.android.tungsten.setupwraith"
+LAUNCHERX = "com.google.android.apps.tv.launcherx"
+CUSTOM = "com.gathin.tvhome"
+RECOVERY = f"{SETUP}/.RecoveryActivity"
+SETTINGS_FALLBACK = "com.android.tv.settings/.system.FallbackHome"
+LAUNCHERX_HOME = f"{LAUNCHERX}/.home.HomeActivity"
+# The Chromecast's HOME claimants, in its order.
+CLAIMS = [LAUNCHERX_HOME, RECOVERY, f"{CUSTOM}/.MainActivity", SETTINGS_FALLBACK]
+WIFI_SETUP = f" cuid=10031 cname={SETUP}:10031 allowAutojoin=true"
+WIFI_SYSTEM = " cuid=1000 cname=android.uid.system:1000 allowAutojoin=true"
+
+
+class DisableKeepsTheOwnerWhileSetupwraithStays(unittest.TestCase):
+ setUp = guard.HomeGuardTest.setUp
+ write_list = guard.HomeGuardTest.write_list
+ disable = guard.HomeGuardTest.disable
+ entries = guard.HomeGuardTest.entries
+ output = guard.HomeGuardTest.output
+
+ def tv(self, **overrides):
+ state = dict(installed=["com.example.ads", SETUP, LAUNCHERX, CUSTOM, "com.android.tv.settings"],
+ home=LAUNCHERX_HOME, claims=CLAIMS, wifi=WIFI_SETUP)
+ state.update(overrides)
+ guard.HomeGuardTest.tv(self, **state)
+
+ def said(self, result):
+ return " ".join(self.output(result).split())
+
+ def test_the_issue_case_keeps_both(self):
+ # The list names both; the Wi-Fi guard keeps setupwraith, so launcherx has to stay too.
+ self.write_list([SETUP, LAUNCHERX, "com.example.ads"])
+ for entry in self.entries():
+ with self.subTest(entry=entry):
+ self.tv()
+ result, sent = self.disable(entry)
+ self.assertEqual(result.returncode, 0, self.output(result))
+ self.assertNotIn(f"pm disable-user --user 0 {LAUNCHERX}", sent)
+ self.assertNotIn(f"pm disable-user --user 0 {SETUP}", sent)
+ self.assertIn("pm disable-user --user 0 com.example.ads", sent)
+ said = self.said(result)
+ self.assertIn(f"Skipping {LAUNCHERX}: it owns Home, and {SETUP} stays enabled", said)
+ self.assertIn("RecoveryActivity", said)
+ self.assertIn("FORCE_HOME=1", said)
+
+ def test_an_unlisted_setupwraith_keeps_the_owner_too(self):
+ self.write_list([LAUNCHERX, "com.example.ads"])
+ for entry in self.entries():
+ with self.subTest(entry=entry):
+ self.tv()
+ result, sent = self.disable(entry)
+ self.assertEqual(result.returncode, 0, self.output(result))
+ self.assertNotIn(f"pm disable-user --user 0 {LAUNCHERX}", sent)
+ self.assertIn(f"Skipping {LAUNCHERX}", self.said(result))
+
+ def test_force_home_disables_the_owner(self):
+ self.write_list([SETUP, LAUNCHERX, "com.example.ads"])
+ for entry in self.entries():
+ with self.subTest(entry=entry):
+ self.tv()
+ result, sent = self.disable(entry, {"FORCE_HOME": "1"})
+ self.assertEqual(result.returncode, 0, self.output(result))
+ self.assertIn(f"pm disable-user --user 0 {LAUNCHERX}", sent)
+ self.assertNotIn(f"pm disable-user --user 0 {SETUP}", sent,
+ "FORCE_HOME is not FORCE_SETUPWRAITH: the Wi-Fi guard still holds")
+
+ def test_setupwraith_disabled_in_the_same_run_lets_the_owner_go(self):
+ # The system owns the saved network, so setupwraith goes with launcherx and cannot take Home.
+ self.write_list([SETUP, LAUNCHERX, "com.example.ads"])
+ for entry in self.entries():
+ with self.subTest(entry=entry):
+ self.tv(wifi=WIFI_SYSTEM)
+ result, sent = self.disable(entry)
+ self.assertEqual(result.returncode, 0, self.output(result))
+ self.assertIn(f"pm disable-user --user 0 {SETUP}", sent)
+ self.assertIn(f"pm disable-user --user 0 {LAUNCHERX}", sent)
+
+ def test_a_launcher_that_owns_home_lets_the_list_disable_launcherx(self):
+ # examples/prismplus-q65-ultra-r10g: com.gathin.tvhome is Home, setupwraith stays on, and the
+ # list disables launcherx. Home's owner is not listed, so this guard has nothing to say.
+ self.write_list([LAUNCHERX, "com.example.ads"])
+ for entry in self.entries():
+ with self.subTest(entry=entry):
+ self.tv(home=f"{CUSTOM}/.MainActivity")
+ result, sent = self.disable(entry)
+ self.assertEqual(result.returncode, 0, self.output(result))
+ self.assertIn(f"pm disable-user --user 0 {LAUNCHERX}", sent)
+ self.assertNotIn("RecoveryActivity", self.said(result))
+
+ def test_without_setupwraith_answering_home_another_launcher_still_counts(self):
+ # Android TV without setupwraith (or with it disabled already): the guard is what it was.
+ self.write_list([LAUNCHERX, "com.example.ads"])
+ for entry in self.entries():
+ with self.subTest(entry=entry):
+ self.tv(claims=[LAUNCHERX_HOME, f"{CUSTOM}/.MainActivity", SETTINGS_FALLBACK])
+ result, sent = self.disable(entry)
+ self.assertEqual(result.returncode, 0, self.output(result))
+ self.assertIn(f"pm disable-user --user 0 {LAUNCHERX}", sent)
+
+
+class CheckFixKeepsHomeWhileSetupwraithStays(unittest.TestCase):
+ setUp = drift.DriftCheckTest.setUp
+ write_list = drift.DriftCheckTest.write_list
+ run_check = drift.DriftCheckTest.run_check
+ sent = drift.DriftCheckTest.sent
+
+ def tv(self, **overrides):
+ state = dict(installed=["com.example.music", SETUP, LAUNCHERX, CUSTOM],
+ disabled=["com.example.music"], home=LAUNCHERX_HOME,
+ home_activities=CLAIMS, wifi=WIFI_SETUP)
+ state.update(overrides)
+ drift.DriftCheckTest.tv(self, **state)
+
+ def test_a_home_switch_that_does_not_take_stops_before_anything_is_disabled(self):
+ # The issue's run: an update turned both back on, setupwraith owns the Wi-Fi network, and the
+ # switch to com.gathin.tvhome does not take. Disabling launcherx then left Home to the
+ # RecoveryActivity.
+ self.write_list([SETUP, LAUNCHERX, "com.example.music"])
+ self.tv(home_locked=True)
+ result = self.run_check("--fix", str(self.list_path))
+ self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
+ self.assertIn("nothing was disabled", result.stdout)
+ self.assertEqual(self.sent(), [f"cmd package set-home-activity --user 0 {CUSTOM}/.MainActivity"])
+
+ def test_a_home_switch_that_takes_lets_launcherx_go(self):
+ # With Home on com.gathin.tvhome, launcherx can go; setupwraith stays for the Wi-Fi network.
+ self.write_list([SETUP, LAUNCHERX, "com.example.music"])
+ self.tv()
+ result = self.run_check("--fix", str(self.list_path))
+ self.assertEqual(result.returncode, 1, result.stdout + result.stderr) # setupwraith left on
+ self.assertIn(f"Home: set to {CUSTOM}/.MainActivity", result.stdout)
+ self.assertIn(f"leaving {SETUP} on", result.stdout)
+ self.assertIn(f"pm disable-user --user 0 {LAUNCHERX}", self.sent())
+ self.assertNotIn(f"pm disable-user --user 0 {SETUP}", self.sent())
+
+ def test_a_launcher_argument_the_list_disables_is_refused(self):
+ self.write_list([LAUNCHERX, "com.example.music"])
+ self.tv()
+ for args in (("--fix", str(self.list_path), LAUNCHERX), (str(self.list_path), LAUNCHERX)):
+ with self.subTest(args=args):
+ result = self.run_check(*args)
+ self.assertEqual(result.returncode, 2, result.stdout + result.stderr)
+ self.assertIn("this list disables it", result.stderr)
+ self.assertEqual(self.sent(), [])
+
+ def test_a_launcher_argument_that_is_no_launcher_is_refused(self):
+ self.write_list(["com.example.music"])
+ self.tv()
+ for preferred in (SETUP, "com.android.tv.settings", "com.duokan.factorytest"):
+ with self.subTest(preferred=preferred):
+ result = self.run_check("--fix", str(self.list_path), preferred)
+ self.assertEqual(result.returncode, 2, result.stdout + result.stderr)
+ self.assertIn("without being a launcher", result.stderr)
+ self.assertEqual(self.sent(), [])
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/check.py b/tools/check.py
index 42a0ab773..d26f9e9d4 100644
--- a/tools/check.py
+++ b/tools/check.py
@@ -98,7 +98,9 @@ def launcher_to_use(dev, listed, preferred=None):
if preferred:
if not recovery.PACKAGE_RE.fullmatch(preferred):
raise SystemExit(f"not a package name: {preferred!r}")
- match = [c for c in home_activities(dev) if home_of(c) == preferred]
+ # A package can register a FallbackHome next to its real Home; only the real one will do.
+ match = [c for c in home_activities(dev)
+ if home_of(c) == preferred and not FALLBACK_HOME_RE.search(c)]
if not match:
raise SystemExit(f"{preferred} has no HOME activity on this TV: is the launcher "
f"installed? (launcher/build-and-install.sh)")
@@ -272,11 +274,13 @@ def fix(dev, listed, back_on, home_drifted, preferred):
recovery.shell(dev, f"cmd package set-home-activity --user 0 {target}")
home = recovery.query_home(dev)
if home != target:
+ # Stop here, as the comment above says: Home is still on what it was, which may be a
+ # package this list disables, and disabling it now leaves the TV with setupwraith's
+ # RecoveryActivity or a placeholder for Home (#1573).
print(f"Home: asked for {target} but the TV still resolves {home or 'nothing'}; "
- f"reboot it and check again")
- failed = True
- else:
- print(f"Home: set to {target}")
+ f"nothing was disabled. Reboot it and check again")
+ return 1
+ print(f"Home: set to {target}")
left_on = []
if back_on:
left_on = safety_checks(dev, back_on)
@@ -350,6 +354,19 @@ def main():
# out: read_list stops with a message, which Python turns into exit 1.
sys.stderr.write(f"{e}. Nothing was checked or changed.\n")
return 2
+ # The launcher argument has to be a Home the TV can stay on: not one this list disables (--fix would
+ # set Home to it and then disable it), and none of what answers HOME without being a launcher. With
+ # `check.py --fix <list> com.google.android.tungsten.setupwraith`, --fix set Home to setupwraith's
+ # RecoveryActivity and called it fixed (#1573).
+ if preferred and (preferred in listed or preferred in NOT_LAUNCHERS
+ or FACTORY_HOME_RE.search(preferred)):
+ why = ("this list disables it" if preferred in listed else
+ "it answers Home without being a launcher (a setup wizard, a settings app or a "
+ "factory test)")
+ sys.stderr.write(f"check.py: {preferred} cannot be the launcher Home is on: {why}. Pass the "
+ f"launcher Home should stay on, or no launcher at all. Nothing was checked "
+ f"or changed.\n")
+ return 2
core = recovery.core_packages(listed)
if core:
# The same refusal as disable.sh: --fix would disable these again (#884).
diff --git a/tools/disable.ps1 b/tools/disable.ps1
index 72c09302d..da4edb6be 100644
--- a/tools/disable.ps1
+++ b/tools/disable.ps1
@@ -113,7 +113,9 @@ function Read-HomeLaunchers {
# Nor is a factory-test app (com.duokan.factorytest/.FactoryLauncher answers HOME on a Mi TV 4A).
$usable = @($parsed | Where-Object { $_.Cls -notmatch 'FallbackHome$' -and $notLaunchers -notcontains $_.Pkg -and $_.Pkg -notmatch 'factorytest|factory_test|factorymode' } |
ForEach-Object { $_.Pkg } | Sort-Object -Unique)
- [pscustomobject]@{ Ok = ($answered -and $parsed.Count -gt 0); Launchers = $usable }
+ # Whether setupwraith answers HOME, for the check below (#1573).
+ $setupAnswers = @($parsed | Where-Object { $_.Pkg -eq $setup }).Count -gt 0
+ [pscustomobject]@{ Ok = ($answered -and $parsed.Count -gt 0); Launchers = $usable; SetupAnswers = $setupAnswers }
}
if (-not $forceHome -and $pkgs.Count -gt 0) {
$homeQuery = 'cmd package resolve-activity --brief -a android.intent.action.MAIN -c android.intent.category.HOME'
@@ -145,6 +147,12 @@ if (-not $forceHome -and $pkgs.Count -gt 0) {
if (-not $found.Ok -or $others.Count -eq 0) {
Write-Warning "Skipping ${homePkg}: it owns Home, and no other app that can answer Home is installed and staying enabled. Make the new launcher Home first (launcher\build-and-install.ps1), then run this list again to disable the old one; or set `$env:FORCE_HOME=1 if you can still reach the TV."
$pkgs = @($pkgs | Where-Object { $_ -ne $homePkg })
+ } elseif ($found.SetupAnswers -and $pkgs -notcontains $setup) {
+ # Same as disable.sh (#1573): setupwraith answers HOME ahead of an installed launcher and
+ # stays enabled (not listed, or skipped above for the Wi-Fi network), so with the owner
+ # disabled Home goes to its RecoveryActivity, not to the other launcher.
+ Write-Warning "Skipping ${homePkg}: it owns Home, and $setup stays enabled and answers Home ahead of the other launchers here, so with $homePkg disabled Home would go to its RecoveryActivity, the black screen system_server can crash-loop on (docs\TROUBLESHOOTING.md). Make the new launcher Home first (launcher\build-and-install.ps1), or disable setupwraith in the same run (if it was skipped for the Wi-Fi network, forget the network and join it again in Settings > Network & Internet), then run this list again; or set `$env:FORCE_HOME=1 if you can still reach the TV."
+ $pkgs = @($pkgs | Where-Object { $_ -ne $homePkg })
}
}
} else {
diff --git a/tools/disable.sh b/tools/disable.sh
index c6505bce7..ec4bb1c4d 100755
--- a/tools/disable.sh
+++ b/tools/disable.sh
@@ -118,15 +118,24 @@ drop_pkg() { PKGS="$(printf '%s\n' "$PKGS" | grep -vxF "$1" || true)"; }
# a placeholder the firmware shows when no launcher is enabled, not a home the viewer can use.
# Nor does a factory-test app: on a Xiaomi Mi TV 4A com.duokan.factorytest/.FactoryLauncher answers
# HOME, and handing Home to it leaves the viewer on the factory test screen.
-home_launchers() {
+# home_claims prints every HOME component as package/activity; home_launchers keeps the launchers.
+home_claims() {
local raw claims
raw=$("$PY" -I tools/tv.py "$CLAIM_QUERY" 2>/dev/null) || return 1
claims=$(printf '%s\n' "$raw" | tr -d '\r' | grep -oE '^ *[A-Za-z0-9_.]+/[A-Za-z0-9_.$]+' | sed -E 's/^ +//' | sort -u || true)
[ -n "$claims" ] || return 1
- printf '%s\n' "$claims" | grep -vE '/[^ ]*FallbackHome$' | cut -d/ -f1 | sort -u \
+ printf '%s\n' "$claims"
+}
+launchers_in() {
+ printf '%s\n' "$1" | grep -vE '/[^ ]*FallbackHome$' | cut -d/ -f1 | sort -u \
| grep -viE 'factorytest|factory_test|factorymode' \
| grep -vxF -e com.google.android.tungsten.setupwraith -e com.android.tv.settings -e com.android.settings -e com.android.provision || true
}
+home_launchers() {
+ local claims
+ claims=$(home_claims) || return 1
+ launchers_in "$claims"
+}
HOME_PKG=""
HOME_CHOOSER=""
if [ -z "${FORCE_HOME:-}" ] && [ -n "$PKGS" ]; then
@@ -156,13 +165,34 @@ if [ -z "${FORCE_HOME:-}" ] && [ -n "$PKGS" ]; then
if printf '%s\n' "$PKGS" | grep -xF "$HOME_PKG" >/dev/null; then
# Nothing left to answer Home once the list is applied, or the TV could not say who does: either
# way the owner is the only Home this run knows about, so it stays enabled.
- LAUNCHERS=$(home_launchers || true)
+ CLAIMS=$(home_claims || true)
+ LAUNCHERS=$(launchers_in "$CLAIMS")
OTHERS=$(printf '%s\n' "$LAUNCHERS" | sed '/^$/d' | grep -vxF "$HOME_PKG" | grep -vxF "$PKGS" || true)
+ # Another launcher is not enough while setupwraith answers HOME and stays enabled (not listed, or
+ # skipped above for the Wi-Fi network): on Google TV its .RecoveryActivity answers ahead of an
+ # installed launcher (priority 1 against 0 on a Chromecast with Google TV 4K), so with the owner
+ # disabled Home goes to it, not to the launcher that is merely installed (#1573). A launcher that
+ # already owns Home is a different case: the owner is then not the stock launcher this guards.
+ # grep without -q: an early exit could SIGPIPE printf and fail open under pipefail (see above).
+ SETUP_HOME=""
+ if printf '%s\n' "$CLAIMS" | grep -F "$SETUP/" >/dev/null \
+ && ! printf '%s\n' "$PKGS" | grep -xF "$SETUP" >/dev/null; then
+ SETUP_HOME=1
+ fi
if [ -z "$OTHERS" ]; then
echo "Skipping $HOME_PKG: it owns Home, and no other app that can answer Home is installed and" >&2
echo "staying enabled. Make the new launcher Home first (launcher/build-and-install.sh), then run" >&2
echo "this list again to disable the old one; or set FORCE_HOME=1 if you can still reach the TV." >&2
drop_pkg "$HOME_PKG"
+ elif [ -n "$SETUP_HOME" ]; then
+ echo "Skipping $HOME_PKG: it owns Home, and $SETUP stays enabled and answers Home" >&2
+ echo "ahead of the other launchers here, so with $HOME_PKG disabled Home would go to its" >&2
+ echo "RecoveryActivity, the black screen system_server can crash-loop on (docs/TROUBLESHOOTING.md)." >&2
+ echo "Make the new launcher Home first (launcher/build-and-install.sh), or disable setupwraith in" >&2
+ echo "the same run (if it was skipped for the Wi-Fi network, forget the network and join it again" >&2
+ echo "in Settings > Network & Internet), then run this list again; or set FORCE_HOME=1 if you can" >&2
+ echo "still reach the TV." >&2
+ drop_pkg "$HOME_PKG"
fi
fi
else