Skip to main content

appium_client/commands/
lock.rs

1//! Lock and unlock the device
2use async_trait::async_trait;
3use fantoccini::error::CmdError;
4use http::Method;
5use serde_json::json;
6use crate::{AndroidClient, AppiumClientTrait, IOSClient};
7use crate::commands::AppiumCommand;
8
9/// Lock device
10#[async_trait]
11pub trait LocksDevice: AppiumClientTrait {
12
13    /// Locks the device. Note: iOS can only be unlocked manually.
14    async fn lock_device(&self) -> Result<(), CmdError> {
15        self.issue_cmd(AppiumCommand::Custom(
16            Method::POST,
17            "appium/device/lock".to_string(),
18            Some(json!({}))
19        )).await?;
20
21        Ok(())
22    }
23}
24
25/// Unlock device
26#[async_trait]
27pub trait UnlocksDevice: AppiumClientTrait {
28
29    /// Unlocks the device.
30    ///
31    /// To unlock a screen with code or pattern, use "unlockType" and "unlockKey" capabilities.
32    /// See <https://github.com/appium/appium-android-driver/blob/master/docs/UNLOCK.md>.
33    async fn unlock_device(&self) -> Result<(), CmdError> {
34        self.issue_cmd(AppiumCommand::Custom(
35            Method::POST,
36            "appium/device/unlock".to_string(),
37                None
38        )).await?;
39
40        Ok(())
41    }
42}
43
44#[async_trait]
45impl LocksDevice for AndroidClient {}
46
47#[async_trait]
48impl LocksDevice for IOSClient {}
49
50#[async_trait]
51impl UnlocksDevice for AndroidClient {}