Skip to content

feat(lock-screen): lock and unlock the screen on Android and iOS simulators - #5057

Merged
thymikee merged 10 commits into
callstack:mainfrom
imranbarbhuiya:feat/lock-screen
Nov 25, 2026
Merged

thymikee merged 10 commits into
callstack:mainfrom
imranbarbhuiya:feat/lock-screen

Conversation

@imranbarbhuiya

@imranbarbhuiya imranbarbhuiya commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #4798. The iOS side follows the reviewed design of #3001.

agent-device lock-screen <lock|unlock> and client.command.lockScreen({ action }) return { action: 'lock-screen', state: 'locked' | 'unlocked', message } once the device reports that state. No app is activated and there is no --settle.

  • Android: KEYCODE_SLEEP, or KEYCODE_WAKEUP then wm dismiss-keyguard, verified by isKeyguardShowing. A screen lock set to None refuses lock with lock-screen-disabled; a PIN, pattern, or password refuses unlock with lock-screen-secure. Both send nothing. A deferred keyguard ("Power button instantly locks" off) is awaited for lock_screen_lock_after_timeout, 5–60 s.
  • iOS simulator: pressLockButton after responds(to:); unlock swipes up from the bottom edge, back to the app in front. A dark screen is woken first. Success needs com.apple.springboard.lockstate, a lock surface for lock, and a lit screen for unlock. A passcode prompt gives lock-screen-secure.
  • Other targets, including physical iPhones and Android TV: UNSUPPORTED_OPERATION.

lock-screen names the surface it shows, like app-switcher. Two system-button cells are picked by the positional, as in hardware-button.

Before / after

Base has no lock-screen. Head, Settings in front:

Pixel 9 AVD, Android 16:
lock (None)       -> lock-screen-disabled, dispatched no; no sleep in logcat
lock (swipe)      -> locked (0.81 s); repeat sends nothing (0.19 s)
unlock            -> unlocked (0.90 s), Settings in front
unlock (PIN)      -> lock-screen-secure, dispatched no; keyguard stays up
lock (PIN, instant lock off, lock after 15 s) -> locked (15.7 s)
iPhone 17 Pro simulator, iOS 27.2:
lock -> locked; repeat presses nothing (0.22 s)
unlock on a dark lock screen -> unlocked (2.61 s), screen on, Settings in front

Validation

  • Head e55a5d4d7: check:affected --run --head passed format, lint, typecheck, layering, Fallow, build, package, integration-node, and vitest-related; pnpm gate passed provider-integration, command-docs, capabilities-matrix, xctest-selection, runner-error-codes, and daemon-wire-compat.
  • Runner lock-screen tests: 18/18 on the simulator. Each Swift and TypeScript mutant fails a test.
  • The chore(gates) commit adds system/lock-screen.ts to APPROVED_CLOSURE_ADDITIONS, because the system family keeps one module per command. Please approve or reject that row; its owner is a placeholder.

…lators

Add `agent-device lock-screen <lock|unlock>` and
`client.command.lockScreen({ action })`. The action selects one of two
new system-button cells, lockScreen or unlockScreen, the way
hardware-button selects a key, and the result reports the lock state the
owner read back: `{ action: 'lock-screen', state, message }`.

Android locks with KEYCODE_SLEEP and unlocks with KEYCODE_WAKEUP then
`wm dismiss-keyguard`, each verified by the keyguard state
`dumpsys window` reports. A keyguard whose foreground user has a PIN,
pattern, or password is refused before anything is sent, with
`lock-screen-secure`. The keyguard read moves to keyguard.ts, shared
with fold.

The iOS runner locks with XCUIDevice's pressLockButton, checked with
responds(to:), and unlocks with a swipe up from the bottom edge, after
the same button wakes a dark screen; a swipe on a dark screen unlocks
SpringBoard but leaves the screen off. Success
needs SpringBoard's lock state, and for a lock also the lock screen date
view or cover sheet window. The verification window starts after the
dispatch returns and every wait is followed by a read. Unlock also needs
com.apple.springboard.hasBlankedScreen to report the screen on. A
passcode prompt is refused with `lock-screen-secure`.

A screen already in the requested state is left alone. Neither command
activates the session app or settles. Physical iPhones and iPads, Android
TV, tvOS, macOS, and web refuse with UNSUPPORTED_OPERATION.
The system family keeps one module per command, so the new facet adds
one module and 15 top-level statements to the client, CLI and
command-surface entries. No maintainer has approved the row yet, so its
owner is a placeholder.
@thymikee

Copy link
Copy Markdown
Member

Thanks for the work on lock and unlock. The code at 28e5e1e is ready, and no conflicts are known. The Smoke Tests failure is in live-automation-scenario.ts:101 (the catalog snapshot still showed the Automation lab), a navigation timing route with no lock-screen call, and the Runner Build job reports every step as success, so both look unrelated to this diff. Not blocking, and fine to take or leave: on Android with the screen lock set to None, lockAndroidScreen sends the sleep key and then throws lock-screen-unverified with dispatched unknown, although the dispatch is known and the screen is off (packages/platform-android/src/lock-screen.ts:93); the 5 s LOCK_STATE_WINDOW_MS can end before a deferred keyguard appears on a secure device (:16); on an iOS simulator reading .unlockedScreenOff, lock presses the lock button, which wakes the screen instead (RunnerTests+LockScreen.swift:79); the lock-screen state values are spelled in four places and could come from one exported const next to LOCK_SCREEN_ACTIONS (packages/session-journal/src/session-event-action-presentation.ts:26); and the lock-screen vocabulary lives in device-rotation.ts, which the name no longer describes. Not verified here: the Pixel 9 AVD and iPhone 17 Pro simulator runs are author-reported, the dumpsys lock_settings format across Android versions, whether XCUI reports the cover sheet while the simulator screen is blanked, and a local rerun of the gates and Swift unit suite. The next step before merge is a maintainer decision on the new APPROVED_CLOSURE_ADDITIONS row, whose owner is still the placeholder 'pending maintainer approval' (scripts/tests/eager-closure-budgets.ts:182), plus a rerun of the Smoke Tests and Runner Build jobs.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 24, 2026
LOCK_SCREEN_STATES sits beside LOCK_SCREEN_ACTIONS, and the result type,
the MCP output schema, the session journal and the daemon rows read it
instead of repeating 'locked' and 'unlocked'.
With the screen lock set to None, Android shows no keyguard, so lock sent
the sleep key and then failed unverified. It now reads the foreground
user's lock settings first and refuses with lock-screen-disabled and
dispatched: no.

On a secure device with "Power button instantly locks" off, the keyguard
appears only after lock_screen_lock_after_timeout. Lock now waits that
long on top of its 5 s window, 5 s when the setting is unset, up to one
minute so the command stays inside the daemon's request envelope.
On a simulator whose screen SpringBoard has blanked while unlocked, the
lock button can wake the screen instead of locking it. lockScreen now
wakes such a screen first and presses again only if it is still
unlocked.
On an Android 16 emulator with a PIN and "Power button instantly locks"
off, the keyguard showed about 0.2 s after lock_screen_lock_after_timeout
and never sooner than 5 s, even with the setting unset, 0 or 2000. The
deferral now has that 5 s floor, so a 0 setting no longer leaves a 5 s
window that ends as the keyguard appears.
The lock dispatch's decision moves into dispatchLock(screenIsBlanked:wake:
readState:press:) so the runner unit tests drive it: a dark screen is
woken and pressed again only while still unlocked, a lit screen is
pressed once, and a wake refusal stops before any press.
@imranbarbhuiya

Copy link
Copy Markdown
Contributor Author
  • Done in ed96b8f: with the screen lock set to None, lock now reads the foreground user's lock settings first and refuses with UNSUPPORTED_OPERATION, reason lock-screen-disabled, dispatched: no, so no sleep key is sent. On the Pixel 9 AVD (None) it refuses and logcat shows no sleep. A failure after the key is sent keeps dispatched: unknown, the only wire value for a send that may have acted.
  • Done in ed96b8f and ac306f6: measured on the Pixel 9 AVD (Android 16) with a PIN. With "Power button instantly locks" on, the keyguard showed after 0.6–0.9 s. With it off, it showed about 0.2 s after lock_screen_lock_after_timeout and never under 5 s: 5.0–5.3 s for unset, 0 and 2000, then 8.2, 15.2 and 30.2 s for 8000, 15000 and 30000. lock now waits its 5 s plus that delay, floored at 5 s and capped at 60 s for the daemon's 90 s envelope. It locked after 5.5 s at 0, 15.7 s at 15000 and 60.8 s at 60000. At 120000 it returned lock-screen-unverified with a hint naming the setting after 65.4 s.
  • Done in dd59186 and c9d03ac: on a blanked screen, lock wakes it first and presses again only if it is still unlocked. dispatchLock(screenIsBlanked:wake:readState:press:) carries that decision, and three runner tests drive it; mutants that drop the re-check or the wake refusal each fail one. On the iPhone 17 Pro simulator I couldn't recreate an unlocked dark screen on this head: both a raw swipe and an unlock without the wake left the screen lit. Lock, repeat lock, and unlock from a dark lock screen pass there.
  • Done in f09be4c: LOCK_SCREEN_STATES and LockScreenState sit beside LOCK_SCREEN_ACTIONS, and the result type, the output schema, the session journal, and the daemon rows read them.
  • Left as is: a module of its own adds one module and 7–17 top-level statements to six eager closures (client, command-surface, daemon, the device facade, device-selection, CLI), which the budget gate refuses. No module those closures already load has a fitting name, and renaming device-rotation.ts, which has 18 importers and also holds the hardware-button and fold vocabulary, belongs in its own refactor.
  • The Smoke Tests failure is the catalog snapshot at live-automation-scenario.ts:101 finding no Settings tab, with no lock-screen call on that route. Runner Build built tvOS, visionOS, and watchOS, then failed in post-job cleanup with a runner "Object reference not set" error. Neither comes from this diff.

@thymikee thymikee removed the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 24, 2026
@thymikee

Copy link
Copy Markdown
Member

Thanks for the follow-up. At e55a5d4 the code looks good, and the notes from the earlier review (#5057 (comment)) are addressed: the refused-lock case, the deferred-keyguard wait, the iOS wake before lock, the help and docs, and the dedupe. No conflicts. Only Body rules is not passing, and it was cancelled rather than failed. It checks PR body and commit metadata, not code this diff changes, and the other 15 checks pass. Before merge, Body rules needs a rerun, and the maintainer needs to decide the APPROVED_CLOSURE_ADDITIONS row for packages/command-surface/src/system/lock-screen.ts, whose owner is still "pending maintainer approval" (https://github.com/callstack/agent-device/blob/e55a5d4/scripts/__tests__/eager-closure-budgets.ts#L182). Not verified here: the live device runs (Pixel 9 AVD on Android 16, iPhone 17 Pro simulator on iOS 27.2) are author-reported and were not reproduced. The new iOS wake-then-repress branch for an unlocked dark screen is covered only by injected runner unit tests. Where dumpsys lock_settings omits IsLockScreenDisabled, a None lock keeps the old behavior (sleep sent, lock-screen-unverified), and lock now refuses with lock-screen-state-unreadable when the foreground user's CredentialType line is missing. Both sit behind documented reasons and are not a regression against main. The Swift unit suite and gates were not rerun locally.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 24, 2026
@thymikee
thymikee merged commit e853b3b into callstack:main Nov 25, 2026
15 of 16 checks passed
kdy1 added a commit to e2e-inc/e2e that referenced this pull request Nov 26, 2026
agent-device 0.21.43 adds the lock-screen command (callstack/agent-device#5057),
which device.lock() and device.unlock() need. The mobile engine and the four
packages that pin agent-device or its plugins move with it.

Refs ENG-1526

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lock and unlock the screen on Android and iOS simulators

2 participants