1e41f4b71Sopenharmony_ci# @ohos.screenLock (Screen Lock)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **screenlock** module is a system module in OpenHarmony. It provides APIs for screen lock applications to subscribe to screen lock status changes as well as callbacks for them to receive the results. It also provides APIs for third-party applications to unlock the screen, obtain the screen locked status, and check whether a lock screen password has been set.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Modules to Import
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```ts
12e41f4b71Sopenharmony_ciimport screenLock from '@ohos.screenLock';
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## screenLock.isScreenLocked<sup>(deprecated)</sup>
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciisScreenLocked(callback: AsyncCallback&lt;boolean&gt;): void
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciChecks whether the screen is locked. This API uses an asynchronous callback to return the result.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci> **NOTE**
22e41f4b71Sopenharmony_ci> 
23e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 9.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Parameters**
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name  | Type                        | Mandatory| Description                                                       |
30e41f4b71Sopenharmony_ci| -------- | ---------------------------- | ---- | ----------------------------------------------------------- |
31e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. The value **true** means that the screen is locked, and **false** means the opposite.|
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**Example**
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci  ```ts
36e41f4b71Sopenharmony_ci  import { BusinessError } from '@ohos.base';
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci  screenLock.isScreenLocked((err: BusinessError, data: Boolean)=>{      
39e41f4b71Sopenharmony_ci    if (err) {
40e41f4b71Sopenharmony_ci      console.error(`Failed to obtain whether the screen is locked, Code: ${err.code}, message: ${err.message}`);
41e41f4b71Sopenharmony_ci      return;    
42e41f4b71Sopenharmony_ci    }
43e41f4b71Sopenharmony_ci    console.info(`Succeeded in Obtaining whether the screen is locked. result: ${data}`);
44e41f4b71Sopenharmony_ci  });
45e41f4b71Sopenharmony_ci  ```
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci## screenLock.isScreenLocked<sup>(deprecated)</sup>
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ciisScreenLocked(): Promise&lt;boolean&gt;
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ciChecks whether the screen is locked. This API uses a promise to return the result.
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci> **NOTE**
54e41f4b71Sopenharmony_ci> 
55e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 9.
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci**Return value**
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci| Type                  | Description                                        |
62e41f4b71Sopenharmony_ci| ---------------------- | ------------------------------------------- |
63e41f4b71Sopenharmony_ci| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the screen is locked, and **false** means the opposite.|
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci**Example**
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci  ```ts
68e41f4b71Sopenharmony_ci  import { BusinessError } from '@ohos.base';
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci  screenLock.isScreenLocked().then((data: Boolean) => {
71e41f4b71Sopenharmony_ci    console.info(`Succeeded in Obtaining whether the screen is locked. result: ${data}`);
72e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
73e41f4b71Sopenharmony_ci    console.error(`Failed to obtain whether the screen is locked, Code: ${err.code}, message: ${err.message}`);
74e41f4b71Sopenharmony_ci  });
75e41f4b71Sopenharmony_ci  ```
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci## screenLock.isSecureMode<sup>(deprecated)</sup>
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ciisSecureMode(callback: AsyncCallback&lt;boolean&gt;): void
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ciChecks whether the device is in secure mode. When the device is in secure mode, its screen requires a password, unlock pattern, or other user credentials to unlock. This API uses an asynchronous callback to return the result.
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci> **NOTE**
84e41f4b71Sopenharmony_ci> 
85e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 9.
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci**Parameters**
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci| Name  | Type           | Mandatory| Description                             |
92e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ------------------------ |
93e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. The value **true** means that the device is in secure mode, and **false** means the opposite.|
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci**Example**
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci  ```ts
98e41f4b71Sopenharmony_ci  import { BusinessError } from '@ohos.base';
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci  screenLock.isSecureMode((err: BusinessError, data: Boolean)=>{
101e41f4b71Sopenharmony_ci    if (err) {
102e41f4b71Sopenharmony_ci      console.error(`Failed to obtain whether the device is in secure mode, Code: ${err.code}, message: ${err.message}`);
103e41f4b71Sopenharmony_ci      return;
104e41f4b71Sopenharmony_ci    }
105e41f4b71Sopenharmony_ci    console.info(`Succeeded in Obtaining whether the device is in secure mode. result: ${data}`);
106e41f4b71Sopenharmony_ci  });
107e41f4b71Sopenharmony_ci  ```
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci## screenLock.isSecureMode<sup>(deprecated)</sup>
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ciisSecureMode(): Promise&lt;boolean&gt;
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ciChecks whether the device is in secure mode. When the device is in secure mode, its screen requires a password, unlock pattern, or other user credentials to unlock. This API uses a promise to return the result.
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci> **NOTE**
116e41f4b71Sopenharmony_ci> 
117e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 9.
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**Return value**
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci| Type                  | Description                                                        |
124e41f4b71Sopenharmony_ci| ---------------------- | ------------------------------------------------------------ |
125e41f4b71Sopenharmony_ci| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the device is in secure mode, and **false** means the opposite.|
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**Example**
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci  ```ts
130e41f4b71Sopenharmony_ci  import { BusinessError } from '@ohos.base';
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci  screenLock.isSecureMode().then((data: Boolean) => {
133e41f4b71Sopenharmony_ci    console.info(`Succeeded in Obtaining whether the device is in secure mode. result: ${data}`);
134e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
135e41f4b71Sopenharmony_ci    console.error(`Failed to obtain whether the device is in secure mode, Code: ${err.code}, message: ${err.message}`);
136e41f4b71Sopenharmony_ci  });
137e41f4b71Sopenharmony_ci  ```
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci## screenLock.unlockScreen<sup>(deprecated)</sup>
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ciunlockScreen(callback: AsyncCallback&lt;void&gt;): void
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ciUnlocks the screen. This API uses an asynchronous callback to return the result.
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci> **NOTE**
146e41f4b71Sopenharmony_ci> 
147e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 9.
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci**Parameters**
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci| Name  | Type             | Mandatory| Description            |
154e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | --------------- |
155e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the screen is unlocked successfully, **err** is **undefined**; otherwise, **err** is an error object.|
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci**Example**
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci  ```ts
160e41f4b71Sopenharmony_ci  import { BusinessError } from '@ohos.base';
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci  screenLock.unlockScreen((err: BusinessError) => {      
163e41f4b71Sopenharmony_ci    if (err) {
164e41f4b71Sopenharmony_ci      console.error(`Failed to unlock the screen, Code: ${err.code}, message: ${err.message}`);
165e41f4b71Sopenharmony_ci      return;    
166e41f4b71Sopenharmony_ci    }
167e41f4b71Sopenharmony_ci    console.info(`Succeeded unlocking the screen.`);
168e41f4b71Sopenharmony_ci  });
169e41f4b71Sopenharmony_ci  ```
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci## screenLock.unlockScreen<sup>(deprecated)</sup>
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ciunlockScreen(): Promise&lt;void&gt;
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ciUnlocks the screen. This API uses a promise to return the result.
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci> **NOTE**
178e41f4b71Sopenharmony_ci> 
179e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 9.
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci**Return value**
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci| Type               | Description                     |
186e41f4b71Sopenharmony_ci| ------------------- | ------------------------- |
187e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise that returns no value.|
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci**Example**
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci  ```ts
192e41f4b71Sopenharmony_ci  import { BusinessError } from '@ohos.base';
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci  screenLock.unlockScreen().then(() => {
195e41f4b71Sopenharmony_ci    console.info('Succeeded unlocking the screen.');
196e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
197e41f4b71Sopenharmony_ci    console.error(`Failed to unlock the screen, Code: ${err.code}, message: ${err.message}`);
198e41f4b71Sopenharmony_ci  });
199e41f4b71Sopenharmony_ci  ```
200