Skip to content

Conversation

@yukunzou-cyber
Copy link

@yukunzou-cyber yukunzou-cyber commented Jan 22, 2026

Fix HarmonyOS Text Input by Passing Coordinates

Summary

Add coordinate parameters to HarmonyOS text input to use the correct inputText X Y command format.

Track the last tap coordinates in ActionHandler and automatically pass them to text input operations for seamless support of HarmonyOS's coordinate-based input command.

Problem

HarmonyOS's uitest text input command requires explicit coordinates:

hdc shell uitest uiInput inputText X Y "文本内容"

Without coordinates, the command falls back to:

hdc shell uitest uiInput text "文本内容"

which is unreliable and often fails. The agent was not passing coordinate information to the input method, causing text input failures on HarmonyOS devices.

Example of failed input:

{
  "_metadata": "do",
  "action": "Type",
  "text": "Search query"
}

The input would fail because coordinates were not available.

Solution

  1. Extend type_text signature (phone_agent/hdc/input.py):

    • Add optional parameters: x: int | None = None and y: int | None = None
    • When both coordinates are provided, use inputText X Y command
    • When coordinates are not provided, fall back to text command (for backward compatibility)
    • Support multi-line text with coordinates
  2. Track tap coordinates (phone_agent/actions/handler.py):

    • Add _last_tap_coords field to ActionHandler.__init__ to store the most recent tap location
    • Update _last_tap_coords in _handle_tap method
    • Pass saved coordinates to type_text in _handle_type method
  3. Maintain device factory compatibility (phone_agent/device_factory.py):

    • Use inspect.signature() to detect if the underlying module supports coordinates
    • For HDC (HarmonyOS): pass coordinates to type_text
    • For ADB/iOS: ignore coordinates (backward compatible)

Changes

Modified Files

  1. phone_agent/hdc/input.py

    • Extended type_text() to accept x and y parameters
    • Implemented logic to choose between inputText X Y and text commands
    • Updated docstring to document new parameters and command format
  2. phone_agent/actions/handler.py

    • Added _last_tap_coords: tuple[int, int] | None = None in __init__
    • Modified _handle_tap() to save tap coordinates
    • Modified _handle_type() to pass coordinates from last tap to type_text()
  3. phone_agent/device_factory.py

    • Updated type_text() method to accept and forward x, y parameters
    • Added inspect.signature() check for backward compatibility with ADB/iOS modules

Benefits

  • ✅ Fixes text input failures on HarmonyOS devices
  • ✅ Maintains full backward compatibility with ADB and iOS
  • ✅ Minimal code changes (only coordinate tracking, no refactoring)
  • ✅ Follows existing "tap then type" workflow
  • ✅ Works with multi-line text input

Testing

The fix has been designed to:

  • Work seamlessly on HarmonyOS (HDC) devices with the new coordinate-based approach
  • Maintain compatibility with Android (ADB) devices without any changes
  • Maintain compatibility with iOS devices without any changes
  • Support both single-line and multi-line text input

Fixes #288 #270 #312

@yukunzou-cyber yukunzou-cyber changed the title fix hdc input issues fix hdc input issues(issues 270+288+312) Jan 22, 2026
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