|
201 | 201 |
|
202 | 202 |
|
203 | 203 | class AndroidDisplay: |
| 204 | + """A selectable Android display. |
| 205 | +
|
| 206 | + ``display_id`` is the logical DisplayManager id consumed by ``input`` |
| 207 | + (tap/swipe/type/keyevent). ``unique_display_id`` is the physical display id |
| 208 | + consumed by ``screencap``. Either may be ``None``, in which case the |
| 209 | + corresponding shell command runs with no ``-d`` flag and therefore targets |
| 210 | + adb's default display (display 0). |
| 211 | +
|
| 212 | + Passing ``None`` for ``display_id`` is only correct when the target screen |
| 213 | + IS the default display; on a multi-display setup where the agent switches |
| 214 | + displays, provide the real logical id instead (a ``None`` input flag ignores |
| 215 | + which display is currently active). Likewise, a display with |
| 216 | + ``unique_display_id=None`` cannot be selected by the model at runtime — the |
| 217 | + ``select_display_by_unique_id`` tool needs a concrete unique id — so use it |
| 218 | + only for a pinned, non-switchable display. |
| 219 | + """ |
| 220 | + |
204 | 221 | def __init__( |
205 | | - self, unique_display_id: int, display_name: str, display_id: int |
| 222 | + self, |
| 223 | + unique_display_id: int | None, |
| 224 | + display_name: str, |
| 225 | + display_id: int | None, |
206 | 226 | ) -> None: |
207 | | - self.unique_display_id: int = unique_display_id |
| 227 | + self.unique_display_id: int | None = unique_display_id |
208 | 228 | self.display_name: str = display_name |
209 | | - self.display_id: int = display_id |
| 229 | + self.display_id: int | None = display_id |
210 | 230 |
|
211 | 231 | def __repr__(self) -> str: |
212 | 232 | return ( |
213 | 233 | f"AndroidDisplay(unique_display_id={self.unique_display_id}, " |
214 | 234 | f"display_name={self.display_name}, display_id={self.display_id})" |
215 | 235 | ) |
216 | 236 |
|
| 237 | + def __str__(self) -> str: |
| 238 | + # Model-facing rendering (used by the display-info tools). Only surface a |
| 239 | + # unique id the model can hand back to select_display_by_unique_id; a |
| 240 | + # None id means "default display" and is not selectable. |
| 241 | + if self.unique_display_id is None: |
| 242 | + return f"display '{self.display_name}' (default display)" |
| 243 | + return ( |
| 244 | + f"display '{self.display_name}' " |
| 245 | + f"(unique_display_id={self.unique_display_id})" |
| 246 | + ) |
| 247 | + |
217 | 248 | def get_display_id_flag(self) -> str: |
218 | 249 | """ |
219 | | - Returns the display ID flag for shell commands. |
| 250 | + Returns the display ID flag for input/tap/swipe/type shell commands. |
220 | 251 |
|
221 | 252 | Returns: |
222 | | - str: The display ID flag in the format `-d {display_id}`. |
| 253 | + str: ``-d {display_id}``, or an empty string when ``display_id`` is |
| 254 | + ``None`` (input then targets adb's default display). |
223 | 255 | """ |
224 | | - return f"-d {self.display_id}" |
| 256 | + return "" if self.display_id is None else f"-d {self.display_id}" |
225 | 257 |
|
226 | 258 | def get_display_unique_id_flag(self) -> str: |
227 | 259 | """ |
228 | | - Returns the display unique ID flag for shell screencap command. |
| 260 | + Returns the display unique ID flag for the screencap shell command. |
229 | 261 |
|
230 | 262 | Returns: |
231 | | - str: The display unique ID flag in the format `-d {unique_display_id}`. |
| 263 | + str: ``-d {unique_display_id}``, or an empty string when |
| 264 | + ``unique_display_id`` is ``None`` (screencap then targets the default |
| 265 | + display). |
232 | 266 | """ |
233 | | - return f"-d {self.unique_display_id}" |
| 267 | + return "" if self.unique_display_id is None else f"-d {self.unique_display_id}" |
234 | 268 |
|
235 | 269 |
|
236 | 270 | class SingleAndroidDisplay(AndroidDisplay): |
237 | 271 | """ |
238 | 272 | Single display when there is only one display connected. |
| 273 | +
|
| 274 | + Both ids are ``None`` so input and screencap run without a ``-d`` flag |
| 275 | + (adb's default display). |
239 | 276 | """ |
240 | 277 |
|
241 | 278 | def __init__(self, display_name: str) -> None: |
242 | | - super().__init__(0, display_name, 0) |
243 | | - |
244 | | - # In case of a single display, the display id flag is not needed |
245 | | - def get_display_id_flag(self) -> str: |
246 | | - return "" |
247 | | - |
248 | | - # In case of a single display, the display unique id flag is not needed |
249 | | - def get_display_unique_id_flag(self) -> str: |
250 | | - return "" |
| 279 | + super().__init__(None, display_name, None) |
251 | 280 |
|
252 | 281 |
|
253 | 282 | class UnknownAndroidDisplay(SingleAndroidDisplay): |
|
0 commit comments