feat(mobile): lock and unlock the screen with device.lock() and device.unlock() (ENG-1526)
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
lock()andunlock()callclient.command.lockScreen({ ...selection, action })throughscreenCommand, so each counts as an action for thetransitionbudget likeback()andshake()(packages/mobile/src/device.ts:479).- 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) withUNSUPPORTED_OPERATION. The existing mapping makes each oneUNSUPPORTED_CAPABILITYwith agent-device's message and hint. A state the device never confirms (lock-screen-unverified) staysENGINE_FAILURE. - A daemon older than the command, such as one a provider pins through
@e2e-dev/eas'sagentDeviceVersion, fails withCOMMAND_FAILEDand reasongeneric-route-runtime-missing.translateErrornow maps that reason toUNSUPPORTED_CAPABILITY(packages/mobile/src/errors.ts:90). - #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/mobile0.12.9 on 0.21.42, fails every allocation with "Install matching versions". Their@e2e-dev/mobilepeer 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. - 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, whichlock()refuses, so the deterministic Android job sets Swipe withadb shell locksettings set-disabled falseand keeps the screen on withsvc power stayon true(.github/workflows/mobile.yml:322); Swipe shows a keyguard whenever the screen turns off. The agentic job keeps None. docs/reference/mobile.mdxdocuments 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 15lock()on a None lock fails withENGINE_FAILUREinstead. 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 laterfillfails its read-back. The JSDoc and the reference say so. The Appium and Maestro migration rows replace theunstable_rawandpressButton('power')workarounds,pressButton's note onpowerpoints atlock()andunlock(), and the mobile guide, thee2eskill, 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 recordsdevice.lock(338 ms),device.unlock(3410 ms), and theemail-inputcheck 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, anddisplayStatus=0, an unlocked device with its display off. Its log shows the lock moving the backlight toInactiveOn, 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 toActiveOn. - A scratch test ran lock, unlock, a 3 s wait, and a fill 8 times on each of three simulators:
| Simulator | Display after the unlock | Fill |
|---|---|---|
| iPhone 17 Pro (always-on display), iOS 26.5 | off in 7 of 8 | failed in 7 of 8 |
| iPhone 16e (no always-on display), iOS 26.5 | on in 8 of 8 | passed in 8 of 8 |
| iPhone 17 Pro, iOS 27.2 | off in 8 of 8 | passed 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.lock1024 ms,device.unlock1888 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 checkpasses, and so do the 669@e2e-dev/mobileunit tests, the transition-budget test withpressButton,lock, andunlocktogether. - 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_settingsoutput (LockSettingsService.java, android-10 through android16) and agent-device 0.21.43'slock-screen.js. - No
pnpm bench:abtable. 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 intranslateError:lock()andunlock()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/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@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