Skip to content

fix: prevent stderr from corrupting IME identifier in keyboard detection#396

Open
Ricardo-M-L wants to merge 1 commit into
zai-org:mainfrom
Ricardo-M-L:fix/ime-detection-stderr-corruption
Open

fix: prevent stderr from corrupting IME identifier in keyboard detection#396
Ricardo-M-L wants to merge 1 commit into
zai-org:mainfrom
Ricardo-M-L:fix/ime-detection-stderr-corruption

Conversation

@Ricardo-M-L
Copy link
Copy Markdown

Problem

detect_and_set_adb_keyboard() concatenates stdout + stderr when reading the current IME:

current_ime = (result.stdout + result.stderr).strip()

If the command fails (e.g. permission denied, device disconnected), the error message from stderr pollutes the IME string. This corrupted string is later passed to restore_keyboard(), which silently fails to restore the original keyboard — leaving the device stuck on ADB Keyboard.

Fix

Only use stdout when the command succeeds (returncode == 0); fall back to empty string on failure.

Affects both:

  • phone_agent/adb/input.py (Android/ADB)
  • phone_agent/hdc/input.py (HarmonyOS/HDC)

`detect_and_set_adb_keyboard()` concatenates stdout and stderr when
reading the current IME. If the adb/hdc command fails (e.g. permission
denied), the error message pollutes the IME string, causing
`restore_keyboard()` to receive an invalid identifier and silently
fail to restore the original keyboard.

Use only stdout when the command succeeds; fall back to empty string
on failure.

Affects both ADB (phone_agent/adb/input.py) and HarmonyOS
(phone_agent/hdc/input.py) code paths.
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.

1 participant