Skip to content

Discard dumpsys stderr so "Broken pipe" does not corrupt parsed output - #376

Open
JordiRubio93 wants to merge 1 commit into
JeffLIrion:masterfrom
JordiRubio93:fix-dumpsys-stderr-broken-pipe
Open

JordiRubio93 wants to merge 1 commit into
JeffLIrion:masterfrom
JordiRubio93:fix-dumpsys-stderr-broken-pipe

Conversation

@JordiRubio93

@JordiRubio93 JordiRubio93 commented Oct 25, 2026 •

Copy link
Copy Markdown

Fixes #373.

Problem

Several CMD_* commands pipe dumpsys into grep -q or grep -m 1. Once grep exits early, dumpsys writes Failed to write while dumping service <name>: Broken pipe to stderr. The ADB shell merges stderr into the output, so the parsers read the wrong characters.

On an Android 14 TCL TV (Google TV launcher), Display Power no longer has a state= field and mScreenOn is gone. CMD_SCREEN_ON therefore falls through to dumpsys display | grep -q ..., and the first character of the output is F instead of 1. _screen_on_awake_wake_lock_size() then reports the screen as off, and the media player stays off while the TV is on.

Output of CMD_SCREEN_ON_AWAKE_WAKE_LOCK_SIZE, captured through Home Assistant's own ADB connection:

before: 'Failed to write while dumping service display: Broken pipe\n10Wake Locks: size=1'
after:  '10Wake Locks: size=1'

On an Android 11 TCL TV the output is identical before and after the change.

Change

  • Add 2>/dev/null to every dumpsys call in androidtv/constants.py, right before its pipe. Only stderr is discarded, so nothing the parsers read from stdout changes.
  • Update the pinned command strings in tests/test_constants.py.
  • Add test_dumpsys_stderr_discarded, which fails if a CMD_* constant contains a dumpsys call that does not discard stderr.

This complements #369, which avoids the expensive dumpsys display fallback for the screen state. This PR also covers CMD_AWAKE, the current-app commands that use grep -m 1, and the audio commands, which hit the same broken pipe.

Testing

  • pytest tests: 233 passed.
  • The new test fails against the current constants.py.
  • Ran the patched commands on both TVs (Android 14 and Android 11) through Home Assistant's ADB connection. Running the patched constants in Home Assistant, the Android 14 TV now reports its real state (idle while the screensaver is on) instead of off.

grep -q / grep -m 1 can exit early; dumpsys then writes a Broken pipe error
to stderr, which the ADB shell merges into the output (fixes JeffLIrion#373).
@JordiRubio93

Copy link
Copy Markdown
Author

A note on the red CI. Neither failure comes from this change:

  • build (3.7) fails at "Set up Python 3.7": Version 3.7 with arch x64 not found. ubuntu-latest no longer provides Python 3.7, so the remaining matrix jobs are cancelled.
  • The lint step fails on black --check for androidtv/__init__.py and androidtv/exceptions.py. This PR does not touch either file. venv_requirements.txt does not pin black, so CI installs a newer release than the one that formatted those files. constants.py passes.

Because lint stops each job, the tests never run in CI. Locally, pytest tests passes: 233 tests, including the new test_dumpsys_stderr_discarded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android 14 Google TV: dumpsys … | grep -q writes "Broken pipe" into output → screen_on/awake misparsed, device reported off

1 participant