Skip to content

Commit 7caf22f

Browse files
DeepMindcopybara-github
authored andcommitted
Update _input_text function to support for non-ASCII characters
PiperOrigin-RevId: 817742556
1 parent 8270470 commit 7caf22f

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

android_env/components/adb_call_parser.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
"""Processes adb_pb2.AdbRequest commands."""
1717

18+
import base64
1819
import os
1920
import re
2021
import subprocess
@@ -616,8 +617,28 @@ def _input_text(
616617
status=adb_pb2.AdbResponse.Status.FAILED_PRECONDITION,
617618
error_message='InputText.text is empty.')
618619

619-
response, _ = self._execute_command(['shell', 'input', 'text', text],
620-
timeout=timeout)
620+
is_ascii = text.isascii()
621+
622+
if is_ascii:
623+
response, _ = self._execute_command(
624+
['shell', 'input', 'text', text], timeout=timeout
625+
)
626+
else:
627+
# text = text.replace('%s', ' ')
628+
b64_text = base64.b64encode(text.encode('utf-8')).decode('ascii')
629+
response, _ = self._execute_command(
630+
[
631+
'shell',
632+
'am',
633+
'broadcast',
634+
'-a',
635+
'ADB_INPUT_B64',
636+
'--es',
637+
'msg',
638+
b64_text,
639+
],
640+
timeout=timeout,
641+
)
621642
return response
622643

623644
def _tap(

0 commit comments

Comments
 (0)