Fix dumpsys parsing quirks for Askey ADT-3 devices (e.g. HTC MagicubOS) - #370
Open
LuckyType wants to merge 1 commit into
Open
Fix dumpsys parsing quirks for Askey ADT-3 devices (e.g. HTC MagicubOS)#370LuckyType wants to merge 1 commit into
LuckyType wants to merge 1 commit into
Conversation
On this reference-platform device (Android 14, manufacturer "askey", product_id "adt3"), `dumpsys window windows` no longer includes `mCurrentFocus`/`mFocusedApp`/`mObscuringWindow`/`imeLayeringTarget` etc. Those fields are only present in the unfiltered `dumpsys window` output. This broke current-app detection, media session state, and app launching for this device, matching the existing per-model quirk pattern already used for the Askey STI6130. Separately, `CMD_SCREEN_ON`'s `dumpsys display` fallback piped directly into `grep -q`, which closes its end of the pipe as soon as it finds a match. On devices with large `dumpsys display` output, the still-writing `dumpsys` process can then fail with "Failed to write while dumping service display: Broken pipe", and that error text gets prepended to the result. Callers that parse the result as a literal "1"/"0" string (e.g. `screen_on_awake_wake_lock_size`) then read a corrupted first character, so an already-on device is reported as off/unavailable. Buffering the `dumpsys display` output via command substitution before grepping it avoids the race. This affects any device that reaches that fallback branch, not just this one. Both fixes were validated against a real ADT-3-based device end to end (state detection, turn_on/turn_off, launch_app, current_app).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Found and fixed two issues while getting an HTC "MagicubOS" projector (an Askey ADT-3-based Android TV reference device, Android 14) working with Home Assistant's
androidtvintegration.1. Missing window-focus fields on
dumpsys window windowsOn this device (
manufacturer=askey,product_id=adt3),dumpsys window windowsno longer includesmCurrentFocus/mFocusedApp/mObscuringWindow/imeLayeringTargetetc. — none of the existing per-version command variants (11/12/13+) find a match. Those fields are only present in the unfiltereddumpsys windowoutput. This brokecurrent_appdetection, media session state, andlaunch_appfor this device.Added a new per-device quirk (
CMD_*_ASKEY_ADT3), following the same pattern as the existing Askey STI6130 quirk, keyed onmanufacturer+product_id.2. Broken pipe corrupting
CMD_SCREEN_ON'sdumpsys displayfallbackCMD_SCREEN_ON's third fallback check pipesdumpsys displaydirectly intogrep -q 'mScreenState=ON'. On devices wheredumpsys displayproduces enough output,grep -qcloses its end of the pipe as soon as it finds a match, and the still-writingdumpsysprocess fails withFailed to write while dumping service display: Broken pipe— text that gets prepended to the result.This is mostly harmless for exit-status-based callers (e.g.
CMD_TURN_ON_ANDROIDTV), but callers that parse the result as a literal"1"/"0"string — specificallyscreen_on_awake_wake_lock_size, viaoutput[0] == "1"— read theFfromFailed...as the first character instead, so an already-on device gets reported as off/unavailable. This exactly matched the symptom I was seeing: the entity stuck showing "off" whiledumpsys powerclearly showedmWakefulness=Awake, and the on/off toggle appearing to do nothing (becauseturn_on()'s exit-status check correctly saw the device was already on and skipped sending a redundant power keyevent).Fixed by buffering the
dumpsys displayoutput via command substitution before grepping it, avoiding the race entirely. This isn't device-specific — any device that reaches that third fallback branch (i.e. doesn't match the cheaperDisplay Power/mScreenOn=truechecks) could hit it.Test plan
pytest tests/— all 232 tests pass,tests/test_constants.pyupdated (new constants +CMD_SCREEN_ONand its derivatives)turn_on/turn_off,launch_app,current_app) — confirmed working live via Home Assistant'sandroidtvintegration after deploying the fix