From 49e38e0fd51bf4a16249b7662091fb4833ba8424 Mon Sep 17 00:00:00 2001 From: DeepMind Date: Fri, 10 Nov 2023 11:53:52 -0800 Subject: [PATCH] Send explicit broadcasts to SET_GRPC and ENABLE_A11Y_TREE_LOGS. changes: -add component field to SendBroadcast in AdbRequest -change the send broadcast function in the call parser to pass the component name if present in the request -in the a11y grpc wrapper, set the component name to match FlagsBroadcastReceiver PiperOrigin-RevId: 581326914 --- android_env/components/adb_call_parser.py | 26 ++++++++++++++++++----- android_env/proto/adb.proto | 5 +++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/android_env/components/adb_call_parser.py b/android_env/components/adb_call_parser.py index da94298..aa64b3c 100644 --- a/android_env/components/adb_call_parser.py +++ b/android_env/components/adb_call_parser.py @@ -230,16 +230,32 @@ def _send_broadcast( An AdbResponse. """ - send_brodcast = request.send_broadcast + send_broadcast = request.send_broadcast response = adb_pb2.AdbResponse(status=adb_pb2.AdbResponse.Status.OK) - if not send_brodcast.action: + if not send_broadcast.action: response.status = adb_pb2.AdbResponse.Status.FAILED_PRECONDITION response.error_message = ('`send_broadcast.{action}` cannot be empty.') return response - response, _ = self._execute_command( - ['shell', 'am', 'broadcast', '-a', send_brodcast.action], - timeout=timeout) + if send_broadcast.component: + response, _ = self._execute_command( + [ + 'shell', + 'am', + 'broadcast', + '-a', + send_broadcast.action, + '-n', + send_broadcast.component, + ], + timeout=timeout, + ) + else: + response, _ = self._execute_command( + ['shell', 'am', 'broadcast', '-a', send_broadcast.action], + timeout=timeout, + ) + return response def _install_apk( diff --git a/android_env/proto/adb.proto b/android_env/proto/adb.proto index 4f298ef..840efa1 100644 --- a/android_env/proto/adb.proto +++ b/android_env/proto/adb.proto @@ -52,6 +52,11 @@ message AdbRequest { message SendBroadcast { // Action to send during the broadcast event. string action = 1; + + // Specify the component name with package name prefix to create an explicit + // intent, such as com.example.app/.ExampleActivity (see -n specification at + // https://developer.android.com/tools/adb#IntentSpec). + string component = 2; } message UninstallPackage {