Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions android_world/env/adb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def check_ok(response: adb_pb2.AdbResponse, message=None) -> None:
else:
raise RuntimeError(
f'ADB command failed with status {response.status}:'
f' {response.generic.output.decode()}.'
f' {response.output.decode()}.'
)


Expand Down Expand Up @@ -238,7 +238,7 @@ def start_activity(
logging.error('Failed to launch activity: %r', activity)
return response

logging.debug('Launch package output %r', response.generic.output)
logging.debug('Launch package output %r', response.output)
return response


Expand Down Expand Up @@ -719,7 +719,7 @@ def close_recents(env: env_interface.AndroidEnvInterface):
response = issue_generic_request('shell dumpsys activity recents', env)
if response.status != adb_pb2.AdbResponse.Status.OK:
return
recents_ids = re.findall(r'id=(\d+)', response.generic.output.decode())
recents_ids = re.findall(r'id=(\d+)', response.output.decode())
for recents_id in recents_ids:
issue_generic_request(['shell', 'am', 'stack', 'remove', recents_id], env)

Expand Down Expand Up @@ -910,7 +910,7 @@ def get_api_level(env: env_interface.AndroidEnvInterface) -> int:
)
if version.status != adb_pb2.AdbResponse.Status.OK:
raise RuntimeError('Failed to get API level.')
return int(version.generic.output)
return int(version.output)


def _toggle_svc(
Expand Down Expand Up @@ -1081,10 +1081,10 @@ def check_airplane_mode(env: env_interface.AndroidEnvInterface) -> bool:
if response.status != adb_pb2.AdbResponse.Status.OK:
raise RuntimeError(
f'ADB command failed with status {response.status}:'
f' {response.generic.output.decode()}.'
f' {response.output.decode()}.'
)

return response.generic.output.decode().replace('\r', '').strip('\n') == '1'
return response.output.decode().replace('\r', '').strip('\n') == '1'


def extract_broadcast_data(raw_output: str) -> Optional[str]:
Expand Down Expand Up @@ -1155,7 +1155,7 @@ def get_clipboard_contents(env: env_interface.AndroidEnvInterface) -> str:
if res.status != adb_pb2.AdbResponse.Status.OK:
raise RuntimeError('Failed to get clipboard content.')

output_str = res.generic.output.decode('utf-8')
output_str = res.output.decode('utf-8')
result = _extract_clipper_output(output_str)

press_back_button(env)
Expand Down Expand Up @@ -1221,7 +1221,7 @@ def set_clipboard_contents(
output_str = issue_generic_request(
['shell', 'am', 'broadcast', '-a', 'clipper.set', '-e', 'text', content],
env,
).generic.output.decode('utf-8')
).output.decode('utf-8')
_extract_clipper_output(output_str)
press_back_button(env)

Expand Down Expand Up @@ -1288,7 +1288,7 @@ def get_call_state(
adb_args = ['shell', 'dumpsys', 'telephony.registry']
response = issue_generic_request(adb_args, env, timeout_sec)

output = response.generic.output.decode('utf-8')
output = response.output.decode('utf-8')
state_match = re.search(r'mCallState=(\d)', output)

state = 'UNKNOWN'
Expand Down Expand Up @@ -1540,7 +1540,7 @@ def get_all_settings(env: env_interface.AndroidEnvInterface) -> dict[str, str]:
settings = {}
for adb_command in adb_commands:
response = issue_generic_request(adb_command, env)
lines = response.generic.output.decode().split('\n')
lines = response.output.decode().split('\n')
for line in lines:
if not line:
continue
Expand Down Expand Up @@ -1602,9 +1602,7 @@ def get_screen_size(env: env_interface.AndroidEnvInterface) -> tuple[int, int]:
"""
adb_command = ['shell', 'wm size']
adb_response = issue_generic_request(adb_command, env)
return _parse_screen_size_response(
adb_response.generic.output.decode('utf-8')
)
return _parse_screen_size_response(adb_response.output.decode('utf-8'))


def get_logical_screen_size(
Expand All @@ -1627,7 +1625,7 @@ def get_logical_screen_size(
'shell dumpsys input | grep logicalFrame', env
)
if response.status:
raw_output = response.generic.output.decode('utf-8')
raw_output = response.output.decode('utf-8')
pattern = r'logicalFrame=\[0, 0, (\d+), (\d+)\]'
matches = re.findall(pattern, raw_output)
for m in matches:
Expand All @@ -1654,7 +1652,7 @@ def get_physical_frame_boundary(
'shell dumpsys input | grep physicalFrame', env
)
if response.status:
raw_output = response.generic.output.decode('utf-8')
raw_output = response.output.decode('utf-8')
pattern = r'physicalFrame=\[(\d+), (\d+), (\d+), (\d+)\]'
matches = re.findall(pattern, raw_output)
for m in matches:
Expand Down Expand Up @@ -1690,7 +1688,7 @@ def get_orientation(
'shell dumpsys window | grep mCurrentRotation', env
)
if response.status:
raw_output = response.generic.output.decode('utf-8')
raw_output = response.output.decode('utf-8')
pattern = r'mCurrentRotation=ROTATION_(\d+)'
matches = re.findall(pattern, raw_output)
for m in matches:
Expand Down Expand Up @@ -1763,7 +1761,7 @@ def set_root_if_needed(
"""
response = issue_generic_request(['shell', 'whoami'], env, timeout_sec)

if response.generic.output.decode('utf-8').strip() == 'root':
if response.output.decode('utf-8').strip() == 'root':
return response

return issue_generic_request(['root'], env, timeout_sec)
Expand All @@ -1777,4 +1775,4 @@ def uiautomator_dump(env, timeout_sec: Optional[float] = 30) -> str:
read_args = 'shell cat /sdcard/window_dump.xml'
response = issue_generic_request(read_args, env, timeout_sec=timeout_sec)

return response.generic.output.decode('utf-8')
return response.output.decode('utf-8')
20 changes: 10 additions & 10 deletions android_world/env/adb_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_get_call_state_idle(self):
mForegroundCallState=0"""
# Setup
mock_dumpsys_response = adb_pb2.AdbResponse()
mock_dumpsys_response.generic.output = dumpsys_content.encode('utf-8')
mock_dumpsys_response.output = dumpsys_content.encode('utf-8')
self.mock_issue_generic_request.return_value = mock_dumpsys_response

# Act
Expand All @@ -65,7 +65,7 @@ def test_get_call_state_ringing(self):
mForegroundCallState=0"""
# Setup
mock_dumpsys_response = adb_pb2.AdbResponse()
mock_dumpsys_response.generic.output = dumpsys_content.encode('utf-8')
mock_dumpsys_response.output = dumpsys_content.encode('utf-8')
self.mock_issue_generic_request.return_value = mock_dumpsys_response

# Act
Expand All @@ -76,13 +76,13 @@ def test_get_call_state_ringing(self):

def test_call_emulator(self):
mock_response = adb_pb2.AdbResponse()
mock_response.generic.output = b'Success'
mock_response.output = b'Success'
self.mock_issue_generic_request.return_value = mock_response

phone_number = '+123456789'
result = adb_utils.call_emulator(self.mock_env, phone_number)

self.assertEqual(result.generic.output.decode(), 'Success')
self.assertEqual(result.output.decode(), 'Success')

@mock.patch.object(adb_utils, 'get_call_state', autospec=True)
def test_end_call_if_active(self, mock_get_call_state):
Expand All @@ -97,38 +97,38 @@ def test_clear_android_emulator_call_log(self):

def test_call_phone_number(self):
mock_response = adb_pb2.AdbResponse()
mock_response.generic.output = b'Success'
mock_response.output = b'Success'
self.mock_issue_generic_request.return_value = mock_response

phone_number = '123456789'
result = adb_utils.call_phone_number(self.mock_env, phone_number)

self.assertEqual(result.generic.output.decode(), 'Success')
self.assertEqual(result.output.decode(), 'Success')

def test_text_emulator(self):
mock_response = adb_pb2.AdbResponse()
mock_response.generic.output = b'Success'
mock_response.output = b'Success'
self.mock_issue_generic_request.return_value = mock_response

phone_number = '+123456789'
message = 'Hello, world!'
result = adb_utils.text_emulator(self.mock_env, phone_number, message)

self.assertEqual(result.generic.output.decode(), 'Success')
self.assertEqual(result.output.decode(), 'Success')


class AdbSettingsTest(AdbTestSetup):

def test_set_default_app(self):
mock_response = adb_pb2.AdbResponse()
mock_response.generic.output = b'Success'
mock_response.output = b'Success'
self.mock_issue_generic_request.return_value = mock_response

setting_key = 'sms_default_application'
package_name = 'com.example.app'
result = adb_utils.set_default_app(self.mock_env, setting_key, package_name)

self.assertEqual(result.generic.output.decode(), 'Success')
self.assertEqual(result.output.decode(), 'Success')

def test_successful_put_operation(self):
self.mock_env.execute_adb_call.return_value = adb_pb2.AdbResponse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def is_successful(self, env: interface.AsyncEnv) -> float:
],
env.controller,
)
file_contents = res.generic.output.decode().replace("\r", "").strip()
file_contents = res.output.decode().replace("\r", "").strip()
match = fuzzy_match_lib.fuzzy_match(file_contents, self.params["text"])
if not match:
logging.info("%s does not match %s", file_contents, self.params["text"])
Expand Down
16 changes: 6 additions & 10 deletions android_world/task_evals/common_validators/file_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_is_successful(self):
self.mock_check_file_or_folder_exists.return_value = True

mock_response_cat = adb_pb2.AdbResponse()
mock_response_cat.generic.output = b"Hello World"
mock_response_cat.output = b"Hello World"
self.mock_issue_generic_request.return_value = mock_response_cat

env = mock.MagicMock()
Expand Down Expand Up @@ -68,7 +68,7 @@ def test_is_successful(
self,
):
response_ls_deleted = adb_pb2.AdbResponse()
response_ls_deleted.generic.output = b"another_note.md\n"
response_ls_deleted.output = b"another_note.md\n"
self.mock_check_file_or_folder_exists.side_effect = [
True, # File exists.
False, # File doesn't exist.
Expand All @@ -88,7 +88,7 @@ def test_is_successful(
def test_is_successful_subfolder(self):
# Create mock adb response for 'ls' command when note is deleted
mock_response_ls_deleted = adb_pb2.AdbResponse()
mock_response_ls_deleted.generic.output = b"another_note.md\n"
mock_response_ls_deleted.output = b"another_note.md\n"
self.mock_check_file_or_folder_exists.side_effect = [
True, # File exists.
False, # File doesn't exist.
Expand All @@ -109,9 +109,7 @@ def test_is_successful_subfolder(self):
def test_is_not_successful(self):
# Create mock adb response for 'ls' command when note still exists
mock_response_ls_still_exists = adb_pb2.AdbResponse()
mock_response_ls_still_exists.generic.output = (
b"test_note.md\nanother_note.md\n"
)
mock_response_ls_still_exists.output = b"test_note.md\nanother_note.md\n"
self.mock_check_file_or_folder_exists.side_effect = [
True, # File exists.
True, # File still exists.
Expand Down Expand Up @@ -143,7 +141,7 @@ def setUp(self):
def test_is_successful(self):
# Create mock adb response for 'ls' command when note is deleted
mock_response_ls_deleted = adb_pb2.AdbResponse()
mock_response_ls_deleted.generic.output = b"another_note.md\n"
mock_response_ls_deleted.output = b"another_note.md\n"

self.mock_check_file_or_folder_exists.side_effect = [
True, # Source file exists.
Expand All @@ -166,9 +164,7 @@ def test_is_successful(self):
def test_is_not_successful(self):
# Create mock adb response for 'ls' command when note still exists
mock_response_ls_still_exists = adb_pb2.AdbResponse()
mock_response_ls_still_exists.generic.output = (
b"test_note.md\nanother_note.md\n"
)
mock_response_ls_still_exists.output = b"test_note.md\nanother_note.md\n"

self.mock_check_file_or_folder_exists.side_effect = [
True, # Source file exists.
Expand Down
10 changes: 3 additions & 7 deletions android_world/task_evals/common_validators/sms_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ def parse_message(row: str) -> dict[str, str]:

def _decode_messages_from_response(response: adb_pb2.AdbResponse) -> list[str]:
"""Decodes the ADB response into a list of messages."""
if (
response.generic.output.decode()
.replace("\r", "")
.startswith("No result found.")
):
if response.output.decode().replace("\r", "").startswith("No result found."):
return []
messages = response.generic.output.split(b"\nRow:")
messages = response.output.split(b"\nRow:")
for i, m in enumerate(messages):
if i > 0:
messages[i] = b"Row:" + m
Expand Down Expand Up @@ -229,7 +225,7 @@ def get_android_time(self, env: env_interface.AndroidEnvInterface) -> int:
adb_output = adb_utils.issue_generic_request(
["shell", "date", "+%s"], env
) # Fetch UNIX timestamp from Android
return int(adb_output.generic.output.strip()) * 1000
return int(adb_output.output.strip()) * 1000

def initialize_task(self, env: interface.AsyncEnv) -> None:
super().initialize_task(env)
Expand Down
16 changes: 6 additions & 10 deletions android_world/task_evals/common_validators/sms_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,13 @@ def setUp(self):
def test_is_successful(self):
# From shell date +%s
mock_response_time = adb_pb2.AdbResponse()
mock_response_time.generic.output = '{}'.format(
str(int(time.time()))
).encode()
mock_response_time.output = '{}'.format(str(int(time.time()))).encode()

# Make stale message.
one_day_s = 24 * 60 * 60
mock_response_sms0 = adb_pb2.AdbResponse()
date0_ms = str(int((time.time() - one_day_s) * 1000))
mock_response_sms0.generic.output = (
mock_response_sms0.output = (
'Row: 0, address=1234567890, body=Hello World, service_center=NULL,'
' date={}'.format(
date0_ms
Expand All @@ -136,7 +134,7 @@ def test_is_successful(self):
# Successful message.
mock_response_sms1 = adb_pb2.AdbResponse()
date1_ms = str(int(time.time() * 1000))
mock_response_sms1.generic.output = (
mock_response_sms1.output = (
'Row: 0, address=1234567890, body=Hello World, service_center=NULL,'
' date={}'.format(
date1_ms
Expand All @@ -163,15 +161,13 @@ def test_is_successful(self):
def test_initialize_task_message_already_sent(self):
# From shell date +%s
mock_response_time = adb_pb2.AdbResponse()
mock_response_time.generic.output = '{}'.format(
str(int(time.time()))
).encode()
mock_response_time.output = '{}'.format(str(int(time.time()))).encode()

# Make stale message.
one_s = 1
mock_response_sms0 = adb_pb2.AdbResponse()
date0_ms = str(int((time.time() - one_s) * 1000))
mock_response_sms0.generic.output = (
mock_response_sms0.output = (
'Row: 0, address=1234567890, body=Hello World, service_center=NULL,'
' date={}'.format(
date0_ms
Expand All @@ -181,7 +177,7 @@ def test_initialize_task_message_already_sent(self):
# Successful message.
mock_response_sms1 = adb_pb2.AdbResponse()
date1_ms = str(int(time.time() * 1000))
mock_response_sms1.generic.output = (
mock_response_sms1.output = (
'Row: 0, address=1234567890, body=Hello World, service_center=NULL,'
' date={}'.format(
date1_ms
Expand Down
Loading
Loading