Skip to content

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

fix(disable): run the Home guard on firmware without cmd package

xbsheng97d31fbc5573
diff --git a/PROMPT.md b/PROMPT.md
index 9b192574b..6e817df77 100644
--- a/PROMPT.md
+++ b/PROMPT.md
@@ -94,7 +94,10 @@ Launcher
ro.build.version.sdk'` against `grep minSdk launcher/app/build.gradle` (26 = Android 8.0). A set
below it answers `INSTALL_FAILED_OLDER_SDK`; lowering `minSdk` is a source change you would then
maintain yourself, and an APK rebuilt elsewhere is nothing this repo can verify. On those sets offer
- the debloat half and say the launcher cannot be installed.
+ the debloat half and say the launcher cannot be installed. With no launcher to hand over to, the
+ stock one stays: `cmd package` does not exist before Android 7, so `tools/disable.sh` asks `dumpsys
+ activity` for Home there and warns when neither answers - that warning means nothing was checked,
+ and a set with no recovery has no way back (#795).
- Don't install a third-party launcher that charges for basics like wallpapers. Build a small native
Android TV launcher instead (Java, AndroidX RecyclerView, minSdk matching the TV, debug build is fine),
install it over ADB, set it as the default home and disable the stock launcher. If several apps claim
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index 3f94df06a..8d5401060 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -152,6 +152,24 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/
nothing else on the TV answers HOME, it skips that entry and says so (`FORCE_HOME=1` overrides),
so applying a list before the handover no longer leaves the TV without a launcher. Apply the list
again after the install script has made the new launcher Home to disable the old one.
+- **The TV stays on the boot logo with ADB gone** after a list, seen on a KitKat-era set
+ ([COOP COTV-0001](https://github.com/Gathin23/cleanyourtv/issues/795): Realtek `rtd298x`, Android
+ 4.4.2, SDK 19). 17 packages were disabled over Ethernet ADB, each answered `new state:
+ disabled-user` and `pm list packages -d` read back all 17; the factory launcher
+ `com.haiersoft.launcherproject2995hk` was among them with no replacement, because the launcher
+ here needs Android 8.0. After the power cycle the set sits on the green robot and `INICIALIZANDO`,
+ port 5555 goes from filtered to "No route to host", and there is no recovery button, no service
+ port and no public firmware for that board, so `tools/restore.sh` cannot run. What is *not* known:
+ whether the disabled packages did it, whether pulling the plug during the first boot damaged
+ something, or whether that firmware just needs a long first boot after package state changes.
+ Treat it as how these sets get lost rather than as a diagnosis, and on a set that cannot take the
+ launcher: leave the stock launcher alone, keep ADB on Ethernet (KitKat has no network-debugging
+ toggle, and Wi-Fi closed 5555 on this one), and apply the list in batches with a reboot between
+ them. `tools/disable.sh` skips Home's owner when it can name it; since
+ [#795](https://github.com/Gathin23/cleanyourtv/issues/795) it asks `dumpsys activity` when `cmd
+ package` is missing (Android 6 and older, where that command does not exist) and warns when
+ neither answers. That warning means the guard did not run, not that the list is safe. Nothing here
+ brings such a set back - a vendor recovery image does, if one exists.
- **China-market Xiaomi rejects a default Home despite `set-home-activity` reporting success**,
verified on MiTV-AETP0 (dofus), Android 9, firmware 22.9.2.851: the framework filters third-party
HOME candidates by a package-name allowlist. Disabling the stock launcher then selects
diff --git a/tests/test_home_guard.py b/tests/test_home_guard.py
index 7b8a11f7e..5aa6c804d 100644
--- a/tests/test_home_guard.py
+++ b/tests/test_home_guard.py
@@ -59,6 +59,8 @@ def answer(command):
if state["home_fails"]:
sys.exit(1)
return (state["home"] or "") + "\n"
+ if command.startswith("dumpsys activity"):
+ return state.get("home_process", "")
if command.startswith("settings get global "):
return "null\n"
return ""
@@ -132,6 +134,7 @@ class HomeGuardTest(unittest.TestCase):
"claims": [STOCK],
"home_fails": False,
"claims_fail": False,
+ "home_process": "",
"commands": [],
}
state.update(overrides)
@@ -229,6 +232,32 @@ class HomeGuardTest(unittest.TestCase):
self.assertEqual(result.returncode, 0, self.output(result))
self.assertNotIn(f"pm disable-user --user 0 {STOCK}", sent)
+ def test_a_firmware_without_cmd_package_still_finds_home(self):
+ # `cmd` arrived with Android 7. On a KitKat set the query answers the shell's own error, and the
+ # guard used to be skipped in silence while the list went on to disable the only Home (#795).
+ # The framework has printed the package holding Home since 4.x: `dumpsys activity` says
+ # "mHomeProcess: ProcessRecord{52f4a5c8 2f4b:com.google.android.tvlauncher/u0a56}".
+ for entry in self.entries():
+ with self.subTest(entry=entry):
+ self.tv(home="/system/bin/sh: cmd: not found",
+ home_process=" mHomeProcess: ProcessRecord{52f4a5c8 2f4b:"
+ + STOCK + "/u0a56}")
+ result, sent = self.disable(entry)
+ self.assertEqual(result.returncode, 0, self.output(result))
+ self.assertNotIn(f"pm disable-user --user 0 {STOCK}", sent,
+ "Home was readable from dumpsys, so the guard must still run")
+ self.assertIn(f"Skipping {STOCK}", self.output(result))
+
+ def test_a_tv_that_cannot_name_its_home_is_told_so(self):
+ # Neither query names Home: the guard cannot check anything, and the run says that instead of
+ # looking like it checked. Silently skipping the guard is what the brick report did not see.
+ for entry in self.entries():
+ with self.subTest(entry=entry):
+ self.tv(home="/system/bin/sh: cmd: not found", home_process="")
+ result, sent = self.disable(entry)
+ self.assertEqual(result.returncode, 0, self.output(result))
+ self.assertIn("Could not tell which app owns Home", self.output(result))
+
def test_force_disables_the_owner(self):
for entry in self.entries():
with self.subTest(entry=entry):
diff --git a/tools/disable.ps1 b/tools/disable.ps1
index 0abb88a97..26cd0cfd2 100644
--- a/tools/disable.ps1
+++ b/tools/disable.ps1
@@ -54,6 +54,17 @@ if (-not $env:FORCE_HOME) {
$homeLine = @(& $py -I (Join-Path $repo 'tools\tv.py') $homeQuery) |
Where-Object { $_ -match '\S' } | Select-Object -Last 1
$homePkg = "$homeLine".Trim() -split '/' | Select-Object -First 1
+ # `cmd` arrived with Android 7 (Nougat): on an older set this query answers nothing, or the shell's
+ # own "cmd: not found", and the guard was skipped without a word (disable.sh, #795). `dumpsys
+ # activity` prints the package holding Home on those sets: mHomeProcess: ProcessRecord{... pkg/u0a56}
+ $named = $homePkg -and ($homePkg -match '^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)+$')
+ if (-not $named) {
+ $fallback = @(& $py -I (Join-Path $repo 'tools\tv.py') 'dumpsys activity' | ForEach-Object {
+ $line = "$_".Trim()
+ if ($line -match 'mHomeProcess:.*[: ]([A-Za-z0-9_.]+)/[A-Za-z0-9_.]+') { $Matches[1] }
+ } | Select-Object -First 1)
+ $homePkg = if ($fallback.Count -gt 0) { "$($fallback[0])" } else { '' }
+ }
if ($homePkg -and ($pkgs -contains $homePkg)) {
# Every package with a HOME activity the TV can start now; a disabled one does not answer.
$claimQuery = 'cmd package query-activities --brief -a android.intent.action.MAIN -c android.intent.category.HOME'
@@ -73,6 +84,10 @@ if (-not $env:FORCE_HOME) {
$pkgs = @($pkgs | Where-Object { $_ -ne $homePkg })
}
}
+ # Neither query named Home, so the guard could not run. Say so (disable.sh, #795).
+ if (-not $homePkg -and $pkgs.Count -gt 0) {
+ Write-Warning 'Could not tell which app owns Home on this TV, so the Home guard did not run: neither "cmd package resolve-activity" (added in Android 7) nor "dumpsys activity" named one. Check by hand that the list does not hold your launcher before running it: the replacement launcher needs Android 8.0 (minSdk 26), so on an older set the stock launcher is the only Home there is, and a set with no recovery has no way back (#795).'
+ }
}
# Same as disable.sh (#321): a package that asks for android.permission.TV_INPUT_HARDWARE is the software
# layer under the HDMI, AV and tuner inputs. Disable one and the port still notices the cable but shows
diff --git a/tools/disable.sh b/tools/disable.sh
index a26f18b54..915dcd181 100755
--- a/tools/disable.sh
+++ b/tools/disable.sh
@@ -61,6 +61,18 @@ ADB_SECURE="$("$PY" -I tools/tv.py "getprop ro.adb.secure" 2>/dev/null | tr -d '
# leaves the TV without a launcher looks before anything is disabled.
HOME_QUERY='cmd package resolve-activity --brief -a android.intent.action.MAIN -c android.intent.category.HOME'
HOME_PKG=$("$PY" -I tools/tv.py "$HOME_QUERY" 2>/dev/null | tail -n 1 | tr -d '\r' | cut -d/ -f1 || true)
+# `cmd` arrived with Android 7 (Nougat): on an older set the query answers nothing, or the shell's own
+# "cmd: not found", and the guard below was skipped without a word - which is how a list disabled the
+# only launcher on a KitKat TV that had no replacement to hand Home over to (#795). Ask the framework
+# instead, which has printed the package holding Home since 4.x:
+# mHomeProcess: ProcessRecord{52f4a5c8 2f4b:com.example.launcher/u0a56}
+# Only a package-shaped answer counts; on a set where Home has not started yet the line says null.
+# grep -c, not -q: under pipefail an early exit could SIGPIPE printf and fail open (see above).
+HOME_SHAPE=$(printf '%s\n' "$HOME_PKG" | grep -cE '^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)+$' || true)
+if [ -n "$PKGS" ] && [ "${HOME_SHAPE:-0}" -eq 0 ]; then
+ HOME_PKG=$("$PY" -I tools/tv.py 'dumpsys activity' 2>/dev/null | tr -d '\r' \
+ | sed -nE 's/.*mHomeProcess:.*[: ]([A-Za-z0-9_.]+)\/[A-Za-z0-9_.]+.*/\1/p' | head -n 1 || true)
+fi
# grep without -q: an early exit could SIGPIPE printf and fail open under pipefail (see above).
if [ -n "$HOME_PKG" ] && printf '%s\n' "$PKGS" | grep -xF "$HOME_PKG" >/dev/null && [ -z "${FORCE_HOME:-}" ]; then
# Every package with a HOME activity the TV can start now: disabled packages do not answer, so this
@@ -84,6 +96,16 @@ if [ -n "$HOME_PKG" ] && printf '%s\n' "$PKGS" | grep -xF "$HOME_PKG" >/dev/null
PKGS="$(printf '%s\n' "$PKGS" | grep -vxF "$HOME_PKG" || true)"
fi
fi
+# Neither query named Home, so the guard above could not run at all. Say so: a silent skip looks
+# exactly like a check that passed, and on a set too old for the launcher there is nothing to lose by
+# keeping every listed package (#795).
+if [ -n "$PKGS" ] && [ -z "$HOME_PKG" ] && [ -z "${FORCE_HOME:-}" ]; then
+ echo "Could not tell which app owns Home on this TV, so the Home guard did not run: neither" >&2
+ echo '"cmd package resolve-activity" (added in Android 7) nor "dumpsys activity" named one.' >&2
+ echo 'Check by hand that the list does not hold your launcher before running it. The replacement' >&2
+ echo 'launcher needs Android 8.0 (minSdk 26), so on an older set the stock launcher is the only Home' >&2
+ echo 'there is: disabled, it leaves nothing to start, and a set with no recovery has no way back (#795).' >&2
+fi
# Only the package's own "requested permissions" block counts: a vendor app in a shared UID would otherwise
# match through its shared user's permissions and be skipped by mistake.