Skip to content

Commit

Permalink
Send explicit broadcasts to SET_GRPC and ENABLE_A11Y_TREE_LOGS.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DeepMind authored and copybara-github committed Nov 10, 2023
1 parent ea0bb87 commit 9a892e1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
16 changes: 12 additions & 4 deletions android_env/components/adb_call_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,24 @@ 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

if send_broadcast.component:
component_args = ['-n', send_broadcast.component]
else:
component_args = []

response, _ = self._execute_command(
['shell', 'am', 'broadcast', '-a', send_brodcast.action],
timeout=timeout)
['shell', 'am', 'broadcast', '-a', send_broadcast.action]
+ component_args,
timeout=timeout,
)

return response

def _install_apk(
Expand Down
12 changes: 12 additions & 0 deletions android_env/components/adb_call_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,18 @@ def test_send_broadcast_successful(self):
self.assertEqual(response.status, adb_pb2.AdbResponse.Status.OK)
self.assertEmpty(response.error_message)

def test_send_broadcast_with_component_successful(self):
adb = mock.create_autospec(adb_controller.AdbController)
parser = adb_call_parser.AdbCallParser(
adb, tmp_dir=absltest.get_default_test_tmpdir()
)
request = adb_pb2.AdbRequest()
request.send_broadcast.action = 'SOME-ACTION'
request.send_broadcast.component = 'SOME-COMPONENT'
response = parser.parse(request)
self.assertEqual(response.status, adb_pb2.AdbResponse.Status.OK)
self.assertEmpty(response.error_message)

def test_uninstall_package_empty_package_name(self):
adb = mock.create_autospec(adb_controller.AdbController)
parser = adb_call_parser.AdbCallParser(
Expand Down
5 changes: 5 additions & 0 deletions android_env/proto/adb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9a892e1

Please sign in to comment.