From bf06177400fda5f928e45ece3d730615ba9a2146 Mon Sep 17 00:00:00 2001 From: Ricardo-M-L Date: Fri, 24 Apr 2026 00:23:24 +0800 Subject: [PATCH] fix: prevent stderr from corrupting IME identifier in keyboard detection `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. --- phone_agent/adb/input.py | 2 +- phone_agent/hdc/input.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phone_agent/adb/input.py b/phone_agent/adb/input.py index 4c1c68cd8..c222f7767 100644 --- a/phone_agent/adb/input.py +++ b/phone_agent/adb/input.py @@ -71,7 +71,7 @@ def detect_and_set_adb_keyboard(device_id: str | None = None) -> str: capture_output=True, text=True, ) - current_ime = (result.stdout + result.stderr).strip() + current_ime = result.stdout.strip() if result.returncode == 0 else "" # Switch to ADB Keyboard if not already set if "com.android.adbkeyboard/.AdbIME" not in current_ime: diff --git a/phone_agent/hdc/input.py b/phone_agent/hdc/input.py index 920cf7ddd..b925f14a2 100644 --- a/phone_agent/hdc/input.py +++ b/phone_agent/hdc/input.py @@ -112,7 +112,7 @@ def detect_and_set_adb_keyboard(device_id: str | None = None) -> str: capture_output=True, text=True, ) - current_ime = (result.stdout + result.stderr).strip() + current_ime = result.stdout.strip() if result.returncode == 0 else "" # If ADB Keyboard equivalent exists for HarmonyOS, switch to it # For now, we'll just return the current IME