Skip to content

Lock and unlock the screen on Android and iOS simulators #4798

Done

Description

@imranbarbhuiya

Purpose

Agents and test runners can't lock or unlock a device. Tests that cover what an app does on a lock (pausing playback, hiding sensitive content, re-auth on return, notifications on the lock screen) fall back to raw adb on Android and have no route on an iOS simulator. hardware-button sleep|wake|power presses a key and leaves the keyguard alone, and it refuses on iOS simulators.

API

agent-device lock-screen lock
agent-device lock-screen unlock
await client.command.lockScreen({ action: 'lock' });
// => { action: 'lock-screen', state: 'lock', message: 'Locked the screen' }
  • One positional, <lock|unlock>, picked the way keyboard <status|dismiss|enter> picks a cell. An unknown value is INVALID_ARGS before any device call.
  • No --settle. The command must not activate or re-foreground the session app.
  • Unlock returns to whatever was in front before the lock.

Behavior

Target lock unlock
Android phone/tablet (emulator or device) KEYCODE_SLEEP KEYCODE_WAKEUP, then wm dismiss-keyguard
iOS simulator runner: XCUIDevice pressLockButton runner: bottom-edge swipe up from the lock screen
iOS physical, tvOS, Android TV, macOS, web UNSUPPORTED_OPERATION UNSUPPORTED_OPERATION
  • A device with a secure lock (PIN, pattern, passcode) is not unlocked. unlock refuses with a typed reason, and nothing types a credential.
  • iOS pressLockButton is a private XCUIDevice selector, the one WebDriverAgent's lock uses. The runner checks responds(to:) and refuses when the selector is missing.

Completion conditions

  • Android: after lock, dumpsys window reports isKeyguardShowing=true. After unlock, it reports false and the previous app is in front.
  • iOS simulator: after lock, a screenshot shows the lock screen. After unlock, the previous app is in front.
  • Tests for the refusals and for each platform's commands, help text, and commands.md.

Prototype evidence (854bba6c5)

  • Pixel 9 AVD, Android 16, lock screen set to swipe:
    • hardware-button sleep then wake gives isKeyguardShowing=true.
    • wm dismiss-keyguard gives false, back in Settings.
  • iPhone 17 Pro simulator, iOS 27.2, with a locally rebuilt runner that called pressLockButton: the lock screen showed.
    • A swipe up from the bottom edge returned to Settings.
    • home also unlocks, but lands on the Home Screen.

Open questions

  1. Is a private XCUIDevice selector acceptable here? feat(hardware-button): press phone volume and power buttons on Android and iOS #3848 left iOS lock out because there's no public API.
  2. One lock-screen <lock|unlock> command, or lock and unlock as two commands?

Activity

  1. added
    enhancement
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions