From ab451217332ae43fe22f9fc4af783a8da80db86f Mon Sep 17 00:00:00 2001 From: Chris Rawles Date: Mon, 4 Nov 2024 13:33:08 -0800 Subject: [PATCH] Fixes for Osmand app * For the tracks task, the wrong method was used to pull the tracks data; now we pull the entire directory * Fix bug where deletion from db wouldn't work if the table didn't exist: sleep a little longer after opening the app General fix: * Fix issue where list files wouldn't work if file names had spaces in them. PiperOrigin-RevId: 693075361 --- android_world/task_evals/single/osmand.py | 4 ++-- .../task_evals/utils/sqlite_utils.py | 2 +- android_world/utils/file_utils.py | 23 +++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/android_world/task_evals/single/osmand.py b/android_world/task_evals/single/osmand.py index 10188b5..b833814 100644 --- a/android_world/task_evals/single/osmand.py +++ b/android_world/task_evals/single/osmand.py @@ -416,8 +416,8 @@ def initialize_task(self, env: interface.AsyncEnv) -> None: ) def is_successful(self, env: interface.AsyncEnv) -> float: - with env.controller.pull_file( - os.path.join(_DEVICE_FILES, 'tracks') + with file_utils.tmp_directory_from_device( + os.path.join(_DEVICE_FILES, 'tracks'), env.controller ) as tracks_directory: for track_file in os.listdir(tracks_directory): if _track_matches( diff --git a/android_world/task_evals/utils/sqlite_utils.py b/android_world/task_evals/utils/sqlite_utils.py index baa245a..9dfd42c 100644 --- a/android_world/task_evals/utils/sqlite_utils.py +++ b/android_world/task_evals/utils/sqlite_utils.py @@ -148,7 +148,7 @@ def delete_all_rows_from_table( if not table_exists(table_name, remote_db_file_path, env): # If the database was never created, opening the app may create it. adb_utils.launch_app(app_name, env.controller) - time.sleep(2.0) + time.sleep(7.0) with env.controller.pull_file( remote_db_file_path, timeout_sec diff --git a/android_world/utils/file_utils.py b/android_world/utils/file_utils.py index ae1aecf..cc6aa3e 100644 --- a/android_world/utils/file_utils.py +++ b/android_world/utils/file_utils.py @@ -453,8 +453,8 @@ def get_file_list_with_metadata( ) -> list[FileWithMetadata]: """Get the list of all (regular) files with metadata in a given directory. - Right now we only list regular files in the given directory and only grab - file name, full directory and change time in metadata. + Right now we only list regular files in the given directory and only grab file + name, full directory and change time in metadata. Args: directory_path: The directory to list all its files. @@ -463,21 +463,17 @@ def get_file_list_with_metadata( Returns: A list of files with metadata. - Raises: RuntimeError: If the input directory path is not valid or shell ls fails. """ if not check_directory_exists(directory_path, env): raise RuntimeError(f"{directory_path} is not a valid directory.") - # Run [adb shell ls] to list all files in the given directory. try: ls_response = adb_utils.issue_generic_request( f"shell ls {directory_path} -ll -au", env, timeout_sec ) - adb_utils.check_ok(ls_response, "Failed to list files in directory.") - files = [] # Each file (including links and directories) will be listed in format as # follows, @@ -487,15 +483,18 @@ def get_file_list_with_metadata( # In shell output, the first character is used to indicate file type and # "-" means the file is a regular file. if file_details.startswith("-"): + parts = file_details.split(None, 8) + if len(parts) < 9: + raise RuntimeError(f"Failed to parse file details: {file_details}") + + file_name = parts[8] # This will preserve spaces in the filename files.append( FileWithMetadata( - file_name=file_details.split(" ")[-1], - full_path=os.path.join( - directory_path, file_details.split(" ")[-1] - ), - file_size=int(file_details.split(" ")[-5]), + file_name=file_name, + full_path=os.path.join(directory_path, file_name), + file_size=int(parts[4]), change_time=datetime.datetime.fromisoformat( - " ".join(file_details.split(" ")[-4:-2])[:-3] + " ".join(parts[5:7])[:-3] ), ) )