1# @ohos.ability.screenLockFileManager (Sensitive Data Access Management Under Lock Screen) 2 3Once the screen is locked, the keys for sensitive data are destroyed, preventing any read or write operations on that data. These keys can be restored only after the screen is unlocked. To facilitate data access on the lock screen, the screenLockFileManager module has been introduced. This module provides APIs to request and release the permission to access sensitive data on the lock screen, thereby managing sensitive data access securely. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import { screenLockFileManager } from '@kit.AbilityKit'; 13``` 14 15## AccessStatus 16 17Enumerates the statuses for requesting access to sensitive data on the lock screen. 18 19 **System capability**: SystemCapability.Security.ScreenLockFileManager 20 21| Name | Value | Description | 22| -------------- | ---- | ------------------------ | 23| ACCESS_DENIED | -1 | Access to sensitive data on the lock screen is denied.| 24| ACCESS_GRANTED | 0 | Access to sensitive data on the lock screen is granted. | 25 26 27## ReleaseStatus 28 29Enumerates the statuses for releasing access permissions to sensitive data on the lock screen. 30 31 **System capability**: SystemCapability.Security.ScreenLockFileManager 32 33| Name| Value| Description| 34|-----------------|----|----| 35| RELEASE_DENIED | -1 | Release of access to sensitive data on the lock screen is denied.| 36| RELEASE_GRANTED | 0 | Release of access to sensitive data on the lock screen is granted. | 37 38## KeyStatus<sup>18+</sup> 39 40Enumerates the statuses for access permissions for sensitive data on the lock screen. 41 42 **System capability**: SystemCapability.Security.ScreenLockFileManager 43 44| Name| Value| Description| 45|-----------------|----|----| 46| KEY_NOT_EXIST | -2 | The application has not enabled sensitive data protection on the lock screen.| 47| KEY_RELEASED | -1 | The access permission for sensitive data on the lock screen has been released.| 48| KEY_EXIST | 0 | The application can access sensitive data on the lock screen. | 49 50## screenLockFileManager.acquireAccess 51 52acquireAccess(): AccessStatus 53 54Requests the permission to access sensitive data on the lock screen. This API returns the result synchronously. Generally sensitive data cannot be accessed after the screen is locked. However, you can call this API to access sensitive data on the lock screen. 55 56**System capability**: SystemCapability.Security.ScreenLockFileManager 57 58**Return value** 59 60| Type | Description | 61| ----------------------------------------------------------- | ------------------------------------- | 62| [AccessStatus](#accessstatus) | State for requesting access to sensitive data on the lock screen.| 63 64**Error codes** 65 66For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [ohos.screenLockFileManager](errorcode-screenLockFileManager.md). 67 68| ID| Error Message | 69| -------- | ------------------------------------------------------------ | 70| 801 | The specified SystemCapability name was not found. | 71| 29300002 | The system ability work abnormally. | 72| 29300003 | The application is not enabled the data protection under lock screen. | 73| 29300004 | File access is denied. | 74 75**Example** 76 77```ts 78// Request the permission to access sensitive data on the lock screen. 79import { screenLockFileManager } from '@kit.AbilityKit'; 80import { BusinessError } from '@kit.BasicServicesKit'; 81import { hilog } from '@kit.PerformanceAnalysisKit'; 82 83try { 84 let acquireStatus = screenLockFileManager.acquireAccess(); 85 if (acquireStatus === screenLockFileManager.AccessStatus.ACCESS_GRANTED) { 86 hilog.info(0x0000, 'testTag', 'acquireAccess successfully.'); 87 } 88} catch (err) { 89 let message = (err as BusinessError).message; 90 hilog.error(0x0000, 'testTag', 'acquireAccess failed: %{public}s', message); 91} 92``` 93 94## screenLockFileManager.releaseAccess 95 96releaseAccess(): ReleaseStatus 97 98Releases the permission to access sensitive data on the lock screen. This API returns the result synchronously. 99 100**System capability**: SystemCapability.Security.ScreenLockFileManager 101 102**Return value** 103 104| Type | Description | 105| ------------------------------- | ------------------------------ | 106| [ReleaseStatus](#releasestatus) | State for releasing access permissions to sensitive data on the lock screen.| 107 108**Error codes** 109 110For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [ohos.screenLockFileManager](errorcode-screenLockFileManager.md). 111 112| ID| Error Message | 113| -------- | ------------------------------------------------------------ | 114| 801 | The specified SystemCapability name was not found. | 115| 29300002 | The system ability work abnormally. | 116| 29300003 | The application is not enabled the data protection under lock screen. | 117| 29300005 | File access was not acquired. | 118 119**Example** 120 121```ts 122// Release the permission to access sensitive data on the lock screen. 123import { screenLockFileManager } from '@kit.AbilityKit'; 124import { BusinessError } from '@kit.BasicServicesKit'; 125import { hilog } from '@kit.PerformanceAnalysisKit'; 126 127try { 128 let releaseStatus = screenLockFileManager.releaseAccess(); 129 if (releaseStatus === screenLockFileManager.ReleaseStatus.RELEASE_GRANTED) { 130 hilog.info(0x0000, 'testTag', 'releaseAccess successfully.'); 131 } 132} catch (err) { 133 let message = (err as BusinessError).message; 134 hilog.error(0x0000, 'testTag', 'releaseAccess failed: %{public}s', message); 135} 136``` 137 138## screenLockFileManager.queryAppKeyState<sup>18+</sup> 139 140queryAppKeyState(): KeyStatus 141 142Obtains the state of access permissions for sensitive data on the lock screen. This API returns the result synchronously. 143 144**System capability**: SystemCapability.Security.ScreenLockFileManager 145 146**Return value** 147 148| Type | Description | 149| ------------------------------- | ------------------------------ | 150| [KeyStatus](#keystatus18) | State of access permissions for sensitive data on the lock screen.| 151 152**Error codes** 153 154For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [ohos.screenLockFileManager](errorcode-screenLockFileManager.md). 155 156| ID| Error Message | 157| -------- | ------------------------------------------------------------ | 158| 801 | The specified SystemCapability name was not found. | 159| 29300002 | The system ability work abnormally. | 160 161**Example** 162 163```ts 164// Obtain the state of access permissions for sensitive data on the lock screen. 165import { screenLockFileManager } from '@kit.AbilityKit'; 166import { BusinessError } from '@kit.BasicServicesKit'; 167import { hilog } from '@kit.PerformanceAnalysisKit'; 168 169try { 170 let keyStatus = screenLockFileManager.queryAppKeyState(); 171 if (keyStatus === screenLockFileManager.KeyStatus.KEY_NOT_EXIST) { 172 hilog.info(0x0000, 'testTag', 'Key does not exist.'); 173 } else if (keyStatus === screenLockFileManager.KeyStatus.KEY_RELEASED) { 174 hilog.info(0x0000, 'testTag', 'Key has been released.'); 175 } else if (keyStatus === screenLockFileManager.KeyStatus.KEY_EXIST) { 176 hilog.info(0x0000, 'testTag', 'Key exists.'); 177 } 178} catch (err) { 179 let message = (err as BusinessError).message; 180 hilog.error(0x0000, 'testTag', 'queryAppKeyState failed: %{public}s', message); 181} 182``` 183