Skip to content

Commit 7db3839

Browse files
Merge pull request #240 from askui/refactor/android-single-display-no-flags
refactor(android): single-display handling and SingleAndroidDisplay
2 parents a15e48c + d050b88 commit 7db3839

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/askui/tools/android/agent_os.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,32 @@ def get_display_unique_id_flag(self) -> str:
229229
return f"-d {self.unique_display_id}"
230230

231231

232-
class UnknownAndroidDisplay(AndroidDisplay):
232+
class SingleAndroidDisplay(AndroidDisplay):
233233
"""
234-
Fallback display for when the Agent OS is not able to determine the displays.
234+
Single display when there is only one display connected.
235235
"""
236236

237-
def __init__(self) -> None:
238-
super().__init__(0, "Unknown", 0)
237+
def __init__(self, display_name: str) -> None:
238+
super().__init__(0, display_name, 0)
239239

240+
# In case of a single display, the display id flag is not needed
240241
def get_display_id_flag(self) -> str:
241242
return ""
242243

244+
# In case of a single display, the display unique id flag is not needed
243245
def get_display_unique_id_flag(self) -> str:
244246
return ""
245247

246248

249+
class UnknownAndroidDisplay(SingleAndroidDisplay):
250+
"""
251+
Fallback display for when the Agent OS is not able to determine the displays.
252+
"""
253+
254+
def __init__(self) -> None:
255+
super().__init__("Unknown")
256+
257+
247258
class AndroidAgentOs(ABC):
248259
"""
249260
Abstract base class for Android Agent OS. Cannot be instantiated directly.

src/askui/tools/android/ppadb_agent_os.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
ANDROID_KEY,
1515
AndroidAgentOs,
1616
AndroidDisplay,
17+
SingleAndroidDisplay,
1718
UnknownAndroidDisplay,
1819
)
1920
from askui.tools.android.android_agent_os_error import AndroidAgentOsError
@@ -116,6 +117,10 @@ def get_connected_displays(self) -> list[AndroidDisplay]:
116117
)
117118
if not displays:
118119
return [UnknownAndroidDisplay()]
120+
121+
if len(displays) == 1:
122+
return [SingleAndroidDisplay(displays[0].display_name)]
123+
119124
return displays
120125

121126
def set_display_by_index(self, display_index: int = 0) -> None:

0 commit comments

Comments
 (0)