fix hdc input issues(issues 270+288+312) #343
Open
+62
−26
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.
Fix HarmonyOS Text Input by Passing Coordinates
Summary
Add coordinate parameters to HarmonyOS text input to use the correct
inputText X Ycommand format.Track the last tap coordinates in
ActionHandlerand automatically pass them to text input operations for seamless support of HarmonyOS's coordinate-based input command.Problem
HarmonyOS's
uitesttext 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
Extend
type_textsignature (phone_agent/hdc/input.py):x: int | None = Noneandy: int | None = NoneinputText X Ycommandtextcommand (for backward compatibility)Track tap coordinates (
phone_agent/actions/handler.py):_last_tap_coordsfield toActionHandler.__init__to store the most recent tap location_last_tap_coordsin_handle_tapmethodtype_textin_handle_typemethodMaintain device factory compatibility (
phone_agent/device_factory.py):inspect.signature()to detect if the underlying module supports coordinatestype_textChanges
Modified Files
phone_agent/hdc/input.py
type_text()to acceptxandyparametersinputText X Yandtextcommandsphone_agent/actions/handler.py
_last_tap_coords: tuple[int, int] | None = Nonein__init___handle_tap()to save tap coordinates_handle_type()to pass coordinates from last tap totype_text()phone_agent/device_factory.py
type_text()method to accept and forwardx, yparametersinspect.signature()check for backward compatibility with ADB/iOS modulesBenefits
Testing
The fix has been designed to:
Fixes #288 #270 #312