From e4b4e9f3e6e080a8372618337fbf45c91e51efdf Mon Sep 17 00:00:00 2001 From: DeepMind Date: Fri, 10 Oct 2025 12:15:09 -0700 Subject: [PATCH] Update _input_text function to support for non-ASCII characters PiperOrigin-RevId: 817742556 --- android_env/components/adb_call_parser.py | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/android_env/components/adb_call_parser.py b/android_env/components/adb_call_parser.py index 2578fd89..9aae35a3 100644 --- a/android_env/components/adb_call_parser.py +++ b/android_env/components/adb_call_parser.py @@ -15,6 +15,7 @@ """Processes adb_pb2.AdbRequest commands.""" +import base64 import os import re import subprocess @@ -616,8 +617,27 @@ def _input_text( status=adb_pb2.AdbResponse.Status.FAILED_PRECONDITION, error_message='InputText.text is empty.') - response, _ = self._execute_command(['shell', 'input', 'text', text], - timeout=timeout) + is_ascii = text.isascii() + + if is_ascii: + response, _ = self._execute_command( + ['shell', 'input', 'text', text], timeout=timeout + ) + else: + b64_text = base64.b64encode(text.encode('utf-8')).decode('ascii') + response, _ = self._execute_command( + [ + 'shell', + 'am', + 'broadcast', + '-a', + 'ADB_INPUT_B64', + '--es', + 'msg', + b64_text, + ], + timeout=timeout, + ) return response def _tap(