Skip to content

Commit 86ad4d3

Browse files
author
The android_world Authors
committed
Add an option to setup apps that are required. It is intended for accelerating the investigation of a subset of tasks without the cost of installing and setting up unneeded apps.
PiperOrigin-RevId: 789891297
1 parent 4b5ec5c commit 86ad4d3

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

android_world/env/setup_device/setup.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,31 @@ def get_app_mapping(app_name: str) -> Type[apps.AppSetup]:
6868
return mapping[app_name]
6969

7070

71+
def get_app_list_to_setup(
72+
task_ids: list[str] | None,
73+
) -> tuple[Type[apps.AppSetup], ...] | None:
74+
"""Returns the list of apps that are required by the tasks.
75+
76+
Args:
77+
task_ids: A list of tasks.
78+
79+
Returns:
80+
A tuple of AppSetup classes.
81+
"""
82+
if not task_ids:
83+
return None
84+
required_apps = set()
85+
for app_class in _APPS:
86+
# Convert app_name to PascalCase, handling existing capitalization.
87+
pascal_case_app_name = "".join(
88+
word.capitalize() for word in app_class.app_name.split()
89+
)
90+
for task_id in task_ids:
91+
if pascal_case_app_name in task_id:
92+
required_apps.add(app_class)
93+
return tuple(required_apps)
94+
95+
7196
def download_and_install_apk(
7297
apk: str, raw_env: env_interface.AndroidEnvInterface
7398
) -> None:
@@ -112,11 +137,16 @@ def maybe_install_app(
112137
raise RuntimeError(f"Failed to download and install APK for {app.app_name}")
113138

114139

115-
def setup_apps(env: interface.AsyncEnv) -> None:
140+
def setup_apps(
141+
env: interface.AsyncEnv,
142+
app_list: tuple[Type[apps.AppSetup], ...] | None = None,
143+
) -> None:
116144
"""Sets up apps for Android World.
117145
118146
Args:
119147
env: The Android environment.
148+
app_list: The list of apps to setup. If not specified, the default list of
149+
apps will be used.
120150
121151
Raises:
122152
RuntimeError: If cannot install APK.
@@ -130,6 +160,8 @@ def setup_apps(env: interface.AsyncEnv) -> None:
130160
"Installing and setting up applications on Android device. Please do not"
131161
" interact with device while installation is running."
132162
)
133-
for app in _APPS:
163+
if app_list is None:
164+
app_list = _APPS
165+
for app in app_list:
134166
maybe_install_app(app, env)
135167
setup_app(app, env)

android_world/env/setup_device/setup_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@
2424
from android_world.utils import app_snapshot
2525

2626

27+
class GetAppListToSetupTest(absltest.TestCase):
28+
29+
def test_get_app_list_to_setup_none(self):
30+
self.assertIsNone(setup.get_app_list_to_setup(None))
31+
32+
def test_get_app_list_to_setup_with_valid_ids(self):
33+
task_ids = ["ClockCreateTimer", "ContactsSearchContact"]
34+
expected_apps = (apps.ClockApp, apps.ContactsApp)
35+
self.assertCountEqual(setup.get_app_list_to_setup(task_ids), expected_apps)
36+
37+
def test_get_app_list_to_setup_with_mixed_ids(self):
38+
task_ids = ["ClockCreateTimer", "InvalidTask", "DialerCallNumber"]
39+
expected_apps = (apps.ClockApp, apps.DialerApp)
40+
self.assertCountEqual(setup.get_app_list_to_setup(task_ids), expected_apps)
41+
42+
def test_get_app_list_to_setup_with_space_in_app_name(self):
43+
task_ids = ["AudioRecorderRecordAudio"]
44+
expected_apps = (apps.AudioRecorder,)
45+
self.assertCountEqual(setup.get_app_list_to_setup(task_ids), expected_apps)
46+
47+
def test_get_app_list_to_setup_with_pascal_case_conversion(self):
48+
task_ids = ["SimpleCalendarProCreateEvent"]
49+
expected_apps = (apps.SimpleCalendarProApp,)
50+
self.assertCountEqual(setup.get_app_list_to_setup(task_ids), expected_apps)
51+
52+
2753
class SetupTest(absltest.TestCase):
2854

2955
def setUp(self):

0 commit comments

Comments
 (0)