feat(mobile): lock and unlock the screen with device.lock() and device.unlock() (ENG-1526)

Merged
KD
3d ago
+305-18

What

The device fixture gets lock() and unlock(). Each is a recorded device.lock / device.unlock step that returns once the device reports the new lock state:

try {
  await device.lock();
} finally {
  await device.unlock();
}
await expect(screen.getByText('Welcome back')).toBeVisible();

They work on Android 11 or newer and on iOS simulators, though on an iPhone simulator with an always-on display unlock() can leave the display off (step 6). unlock() never enters a PIN, pattern, password, or passcode.

Why

Appium (driver.lock(), driver.unlock(), mobile: lock) and Maestro (pressKey: lock) tests had no e2e equivalent: the only routes were device.unstable_raw.client, which records no step, and on Android device.pressButton('power'), which turns the screen off but never waits for the device to report it locked and cannot unlock it. agent-device 0.21.43 adds the lock-screen command (callstack/agent-device#5057), and main already pins it (#2304), so this wraps it.

How it works

  1. lock() and unlock() call client.command.lockScreen({ ...selection, action }) through screenCommand, so each counts as an action for the transition budget like back() and shake() (packages/mobile/src/device.ts:479).
  2. agent-device refuses an unsupported device (a physical iPhone or iPad, a TV), an Android screen lock set to None (lock-screen-disabled), and a lock with a credential on unlock (lock-screen-secure) with UNSUPPORTED_OPERATION. The existing mapping makes each one UNSUPPORTED_CAPABILITY with agent-device's message and hint. A state the device never confirms (lock-screen-unverified) stays ENGINE_FAILURE.
  3. A daemon older than the command, such as one a provider pins through @e2e-dev/eas's agentDeviceVersion, fails with COMMAND_FAILED and reason generic-route-runtime-missing. translateError now maps that reason to UNSUPPORTED_CAPABILITY (packages/mobile/src/errors.ts:90).
  4. #2304 moved agent-device and the Revyl and TestMu AI plugins to 0.21.43 on main but left the provider peer floors alone. Revyl, TestMu AI, and Limrun refuse an agent-device that differs from the engine's, so a consumer who updates one of them alone, with @e2e-dev/mobile 0.12.9 on 0.21.42, fails every allocation with "Install matching versions". Their @e2e-dev/mobile peer floor rises to 0.12.10, the first release on 0.21.43. E2B installs the engine's own version in its sandbox, so its floor stays.
  5. The mobile benchmark gets a lock round-trip test, on Android only, since the iOS limit in step 6 hits CI's iPhone 17 Pro (apps/mobile-benchmark/tests/device.e2e.ts:108). A new API 36 AVD has its screen lock set to None, which lock() refuses, so the deterministic Android job sets Swipe with adb shell locksettings set-disabled false and keeps the screen on with svc power stayon true (.github/workflows/mobile.yml:322); Swipe shows a keyguard whenever the screen turns off. The agentic job keeps None.
  6. docs/reference/mobile.mdx documents both methods (#### lock, #### unlock) with their refusals and the Android version limits that come from agent-device. Android 16 is the first that reports a None screen lock, so on Android 11 to 15 lock() on a None lock fails with ENGINE_FAILURE instead. Android 10 reports no lock type at all, so both methods fail there whenever they would change the state. On an iPhone simulator with an always-on display, such as CI's iPhone 17 Pro, the lock dims the display instead of turning it off. agent-device's unlock wakes the display only when SpringBoard reports it blanked, and that flag flickers while the dimmed display settles, so the swipe can unlock the device with the display still off. Taps and screen reads keep working, screenshots repeat the last frame, and on iOS 26.5 every later fill fails its read-back. The JSDoc and the reference say so. The Appium and Maestro migration rows replace the unstable_raw and pressButton('power') workarounds, pressButton's note on power points at lock() and unlock(), and the mobile guide, the e2e skill, the package README, and the changeset follow.

Issue

ENG-1526

Verified

Ran it locally: yes

  • iOS 27.2: the mobile benchmark on an iPhone 17 Pro simulator, e2e run tests/device.e2e.ts --target ios-simulator --grep lock --video on, before the test became Android only. The report records device.lock (338 ms), device.unlock (3410 ms), and the email-input check after them, all passed. The video shows the app, then the lock screen, and no frame after it; per the table below, an iOS 27.2 iPhone 17 Pro keeps its display off after the unlock.
  • iOS 26.5, in this PR's first CI run: the lock test passed, then every later test that fills a field on that simulator failed with text entry read-back did not match the requested text, while the tests that only tap passed. Its failure screenshots all show the time of the lock.
  • The same failure reproduced locally on an iOS 26.5 iPhone 17 Pro, with the lock test back on iOS: the same 8 tests failed. Afterwards SpringBoard reported lockstate=0, hasBlankedScreen=1, and displayStatus=0, an unlocked device with its display off. Its log shows the lock moving the backlight to InactiveOn, the unlock starting 8 ms after the lock returned while the display read not blanked, and no wake before the swipe. In a shorter local run that passed, the display read blanked when the unlock started, so the runner pressed the lock button first and the backlight went back to ActiveOn.
  • A scratch test ran lock, unlock, a 3 s wait, and a fill 8 times on each of three simulators:
SimulatorDisplay after the unlockFill
iPhone 17 Pro (always-on display), iOS 26.5off in 7 of 8failed in 7 of 8
iPhone 16e (no always-on display), iOS 26.5on in 8 of 8passed in 8 of 8
iPhone 17 Pro, iOS 27.2off in 8 of 8passed in 8 of 8
  • Android: an Android 16 emulator without the benchmark APK, so a scratch project on the Settings app ran the same lock, unlock, and check. With the screen lock set to Swipe, it passed (device.lock 1024 ms, device.unlock 1888 ms); the video shows Settings, the lock screen, then Settings again. With the screen lock set to None, the refusal reads:
UNSUPPORTED_CAPABILITY: device.lock failed: The screen lock of e2e api36 anr is set to None, so there is no lock screen to show Hint: Set a screen lock other than None in Settings > Security > Screen lock (Swipe needs no credential), then retry.
  • After the rebase onto main, which added device.pressButton: pnpm check passes, and so do the 669 @e2e-dev/mobile unit tests, the transition-budget test with pressButton, lock, and unlock together.
  • CI on a045bbe, before the rebase: the deterministic Android job, with the Swipe step, passed 64 tests (1 skipped), the lock test among them in 4.8 s; the agentic Android job, on None, passed all 20; the deterministic iOS job passed 62 (1 skipped) with the lock test left to Android.
  • Not run: Android 15 or older, a PIN or passcode lock, a physical device, and a hosted provider. The Android version limits come from AOSP's dumpsys lock_settings output (LockSettingsService.java, android-10 through android16) and agent-device 0.21.43's lock-screen.js.
  • No pnpm bench:ab table. Before main moved to agent-device 0.21.43 the two builds could not share one daemon (the base's 0.21.42 client refused the branch's 0.21.43 daemon), and the run was not repeated after the rebase. The diff changes no existing path except one more error reason in translateError: lock() and unlock() run only when a test calls them.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

šŸ¤– Generated with Claude Code

https://github.com/user-attachments/assets/fdfc44ba-3d20-4960-aed8-3a40000010cc

https://github.com/user-attachments/assets/4257d54e-032b-4fa8-baf8-ead14f4c792f