• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Screen Lock Management
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
10## Modules to Import
11
12
13```js
14import screenlock from '@ohos.screenLock';
15```
16
17
18## screenlock.isScreenLocked
19
20isScreenLocked(callback: AsyncCallback<boolean>): void
21
22Checks whether the screen is locked. This API uses an asynchronous callback to return the result.
23
24**System capability**: SystemCapability.MiscServices.ScreenLock
25
26**Parameters**
27| Name| Type| Mandatory| Description|
28| -------- | -------- | -------- | -------- |
29| callback | AsyncCallback<boolean> | Yes| Returns **true** if the screen is locked; returns **false** otherwise.|
30
31**Example**
32
33  ```js
34  screenlock.isScreenLocked((err, data)=>{
35     if (err) {
36          console.error('isScreenLocked callback error -> ${JSON.stringify(err)}');
37          return;
38     }
39     console.info('isScreenLocked callback success data -> ${JSON.stringify(data)}');
40  });
41  ```
42
43
44## screenlock.isScreenLocked
45
46isScreenLocked(): Promise<boolean>
47
48Checks whether the screen is locked. This API uses a promise to return the result.
49
50**System capability**: SystemCapability.MiscServices.ScreenLock
51
52**Return value**
53| Type| Description|
54| -------- | -------- |
55| Promise<boolean> | Promise used to return the result.|
56
57**Example**
58
59  ```js
60  screenlock.isScreenLocked().then((data) => {
61      console.log('isScreenLocked success: data -> ${JSON.stringify(data)}');
62  }).catch((err) => {
63      console.error('isScreenLocked fail, promise: err -> ${JSON.stringify(err)}');
64  });
65  ```
66
67
68## screenlock.isSecureMode
69
70isSecureMode(callback: AsyncCallback<boolean>): void
71
72
73Checks whether a device is in secure mode. This API uses an asynchronous callback to return the result.
74
75
76**System capability**: SystemCapability.MiscServices.ScreenLock
77
78
79**Parameters**
80| Name| Type| Mandatory| Description|
81| -------- | -------- | -------- | -------- |
82| callback | AsyncCallback<boolean> | Yes| Returns **true** if the device is in secure mode; returns **false** otherwise.|
83
84**Example**
85
86  ```js
87  screenlock.isSecureMode((err, data)=>{
88     if (err) {
89          console.error('isSecureMode callback error -> ${JSON.stringify(err)}');
90          return;
91     }
92     console.info('isSecureMode callback success data -> ${JSON.stringify(err)}');
93  });
94  ```
95
96
97## screenlock.isSecureMode
98
99isSecureMode(): Promise<boolean>
100
101Checks whether a device is in secure mode. This API uses a promise to return the result.
102
103**System capability**: SystemCapability.MiscServices.ScreenLock
104
105**Return value**
106| Type| Description|
107| -------- | -------- |
108| Promise<boolean> | Promise used to return the result.|
109
110**Example**
111
112  ```js
113  screenlock.isSecureMode().then((data) => {
114      console.log('isSecureMode success: data->${JSON.stringify(data)}');
115  }).catch((err) => {
116      console.error('isSecureMode fail, promise: err->${JSON.stringify(err)}');
117  });
118  ```
119
120
121## screenlock.unlockScreen
122
123unlockScreen(callback: AsyncCallback<void>): void
124
125
126Unlocks the screen. This API uses an asynchronous callback to return the result.
127
128
129**System capability**: SystemCapability.MiscServices.ScreenLock
130
131
132**Parameters**
133| Name| Type| Mandatory| Description|
134| -------- | -------- | -------- | -------- |
135| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation failed, an error message is returned.|
136
137**Example**
138
139  ```js
140  screenlock.unlockScreen((err) => {
141     if (err) {
142          console.error('unlockScreen callback error -> ${JSON.stringify(err)}');
143          return;
144     }
145     console.info('unlockScreen callback success');
146  });
147  ```
148
149
150## screenlock.unlockScreen
151
152unlockScreen(): Promise<void>
153
154Unlocks the screen. This API uses a promise to return the result.
155
156**System capability**: SystemCapability.MiscServices.ScreenLock
157
158**Return value**
159| Type| Description|
160| -------- | -------- |
161| Promise<void> | Promise used to return the result.|
162
163**Example**
164
165  ```js
166  screenlock.unlockScreen().then(() => {
167      console.log('unlockScreen success');
168  }).catch((err) => {
169      console.error('unlockScreen fail, promise: err->${JSON.stringify(err)}');
170  });
171  ```
172