Skip to content

Commit c698fe4

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

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

android_env/components/adb_call_parser.py

Lines changed: 22 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,27 @@ 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+
b64_text = base64.b64encode(text.encode('utf-8')).decode('ascii')
628+
response, _ = self._execute_command(
629+
[
630+
'shell',
631+
'am',
632+
'broadcast',
633+
'-a',
634+
'ADB_INPUT_B64',
635+
'--es',
636+
'msg',
637+
b64_text,
638+
],
639+
timeout=timeout,
640+
)
621641
return response
622642

623643
def _tap(

0 commit comments

Comments
 (0)