How to modify wd proxy and uiautomator2 source code (to support unicode)

Platform  Android
Appium version 1.20.2
Emulator
Client langauage c#
OS Win

I need to send unicode chars to android, not as a setvalue which does sendkeys.
Exactly I need to test typing in my app and emulate human behavior in typing.
Im using c# so code is:
Actions a = new Actions(driver); a.SendKeys("تست"); a.Perform();
i see uiautomator2 calls wd proxy, so I need to modify that to support unicode
[WD Proxy] Proxying [POST /actions] to [POST http://127.0.0.1:8214/wd/hub/session/elementid/actions] with body: {“actions”:[{“type”:“key”,“id”:“default keyboard”,“actions”:[{“type”:“keyDown”,“value”:“t”},{“type”:“keyUp”,“value”:“t”},{“type”:“keyDown”,“value”:“e”},{“type”:“keyUp”,“value”:“e”},{“type”:“keyDown”,“value”:“s”},{“type”:“keyUp”,“value”:“s”},{“type”:“keyDown”,“value”:“t”},{“type”:“keyUp”,“value”:“t”}]}]}

I searched in C:\Program Files\Appium\resources\app\node_modules\wd\lib
but no success

thanks for your help

Try mobile: type extension

about mobile:type I get this error in c#:
OpenQA.Selenium.WebDriverException: 'An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: ‘Command ‘C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 shell input text &BioGMwYq-’ exited with code 127’; Stderr: '/system/bin/sh: BioGMwYq-: not found
Error: Invalid arguments for command: text
Usage: input [] […]

and this log in appium console:
[HTTP] --> POST /wd/hub/session/48382df8-45e2-4064-af51-63cbfb02f97e/execute/sync
[HTTP] {“script”:“mobile: type”,“args”:[{“text”:“تست”}]}
[W3C (48382df8)] Calling AppiumDriver.execute() with args: [“mobile: type”,[{“text”:“تست”}],“48382df8-45e2-4064-af51-63cbfb02f97e”]
[AndroidDriver] Executing native command ‘mobile: type’
[ADB] Typing 3 characters
[ADB] Running ‘C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 shell settings get secure default_input_method’
[ADB] The original IME is the same as ‘io.appium.settings/.UnicodeIME’. There is no need to reset it
[ADB] Running ‘C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 shell input text &BioGMwYq-’
[W3C (48382df8)] Encountered internal error running command: Error executing adbExec. Original error: ‘Command ‘C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 shell input text &BioGMwYq-’ exited with code 127’; Stderr: ‘/system/bin/sh: BioGMwYq-: not found
[W3C (48382df8)] Error: Invalid arguments for command: text
[W3C (48382df8)] Usage: input [] […]
[W3C (48382df8)]
[W3C (48382df8)] The sources are:
[W3C (48382df8)] keyboard
[W3C (48382df8)] mouse
[W3C (48382df8)] joystick
[W3C (48382df8)] touchnavigation
[W3C (48382df8)] touchpad
[W3C (48382df8)] trackball
[W3C (48382df8)] dpad
[W3C (48382df8)] stylus
[W3C (48382df8)] gamepad
[W3C (48382df8)] touchscreen
[W3C (48382df8)]
[W3C (48382df8)] The commands and default sources are:
[W3C (48382df8)] text (Default: touchscreen)
[W3C (48382df8)] keyevent [–longpress] … (Default: keyboard)
[W3C (48382df8)] tap (Default: touchscreen)
[W3C (48382df8)] swipe [duration(ms)] (Default: touchscreen)
[W3C (48382df8)] press (Default: trackball)
[W3C (48382df8)] roll (Default: trackball)’; Code: ‘127’
[W3C (48382df8)] Error: Command ‘C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 shell input text &BioGMwYq-’ exited with code 127
[W3C (48382df8)] at ChildProcess. (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\teen_process\lib\exec.js:113:19)
[W3C (48382df8)] at ChildProcess.emit (events.js:203:13)
[W3C (48382df8)] at maybeClose (internal/child_process.js:1021:16)
[W3C (48382df8)] at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

about mobile:type I think problem is conflict with cmd in windows
my text converted to &BioGMwYq so the & sign is problem in cmd which waits for second command after adb not getting converted text as parameter

https://github.com/appium/appium-adb/pull/567 should fix that

Thanks a lot
‘\’ did not escape that
I fixed problem for now, I’ve replaced ‘&’ with ‘~’ in utf7 encoder and in android decoder
after all replace ~ with & back on unshift method android

another problem showed up!
space char
when having space in text, it does not send

with space:
[ADB] Running ‘C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 shell input text ‘~BioGMwYq- ~BioGMwYq-’’

without space:
[ADB] Running ‘C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 shell input text ~BioGMwYq-’

a backslash comes before port when text has spaces, how should fix?

‘\’ did not escape that

Could you please provide the full log? Also, have you tried to run the command C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 shell input text \&BioGMwYq- manually? What is the output there?

I would also like to see the full log here. Perhaps, we could find an acceptable solution there

I did several updates to the PR. It should perform better now

No log, because I tested manually in cmd:
C:\Users\user>C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 s
hell input text &BioGMwYq-
Error: Invalid arguments for command: text

C:\Users\user>C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 s
hell input text \&BioGMwYq-
‘BioGMwYq-’ is not recognized as an internal or external command,
operable program or batch file.

C:\Users\MRKP>C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 s
hell input text ^&BioGMwYq-
/system/bin/sh: BioGMwYq-: not found
Error: Invalid arguments for command: text

[HTTP] --> POST /wd/hub/session/1ab1a6e0-7f1b-4552-ad89-50c5a0ee40f0/execute/sync

[HTTP] {“script”:“mobile: type”,“args”:[{“text”:“تست تست”}]}

[W3C (1ab1a6e0)] Calling AppiumDriver.execute() with args: [“mobile: type”,[{“text”:“تست تست”}],“1ab1a6e0-7f1b-4552-ad89-50c5a0ee40f0”]

[AndroidDriver] Executing native command ‘mobile: type’

[ADB] Typing 7 characters

[ADB] Running ‘C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 shell settings get secure default_input_method’

[ADB] The original IME is the same as ‘io.appium.settings/.UnicodeIME’. There is no need to reset it

[ADB] Running ‘C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:62040 shell input text ‘~BioGMwYq- ~BioGMwYq-’’

[W3C (1ab1a6e0)] Responding to client with driver.execute() result: true

[HTTP] <-- POST /wd/hub/session/1ab1a6e0-7f1b-4552-ad89-50c5a0ee40f0/execute/sync 200 1589 ms - 14

this works as you edited, Itested manually

C:\Users\MRKP>C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 s
hell input text ‘^&BioGMwYq-’

I added your changes to files, but it does not escape
as I see escapeArg function does not called
any build or other work should I do to test new code?

Thanks, you are perfect

For the space input we could check the following option:

C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:62040 shell input text ^&BioGMwYq-%%s^&BioGMwYq-

To test my branch you could use the same steps as described in https://github.com/appium/appium/issues/14693#issuecomment-684878582 just use the appium-adb module instead of appium-base-driver,

this works fine in cmd, no need to escape space I think, using ’ ’ around text is ok:
C:\Users\user>C:\android-sdk\platform-tools\adb.exe -P 5037 -s 127.0.0.1:62040 s
hell input text ‘^&BioGMwYq- ^&BioGMwYq-’

Cool, could you please confirm that the PR is working? If yes I could merge it and publish to appium@beta to unblock you

my problem is after doing this:

my appium stopped running uiautomator2
let me fix my installation and test, I will send my experience soon