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