Skip to content

Commit

Permalink
Fixes for Osmand app
Browse files Browse the repository at this point in the history
* 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: 693044160
  • Loading branch information
Chris Rawles authored and The android_world Authors committed Nov 4, 2024
1 parent 27ce392 commit 29fc3d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions android_world/task_evals/single/osmand.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion android_world/task_evals/utils/sqlite_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions android_world/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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]
),
)
)
Expand Down

0 comments on commit 29fc3d8

Please sign in to comment.