Skip to content

feat(lock-screen): read the lock state with lock-screen status - #5116

Open
kdy1 wants to merge 9 commits into
callstack:mainfrom
kdy1:feat/lock-screen-status
Open

kdy1 wants to merge 9 commits into
callstack:mainfrom
kdy1:feat/lock-screen-status

Conversation

@kdy1

@kdy1 kdy1 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add lock-screen status and client.command.lockScreen({ action: 'status' }). It returns the { action: 'lock-screen', state, message } shape of lock and unlock and changes nothing. Appium users (driver.isLocked(), mobile: isLocked) had no way to ask.

  • Android reads isKeyguardShowing from dumpsys window, the read lock and unlock verify. A dump without it fails with lock-screen-state-unreadable.
  • iPhone and iPad simulators get a lockScreenStatus runner command that reads com.apple.springboard.lockstate, without bringing the session app forward.
  • Other targets refuse it like lock and unlock.
  • status keeps the ref frame and records as an observation. On Android it runs neither the blocking-dialog guard nor the screen-recording dialog recovery, so an ANR is not closed first.

Before / after

$ agent-device lock-screen status --platform android   # base 24f8181c3
Error (INVALID_ARGS): lock-screen requires exactly one action: lock, unlock.
$ agent-device lock-screen status                      # head
The screen is unlocked

Validation

  • At 0233f177b, pnpm check:affected --run --base upstream/main passed with exactCommit: true. CI owns coverage, Swift runner builds, and smoke lanes.
  • At b526a7c25, status → lock → status → unlock → status returned unlocked, locked, unlocked on an Android 16 emulator, matching isKeyguardShowing each time, and on an iOS 27.2 simulator. The 29 lock-screen and model runner XCTests passed.
  • Risk: a provider plugin built before this change has no lockScreenStatus fact, as with shake and lock.

🤖 Generated with Claude Code


Prove it works
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff

kdy1 and others added 9 commits November 26, 2026 10:26
Add `agent-device lock-screen status` and
`client.command.lockScreen({ action: 'status' })`. It returns the same
`{ action: 'lock-screen', state, message }` shape as lock and unlock,
and changes nothing on the device. Users who migrate from Appium
(`driver.isLocked()`, `mobile: isLocked`) had no way to ask whether
the device is locked.

The action selects a new `lockScreenStatus` runtime cell. It returns
the state, so it is not a system button, but its fact is built by
`systemButtonRuntimeOperationFacts` beside lockScreen and unlockScreen:
every owner that does not name it refuses it, and Android and the
iPhone and iPad simulator name it where they name the other two.

Android reads `isKeyguardShowing` from `dumpsys window`, the read that
lock and unlock verify against. A dump without it refuses with
`lock-screen-state-unreadable` instead of reporting unlocked.

The iOS runner gets a `lockScreenStatus` command that reads
`com.apple.springboard.lockstate` once and answers `data.locked`. It
is a presented-surface query: read-only, replayable, and it does not
bring the session app forward, which would dismiss the lock screen it
reports on. A dark screen that is not locked is unlocked. An
unreadable state answers OBSERVATION_UNAVAILABLE.

The registry classifies `status` as a read: it keeps the ref frame and
records as an observation, and the session journal summarizes it as
the state it read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Describe what `lock-screen status` reads on each platform, that it
changes nothing, and that an unreadable state is an error, in the
command reference, the client API page, and the runner protocol.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… status

`lock-screen status` inherited `androidBlockingDialogGuard: true` from
the generic mutating traits. On a local Android session whose app
showed an Application Not Responding dialog, the generic route tapped
Close app and relaunched the app before it read the keyguard, so a
read changed the device.

The descriptor field now also takes a resolver of the request, the way
`refFrameEffect` does, and `lock-screen` answers false for `status`.
Read commands on the interaction route, such as `get` and `is`, already
skip the guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`lock-screen status` keeps the ref frame and lock and unlock expire it,
but no test failed when the resolver returned may-invalidate for every
action. Pin each action beside keyboard, alert, and settings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…able hint

A dump without isKeyguardShowing reused the lock-settings hint, which
sent the caller to dumpsys lock_settings and the current user. A
keyguard read, and so every `lock-screen status`, uses neither. Each
unreadable read now names the dump it came from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The iOS scenario answered every lockScreenStatus with locked: true, so a
decoder that read a missing field as unlocked still passed. It now also
answers locked: false and an answer with no lock state, which must fail
with COMMAND_FAILED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tatus

The previous fix kept the per-command blocking-dialog guard away from
`lock-screen status`, but while a screen recording ran, the generic
route still called the recording's dialog recovery first. With an app
ANR on screen, a status read tapped Close app and relaunched the app.

A descriptor can now name the requests that must not change the device
(`leavesDeviceUntouched`). The generic route runs neither the guard nor
the recording recovery for them, and `lock-screen` names `status`. This
replaces the request resolver on `androidBlockingDialogGuard`, which
covered only the guard. Other commands, `screenshot` included, keep
both recoveries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Swift status tests fed lockScreenStatusResponse the shared
LockScreenStateRead, including unlockedScreenOff, which the status
read never produces. A change that made status read the blanked-screen
state too would have passed every test.

lockScreenStatusResponse now takes the one SpringBoard notify read the
command makes, com.apple.springboard.lockstate, so the tests drive it
with the values that read returns: zero, nonzero, and a failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ames

The MCP tool loading metadata refuses a searchHint word that the tool
description already contains, and the lock-screen description names
the keyguard. Keep only the hint words the description lacks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 60 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/contracts/src/system-button-runtime.test.ts">

<violation number="1" location="packages/contracts/src/system-button-runtime.test.ts:83">
P2: This assertion accepts any exception, so it would pass for an unrelated resolver failure or abort and would not prove the fail-closed runtime-contract behavior. Match `COMMAND_FAILED`, `details.reason: 'runtime-contract-invalid'`, and the `lock-screen status` message as the neighboring binding test does.</violation>
</file>

<file name="apple/runner/RUNNER_PROTOCOL.md">

<violation number="1" location="apple/runner/RUNNER_PROTOCOL.md:338">
P2: This description makes `OBSERVATION_UNAVAILABLE` appear to be the failure for every target, but the runner supports `lockScreenStatus` only on iPhone and iPad simulators and returns `HARDWARE_CONTROL_UNAVAILABLE` elsewhere. State the supported targets and the unsupported-target response so callers do not treat this as a readable observation on physical devices or other Apple targets.</violation>
</file>

<file name="packages/contracts/src/system-button-runtime.ts">

<violation number="1" location="packages/contracts/src/system-button-runtime.ts:23">
P3: This new JSDoc sentence is incomplete: `built with the family's.` leaves the reader to infer what the fact is built with. Say that the fact is built alongside the family’s cells.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

new AbortController().signal,
async () => ({}) as unknown as Interactor,
);
await expect(missing.lockScreenStatus({})).rejects.toThrow();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This assertion accepts any exception, so it would pass for an unrelated resolver failure or abort and would not prove the fail-closed runtime-contract behavior. Match COMMAND_FAILED, details.reason: 'runtime-contract-invalid', and the lock-screen status message as the neighboring binding test does.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/contracts/src/system-button-runtime.test.ts, line 83:

<comment>This assertion accepts any exception, so it would pass for an unrelated resolver failure or abort and would not prove the fail-closed runtime-contract behavior. Match `COMMAND_FAILED`, `details.reason: 'runtime-contract-invalid'`, and the `lock-screen status` message as the neighboring binding test does.</comment>

<file context>
@@ -46,10 +47,40 @@ test('an omitted button reports the family denial, a named one its own cell', ()
+    new AbortController().signal,
+    async () => ({}) as unknown as Interactor,
+  );
+  await expect(missing.lockScreenStatus({})).rejects.toThrow();
 });
 
</file context>
Suggested change
await expect(missing.lockScreenStatus({})).rejects.toThrow();
await expect(missing.lockScreenStatus({})).rejects.toMatchObject({
code: 'COMMAND_FAILED',
message: 'lock-screen status was admitted but its bound interactor has no implementation.',
details: { reason: 'runtime-contract-invalid' },
});

Comment on lines +338 to +340
`lockScreenStatus` reads `com.apple.springboard.lockstate` once and answers `data.locked`, true
while the lock screen is up. It changes nothing and brings no app forward. A dark screen that is
not locked answers `false`. A lock state the runner cannot read answers `OBSERVATION_UNAVAILABLE`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This description makes OBSERVATION_UNAVAILABLE appear to be the failure for every target, but the runner supports lockScreenStatus only on iPhone and iPad simulators and returns HARDWARE_CONTROL_UNAVAILABLE elsewhere. State the supported targets and the unsupported-target response so callers do not treat this as a readable observation on physical devices or other Apple targets.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At apple/runner/RUNNER_PROTOCOL.md, line 338:

<comment>This description makes `OBSERVATION_UNAVAILABLE` appear to be the failure for every target, but the runner supports `lockScreenStatus` only on iPhone and iPad simulators and returns `HARDWARE_CONTROL_UNAVAILABLE` elsewhere. State the supported targets and the unsupported-target response so callers do not treat this as a readable observation on physical devices or other Apple targets.</comment>

<file context>
@@ -335,6 +335,10 @@ prompt, which the runner leaves unanswered. Either can follow a dispatch, so the
 `lock-screen-secure`. A runtime without XCUIDevice's lock button answers
 `HARDWARE_CONTROL_UNAVAILABLE` before pressing anything.
 
+`lockScreenStatus` reads `com.apple.springboard.lockstate` once and answers `data.locked`, true
+while the lock screen is up. It changes nothing and brings no app forward. A dark screen that is
+not locked answers `false`. A lock state the runner cannot read answers `OBSERVATION_UNAVAILABLE`.
</file context>
Suggested change
`lockScreenStatus` reads `com.apple.springboard.lockstate` once and answers `data.locked`, true
while the lock screen is up. It changes nothing and brings no app forward. A dark screen that is
not locked answers `false`. A lock state the runner cannot read answers `OBSERVATION_UNAVAILABLE`.
`lockScreenStatus` is supported only on iPhone and iPad simulators. It reads `com.apple.springboard.lockstate` once and answers `data.locked`, true
while the lock screen is up. It changes nothing and brings no app forward. A dark screen that is not locked answers `false`. Other targets answer
`HARDWARE_CONTROL_UNAVAILABLE`; an unreadable lock state on a supported simulator answers `OBSERVATION_UNAVAILABLE`.

* returns only once the device reports the requested lock state, and throws otherwise. What
* returns only once the device reports the requested lock state, and throws otherwise. The third
* `lock-screen` cell, `lockScreenStatus`, returns the lock state, so it is not a button: its
* operation and binder sit below the family, and its fact is built with the family's. What

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This new JSDoc sentence is incomplete: built with the family's. leaves the reader to infer what the fact is built with. Say that the fact is built alongside the family’s cells.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/contracts/src/system-button-runtime.ts, line 23:

<comment>This new JSDoc sentence is incomplete: `built with the family's.` leaves the reader to infer what the fact is built with. Say that the fact is built alongside the family’s cells.</comment>

<file context>
@@ -14,7 +18,9 @@ import type { SnapshotRuntimeExecution } from './snapshot-runtime.ts';
- * returns only once the device reports the requested lock state, and throws otherwise. What
+ * returns only once the device reports the requested lock state, and throws otherwise. The third
+ * `lock-screen` cell, `lockScreenStatus`, returns the lock state, so it is not a button: its
+ * operation and binder sit below the family, and its fact is built with the family's. What
  * varies between them is which
  * owners carry the control, and that is the fact table's job, not a per-button module's: a
</file context>
Suggested change
* operation and binder sit below the family, and its fact is built with the family's. What
* operation and binder sit below the family, and its fact is built alongside the family's cells. What

@thymikee

Copy link
Copy Markdown
Member

Thanks for adding a read-only lock state check.

The answers to these questions decide whether the change fits the project:

  • Which task needs to read the lock state without changing it, where lock or unlock (both idempotent and returning state) or a screenshot is not enough?
  • Is there a user report or issue that asks for this, beyond Appium parity?
  • Could the Android dialog-recovery skip reuse the existing isReadOnlyRequest classification instead of a new leavesDeviceUntouched descriptor field?
  • Should lock-screen status follow keyboard status, which keeps the Android blocking-dialog guard?

At 0233f17, one defect needs a fix. A direct runner lockScreenStatus request on tvOS, visionOS or macOS can foreground or launch the app before it is refused, although the new runner protocol promises that it changes nothing and brings no app forward. The query uses presentedSurfaceQuery, so app preparation runs first. With no system surface in front and a new or stale bundle target, it can activate the app before the platform refusal. The CLI and client already block these targets before dispatch. This side effect is separate from the error-code wording issue in an open thread. The runner-owned lock state query must be handled in executeOnMain before any app preparation, with no remaining branch for it on the prepared path. Please validate the unsupported dispatch with an app bundle and show that it is refused before any app activation.

Could the status cell stay while the leavesDeviceUntouched field, its accessor and lockScreenLeavesDeviceUntouched are deleted, with both Android recoveries on the generic route using isReadOnlyRequest(req) (or keeping the dialog guard, as keyboard status does)? That removes one concept and three symbols. The feature also adds about 290 net production lines across contracts, registry, daemon, two platforms, the Swift runner and its wire protocol. Before merge, should a maintainer decide whether observing the lock state earns a runner command, given that lock and unlock already report state and a screenshot shows the lock screen?

Two high-priority open threads still apply: missing-member test assertion (test strength only) and protocol error-code wording (wording only, as those targets are refused before the runner through the CLI and client). One lower-priority thread also still applies. This thread does not apply and can be resolved: the reason is typed and documented for callers, the help already says an unreported state is an error, and the earlier help never listed this reason for lock or unlock either.

The required evidence is in place. The live Android 16 emulator and iOS 27.2 simulator runs are author-reported without transcripts, at b526a7c, which differs from the reviewed head only in a help searchHint string. Not verified here: those live runs were not reproduced, and the Swift runner suite and other tests were not run locally. Not verified here: on a device, that lockScreenStatus avoids app activation when the runner first has to start or restart (a path shared with lock and unlock). Not verified here: whether a shared Android screen-recording session ever needs recording-dialog recovery before a read to stay usable.

The only checks not passing are the two Body rules runs. Both were cancelled, not failed, and they are likely unrelated because they check PR body and commit metadata, which the diff does not touch on that route. The other 16 checks pass.

Before merge, the runner must refuse this request on unsupported platforms without activating the app, and the questions on need and design must be answered.

@kdy1

kdy1 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

Need. The caller is the mobile engine of e2e (@e2e-dev/mobile), which runs on agent-device. It wants device.isLocked() for users who move Appium tests over (driver.isLocked(), mobile: isLocked). There is no user report in this repository, so Appium parity is the whole request.

lock and unlock are not enough when a test must check the lock state without setting it. Two examples:

  • An app that keeps the screen awake, such as a video player. The test waits past the auto-lock timeout and asserts that the device is still unlocked. lock or unlock would set the state that the test checks.
  • An alarm or call screen that shows over the lock screen. The test asserts that the device is still locked after the app shows it.

A screenshot shows the lock screen, but a test then needs a model or a pixel heuristic to get a boolean from it. status reads the same keyguard state that lock and unlock already verify against.

Runner command. It does not need one. The host can read the same notify key with xcrun simctl spawn <udid> notifyutil -g com.apple.springboard.lockstate. On an iOS 27.2 simulator it read 0, 1, 0 across unlocked, lock-screen lock, and lock-screen unlock, the same as lock-screen status, in about 0.24 s per read. readBiometricEnrollmentState in platform-apple/src/core/app-settings.ts already reads notify state this way. I will move the iOS read to the host and remove the runner command, its protocol section, and the runner fixtures. This also removes the tvOS, visionOS, and macOS activation defect, because the runner no longer gets this request.

Android recovery. I will delete leavesDeviceUntouched, its accessor, and lockScreenLeavesDeviceUntouched, and skip both Android recoveries on the generic route when isReadOnlyRequest(req) is true. On that route it is true only for screenshot and lock-screen status. screenshot has no dialog guard, so the guard change affects only status. But a screenshot during an Android screen recording would also stop running the recording-dialog recovery first. Is that acceptable? If not, I will keep the guard for status, as keyboard status does.

Threads. The same push will make the test assertion strict and fix the JSDoc sentence. The protocol wording thread goes away with the runner command. I resolved the reason thread, as you suggested.

I will wait for your decision on the need before I push.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants