diff --git a/android_world/env/adb_utils.py b/android_world/env/adb_utils.py index 17a53f53..ef1e3b48 100644 --- a/android_world/env/adb_utils.py +++ b/android_world/env/adb_utils.py @@ -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()}.' ) @@ -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 @@ -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) @@ -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( @@ -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]: @@ -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) @@ -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) @@ -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' @@ -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 @@ -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( @@ -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: @@ -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: @@ -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: @@ -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) @@ -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') diff --git a/android_world/env/adb_utils_test.py b/android_world/env/adb_utils_test.py index b7b38f7c..047de48d 100644 --- a/android_world/env/adb_utils_test.py +++ b/android_world/env/adb_utils_test.py @@ -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 @@ -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 @@ -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): @@ -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() diff --git a/android_world/task_evals/common_validators/file_validators.py b/android_world/task_evals/common_validators/file_validators.py index c250c116..4b15808d 100644 --- a/android_world/task_evals/common_validators/file_validators.py +++ b/android_world/task_evals/common_validators/file_validators.py @@ -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"]) diff --git a/android_world/task_evals/common_validators/file_validators_test.py b/android_world/task_evals/common_validators/file_validators_test.py index f4c3eebd..705aad71 100644 --- a/android_world/task_evals/common_validators/file_validators_test.py +++ b/android_world/task_evals/common_validators/file_validators_test.py @@ -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() @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/android_world/task_evals/common_validators/sms_validators.py b/android_world/task_evals/common_validators/sms_validators.py index 85db111d..71f2c1f0 100644 --- a/android_world/task_evals/common_validators/sms_validators.py +++ b/android_world/task_evals/common_validators/sms_validators.py @@ -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 @@ -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) diff --git a/android_world/task_evals/common_validators/sms_validators_test.py b/android_world/task_evals/common_validators/sms_validators_test.py index a2ff239c..ee0339a5 100644 --- a/android_world/task_evals/common_validators/sms_validators_test.py +++ b/android_world/task_evals/common_validators/sms_validators_test.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/android_world/task_evals/composite/markor_sms_test.py b/android_world/task_evals/composite/markor_sms_test.py index 9612d83b..379bc776 100644 --- a/android_world/task_evals/composite/markor_sms_test.py +++ b/android_world/task_evals/composite/markor_sms_test.py @@ -39,25 +39,21 @@ def setUp(self): def test_MarkorCreateNoteAndSms_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() # Create mock adb response for 'cat' command mock_response_cat = adb_pb2.AdbResponse() - mock_response_cat.generic.output = b'Hello World' + mock_response_cat.output = b'Hello World' # 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 @@ -67,7 +63,7 @@ def test_MarkorCreateNoteAndSms_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 @@ -99,25 +95,21 @@ def test_MarkorCreateNoteAndSms_is_successful(self): def test_MarkorCreateNoteAndSms_partial_success(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() # Create mock adb response for 'cat' command mock_response_cat = adb_pb2.AdbResponse() - mock_response_cat.generic.output = b'Hello World' + mock_response_cat.output = b'Hello World' # 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 @@ -126,9 +118,7 @@ def test_MarkorCreateNoteAndSms_partial_success(self): # No message found response. mock_response_sms1 = adb_pb2.AdbResponse() - mock_response_sms1.generic.output = ( - 'No result found.'.encode() - ) + mock_response_sms1.output = 'No result found.'.encode() self.mock_issue_generic_request.side_effect = [ mock_response_time, diff --git a/android_world/task_evals/miniwob/miniwob_base.py b/android_world/task_evals/miniwob/miniwob_base.py index fe5f74fd..f2b381b2 100644 --- a/android_world/task_evals/miniwob/miniwob_base.py +++ b/android_world/task_evals/miniwob/miniwob_base.py @@ -32,9 +32,7 @@ def _extract_data( """Issues broadcast and extracts data with retries.""" for _ in range(3): raw = adb_utils.send_android_intent("broadcast", action, env) - result = adb_utils.extract_broadcast_data( - raw.generic.output.decode("utf-8") - ) + result = adb_utils.extract_broadcast_data(raw.output.decode("utf-8")) if result is not None: return result time.sleep(1) # App still needs to load. diff --git a/android_world/task_evals/single/camera.py b/android_world/task_evals/single/camera.py index 79673281..4dd66cd4 100644 --- a/android_world/task_evals/single/camera.py +++ b/android_world/task_evals/single/camera.py @@ -60,9 +60,9 @@ def initialize_task(self, env: interface.AsyncEnv) -> None: ["shell", "ls", device_constants.VIDEOS_DATA], env.controller, ) - logging.info("before_videos: %s", contents.generic.output.decode()) + logging.info("before_videos: %s", contents.output.decode()) self.before_videos = set( - contents.generic.output.decode().replace("\r", "").split("\n") + contents.output.decode().replace("\r", "").split("\n") ) logging.info("num before_videos: %s", self.before_videos) @@ -72,10 +72,8 @@ def is_successful(self, env: interface.AsyncEnv) -> float: ["shell", "ls", device_constants.VIDEOS_DATA], env.controller, ) - logging.info("before_videos: %s", contents.generic.output.decode()) - after_videos = set( - contents.generic.output.decode().replace("\r", "").split("\n") - ) + logging.info("before_videos: %s", contents.output.decode()) + after_videos = set(contents.output.decode().replace("\r", "").split("\n")) logging.info("num after_videos: %s", after_videos) logging.info( "number of after_videos - number of before_videos: %s", @@ -105,9 +103,9 @@ def initialize_task(self, env: interface.AsyncEnv) -> None: contents = adb_utils.issue_generic_request( ["shell", "ls", device_constants.PHOTOS_DATA], env.controller ) - logging.info("before_photos: %s", contents.generic.output.decode()) + logging.info("before_photos: %s", contents.output.decode()) self.before_photos = set( - contents.generic.output.decode().replace("\r", "").split("\n") + contents.output.decode().replace("\r", "").split("\n") ) logging.info("num before_photos: %s", self.before_photos) @@ -116,10 +114,8 @@ def is_successful(self, env: interface.AsyncEnv) -> float: contents = adb_utils.issue_generic_request( ["shell", "ls", device_constants.PHOTOS_DATA], env.controller ) - logging.info("after_photos: %s", contents.generic.output.decode()) - after_photos = set( - contents.generic.output.decode().replace("\r", "").split("\n") - ) + logging.info("after_photos: %s", contents.output.decode()) + after_photos = set(contents.output.decode().replace("\r", "").split("\n")) logging.info("num after_photos: %s", after_photos) logging.info( "number of after_photos - number of before_photos: %s", diff --git a/android_world/task_evals/single/markor.py b/android_world/task_evals/single/markor.py index d353d84c..f01f75d4 100644 --- a/android_world/task_evals/single/markor.py +++ b/android_world/task_evals/single/markor.py @@ -233,7 +233,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() logging.info("Retrieved file contents: %s", file_contents) if self.params["edit_type"] == "header": @@ -620,7 +620,7 @@ def is_successful(self, env: interface.AsyncEnv) -> float: ], env.controller, ) - .generic.output.decode() + .output.decode() .replace("\r", "") .strip() ) diff --git a/android_world/task_evals/single/markor_test.py b/android_world/task_evals/single/markor_test.py index 2cbc5f4f..7dabf6db 100644 --- a/android_world/task_evals/single/markor_test.py +++ b/android_world/task_evals/single/markor_test.py @@ -30,7 +30,7 @@ class TestMarkorEditNote(test_utils.AdbEvalTestBase): def test_is_successful_edit_header(self): self.mock_create_file.return_value = 'Original Content' edited_content = adb_pb2.AdbResponse() - edited_content.generic.output = b'Header\nOriginal Content' + edited_content.output = b'Header\nOriginal Content' self.mock_issue_generic_request.return_value = edited_content env = mock.create_autospec(interface.AsyncEnv) params = { @@ -51,7 +51,7 @@ def test_is_successful_edit_footer(self): self.mock_create_file.return_value = 'Original Content' edited_content = adb_pb2.AdbResponse() - edited_content.generic.output = b'Original Content\nFooter' + edited_content.output = b'Original Content\nFooter' self.mock_issue_generic_request.return_value = edited_content @@ -76,7 +76,7 @@ def test_is_successful_edit_replace(self): self.mock_create_file.return_value = 'Original Content' mock_edited_content = adb_pb2.AdbResponse() - mock_edited_content.generic.output = b'Replacement Text' + mock_edited_content.output = b'Replacement Text' self.mock_issue_generic_request.return_value = mock_edited_content @@ -101,7 +101,7 @@ def test_is_not_successful(self): self.mock_create_file.return_value = 'Original Content' mock_edited_content = adb_pb2.AdbResponse() - mock_edited_content.generic.output = b'Original Content' + mock_edited_content.output = b'Original Content' self.mock_issue_generic_request.return_value = mock_edited_content @@ -279,7 +279,7 @@ def test_is_successful( self.mock_check_file_or_folder_exists.return_value = True merged_content = adb_pb2.AdbResponse() - merged_content.generic.output = ( + merged_content.output = ( b'file1 content.\n\nfile2 content.\n\nfile3 content.\n' ) self.mock_issue_generic_request.side_effect = [ @@ -296,7 +296,7 @@ def test_is_successful(self): env = mock.create_autospec(interface.AsyncEnv) self.mock_check_file_or_folder_exists.side_effect = [True, False, True] new_content = adb_pb2.AdbResponse() - new_content.generic.output = b'new content' + new_content.output = b'new content' self.mock_issue_generic_request.return_value = new_content task = markor.MarkorChangeNoteContent({ @@ -314,7 +314,7 @@ def test_is_successful(self): env = mock.create_autospec(interface.AsyncEnv) self.mock_check_file_or_folder_exists.side_effect = [True, False, True] new_content = adb_pb2.AdbResponse() - new_content.generic.output = b'header to add\n\noriginal content\n' + new_content.output = b'header to add\n\noriginal content\n' self.mock_issue_generic_request.return_value = new_content task = markor.MarkorAddNoteHeader({ diff --git a/android_world/task_evals/single/osmand.py b/android_world/task_evals/single/osmand.py index 576e32d7..868c4e80 100644 --- a/android_world/task_evals/single/osmand.py +++ b/android_world/task_evals/single/osmand.py @@ -326,7 +326,7 @@ def _clear_tracks(env: env_interface.AndroidEnvInterface): if response.status != adb_pb2.AdbResponse.OK: raise RuntimeError( f'ADB command failed with status {response.status}:' - f' {response.generic.output.decode()}.' + f' {response.output.decode()}.' ) diff --git a/android_world/task_evals/single/sms_test.py b/android_world/task_evals/single/sms_test.py index dafe9db1..724571de 100644 --- a/android_world/task_evals/single/sms_test.py +++ b/android_world/task_evals/single/sms_test.py @@ -179,7 +179,7 @@ def test_is_successful(self): new_message = 'New message' mock_sent_message = adb_pb2.AdbResponse() date_ms = str(int(time.time() * 1000)) - mock_sent_message.generic.output = ( + mock_sent_message.output = ( 'Row: 0, address={}, body={}, service_center=NULL, date={}'.format( self.most_recent_number, new_message, date_ms ).encode() @@ -281,7 +281,7 @@ def test_is_successful(self): # Add successful message mock_sent_message = adb_pb2.AdbResponse() date_ms = str(int(time.time() * 1000)) - mock_sent_message.generic.output = ( + mock_sent_message.output = ( 'Row: 0, address={}, body={}, service_center=NULL, date={}'.format( self.relevant_number, new_message, date_ms ).encode() diff --git a/android_world/task_evals/single/system.py b/android_world/task_evals/single/system.py index c9e4cc72..6f41df14 100644 --- a/android_world/task_evals/single/system.py +++ b/android_world/task_evals/single/system.py @@ -44,7 +44,7 @@ def is_successful(self, env: interface.AsyncEnv) -> float: ['shell', 'settings', 'get', 'system', 'screen_brightness'], env.controller, ) - brightness_level = int(res.generic.output.decode().strip()) + brightness_level = int(res.output.decode().strip()) if self.params['max_or_min'] == 'max': return 1.0 if brightness_level == 255 else 0.0 @@ -133,7 +133,7 @@ def is_successful(self, env: interface.AsyncEnv) -> float: res = adb_utils.issue_generic_request( ['shell', 'settings', 'get', 'global', 'wifi_on'], env.controller ) - wifi_status = res.generic.output.decode().strip() + wifi_status = res.output.decode().strip() if self.params['on_or_off'] == 'on': # WiFi is on when the value is either 1 or 2. If Airplane mode is on, and @@ -225,7 +225,7 @@ def is_successful(self, env: interface.AsyncEnv) -> float: res = adb_utils.issue_generic_request( ['shell', 'settings', 'get', 'global', 'bluetooth_on'], env.controller ) - bluetooth_status = res.generic.output.decode().strip() + bluetooth_status = res.output.decode().strip() expected_status = '1' if self.params['on_or_off'] == 'on' else '0' return 1.0 if bluetooth_status == expected_status else 0.0 diff --git a/android_world/utils/contacts_utils.py b/android_world/utils/contacts_utils.py index 5f23281a..192e2c6c 100644 --- a/android_world/utils/contacts_utils.py +++ b/android_world/utils/contacts_utils.py @@ -100,9 +100,9 @@ def parse(adb_output: str) -> Iterator[Contact]: return list( parse( - adb_utils.issue_generic_request( - adb_command, env - ).generic.output.decode("utf-8") + adb_utils.issue_generic_request(adb_command, env).output.decode( + "utf-8" + ) ) ) diff --git a/android_world/utils/contacts_utils_test.py b/android_world/utils/contacts_utils_test.py index 503c3d87..881e6237 100644 --- a/android_world/utils/contacts_utils_test.py +++ b/android_world/utils/contacts_utils_test.py @@ -54,7 +54,7 @@ def test_list_contacts(self, unused_mock_click_element, mock_generic_request): """Test listing all contacts.""" mock_env = mock.create_autospec(env_interface.AndroidEnvInterface) adb_response = adb_pb2.AdbResponse() - adb_response.generic.output = """ + adb_response.output = """ Row: 0 display_name=Jane Doe, number=1 (234) 567-89 Row: 0 display_name=Chen, number=98765 """.encode("utf-8") diff --git a/android_world/utils/datetime_utils.py b/android_world/utils/datetime_utils.py index 8ee68a0d..ace90a33 100644 --- a/android_world/utils/datetime_utils.py +++ b/android_world/utils/datetime_utils.py @@ -171,9 +171,9 @@ def advance_system_time( # Get current system time by parsing the output of running adb shell date # which looks like "Sun Oct 15 17:04:16 UTC 2023". current_time = datetime.datetime.strptime( - adb_utils.issue_generic_request( - ['shell', 'date'], env - ).generic.output.decode().strip(), + adb_utils.issue_generic_request(['shell', 'date'], env) + .output.decode() + .strip(), '%a %b %d %H:%M:%S %Z %Y', ) diff --git a/android_world/utils/datetime_utils_test.py b/android_world/utils/datetime_utils_test.py index cb64b7a1..4ad0dfa2 100644 --- a/android_world/utils/datetime_utils_test.py +++ b/android_world/utils/datetime_utils_test.py @@ -61,9 +61,7 @@ def test_advance_system_time(self, mock_issue_generic_request): env_mock = mock.create_autospec(env_interface.AndroidEnvInterface) mock_issue_generic_request.return_value = adb_pb2.AdbResponse( status=adb_pb2.AdbResponse.Status.OK, - generic=adb_pb2.AdbResponse.GenericResponse( - output=bytes('Sun Oct 15 17:04:16 UTC 2023\n', 'utf-8') - ), + output=bytes('Sun Oct 15 17:04:16 UTC 2023\n', 'utf-8'), ) datetime_utils.advance_system_time(datetime.timedelta(hours=2), env_mock) mock_issue_generic_request.assert_has_calls([ diff --git a/android_world/utils/fake_adb_responses.py b/android_world/utils/fake_adb_responses.py index cb86d3c9..91d1e513 100644 --- a/android_world/utils/fake_adb_responses.py +++ b/android_world/utils/fake_adb_responses.py @@ -26,9 +26,7 @@ def create_successful_generic_response(output: str) -> adb_pb2.AdbResponse: return adb_pb2.AdbResponse( status=adb_pb2.AdbResponse.Status.OK, - generic=adb_pb2.AdbResponse.GenericResponse( - output=output.encode("utf-8") - ), + output=output.encode("utf-8"), ) diff --git a/android_world/utils/file_utils.py b/android_world/utils/file_utils.py index bf228034..bdda8177 100644 --- a/android_world/utils/file_utils.py +++ b/android_world/utils/file_utils.py @@ -119,7 +119,7 @@ def clear_directory( res = adb_utils.issue_generic_request( ["shell", "ls", "-1", directory_path], env ) - folder_contents = res.generic.output.decode().replace("\r", "").strip() + folder_contents = res.output.decode().replace("\r", "").strip() if folder_contents: adb_utils.check_ok( @@ -252,7 +252,7 @@ def check_file_or_folder_exists( if not res.status: raise RuntimeError("ADB command failed.") - all_paths = set(res.generic.output.decode().replace("\r", "").split("\n")) + all_paths = set(res.output.decode().replace("\r", "").split("\n")) full_target_path = convert_to_posix_path(base_path, target) return full_target_path in all_paths @@ -282,9 +282,9 @@ def check_file_exists( fi """ response = adb_utils.issue_generic_request(["shell", bash_script], env) - if "Exists" in response.generic.output.decode("utf-8"): + if "Exists" in response.output.decode("utf-8"): return True - elif "Does not exist" in response.generic.output.decode("utf-8"): + elif "Does not exist" in response.output.decode("utf-8"): return False else: raise errors.AdbControllerError("Unexpected output from file check") @@ -350,7 +350,7 @@ def tmp_directory_from_device( with open( convert_to_posix_path(tmp_directory, file.file_name), "wb" ) as f: - f.write(pull_response.pull.content) + f.write(pull_response.output) yield tmp_directory @@ -406,7 +406,7 @@ def tmp_file_from_device( adb_utils.check_ok(pull_response) with open(local_file, "wb") as f: - f.write(pull_response.pull.content) + f.write(pull_response.output) yield local_file finally: @@ -525,7 +525,7 @@ def get_file_list_with_metadata( # follows, # -rw-rw---- 1 u0_a158 media_rw 0 2023-11-28 23:17:43.176000000 +0000 1.txt # We loop through all the files and collect regular files with metadata. - for file_details in ls_response.generic.output.decode("utf-8").split("\n"): + for file_details in ls_response.output.decode("utf-8").split("\n"): # In shell output, the first character is used to indicate file type and # "-" means the file is a regular file. if file_details.startswith("-"): @@ -578,7 +578,7 @@ def check_file_content( res = adb_utils.issue_generic_request( ["shell", "cat", file_full_path], env, timeout_sec ) - res_content = res.generic.output.decode().replace("\r", "") + res_content = res.output.decode().replace("\r", "") if exact_match: return res_content == content return fuzzy_match_lib.fuzzy_match(res_content.strip(), content) diff --git a/android_world/utils/file_utils_test.py b/android_world/utils/file_utils_test.py index cd4c2229..ae460f82 100644 --- a/android_world/utils/file_utils_test.py +++ b/android_world/utils/file_utils_test.py @@ -44,14 +44,14 @@ def tearDown(self): mock.patch.stopall() def test_check_directory_exists(self): - self.mock_issue_generic_request.return_value.generic.output.decode.return_value = ( + self.mock_issue_generic_request.return_value.output.decode.return_value = ( 'Exists' ) result = file_utils.check_directory_exists('/existing/path', self.mock_env) self.assertTrue(result) # Test case where directory does not exist - self.mock_issue_generic_request.return_value.generic.output.decode.return_value = ( + self.mock_issue_generic_request.return_value.output.decode.return_value = ( 'Does not exist' ) result = file_utils.check_directory_exists( @@ -78,14 +78,12 @@ def test_tmp_directory_from_device( mock_check_directory_exists.return_value = True self.mock_issue_generic_request.return_value = adb_pb2.AdbResponse( status=adb_pb2.AdbResponse.Status.OK, - generic=adb_pb2.AdbResponse.GenericResponse( - output=bytes( - '-rw-rw---- 1 u0_a158 media_rw 0 2023-11-28 23:17:43.176000000' - f' +0000 {file_names[0]}\n' - '-rw-rw---- 1 u0_a158 media_rw 0 2023-11-28 23:17:43.176000000' - f' +0000 {file_names[1]}', - 'utf-8', - ) + output=bytes( + '-rw-rw---- 1 u0_a158 media_rw 0 2023-11-28 23:17:43.176000000' + f' +0000 {file_names[0]}\n' + '-rw-rw---- 1 u0_a158 media_rw 0 2023-11-28 23:17:43.176000000' + f' +0000 {file_names[1]}', + 'utf-8', ), ) @@ -218,12 +216,10 @@ def test_get_file_list_with_metadata(self, mock_check_directory_exists): mock_check_directory_exists.return_value = True self.mock_issue_generic_request.return_value = adb_pb2.AdbResponse( status=adb_pb2.AdbResponse.Status.OK, - generic=adb_pb2.AdbResponse.GenericResponse( - output=bytes( - '-rw-rw---- 1 u0_a158 media_rw 0 2023-11-28 23:17:43.176000000' - ' +0000 test.txt', - 'utf-8', - ) + output=bytes( + '-rw-rw---- 1 u0_a158 media_rw 0 2023-11-28 23:17:43.176000000' + ' +0000 test.txt', + 'utf-8', ), ) file_list = file_utils.get_file_list_with_metadata( @@ -243,11 +239,9 @@ def test_get_file_list_with_metadata(self, mock_check_directory_exists): def test_check_file_content(self): self.mock_issue_generic_request.return_value = adb_pb2.AdbResponse( status=adb_pb2.AdbResponse.Status.OK, - generic=adb_pb2.AdbResponse.GenericResponse( - output=bytes( - 'test content.', - 'utf-8', - ) + output=bytes( + 'test content.', + 'utf-8', ), )