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
Fix for #2398: on Android 6 and newer a package that asks for no permissions passes the input-driver check
Gathin23b8fcbabe3a74
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex 9764bd737..a6c52edc4 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -169,9 +169,9 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/and returns once the request is accepted. The TV is still restarting at that point, so let itanswer again (`tools/tv.py --probe`) before the next command.- **Every `dumpsys` answers `Service dumps disabled due to hung system process.`**, and `tools/disable.sh`- skips every package in the list with "the TV's dumpsys shows neither a requested nor a granted permission- block". That message names Android 5.x, but the cause here is another one: Android's watchdog turns service- dumps off once it has seen `system_server` hang, and they stay off until `system_server` restarts.+ skips every package in the list and says to reboot first (older copies of the script said "the TV's dumpsys+ shows neither a requested nor a granted permission block" and named Android 5.x instead). Android's watchdog+ turns service dumps off once it has seen `system_server` hang, and they stay off until `system_server` restarts.`dumpsys activity` and `dumpsys connectivity` print nothing useful either, so the Home check cannot read thefocused app. On a Xiaomi Mi TV 4A (MiTV-MOOQ1, Android TV 11, `RTM4.220307.164.8277`) that had been up foralmost eight days, the load average was around 62 and `logcat` held repeated watchdog lines fromdiff --git a/tests/test_drift_check.py b/tests/test_drift_check.pyindex 922102a99..b109c5d85 100644--- a/tests/test_drift_check.py+++ b/tests/test_drift_check.py@@ -52,6 +52,8 @@ def answer(command):return state.get("wifi", "")if command.startswith("dumpsys package "):return dumpsys_package(command.split()[-1])+ if command == "getprop ro.build.version.sdk":+ return state.get("sdk", "")if "resolve-activity" in command:return (state["home"] or "") + "\n"if "query-activities" in command and "category.HOME" in command:@@ -63,6 +65,8 @@ def answer(command):def dumpsys_package(name):"""What `dumpsys package <name>` prints, scoped to the permissions the package asks for."""+ if name in state.get("dumps", {}):+ return state["dumps"][name]requested = ["android.permission.INTERNET"]if name in state.get("input_drivers", []):requested.append("android.permission.TV_INPUT_HARDWARE")@@ -361,6 +365,35 @@ class DriftCheckTest(unittest.TestCase):self.assertEqual(result.returncode, 0, result.stdout + result.stderr)self.assertIn(f"pm disable-user --user 0 {MEDIATEK_INPUT}", self.sent())+ def test_fix_reads_a_package_that_asks_for_nothing_as_no_input_driver(self):+ # #2398: from Android 6.0 a readable dump with no requested block asks for nothing, so --fix+ # disables it as disable.sh does; Lollipop prints no block for packages that do ask (#1753),+ # and a TV that reports no SDK is read the same way, so there it stays on.+ no_perms = "android.autoinstalls.config.nvidia"+ dump = f"Packages:\n Package [{no_perms}] (8e7f1b4):\n userId=10037\n"+ for sdk, disabled in (("30", True), ("22", False), ("", False)):+ with self.subTest(sdk=sdk):+ self.write_list([no_perms, "com.example.music"])+ self.tv(installed=BASE + [no_perms], disabled=["com.example.store", STOCK],+ sdk=sdk, dumps={no_perms: dump})+ result = self.run_check("--fix", str(self.list_path))+ self.assertEqual(f"pm disable-user --user 0 {no_perms}" in self.sent(), disabled,+ result.stdout)+ self.assertIn("pm disable-user --user 0 com.example.music", self.sent())+ if not disabled:+ self.assertIn(f"leaving {no_perms} on", result.stdout)++ def test_fix_says_reboot_when_the_watchdog_switched_dumps_off(self):+ self.write_list(["com.example.music"])+ self.tv(disabled=["com.example.store", STOCK], sdk="30",+ dumps={"com.example.music": "Service dumps disabled due to hung system process.\n"})+ result = self.run_check("--fix", str(self.list_path))+ self.assertEqual(result.returncode, 1)+ self.assertNotIn("pm disable-user --user 0 com.example.music", self.sent())+ self.assertIn("leaving com.example.music on", result.stdout)+ self.assertIn("reboot the TV first", result.stdout)+ self.assertNotIn("Android 5.x", result.stdout)+def test_fix_prefers_the_launcher_over_a_vendor_fallback(self):# A FallbackHome is the placeholder a TCL set shows when no launcher is enabled; taking it# as Home would leave the TV in the placeholder (#435).diff --git a/tests/test_tvinput_guard_dumps.py b/tests/test_tvinput_guard_dumps.pynew file mode 100644index 000000000..bcaeb3a2d--- /dev/null+++ b/tests/test_tvinput_guard_dumps.py@@ -0,0 +1,186 @@+"""The input-driver guard reads each `dumpsys package` the way the TV prints it (#2398, #1753).++tests/test_tvinput_guard.py answers the guard's lookup with a ready list of names. Here the lookup+itself runs: the loop disable.sh and disable.ps1 send to the TV is handed to a local `sh`, with+`dumpsys` and `getprop` on PATH answering what a TV of a given Android version prints.++Android 6.0 (SDK 23) and later print a "requested permissions:" block whenever a package asks for+anything, so a readable dump without one is a package that asks for nothing: it cannot be an input+driver, and the guard lets it through. On a Xiaomi Mi TV 4A (MiTV-MOOQ1) and an NVIDIA SHIELD TV+2019, both Android 11, the guard used to keep such packages on as unreadable (#2398). Lollipop prints+neither block for packages that do ask, so below SDK 23 the same dump still keeps the package on+(#1753). A TV whose watchdog has switched every dump off says so, and the run says to reboot first.++Run from the repository root: python3 -m unittest discover -s tests -v+The PowerShell cases need `pwsh` on PATH and skip without it.+"""+from pathlib import Path+import sys+import unittest++sys.path.insert(0, str(Path(__file__).resolve().parent))+import test_home_guard as home_guard # noqa: E402++BEFORE = "com.example.before"+AFTER = "com.example.after"+# Asks for no permission at all: on the SHIELD, a single DummyReceiver and nothing else.+NO_PERMS = "android.autoinstalls.config.nvidia"+MEDIATEK = "com.mediatek.tvinput"+HUNG = "Service dumps disabled due to hung system process.\n"++# The guard's loop is the one command that runs `dumpsys package` for every listed name. Run it in a+# local shell, with this test's dumpsys and getprop first on PATH.+RUN_LOOP = r'''++# Added by tests/test_tvinput_guard_dumps.py: the input-driver loop runs in a real shell.+home_guard_answer = answer+++def answer(command):+ if "for p in " in command and "dumpsys package" in command:+ import subprocess+ env = dict(os.environ, PATH=os.environ["FAKE_BIN"] + os.pathsep + os.environ["PATH"])+ return subprocess.run(["sh", "-c", command], env=env, capture_output=True,+ text=True).stdout+ return home_guard_answer(command)+'''+MAIN = '\nif __name__ == "__main__":'++# The TV's dumpsys: one file per package, or ALL for an answer every package gets.+DUMPSYS = '''#!/bin/sh+if [ -f "$FAKE_DUMPS/ALL" ]; then cat "$FAKE_DUMPS/ALL"+elif [ -f "$FAKE_DUMPS/$2" ]; then cat "$FAKE_DUMPS/$2"+else echo "Unable to find package: $2"; fi+'''+GETPROP = '''#!/bin/sh+[ -f "$FAKE_DUMPS/sdk" ] && cat "$FAKE_DUMPS/sdk"+true+'''+++def android11(name, requested=()):+ """`dumpsys package <name>` on Android 11; no requested block when the package asks for nothing."""+ lines = ["Receiver Resolver Table:", " Non-Data Actions:",+ " android.autoinstalls.config.action.PLAY_AUTO_INSTALL:",+ f" 5d1c0a2 {name}/.DummyReceiver", "",+ # Not the package's own section, though it carries the name in brackets.+ "Key Set Manager:", f" [{name}]", " Signing KeySets: 3", "",+ "Packages:", f" Package [{name}] (8e7f1b4):", " userId=10037",+ " codePath=/system/app/PlayAutoInstallConfig"]+ if requested:+ lines += [" requested permissions:"] + [f" {p}" for p in requested]+ lines += [" install permissions:"] + [f" {p}: granted=true" for p in requested]+ lines += [" User 0: ceDataInode=0 installed=true hidden=false enabled=0", " gids=[3003]",+ " runtime permissions:"]+ return "\n".join(lines) + "\n"+++def lollipop(name):+ """A Lollipop dump of a package whose permissions it does not print in either form."""+ return "\n".join(["Packages:", f" Package [{name}] (2f4b9c1):", " userId=10052",+ " codePath=/system/app/Example.apk"]) + "\n"+++class TvInputGuardDumpsTest(unittest.TestCase):+ home_guard_setup = home_guard.HomeGuardTest.setUp+ write_list = home_guard.HomeGuardTest.write_list+ tv = home_guard.HomeGuardTest.tv+ disable_with = home_guard.HomeGuardTest.disable+ entries = home_guard.HomeGuardTest.entries+ output = home_guard.HomeGuardTest.output++ def setUp(self):+ self.home_guard_setup()+ self.assertIn(MAIN, home_guard.FAKE_TV, "the Home guard test's fake changed shape")+ (self.tools / "tv.py").write_text(home_guard.FAKE_TV.replace(MAIN, RUN_LOOP + MAIN, 1))+ self.bin = self.base / "bin"+ self.dumps = self.base / "dumps"+ self.bin.mkdir()+ self.dumps.mkdir()+ for name, text in (("dumpsys", DUMPSYS), ("getprop", GETPROP)):+ (self.bin / name).write_text(text)+ (self.bin / name).chmod(0o755)+ self.write_list([BEFORE, NO_PERMS, AFTER])++ def dumps_on(self, sdk, dumps):+ """What this TV's getprop and dumpsys answer; sdk None is a TV that reports no SDK."""+ for f in self.dumps.iterdir():+ f.unlink()+ if sdk is not None:+ (self.dumps / "sdk").write_text(f"{sdk}\n")+ for name, text in dumps.items():+ (self.dumps / name).write_text(text)+ self.tv(installed=[BEFORE, NO_PERMS, MEDIATEK, AFTER, home_guard.STOCK])++ def disable(self, entry):+ result, sent = self.disable_with(entry, {"FAKE_BIN": str(self.bin),+ "FAKE_DUMPS": str(self.dumps)})+ self.assertEqual(result.returncode, 0, self.output(result))+ return " ".join(self.output(result).split()), sent++ def test_a_package_that_asks_for_nothing_passes_on_android_6_and_later(self):+ for entry in self.entries():+ for sdk in (23, 30):+ with self.subTest(entry=entry, sdk=sdk):+ self.dumps_on(sdk, {BEFORE: android11(BEFORE, ["android.permission.INTERNET"]),+ NO_PERMS: android11(NO_PERMS),+ AFTER: android11(AFTER, ["android.permission.INTERNET"])})+ said, sent = self.disable(entry)+ self.assertIn(f"pm disable-user --user 0 {NO_PERMS}", sent)+ self.assertNotIn("Skipping", said)++ def test_an_input_driver_is_still_skipped_on_android_11(self):+ self.write_list([BEFORE, NO_PERMS, MEDIATEK])+ for entry in self.entries():+ with self.subTest(entry=entry):+ self.dumps_on(30, {BEFORE: android11(BEFORE, ["android.permission.INTERNET"]),+ NO_PERMS: android11(NO_PERMS),+ MEDIATEK: android11(MEDIATEK, [+ "android.permission.TV_INPUT_HARDWARE"])})+ said, sent = self.disable(entry)+ self.assertNotIn(f"pm disable-user --user 0 {MEDIATEK}", sent)+ self.assertIn(f"pm disable-user --user 0 {NO_PERMS}", sent)+ self.assertIn(f"Skipping {MEDIATEK}: it asks for android.permission.TV_INPUT_HARDWARE",+ said)++ def test_the_same_dump_stays_unchecked_on_lollipop(self):+ # #1753: Lollipop prints neither block for a package that does ask, so no block proves nothing.+ for entry in self.entries():+ with self.subTest(entry=entry):+ self.dumps_on(22, {NO_PERMS: lollipop(NO_PERMS)})+ said, sent = self.disable(entry)+ self.assertNotIn(f"pm disable-user --user 0 {NO_PERMS}", sent)+ self.assertIn(f"Skipping {NO_PERMS}: the TV's dumpsys shows neither", said)+ self.assertIn(f"pm disable-user --user 0 {BEFORE}", sent)++ def test_a_tv_that_reports_no_sdk_keeps_the_package_on(self):+ for entry in self.entries():+ with self.subTest(entry=entry):+ self.dumps_on(None, {NO_PERMS: android11(NO_PERMS)})+ said, sent = self.disable(entry)+ self.assertNotIn(f"pm disable-user --user 0 {NO_PERMS}", sent)+ self.assertIn(f"Skipping {NO_PERMS}: the TV's dumpsys shows neither", said)++ def test_a_dump_without_the_package_section_stays_unchecked(self):+ # Readable means the package's own section is there; anything else is not an answer.+ for entry in self.entries():+ with self.subTest(entry=entry):+ self.dumps_on(30, {NO_PERMS: f"Key Set Manager:\n [{NO_PERMS}]\n"})+ said, sent = self.disable(entry)+ self.assertNotIn(f"pm disable-user --user 0 {NO_PERMS}", sent)+ self.assertIn(f"Skipping {NO_PERMS}: the TV's dumpsys shows neither", said)++ def test_dumps_switched_off_by_the_watchdog_say_reboot_first(self):+ for entry in self.entries():+ with self.subTest(entry=entry):+ self.dumps_on(30, {"ALL": HUNG})+ said, sent = self.disable(entry)+ for name in (BEFORE, NO_PERMS, AFTER):+ self.assertNotIn(f"pm disable-user --user 0 {name}", sent)+ self.assertIn("hung system process", said)+ self.assertIn("Reboot the TV first", said)+ self.assertNotIn("Android 5.x", said, "the dumps are off, not an old Android")+++if __name__ == "__main__":+ unittest.main()diff --git a/tools/check.py b/tools/check.pyindex 24a9711ba..f4e949ba9 100644--- a/tools/check.py+++ b/tools/check.py@@ -61,6 +61,9 @@ FACTORY_HOME_RE = re.compile(r"factorytest|factory_test|factorymode", re.I)# The first-run wizard's app. Android deletes a Wi-Fi network saved by it the moment it is disabled.SETUPWRAITH = "com.google.android.tungsten.setupwraith"INPUT_PERMISSION = "android.permission.TV_INPUT_HARDWARE"+# What asks_for_input_hardware answers when Android's watchdog has switched dumps off: "Service dumps+# disabled due to hung system process" until a reboot (docs/TROUBLESHOOTING.md).+HUNG = "hung"# 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, the same reason disable.sh scopes its grep.REQUESTED_RE = re.compile(r"requested permissions:(.*?)"@@ -172,11 +175,12 @@ def setupwraith_owns_wifi(dev):return any("setupwraith" in owner for owner in owners)-def asks_for_input_hardware(dev, name):+def asks_for_input_hardware(dev, name, sdk):"""Whether the package itself asks for TV_INPUT_HARDWARE, i.e. it drives the HDMI/AV inputs.True or False from a dump that can be read; None when the dump shows neither a requested nor a- granted permission block, so the check could not run — Android 5.x prints neither (#1753)."""+ granted permission block, so the check could not run — Android 5.x prints neither (#1753); HUNG+ when the watchdog has switched every dump off. `sdk` is ro.build.version.sdk, None if unread."""dump = recovery.shell(dev, f"dumpsys package {name}")block = REQUESTED_RE.search(dump)if block:@@ -188,6 +192,12 @@ def asks_for_input_hardware(dev, name):# Lollipop's per-package dump has no permission block but lists what serves the input# service: the decisive check the requested-permission grep stands in for.return "android.media.tv.TvInputService" in dump+ if "hung system process" in dump:+ return HUNG+ if sdk is not None and sdk >= 23 and f"Package [{name}]" in dump:+ # From Android 6.0 a package that asks for anything has a requested block, so a readable dump+ # without one asks for nothing (#2398), the same as disable.sh.+ return Falsereturn None@@ -222,11 +232,19 @@ def safety_checks(dev, names):"showed none); set FORCE_SETUPWRAITH=1 if the TV uses Ethernet")skipped.append((SETUPWRAITH, why))if not os.environ.get("TVINPUT_ALLOW"):+ sdk = recovery.shell(dev, "getprop ro.build.version.sdk")+ sdk = int(sdk) if sdk.isdigit() else Nonefor name in names:if any(name == skipped_name for skipped_name, _ in skipped):continue- hw = asks_for_input_hardware(dev, name)- if hw is None:+ hw = asks_for_input_hardware(dev, name, sdk)+ if hw is HUNG:+ skipped.append((name, "the TV answers dumpsys with \"Service dumps disabled due to hung "+ "system process\", so the input-driver check cannot read it: "+ "reboot the TV first (tools/tv.py --reboot), then run --fix "+ "again; TVINPUT_ALLOW=1 is not the way past this, the check "+ "did not run"))+ elif hw is None:# Fail closed, the same as disable.sh: a dump this firmware cannot be read from# keeps the package on (#1753), and the owner is told what it costs.skipped.append((name, "could not check whether it drives the HDMI/AV inputs (the "diff --git a/tools/disable.ps1 b/tools/disable.ps1index 6fd09eddf..2d1d0c67b 100644--- a/tools/disable.ps1+++ b/tools/disable.ps1@@ -194,9 +194,12 @@ if (-not $tvinputAllow -and $pkgs.Count -gt 0) {# Per package: the "requested permissions" block (Android 6.0+); on a dump with no such block —# Lollipop prints only "grantedPermissions:" — the package's own granted block; then its Service# Resolver Table, which Lollipop's per-package dump prints and which names what serves- # android.media.tv.TvInputService. "Unable to find" is a package not on this TV. A dump with+ # android.media.tv.TvInputService. "Unable to find" is a package not on this TV. From Android 6.0+ # (SDK 23) a readable dump (its own "Package [name]" section) with no block is a package that asks+ # for nothing, so it passes (#2398); below SDK 23, or with no SDK reported, it stays NOCHK. "Service+ # dumps disabled due to hung system process" is the watchdog switching dumps off (HUNG). A dump with# neither block nor error (NOCHK) is one the guard cannot read: the package is kept on (#1753).- $loop = 'for p in ' + ($pkgs -join ' ') + '; do d=$(dumpsys package $p 2>/dev/null); case $d in *"requested permissions:"*) printf ''%s\n'' "$d" | sed -n -E ''/requested permissions:/,/(install|runtime) permissions:|User [0-9]+:/p'' | grep -q TV_INPUT_HARDWARE && echo $p;; *"grantedPermissions:"*) printf ''%s\n'' "$d" | sed -n -E ''/grantedPermissions:/,/(install|runtime) permissions:|User [0-9]+:/p'' | grep -q TV_INPUT_HARDWARE && echo $p;; *"Service Resolver Table:"*) printf ''%s\n'' "$d" | grep -q ''android.media.tv.TvInputService'' && echo $p;; *"Unable to find"*) :;; *) echo "NOCHK $p";; esac; done; true'+ $loop = 's=$(getprop ro.build.version.sdk); for p in ' + ($pkgs -join ' ') + '; do d=$(dumpsys package $p 2>/dev/null); case $d in *"requested permissions:"*) printf ''%s\n'' "$d" | sed -n -E ''/requested permissions:/,/(install|runtime) permissions:|User [0-9]+:/p'' | grep -q TV_INPUT_HARDWARE && echo $p;; *"grantedPermissions:"*) printf ''%s\n'' "$d" | sed -n -E ''/grantedPermissions:/,/(install|runtime) permissions:|User [0-9]+:/p'' | grep -q TV_INPUT_HARDWARE && echo $p;; *"Service Resolver Table:"*) printf ''%s\n'' "$d" | grep -q ''android.media.tv.TvInputService'' && echo $p;; *"Unable to find"*) :;; *"hung system process"*) echo "HUNG $p";; *"Package [$p]"*) [ "${s:-0}" -ge 23 ] 2>/dev/null || echo "NOCHK $p";; *) echo "NOCHK $p";; esac; done; true'# Windows PowerShell turns redirected stderr into an error that 'Stop' would throw (see getprop).$ErrorActionPreference = 'Continue'$tvhw = @(& $py -I (Join-Path $repo 'tools\tv.py') $loop 2>$null)@@ -205,6 +208,18 @@ if (-not $tvinputAllow -and $pkgs.Count -gt 0) {if (-not $checked) {Write-Warning 'Could not check which listed packages drive the HDMI/AV inputs (tv.py failed). Check every input after this run: a port that notices the cable and stays black means one of them was disabled, and only a full restore and a cold boot bring it back (#321).'} else {+ # Dumps switched off by the watchdog: the cure is a reboot, not TVINPUT_ALLOW (disable.sh).+ $hung = @()+ foreach ($p in ($tvhw | Where-Object { $_ -match '^HUNG ' })) {+ $p = ($p -replace '^HUNG ', '').Trim()+ if ($pkgs -contains $p) {+ $hung += $p+ $pkgs = @($pkgs | Where-Object { $_ -ne $p })+ }+ }+ if ($hung.Count -gt 0) {+ Write-Warning "Skipping $($hung -join ' '): the TV answers dumpsys with `"Service dumps disabled due to hung system process`", so the input-driver check cannot read them. Android's watchdog turns every dump off after system_server hangs, and only a restart turns them back on. Reboot the TV first (tools\tv.py --reboot), then run the list again. `$env:TVINPUT_ALLOW=1 is not the way past this: the check did not run, which is not the same as passing (docs/TROUBLESHOOTING.md)."+ }foreach ($p in ($tvhw | Where-Object { $_ -match '^NOCHK ' })) {$p = ($p -replace '^NOCHK ', '').Trim()if ($pkgs -contains $p) {@@ -212,7 +227,7 @@ if (-not $tvinputAllow -and $pkgs.Count -gt 0) {$pkgs = @($pkgs | Where-Object { $_ -ne $p })}}- foreach ($p in ($tvhw | ForEach-Object { $_.Trim() } | Where-Object { $_ -and $_ -notmatch '^NOCHK ' })) {+ foreach ($p in ($tvhw | ForEach-Object { $_.Trim() } | Where-Object { $_ -and $_ -notmatch '^(NOCHK|HUNG) ' })) {if ($pkgs -contains $p) {Write-Warning "Skipping ${p}: it asks for android.permission.TV_INPUT_HARDWARE, so it is the software layer under the HDMI/AV/tuner inputs. With it disabled those inputs still notice the cable but stay black (No Signal), and re-enabling the pieces in batches does not restore the picture: a full restore plus a cold boot does (#321). Set `$env:TVINPUT_ALLOW=1 to disable it."$pkgs = @($pkgs | Where-Object { $_ -ne $p })diff --git a/tools/disable.sh b/tools/disable.shindex 10274b334..77409f377 100755--- a/tools/disable.sh+++ b/tools/disable.sh@@ -265,13 +265,36 @@ if [ -n "$PKGS" ] && [ -z "${TVINPUT_ALLOW:-}" ]; then# then on a dump with no such block at all — Lollipop prints only "grantedPermissions:" — the# package's own granted block, then its Service Resolver Table, which Lollipop's per-package dump# prints and which names what serves android.media.tv.TvInputService. "Unable to find" is a package- # that is not on this TV, not a check that failed. A dump with neither block nor error (NOCHK) is- # one the guard cannot read: the package is kept off the batch below instead of passing silently.+ # that is not on this TV, not a check that failed. From Android 6.0 (SDK 23) the dump prints the+ # requested block whenever the package asks for anything, so there a readable dump (its own+ # "Package [name]" section) with no block at all is a package that asks for nothing, which cannot+ # include TV_INPUT_HARDWARE: it passes (#2398, a Mi TV 4A and a SHIELD on Android 11). Below SDK 23,+ # or with an SDK the TV does not report, the same dump stays NOCHK, since Lollipop prints neither+ # block for packages that do ask (#1753). "Service dumps disabled due to hung system process" is+ # Android's watchdog switching every dump off (HUNG). A dump with neither block nor error (NOCHK) is+ # one the guard cannot read: either way the package is kept off the batch below instead of passing+ # silently.if TV_HW="$("$PY" -I tools/tv.py \- "for p in $NAMES; do d=\$(dumpsys package \$p 2>/dev/null); case \$d in *'requested permissions:'*) printf '%s\n' \"\$d\" | sed -n -E '/requested permissions:/,/(install|runtime) permissions:|User [0-9]+:/p' | grep -q TV_INPUT_HARDWARE && echo \$p;; *'grantedPermissions:'*) printf '%s\n' \"\$d\" | sed -n -E '/grantedPermissions:/,/(install|runtime) permissions:|User [0-9]+:/p' | grep -q TV_INPUT_HARDWARE && echo \$p;; *'Service Resolver Table:'*) printf '%s\n' \"\$d\" | grep -q 'android.media.tv.TvInputService' && echo \$p;; *'Unable to find'*) :;; *) echo \"NOCHK \$p\";; esac; done; true" \+ "s=\$(getprop ro.build.version.sdk); for p in $NAMES; do d=\$(dumpsys package \$p 2>/dev/null); case \$d in *'requested permissions:'*) printf '%s\n' \"\$d\" | sed -n -E '/requested permissions:/,/(install|runtime) permissions:|User [0-9]+:/p' | grep -q TV_INPUT_HARDWARE && echo \$p;; *'grantedPermissions:'*) printf '%s\n' \"\$d\" | sed -n -E '/grantedPermissions:/,/(install|runtime) permissions:|User [0-9]+:/p' | grep -q TV_INPUT_HARDWARE && echo \$p;; *'Service Resolver Table:'*) printf '%s\n' \"\$d\" | grep -q 'android.media.tv.TvInputService' && echo \$p;; *'Unable to find'*) :;; *'hung system process'*) echo \"HUNG \$p\";; *\"Package [\$p]\"*) [ \"\${s:-0}\" -ge 23 ] 2>/dev/null || echo \"NOCHK \$p\";; *) echo \"NOCHK \$p\";; esac; done; true" \</dev/null 2>/dev/null | tr -d '\r')"; then# Packages whose dump shows neither block: keep them enabled (a black input is easy to blame on# the cable, and the ports are the one thing the owner cannot test from here) and say why.+ # Dumps switched off by the watchdog: every package answers the same, and the cure is a reboot,+ # not TVINPUT_ALLOW=1 (the check did not run, which is not the same as passing).+ HUNG="$(printf '%s\n' "$TV_HW" | sed -n -E 's/^HUNG ([^[:space:]]+)$/\1/p')"+ HUNG_SKIPPED=""+ for p in $HUNG; do+ printf '%s\n' "$PKGS" | grep -xF "$p" >/dev/null || continue+ HUNG_SKIPPED="$HUNG_SKIPPED $p"+ PKGS="$(printf '%s\n' "$PKGS" | grep -vxF "$p" || true)"+ done+ if [ -n "$HUNG_SKIPPED" ]; then+ echo "Skipping$HUNG_SKIPPED: the TV answers dumpsys with \"Service dumps disabled due to hung" >&2+ echo "system process\", so the input-driver check cannot read them. Android's watchdog turns every" >&2+ echo "dump off after system_server hangs, and only a restart turns them back on. Reboot the TV" >&2+ echo "first (tools/tv.py --reboot), then run the list again. TVINPUT_ALLOW=1 is not the way past" >&2+ echo "this: the check did not run, which is not the same as passing (docs/TROUBLESHOOTING.md)." >&2+ fiUNCHECKED="$(printf '%s\n' "$TV_HW" | sed -n -E 's/^NOCHK ([^[:space:]]+)$/\1/p')"for p in $UNCHECKED; doprintf '%s\n' "$PKGS" | grep -xF "$p" >/dev/null || continue@@ -281,7 +304,7 @@ if [ -n "$PKGS" ] && [ -z "${TVINPUT_ALLOW:-}" ]; thenecho "TVINPUT_ALLOW=1 to disable it (#321)." >&2PKGS="$(printf '%s\n' "$PKGS" | grep -vxF "$p" || true)"done- TV_HW="$(printf '%s\n' "$TV_HW" | grep -v '^NOCHK ' || true)"+ TV_HW="$(printf '%s\n' "$TV_HW" | grep -vE '^(NOCHK|HUNG) ' || true)"for p in $TV_HW; do# grep without -q: with pipefail an early exit could SIGPIPE printf and fail the run (see above).printf '%s\n' "$PKGS" | grep -xF "$p" >/dev/null || continue