Skip to content

Drivers list the phones on USB, enrolled or not #1507

Closed

Description

@V3RON

Part of #1503.

Scope

Each driver can name every phone plugged into the worker by USB, enrolled or not, without sending anything to a phone. Nothing reads it yet: the next task's auto-enroll does. No user-visible change.

In short

A new driver read, listAttachedPhysical(), answers the canonical IDs of the phones on USB: the Android USB serial, the iOS UDID. It answers in any adb or pairing state, so a phone that is not trusted yet is listed. A phone reached only over the network, an emulator and a simulator are not listed. When the platform cannot be read, it throws, so a caller can't mistake a failed read for "no phones".

flowchart LR
  C[caller] --> D["Driver.listAttachedPhysical() (new)"]
  D --> A["Android: adb devices -l on 5037, behind the protocol gate"]
  D --> I["iOS: devicectl list devices"]
Loading

If this goes wrong, a user would later see a plugged-in phone never auto-enrolled, or a log line about a network phone.

Technical spec

Facts

Commit e4adf46 (origin/main).

# Fact Source
F1 Driver declares inspectPhysical and listPresentPhysical(enrolledIds); there is no method that lists every phone. src/core/driver.ts:322-323
F2 Four classes implement it: the Android driver, the iOS driver, core's FakeDriver and the e2e fake driver. git grep -n "listPresentPhysical(" on origin/main: src/drivers/android/index.ts:700, src/drivers/ios/index.ts:1527, src/core/fake-driver.ts:599, e2e/fake-driver/fake-driver.ts:607
F3 Android runs adb -P 5037 devices -l through #run, which first calls #gate.check() and answers blocked with no command when it is not open. A non-zero exit or a throw answers failed. src/drivers/android/physical-handler.ts:323-335, :186
F4 parseDevices marks an entry usb when a token starts with usb:; on Windows, also when the serial is not a network or emulator serial. src/drivers/android/physical-handler.ts:344-355, :363-365
F5 Today a failed Android listing is read as no entries, so every enrolled phone reads not present. src/drivers/android/physical-handler.ts:186-187
F6 iOS runs devicectl list devices --json-output <file> with a 30 s limit, reading result.devices. A timeout, a non-zero exit, or a missing or malformed list answers ok: false. src/drivers/ios/physical.ts:325-337, :382-391
F7 iOS presence counts an entry only with transportType wired and reality not simulated. pairingState other than paired is untrusted. src/drivers/ios/physical.ts:201-204
F8 pickEntry prefers a wired entry when one UDID is listed more than once. src/drivers/ios/physical.ts:107-114
F9 The Android canonical ID is the USB serial; the iOS one is the UDID. ADR 0022 §6
F10 When nothing listens on 5037 the gate is open, so adb -P 5037 devices -l starts the default server, as any physical adb command may. src/drivers/android/physical-handler.ts:323-328; ADR 0022 §5 "Simlock's call may start that server"

Modules touched

Searches: listPresentPhysical( (F2), parseDevices, #list(.

flowchart LR
  CD["core/driver.ts (changed)"]
  AD["drivers/android index + physical-handler (changed)"]
  ID["drivers/ios index + physical (changed)"]
  FD["core/fake-driver.ts (changed)"]
  ED["e2e/fake-driver (changed)"]
  AD --> CD
  ID --> CD
  FD --> CD
  ED --> CD
Loading
  • src/core/driver.ts: listAttachedPhysical(): Promise<readonly string[]> on Driver, with a doc comment: canonical IDs of USB phones in any state, sorted, no duplicates; throws when the platform cannot be read.
  • src/drivers/android/physical-handler.ts, index.ts: from parseDevices, every usb entry's serial. The List of devices attached header line is no entry: today parseDevices reads it as serial List, state of, and on Windows marks it usb (F4), so the listing drops it (or parseDevices stops returning it). blocked or failed throws an Error naming the reason (the gate's message, or "could not read the device list (adb devices -l)").
  • src/drivers/ios/physical.ts, index.ts: from #list, the udid of every entry with transportType wired and reality not simulated, in any pairingState. ok: false throws with its why.
  • e2e/fake-driver/fake-driver.ts and types.ts: the fake lists ids[0] of every scripted physical device that is attached: present is not false, or absentReason is locked or untrusted.
  • src/core/fake-driver.ts: its presence is the separate map setPhysicalPresence fills, and a device is not present until it is called (src/core/fake-driver.ts:73-80, :198). It lists ids[0] of each device whose presence is set to present, or absent with reason locked or untrusted. A scripted failure throws, like the fake's other scripted calls.
  • docs/internal/agent-rules/safety.md rules 7 and 8: name the host-level USB list as the one read made beyond enrolled IDs (ADR 0073 §5).
  • src/drivers/android/AGENTS.md "Physical phones": the listing may start the 5037 server (F10).

Contract and event changes

None: Driver is internal. Searched src/contract for listPresentPhysical: no hits.

Other code on the same state

None. The new read keeps no state and runs the same host commands the presence read does (F3, F6). Searched for devices -l and "list", "devices": the presence and inspection reads only, each a separate invocation.

Failure modes

Call Outcome What happens Limit, counted from
Android adb devices -l ok USB serials listed 30 s (READ_TIMEOUT_MS, physical-handler.ts:24), from the call
Android gate not open throws the gate's message; no adb command runs the gate's 5 s (ADR 0022 §5), from the check
Android exits non-zero, times out or throws throws 30 s
iOS devicectl list devices ok wired UDIDs listed 30 s, from the call
iOS timed out, non-zero, malformed throws with the reason 30 s

No state is written.

Rules in play

  • Safety rule 7, "read only for enrolled IDs": narrowed by ADR 0073 §5 to allow the host-level list. This task edits the rule's text to say so.
  • Safety rule 8, "listPresentPhysical() answers only for enrolled IDs": unchanged for that method. The new one is named as the exception.
  • ADR 0022 §5, "Right before every physical adb command it sends … reads the server's protocol version": the listing goes through #run, so the gate runs first.
  • Safety rule 1, "never runs a command on one that is not enrolled": both commands are host-level and name no phone.
  • src/drivers/android/AGENTS.md, "The 5037 server is never started, stopped or adopted on purpose": the listing may start it as a side effect of adb, as today's reads do (F10). This task adds that to the manual's line.

Tests

Seam: each handler's own test file with its scripted process runner, modelled on the listPresentPhysical describes (src/drivers/android/physical-handler.test.ts:1059, src/drivers/ios/physical.test.ts). Fixtures are copies of real adb devices -l and devicectl list devices output already used there (src/drivers/ios/fixtures/devicectl-list-devices.json holds wired, localNetwork and sameMachine entries).

  • The Android driver lists the phones on USB: one table, usb: in device, unauthorized and offline are listed; a 192.168.1.5:5555 serial and emulator-5554 are not; a protocol mismatch throws and runs no adb command; a non-zero adb exit throws; on Windows (platform: "win32", as the physical handler on Windows describe at :1659) a USB serial is listed and the header line is not.
  • The iOS driver lists the wired phones: one table, wired paired and wired unpaired are listed; a localNetwork entry, a sameMachine entry and a simulated entry are not; one UDID listed wired and over the network is listed once; a timeout, a non-zero exit and a missing result.devices throw.

Done when

  • pnpm exec vitest run --project unit src/drivers/android/physical-handler.test.ts and … src/drivers/ios/physical.test.ts pass, with the two Tests lines' cases.
  • Driver.listAttachedPhysical exists on every implementer in F2 (git grep -n "listAttachedPhysical("), and CI's typecheck passes.
  • Safety rules 7 and 8 name the host-level list.

Out of scope

Depends on

Written by an agent.

Activity

  1. added
    task:draft
    platform:ios
    platform:android
    on Nov 10, 2026
  2. added
    task:ready
    and removed
    task:draft
    on Nov 10, 2026
  3. self-assigned this
    on Nov 10, 2026
  4. added a commit that references this issue on Nov 10, 2026
    66593a5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

platform:androidplatform:iostask:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions