feat(android): add opt-in dp coordinate unit

Merged
SA
5h ago
+2106-97

Summary

Android geometry is physical pixels. This adds an opt-in coordinateUnit: 'dp', on the client config or per call; native stays the default.

  • The daemon converts at the router: dp input becomes whole pixels before dispatch, and results come back in dp with a coordinates label. Handlers and .ad scripts keep pixels.
  • Density comes from the request's own capture, else the device's read (wm density, or mobile: deviceInfo on WebDriver hubs), else the caller's coordinateDensity. Nothing is kept between requests.
  • Without a density, a dp request with geometry is refused before dispatch (coordinate_unit_density_unknown).

Before / after

const client = createAgentDeviceClient({ coordinateUnit: 'dp' });
await client.capture.snapshot();
// before: viewport { width: 1080, height: 2400 }
// after:  viewport { width: 411.43, height: 914.29 }, coordinates { unit: 'dp', pixelDensity: 2.625 }
await client.interactions.press({ x: 200, y: 450 });
// before: taps (200, 450); after: taps (525, 1181)

Validation

Hosted runs at 5e1ed75c71, with dp and no coordinateDensity. Every session was released.

ProviderDeviceDensityResult
LimrunAndroid emulator1.75press hit target
BrowserStackPixel 8, Android 142.625press hit target
RevylAndroid emulatornonerefused, dispatched: no
Sauce LabsPixel 7 emulator420 dpiraw hub check
TestMu AI——unit tests only

CI owns the gates. Risk: TestMu AI has no live run.