1e41f4b71Sopenharmony_ci# @ohos.screenLock (Screen Lock) (System API) 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>This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.screenLock (Screen Lock)](js-apis-screen-lock.md). 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport screenLock from '@ohos.screenLock'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## EventType<sup>9+</sup> 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciDefines the system event type. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**System API**: This is a system API. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| Event Type | Description | 26e41f4b71Sopenharmony_ci| ------------------ | ------------------------ | 27e41f4b71Sopenharmony_ci| beginWakeUp | Wakeup starts.| 28e41f4b71Sopenharmony_ci| endWakeUp | Wakeup ends.| 29e41f4b71Sopenharmony_ci| beginScreenOn | Screen turn-on starts.| 30e41f4b71Sopenharmony_ci| endScreenOn | Screen turn-on ends.| 31e41f4b71Sopenharmony_ci| beginScreenOff | Screen turn-off starts.| 32e41f4b71Sopenharmony_ci| endScreenOff | Screen turn-off ends.| 33e41f4b71Sopenharmony_ci| unlockScreen | The screen is unlocked. | 34e41f4b71Sopenharmony_ci| lockScreen | The screen is locked. | 35e41f4b71Sopenharmony_ci| beginExitAnimation | Exit animation starts. | 36e41f4b71Sopenharmony_ci| beginSleep | The device enters sleep mode. | 37e41f4b71Sopenharmony_ci| endSleep | The device exits sleep mode. | 38e41f4b71Sopenharmony_ci| changeUser | The user is switched. | 39e41f4b71Sopenharmony_ci| screenlockEnabled | Screen lock is enabled. | 40e41f4b71Sopenharmony_ci| serviceRestart | The screen lock service is restarted. | 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci## SystemEvent<sup>9+</sup> 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ciDefines the structure of the system event callback. 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci**System API**: This is a system API. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 51e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------- | 52e41f4b71Sopenharmony_ci| eventType | [EventType](#eventtype9) | Yes | System event type.| 53e41f4b71Sopenharmony_ci| params | string | Yes | System event parameters.| 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci## screenLock.isLocked<sup>9+</sup> 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ciisLocked(): boolean 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ciChecks whether the screen is locked. 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci**System API**: This is a system API. 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci**Return value** 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci| Type | Description | 68e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------- | 69e41f4b71Sopenharmony_ci| boolean | Returns **true** if the screen is locked; returns **false** otherwise.| 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**Error codes** 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci| ID| Error Message| 76e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 77e41f4b71Sopenharmony_ci| 202 | permission verification failed, application which is not a system application uses system API. | 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**Example** 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci```ts 82e41f4b71Sopenharmony_cilet isLocked = screenLock.isLocked(); 83e41f4b71Sopenharmony_ci``` 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci## screenLock.unlock<sup>9+</sup> 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ciunlock(callback: AsyncCallback<boolean>): void 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ciUnlocks the screen. This API uses an asynchronous callback to return the result. 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**System API**: This is a system API. 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**Parameters** 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 98e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ------------------------- | 99e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the screen is unlocked successfully, and **false** means that screen unlocked is canceled.| 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci**Error codes** 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ciFor details about error codes, see [Universal Error Codes](../errorcode-universal.md) and [Screen Lock Error Codes](errorcode-screenlock.md). 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci| ID| Error Message| 106e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 107e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 108e41f4b71Sopenharmony_ci| 202 | permission verification failed, application which is not a system application uses system API. | 109e41f4b71Sopenharmony_ci| 13200002 | the screenlock management service is abnormal. | 110e41f4b71Sopenharmony_ci| 13200003 | illegal use. | 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**Example** 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci ```ts 115e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci screenLock.unlock((err: BusinessError, data: Boolean) => { 118e41f4b71Sopenharmony_ci if (err) { 119e41f4b71Sopenharmony_ci console.error(`Failed to unlock the screen, Code: ${err.code}, message: ${err.message}`); 120e41f4b71Sopenharmony_ci return; 121e41f4b71Sopenharmony_ci } 122e41f4b71Sopenharmony_ci console.info(`Succeeded in unlocking the screen. result: ${data}`); 123e41f4b71Sopenharmony_ci }); 124e41f4b71Sopenharmony_ci ``` 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci> **NOTE** 127e41f4b71Sopenharmony_ci> 128e41f4b71Sopenharmony_ci> The error code **13200003 illegal use** is added since API version 11. 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci## screenLock.unlock<sup>9+</sup> 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ciunlock(): Promise<boolean> 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ciUnlocks the screen. This API uses a promise to return the result. 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**System API**: This is a system API. 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**Return value** 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci| Type | Description | 143e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------------------------ | 144e41f4b71Sopenharmony_ci| Promise<boolean> | Promise used to return the result. The value **true** means that the screen is unlocked successfully, and **false** means that screen unlocked is canceled.| 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci**Error codes** 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ciFor details about error codes, see [Universal Error Codes](../errorcode-universal.md) and [Screen Lock Error Codes](errorcode-screenlock.md). 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci| ID| Error Message| 151e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 152e41f4b71Sopenharmony_ci| 202 | permission verification failed, application which is not a system application uses system API. | 153e41f4b71Sopenharmony_ci| 13200002 | the screenlock management service is abnormal. | 154e41f4b71Sopenharmony_ci| 13200003 | illegal use. | 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci**Example** 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci ```ts 159e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci screenLock.unlock().then((data: Boolean) => { 162e41f4b71Sopenharmony_ci console.info(`Succeeded in unlocking the screen. result: ${data}`); 163e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 164e41f4b71Sopenharmony_ci console.error(`Failed to unlock the screen, Code: ${err.code}, message: ${err.message}`); 165e41f4b71Sopenharmony_ci }); 166e41f4b71Sopenharmony_ci ``` 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci> **NOTE** 169e41f4b71Sopenharmony_ci> 170e41f4b71Sopenharmony_ci> The error code **13200003 illegal use** is added since API version 11. 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci## screenLock.lock<sup>9+</sup> 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_cilock(callback: AsyncCallback<boolean>): void 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ciLocks the screen. This API uses an asynchronous callback to return the result. 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_INNER 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**System API**: This is a system API. 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**Parameters** 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 187e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ---------------- | 188e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the screen is locked successfully, and **false** means the opposite.| 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci**Error codes** 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ciFor details about error codes, see [Universal Error Codes](../errorcode-universal.md) and [Screen Lock Error Codes](errorcode-screenlock.md). 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci| ID| Error Message| 195e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 196e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 197e41f4b71Sopenharmony_ci| 201 | permission denied. | 198e41f4b71Sopenharmony_ci| 202 | permission verification failed, application which is not a system application uses system API. | 199e41f4b71Sopenharmony_ci| 13200002 | the screenlock management service is abnormal. | 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci**Example** 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci ```ts 204e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci screenLock.lock((err: BusinessError, data: Boolean) => { 207e41f4b71Sopenharmony_ci if (err) { 208e41f4b71Sopenharmony_ci console.error(`Failed to lock the screen, Code: ${err.code}, message: ${err.message}`); 209e41f4b71Sopenharmony_ci return; 210e41f4b71Sopenharmony_ci } 211e41f4b71Sopenharmony_ci console.info(`Succeeded in locking the screen. result: ${data}`); 212e41f4b71Sopenharmony_ci }); 213e41f4b71Sopenharmony_ci ``` 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci## screenLock.lock<sup>9+</sup> 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_cilock(): Promise<boolean> 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ciLocks the screen. This API uses a promise to return the result. 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_INNER 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**System API**: This is a system API. 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**Return value** 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci| Type | Description | 230e41f4b71Sopenharmony_ci| ---------------------- | ------------------------------------------------------------ | 231e41f4b71Sopenharmony_ci| Promise<boolean> | Promise used to return the result. The value **true** means that the screen is locked successfully, and **false** means the opposite.| 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci**Error codes** 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ciFor details about error codes, see [Universal Error Codes](../errorcode-universal.md) and [Screen Lock Error Codes](errorcode-screenlock.md). 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci| ID| Error Message| 238e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 239e41f4b71Sopenharmony_ci| 201 | permission denied. | 240e41f4b71Sopenharmony_ci| 202 | permission verification failed, application which is not a system application uses system API. | 241e41f4b71Sopenharmony_ci| 13200002 | the screenlock management service is abnormal. | 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci**Example** 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci ```ts 246e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci screenLock.lock().then((data: Boolean) => { 249e41f4b71Sopenharmony_ci console.info(`Succeeded in locking the screen. result: ${data}`); 250e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 251e41f4b71Sopenharmony_ci console.error(`Failed to lock the screen, Code: ${err.code}, message: ${err.message}`); 252e41f4b71Sopenharmony_ci }); 253e41f4b71Sopenharmony_ci ``` 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci## screenLock.onSystemEvent<sup>9+</sup> 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_cionSystemEvent(callback: Callback<SystemEvent>): boolean 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ciRegisters a callback for system events related to screen locking. This API can be called only by screen lock applications. 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_INNER 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci**System API**: This is a system API. 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci**Parameters** 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 270e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ----------------- | 271e41f4b71Sopenharmony_ci| callback | Callback\<[SystemEvent](#systemevent9)> | Yes | Callback for system events related to screen locking.| 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci**Return value** 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci| Type | Description | 276e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------- | 277e41f4b71Sopenharmony_ci| boolean | Returns **true** if the callback is registered successfully; returns **false** otherwise.| 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci**Error codes** 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ciFor details about error codes, see [Universal Error Codes](../errorcode-universal.md) and [Screen Lock Error Codes](errorcode-screenlock.md). 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci| ID| Error Message| 284e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 285e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 286e41f4b71Sopenharmony_ci| 201 | permission denied. | 287e41f4b71Sopenharmony_ci| 202 | permission verification failed, application which is not a system application uses system API. | 288e41f4b71Sopenharmony_ci| 13200002 | the screenlock management service is abnormal. | 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci**Example** 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci ```ts 293e41f4b71Sopenharmony_ci try { 294e41f4b71Sopenharmony_ci let isSuccess = screenLock.onSystemEvent((event: screenLock.SystemEvent) => { 295e41f4b71Sopenharmony_ci console.log(`Succeeded in Registering the system event which related to screenlock. eventType: ${event.eventType}`) 296e41f4b71Sopenharmony_ci }); 297e41f4b71Sopenharmony_ci } catch (err) { 298e41f4b71Sopenharmony_ci let error = err as BusinessError; 299e41f4b71Sopenharmony_ci console.error(`Failed to register the system event which related to screenlock, Code: ${error.code}, message: ${error.message}`) 300e41f4b71Sopenharmony_ci } 301e41f4b71Sopenharmony_ci ``` 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci## screenLock.sendScreenLockEvent<sup>9+</sup> 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_cisendScreenLockEvent(event: String, parameter: number, callback: AsyncCallback<boolean>): void 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ciSends an event to the screen lock service. This API can be called only by screen lock applications. It uses an asynchronous callback to return the result. 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_INNER 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci**System API**: This is a system API. 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci**Parameters** 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 318e41f4b71Sopenharmony_ci| --------- | ------------------------ | ---- | -------------------- | 319e41f4b71Sopenharmony_ci| event | String | Yes | Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"lockScreenResult"**: Screen lock result.<br>- **"screenDrawDone"**: Screen drawing is complete.| 320e41f4b71Sopenharmony_ci| parameter | number | Yes | Result.<br>- **0**: The operation is successful. For example, the screen is locked or unlocked successfully.<br>- **1**, the operation fails. For example, screen locking or unlocking fails.<br>- **2**: The operation is canceled. For example, screen locking or unlocking is canceled.| 321e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The **value** true means that the event is sent successfully, and **false** means the opposite. | 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ci**Error codes** 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ciFor details about error codes, see [Universal Error Codes](../errorcode-universal.md) and [Screen Lock Error Codes](errorcode-screenlock.md). 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci| ID| Error Message| 328e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 329e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 330e41f4b71Sopenharmony_ci| 201 | permission denied. | 331e41f4b71Sopenharmony_ci| 202 | permission verification failed, application which is not a system application uses system API. | 332e41f4b71Sopenharmony_ci| 13200002 |the screenlock management service is abnormal. | 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci**Example** 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci ```ts 337e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci screenLock.sendScreenLockEvent('unlockScreenResult', 0, (err: BusinessError, result: Boolean) => { 340e41f4b71Sopenharmony_ci if (err) { 341e41f4b71Sopenharmony_ci console.error(`Failed to send screenlock event, Code: ${err.code}, message: ${err.message}`); 342e41f4b71Sopenharmony_ci return; 343e41f4b71Sopenharmony_ci } 344e41f4b71Sopenharmony_ci console.info(`Succeeded in Sending screenlock event. result: ${result}`); 345e41f4b71Sopenharmony_ci }); 346e41f4b71Sopenharmony_ci ``` 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci## screenLock.sendScreenLockEvent<sup>9+</sup> 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_cisendScreenLockEvent(event: String, parameter: number): Promise<boolean> 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ciSends an event to the screen lock service. This API can be called only by screen lock applications. It uses a promise to return the result. 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.ScreenLock 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_INNER 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci**System API**: This is a system API. 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci**Parameters** 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 363e41f4b71Sopenharmony_ci| --------- | ------ | ---- | --------------------------------------- | 364e41f4b71Sopenharmony_ci| event | String | Yes | Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"lockScreenResult"**: Screen lock result.<br>- **"screenDrawDone"**: Screen drawing is complete.| 365e41f4b71Sopenharmony_ci| parameter | number | Yes | Result.<br>- **0**: The operation is successful. For example, the screen is locked or unlocked successfully.<br>- **1**, the operation fails. For example, screen locking or unlocking fails.<br>- **2**: The operation is canceled. For example, screen locking or unlocking is canceled.| 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci**Return value** 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci| Type | Description | 370e41f4b71Sopenharmony_ci| ----------------- | ---------------------------------------------- | 371e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the result. The **value** true means that the event is sent successfully, and **false** means the opposite.| 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci**Error codes** 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ciFor details about error codes, see [Universal Error Codes](../errorcode-universal.md) and [Screen Lock Error Codes](errorcode-screenlock.md). 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci| ID| Error Message| 378e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 379e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 380e41f4b71Sopenharmony_ci| 201 | permission denied. | 381e41f4b71Sopenharmony_ci| 202 | permission verification failed, application which is not a system application uses system API. | 382e41f4b71Sopenharmony_ci| 13200002 | the screenlock management service is abnormal. | 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci**Example** 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci ```ts 387e41f4b71Sopenharmony_ci import { BusinessError } from '@ohos.base'; 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci screenLock.sendScreenLockEvent('unlockScreenResult', 0).then((result: Boolean) => { 390e41f4b71Sopenharmony_ci console.info(`Succeeded in Sending screenlock event. result: ${result}`); 391e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 392e41f4b71Sopenharmony_ci console.error(`Failed to send screenlock event, Code: ${err.code}, message: ${err.message}`); 393e41f4b71Sopenharmony_ci }); 394e41f4b71Sopenharmony_ci ``` 395