Skip to content

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

Fix for #2615: the Chromecast 4K Cast restart uses am crash and checks the pid survives 30 s

Gathin232c5c7b346483
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index a6c52edc4..1f7a17d86 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -704,10 +704,18 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/
that restarts it (a crash, a force-stop, an update) needs the same sequence. Re-enabling the
wizard is not always enough after a reboot: on a Chromecast with Google TV 4K (`sabrina`,
UTTC.250917.004) no `ClientAuthSigner` line came within 3 minutes and phones did not even list the
- device. Restart the receiver while setupwraith is enabled instead: `am force-stop
- com.google.android.apps.mediashell`, then `am start-foreground-service -n
- com.google.android.apps.mediashell/.CastReceiverService` (after a force-stop nothing starts it
- again), and the signer line and `MdnsAppFilter: Done announcing.` follow within seconds. Reported on Google's
+ device. Restart the receiver while setupwraith is enabled instead: `pm enable
+ com.google.android.tungsten.setupwraith`, `logcat -c`, then `am crash com.google.android.apps.mediashell`.
+ The system starts the receiver again with a new pid, and `Created singleton instance of ClientAuthSigner`
+ follows within seconds. Before trusting that line, check the pid (`pidof
+ com.google.android.apps.mediashell`) is still the same 30 s later, then `pm disable-user --user 0
+ com.google.android.tungsten.setupwraith`; with no `No private key` line after that, casting works
+ ([#2615](https://github.com/Gathin23/cleanyourtv/issues/2615)). Do not restart it with `am force-stop`
+ plus `am start-foreground-service -n com.google.android.apps.mediashell/.CastReceiverService`: started
+ that way the receiver never calls `startForeground()`, Android kills it after 30 s
+ (`ForegroundServiceDidNotStartInTimeException`), and the copy that comes back once setupwraith is off
+ has no credentials, although the killed one had logged the signer line. `am kill` leaves it running
+ with the same pid. Reported on Google's
own Chromecast hardware (`boreal`) and, with the same log lines, on a Google TV Streamer
(`kirkwood`, `UTTK.260317.003`), where the `CastInfoProvider` also lives inside the setupwraith
APK; the Xiaomi Mi Box S 2nd gen list says casting from a Pixel still works there with
diff --git a/examples/google-chromecast-gtv-4k/debloat.txt b/examples/google-chromecast-gtv-4k/debloat.txt
index c0351042f..56941a669 100644
--- a/examples/google-chromecast-gtv-4k/debloat.txt
+++ b/examples/google-chromecast-gtv-4k/debloat.txt
@@ -41,10 +41,16 @@
# holds the credentials in memory, so casting works until the next reboot
# (docs/TROUBLESHOOTING.md, "Casting fails with Untrusted device").
# Seen again after a reboot: re-enabling setupwraith brought no ClientAuthSigner line within 3 minutes
-# and phones did not list the device at all. With setupwraith enabled, restart the receiver instead:
-# am force-stop com.google.android.apps.mediashell
-# am start-foreground-service -n com.google.android.apps.mediashell/.CastReceiverService
-# (nothing starts it again after a force-stop); the signer line follows within seconds.
+# and phones did not list the device at all. Restart the receiver while setupwraith is enabled:
+# pm enable com.google.android.tungsten.setupwraith
+# logcat -c
+# am crash com.google.android.apps.mediashell
+# The system starts it again with a new pid, and "Created singleton instance of ClientAuthSigner"
+# follows within seconds. Check that pid (pidof com.google.android.apps.mediashell) is still the same
+# 30 s later, then: pm disable-user --user 0 com.google.android.tungsten.setupwraith
+# Not am force-stop plus am start-foreground-service: started that way the receiver never calls
+# startForeground(), Android kills it after 30 s, and the copy that comes back with setupwraith
+# already off has no credentials (the signer line came from the killed process) (#2615).
# - Turning USB debugging off leaves Wireless debugging listening on its own port. Switch both off when
# you are done. tools/adb-closed.py checks 5555 unless it is given that port: note the port from
# `adb mdns services` first, and check it with tools/adb-closed.py <ip> <port> before the reboot.
diff --git a/tests/test_sabrina_cast_restart_note.py b/tests/test_sabrina_cast_restart_note.py
index 577decfdc..8b8e2fa7a 100644
--- a/tests/test_sabrina_cast_restart_note.py
+++ b/tests/test_sabrina_cast_restart_note.py
@@ -1,10 +1,13 @@
"""The Chromecast with Google TV 4K notes must keep the receiver restart and the wireless-debugging close.
On `sabrina` (UTTC.250917.004), after a reboot, re-enabling setupwraith alone brought no
-`ClientAuthSigner` line within 3 minutes and phones did not list the device. Force-stopping the
-receiver with setupwraith enabled and starting `CastReceiverService` by hand loaded the credentials in
-seconds. Closing up, turning USB debugging off left the Wireless debugging port open, which
-tools/adb-closed.py does not check.
+`ClientAuthSigner` line within 3 minutes and phones did not list the device. Restarting the receiver
+with setupwraith enabled loads the credentials in seconds, but only `am crash` restarts it for good:
+started by hand with `am start-foreground-service`, `CastReceiverService` never calls
+`startForeground()`, Android kills it 30 s later, and the copy that comes back after setupwraith is off
+has no credentials (#2615). So the notes say `am crash`, and to check the pid survives 30 s before
+disabling setupwraith. Closing up, turning USB debugging off left the Wireless debugging port open,
+which tools/adb-closed.py does not check.
Run from the repository root:
python3 -m unittest discover -s tests -v
@@ -17,7 +20,8 @@ import unittest
ROOT = Path(__file__).resolve().parents[1]
DOC = (ROOT / "docs" / "TROUBLESHOOTING.md").read_text(encoding="utf-8")
EXAMPLE = (ROOT / "examples" / "google-chromecast-gtv-4k" / "debloat.txt").read_text(encoding="utf-8")
-START = "am start-foreground-service -n com.google.android.apps.mediashell/.CastReceiverService"
+CRASH = "am crash com.google.android.apps.mediashell"
+PIDOF = "pidof com.google.android.apps.mediashell"
def bullets(text):
@@ -49,9 +53,13 @@ class SabrinaCastRestartNoteTest(unittest.TestCase):
def test_the_casting_bullet_restarts_the_receiver(self):
casting = bullet_containing("Casting from a phone fails")
self.assertIn("sabrina", casting)
- self.assertIn("am force-stop com.google.android.apps.mediashell", casting)
- self.assertIn(START, casting)
+ self.assertIn(CRASH, casting)
+ self.assertIn(PIDOF, casting)
+ self.assertIn("30 s", casting)
self.assertIn("ClientAuthSigner", casting)
+ # The receiver is restarted before setupwraith goes off again, not after.
+ self.assertLess(casting.index(CRASH),
+ casting.index("pm disable-user --user 0 com.google.android.tungsten.setupwraith"))
def test_the_wireless_bullet_says_to_switch_it_off_separately(self):
wireless = bullet_containing("USB debugging never opens port 5555")
@@ -60,8 +68,10 @@ class SabrinaCastRestartNoteTest(unittest.TestCase):
def test_the_example_header_carries_both(self):
header = "\n".join(l for l in EXAMPLE.splitlines() if l.startswith("#"))
- self.assertIn("am force-stop com.google.android.apps.mediashell", header)
- self.assertIn(START, header)
+ self.assertIn(CRASH, header)
+ self.assertIn(PIDOF, header)
+ # The old restart is only named as the one not to use.
+ self.assertIn("Not am force-stop plus am start-foreground-service", header)
self.assertIn("Wireless debugging", header)