Skip to content
Merged
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
2 changes: 1 addition & 1 deletion android_world/env/adb_utils.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you check that this worked on unix-based environments as well? I will try and confirm that it does before merging this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I haven't check it on unix-based environments. It will be great if you can do this.

Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ def extract_broadcast_data(raw_output: str) -> Optional[str]:
Extracted data as a string, or None if the result is 0.
"""
if 'Broadcast completed: result=-1, data=' in raw_output:
return raw_output.split('data=')[1].strip('"\n')
return raw_output.split('data=')[1].strip('"\r\n')
elif 'Broadcast completed: result=0' in raw_output:
return None
else:
Expand Down
2 changes: 1 addition & 1 deletion android_world/env/android_world_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def get_a11y_tree(
return forest


_TASK_PATH = '/tmp/default.textproto'
_TASK_PATH = file_utils.convert_to_posix_path(file_utils.get_local_tmp_directory(), 'default.textproto')
DEFAULT_ADB_PATH = '~/Android/Sdk/platform-tools/adb'


Expand Down
4 changes: 2 additions & 2 deletions android_world/env/android_world_controller_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

def create_file_with_contents(contents: str) -> str:
temp_dir = tempfile.mkdtemp()
file_path = os.path.join(temp_dir, 'file.txt')
file_path = file_utils.convert_to_posix_path(temp_dir, 'file.txt')
with open(file_path, 'w') as f:
f.write(contents)
return file_path
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_pull_file(self):

with env.pull_file(remote_file_path) as local_dir:
local_path = os.path.split(remote_file_path)[1]
local_file = open(os.path.join(local_dir, local_path), 'r')
local_file = open(file_utils.convert_to_posix_path(local_dir, local_path), 'r')
self.assertEqual(open(remote_file_path, 'r').read(), local_file.read())

self.mock_copy_db.assert_called_once_with(
Expand Down
8 changes: 4 additions & 4 deletions android_world/env/setup_device/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
import requests


APP_DATA = os.path.join(os.path.dirname(__file__), 'app_data')
APP_DATA = file_utils.convert_to_posix_path(os.path.dirname(__file__), 'app_data')


def download_app_data(file_name: str) -> str:
"""Downloads file from a GCS bucket, if not cached, and installs it."""
cache_dir = "/tmp/android_world/app_data"
cache_dir = file_utils.convert_to_posix_path(file_utils.get_local_tmp_directory(), 'android_world', 'app_data')
remote_url = (
f"https://storage.googleapis.com/gresearch/android_world/{file_name}"
)
full_path = os.path.join(cache_dir, file_name)
full_path = file_utils.convert_to_posix_path(cache_dir, file_name)
os.makedirs(cache_dir, exist_ok=True)
if not os.path.isfile(full_path):
logging.info("Downloading file_name %s to cache %s", file_name, cache_dir)
Expand Down Expand Up @@ -580,7 +580,7 @@ def setup(cls, env: interface.AsyncEnv) -> None:
"shell",
"chcon",
"u:object_r:media_rw_data_file:s0",
os.path.join(cls.DEVICE_MAPS_PATH, map_file),
file_utils.convert_to_posix_path(cls.DEVICE_MAPS_PATH, map_file),
],
env.controller,
)
Expand Down
8 changes: 4 additions & 4 deletions android_world/task_evals/common_validators/file_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class MoveFile(task_eval.TaskEval):
def __init__(self, params: dict[str, Any], data_directory: str):
"""Initialize the task."""
super().__init__(params)
self.source_directory = os.path.join(
self.source_directory = file_utils.convert_to_posix_path(
data_directory, self.params["source_folder"]
)
self.dest_directory = os.path.join(
self.dest_directory = file_utils.convert_to_posix_path(
data_directory, self.params["destination_folder"]
)

Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(self, params: dict[str, Any], data_directory: str):
"""
super().__init__(params)
if "subfolder" in self.params:
self.data_directory = os.path.join(
self.data_directory = file_utils.convert_to_posix_path(
data_directory, self.params["subfolder"]
)
else:
Expand Down Expand Up @@ -214,7 +214,7 @@ def is_successful(self, env: interface.AsyncEnv) -> float:
[
"shell",
"cat",
os.path.join(self.data_directory, file_name),
file_utils.convert_to_posix_path(self.data_directory, file_name),
],
env.controller,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def parse_message(row: str) -> dict[str, str]:
"""
parsed_dict = {}

row = row.strip()
body_start = row.find("body=")

if body_start != -1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from typing import Any, Generic, Type, TypeVar
from android_world.task_evals.information_retrieval import information_retrieval
from android_world.task_evals.information_retrieval.proto import task_pb2
from android_world.utils import file_utils
from google.protobuf import text_format

TaskType = TypeVar('TaskType', bound=information_retrieval.InformationRetrieval)
Expand All @@ -50,7 +51,7 @@ def registry(
def _read_tasks(self) -> task_pb2.Tasks:
proto = task_pb2.Tasks()
script_dir = os.path.dirname(os.path.abspath(__file__))
local_path = os.path.join(script_dir, 'proto', 'tasks.textproto')
local_path = file_utils.convert_to_posix_path(script_dir, 'proto', 'tasks.textproto')
with open(local_path, 'r') as f:
textproto_content = f.read()
text_format.Merge(textproto_content, proto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from android_world.task_evals.information_retrieval.proto import task_pb2
from android_world.task_evals.utils import sqlite_schema_utils
from android_world.task_evals.utils import sqlite_utils
from android_world.utils import file_utils

_NOTES_TABLE = "notes"
_NOTES_NORMALIZED_TABLE = "notes_normalized"
Expand Down Expand Up @@ -84,7 +85,7 @@ def _get_folder_to_id(
) -> dict[str, str]:
"""Gets a mapping from folder title to ID as represented in Folder table."""
with env.controller.pull_file(_DB_PATH) as local_db_directory:
local_db_path = os.path.join(local_db_directory, os.path.split(_DB_PATH)[1])
local_db_path = file_utils.convert_to_posix_path(local_db_directory, os.path.split(_DB_PATH)[1])
folder_info = sqlite_utils.execute_query(
f"select * from {_FOLDER_TABLE};",
local_db_path,
Expand Down
7 changes: 4 additions & 3 deletions android_world/task_evals/single/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ def initialize_task(self, env: interface.AsyncEnv):
)

html = self.HTML.replace('%%SEED%%', str(self.params['browser_task_seed']))
with open('/tmp/task.html', 'w') as f:
task_html_path = file_utils.convert_to_posix_path(file_utils.get_local_tmp_directory(), 'task.html')
with open(task_html_path, 'w') as f:
f.write(html)
file_utils.copy_data_to_device(
'/tmp/task.html',
os.path.join(device_constants.DOWNLOAD_DATA, 'task.html'),
task_html_path,
file_utils.convert_to_posix_path(device_constants.DOWNLOAD_DATA, 'task.html'),
env.controller,
)

Expand Down
13 changes: 7 additions & 6 deletions android_world/task_evals/single/markor.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def is_successful(self, env: interface.AsyncEnv) -> float:
[
"shell",
"cat",
os.path.join(
file_utils.convert_to_posix_path(
device_constants.MARKOR_DATA, self.params["file_name"]
),
],
Expand Down Expand Up @@ -614,7 +614,7 @@ def is_successful(self, env: interface.AsyncEnv) -> float:
[
"shell",
"cat",
os.path.join(
file_utils.convert_to_posix_path(
device_constants.MARKOR_DATA, self.params["new_file_name"]
),
],
Expand Down Expand Up @@ -711,7 +711,7 @@ def is_successful(self, env: interface.AsyncEnv) -> float:
):
return 0.0
content_updated = file_utils.check_file_content(
os.path.join(device_constants.MARKOR_DATA, self.params["new_name"]),
file_utils.convert_to_posix_path(device_constants.MARKOR_DATA, self.params["new_name"]),
self.params["updated_content"],
env.controller,
)
Expand Down Expand Up @@ -793,7 +793,7 @@ def is_successful(self, env: interface.AsyncEnv) -> float:
):
return 0.0
correct = file_utils.check_file_content(
os.path.join(device_constants.MARKOR_DATA, self.params["new_name"]),
file_utils.convert_to_posix_path(device_constants.MARKOR_DATA, self.params["new_name"]),
self.params["header"] + "\n\n" + self.params["original_content"] + "\n",
env.controller,
exact_match=True,
Expand Down Expand Up @@ -840,9 +840,10 @@ def initialize_task(self, env: interface.AsyncEnv) -> None:
"""Initializes the task for creating a receipt markdown file."""
super().initialize_task(env)
self.create_file_task.initialize_task(env)
self.img.save("/tmp/receipt.png")
receipt_img_path = file_utils.convert_to_posix_path(file_utils.get_local_tmp_directory(), 'receipt.png')
self.img.save(receipt_img_path)
file_utils.copy_data_to_device(
"/tmp/receipt.png",
receipt_img_path,
device_constants.GALLERY_DATA,
env.controller,
)
Expand Down
5 changes: 3 additions & 2 deletions android_world/task_evals/single/markor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ def test_initialize_task(self, mock_copy_data_to_device):

task.initialize_task(mock_env)

task.img.save.assert_called_once_with('/tmp/receipt.png')
receipt_img_path = file_utils.convert_to_posix_path(file_utils.get_local_tmp_directory(), 'receipt.png')
task.img.save.assert_called_once_with(receipt_img_path)
mock_copy_data_to_device.assert_called_once_with(
'/tmp/receipt.png',
receipt_img_path,
device_constants.GALLERY_DATA,
mock_env.controller,
)
Expand Down
12 changes: 6 additions & 6 deletions android_world/task_evals/single/osmand.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

_DEVICE_FILES = '/data/media/0/Android/data/net.osmand/files'
_LEGACY_FILES = '/data/data/net.osmand/files'
_FAVORITES_PATH = os.path.join(_DEVICE_FILES, 'favorites/favorites.gpx')
_LEGACY_FAVORITES_PATH = os.path.join(_LEGACY_FILES, 'favourites_bak.gpx')
_BACKUP_DIR_PATH = os.path.join(_LEGACY_FILES, 'backup')
_FAVORITES_PATH = file_utils.convert_to_posix_path(_DEVICE_FILES, 'favorites/favorites.gpx')
_LEGACY_FAVORITES_PATH = file_utils.convert_to_posix_path(_LEGACY_FILES, 'favourites_bak.gpx')
_BACKUP_DIR_PATH = file_utils.convert_to_posix_path(_LEGACY_FILES, 'backup')

# Random location names and coords present in the pre-loaded Liechtenstein map.
_PRELOADED_MAP_LOCATIONS = {
Expand Down Expand Up @@ -312,7 +312,7 @@ def _clear_tracks(env: env_interface.AndroidEnvInterface):
Raises:
RuntimeError: If there is an adb communication issue.
"""
adb_args = ['shell', 'rm -rf', os.path.join(_DEVICE_FILES, 'tracks', '*')]
adb_args = ['shell', 'rm -rf', file_utils.convert_to_posix_path(_DEVICE_FILES, 'tracks', '*')]
# Issue ADB pull command to copy the directory
response = adb_utils.issue_generic_request(adb_args, env)
if response.status != adb_pb2.AdbResponse.OK:
Expand Down Expand Up @@ -417,13 +417,13 @@ def initialize_task(self, env: interface.AsyncEnv) -> None:

def is_successful(self, env: interface.AsyncEnv) -> float:
with file_utils.tmp_directory_from_device(
os.path.join(_DEVICE_FILES, 'tracks'), env.controller
file_utils.convert_to_posix_path(_DEVICE_FILES, 'tracks'), env.controller
) as tracks_directory:
for track_file in os.listdir(tracks_directory):
if _track_matches(
_track_points(
ElementTree.parse(
os.path.join(tracks_directory, track_file)
file_utils.convert_to_posix_path(tracks_directory, track_file)
).getroot()
),
self._target_waypoint_coords,
Expand Down
12 changes: 6 additions & 6 deletions android_world/task_evals/single/retro_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _get_playlist_data(
with env.controller.pull_file(
_PLAYLIST_DB_PATH, timeout_sec=3
) as local_db_directory:
local_db_path = os.path.join(
local_db_path = file_utils.convert_to_posix_path(
local_db_directory, os.path.split(_PLAYLIST_DB_PATH)[1]
)
return sqlite_utils.execute_query(
Expand All @@ -86,7 +86,7 @@ class Queue(sqlite_schema_utils.SQLiteRow):
with env.controller.pull_file(
_PLAYBACK_DB_PATH, timeout_sec=3
) as local_db_directory:
local_db_path = os.path.join(
local_db_path = file_utils.convert_to_posix_path(
local_db_directory, os.path.split(_PLAYBACK_DB_PATH)[1]
)
result = sqlite_utils.execute_query(
Expand Down Expand Up @@ -151,7 +151,7 @@ def initialize_task(self, env: interface.AsyncEnv):

for file in self.params['files'] + self.params['noise_files']:
user_data_generation.write_mp3_file_to_device(
os.path.join(device_constants.MUSIC_DATA, file),
file_utils.convert_to_posix_path(device_constants.MUSIC_DATA, file),
env,
title=file.split('.')[0],
artist=random.choice(user_data_generation.COMMON_GIVEN_NAMES),
Expand Down Expand Up @@ -223,7 +223,7 @@ def goal(self) -> str:

def is_successful(self, env: interface.AsyncEnv) -> float:
playlist_exists = file_utils.check_file_exists(
os.path.join(
file_utils.convert_to_posix_path(
device_constants.DOWNLOAD_DATA,
self.params['playlist_name'] + '.m3u',
),
Expand Down Expand Up @@ -266,7 +266,7 @@ def initialize_task(self, env: interface.AsyncEnv):
)
for file, duration in zip(self.params['files'], durations):
user_data_generation.write_mp3_file_to_device(
os.path.join(device_constants.MUSIC_DATA, file),
file_utils.convert_to_posix_path(device_constants.MUSIC_DATA, file),
env,
title=file.split('.')[0],
artist=random.choice(user_data_generation.COMMON_GIVEN_NAMES),
Expand All @@ -275,7 +275,7 @@ def initialize_task(self, env: interface.AsyncEnv):

for file in self.params['noise_files']:
user_data_generation.write_mp3_file_to_device(
os.path.join(device_constants.MUSIC_DATA, file),
file_utils.convert_to_posix_path(device_constants.MUSIC_DATA, file),
env,
title=file.split('.')[0],
artist=random.choice(user_data_generation.COMMON_GIVEN_NAMES),
Expand Down
2 changes: 1 addition & 1 deletion android_world/task_evals/single/simple_draw_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, params: dict[str, Any]):
super().__init__(params)
self.initialized = False
self.create_file_task = file_validators.CreateFile(
params, os.path.join(device_constants.EMULATOR_DATA, "Pictures")
params, file_utils.convert_to_posix_path(device_constants.EMULATOR_DATA, "Pictures")
)

def initialize_task(self, env: interface.AsyncEnv) -> None:
Expand Down
2 changes: 1 addition & 1 deletion android_world/task_evals/single/simple_gallery_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def initialize_task(self, env: interface.AsyncEnv) -> None:
super().initialize_task(env)
user_data_generation.clear_device_storage(env)
receipt_image = self.params["receipt_image"]
temp_storage_location = os.path.join("/tmp/", self.params["file_name"])
temp_storage_location = file_utils.convert_to_posix_path(file_utils.get_local_tmp_directory(), self.params["file_name"])
receipt_image.save(temp_storage_location)
file_utils.copy_data_to_device(
temp_storage_location,
Expand Down
3 changes: 2 additions & 1 deletion android_world/task_evals/single/simple_gallery_pro_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from android_world.utils import app_snapshot
from android_world.utils import datetime_utils
from android_world.utils import fake_adb_responses
from android_world.utils import file_utils
from PIL import Image


Expand All @@ -35,7 +36,7 @@ def _touch_temp_file(file_name):
Args:
file_name: The name of the file.
"""
path = os.path.join(tempfile.gettempdir(), file_name)
path = file_utils.convert_to_posix_path(tempfile.gettempdir(), file_name)
with open(path, "w") as f:
f.write("")

Expand Down
2 changes: 1 addition & 1 deletion android_world/task_evals/single/vlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _get_playlist_file_info(
) -> list[sqlite_schema_utils.PlaylistInfo]:
"""Executes join query to fetch playlist file info."""
with env.controller.pull_file(_DB_PATH, timeout_sec=3) as local_db_directory:
local_db_path = os.path.join(local_db_directory, os.path.split(_DB_PATH)[1])
local_db_path = file_utils.convert_to_posix_path(local_db_directory, os.path.split(_DB_PATH)[1])
return sqlite_utils.execute_query(
_get_playlist_info_query(),
local_db_path,
Expand Down
4 changes: 2 additions & 2 deletions android_world/task_evals/single/vlc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def setUp(self):
self.env_mock.controller = self.controller

temp_dir = tempfile.mkdtemp()
self.test_db_path = os.path.join(temp_dir, 'app_db/vlc_media.db')
self.test_db_path = file_utils.convert_to_posix_path(temp_dir, 'app_db/vlc_media.db')
os.makedirs(
os.path.join(os.path.dirname(self.test_db_path), 'app_db'),
file_utils.convert_to_posix_path(os.path.dirname(self.test_db_path), 'app_db'),
exist_ok=True,
)

Expand Down
3 changes: 2 additions & 1 deletion android_world/task_evals/utils/sqlite_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from android_world.env import device_constants
from android_world.task_evals.utils import sqlite_schema_utils
from android_world.utils import file_utils


def setup_test_db() -> str:
Expand All @@ -28,7 +29,7 @@ def setup_test_db() -> str:
temp_dir = tempfile.mkdtemp()

# Path for the new database
db_path = os.path.join(temp_dir, 'events.db')
db_path = file_utils.convert_to_posix_path(temp_dir, 'events.db')

conn = sqlite3.connect(db_path)
cursor = conn.cursor()
Expand Down
Loading