refactor(device): remove single-device state and test branches

This commit is contained in:
somew1nd committed 2026-09-01 11:50:14 -07:00
1 parent cbe8f4f0c6
commit 33c4a0d112
12 files changed
+175 -88

No files matched your search

+13 -4
View File
@@ -150,7 +150,7 @@ def _configure_usb_stay_awake(device_id: str) -> str | None:
def _discover_connected_device_ids() -> list[str]:
"""Return the selected or all connected local Android devices."""
"""Return the explicitly targeted device, or the connected devices Artemis manages."""
if not _awake_enabled() or os.environ.get("ARTEMIS_CLOUD_MODE") == "1":
return []
@@ -171,9 +171,18 @@ def _discover_connected_device_ids() -> list[str]:
if target:
return [target] if target in serials else []
# Artemis has a single-device execution policy. Do not modify unrelated
# devices that happen to share the ADB server.
return serials[:1]
# Keep awake only the devices Artemis actually manages: serials claimed in
# the device pool by an active execution lock or a live queue reservation.
# Other devices sharing the same ADB server belong to unrelated tools or
# users, and their power policy must not be touched.
try:
from artemis.runtime.device_pool import device_pool
claimed = device_pool.get_claimed_serials()
except Exception as exc:
logger.debug(f"Could not query claimed devices for the awake policy: {exc}")
return []
return [serial for serial in serials if serial in claimed]
class ScreenAwakeService:
+24 -10
View File
@@ -398,6 +398,30 @@ class DevicePool:
"""Return ready devices that are not currently holding an execution lock."""
return [d for d in self.list_devices() if d.state == "device" and not d.is_busy]
def get_claimed_serials(self) -> set[str]:
"""Return device serials Artemis currently claims on the ADB server.
A device is claimed while any Artemis process holds its execution lock
or has a live pending queue reservation targeting it. Placeholder
reservations not yet bound to a concrete device ("pending"/"any")
claim nothing. Read-only: computed purely from cross-process lock and
queue metadata, without any adb traffic.
"""
claimed: set[str] = set()
try:
for owner in DeviceExecutionLock.get_active_owners().values():
if owner.device_id:
claimed.add(str(owner.device_id))
for item in DeviceExecutionLock.get_queued_tasks():
serial = item.get("device_serial")
if serial:
claimed.add(str(serial))
except Exception as exc:
logger.debug(f"Could not compute claimed device serials: {exc}")
claimed.discard("pending")
claimed.discard("any")
return claimed
def select_device(self, preferred_serial: str | None = None) -> str | None:
"""Select a target device serial for task execution.
@@ -419,16 +443,6 @@ class DevicePool:
# If not detected by ADB, still return it so ADB can attempt connection
return preferred_serial
# Prefer active ready device from readiness engine if available
try:
from artemis.core.diagnostics import readiness_engine
active_serial = readiness_engine.get_active_device_serial()
if active_serial and any(d.serial == active_serial and d.state == "device" for d in all_devs):
return active_serial
except Exception:
pass
# Pick first idle device
for dev in ready_devs:
if not dev.is_busy: