1e41f4b71Sopenharmony_ci# @ohos.ability.screenLockFileManager (Sensitive Data Access Management Under Lock Screen) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciOnce 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 revoke the permission to access sensitive data on the lock screen, thereby managing sensitive data access securely.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci> - 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.
7e41f4b71Sopenharmony_ci>
8e41f4b71Sopenharmony_ci> - This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.ability.screenLockFileManager](js-apis-screenLockFileManager.md).
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Modules to Import
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport { screenLockFileManager } from '@kit.AbilityKit';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## DataType
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciEnumerates the types of sensitive data that can be accessed on the lock screen.
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci **System capability**: SystemCapability.Security.ScreenLockFileManager
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci **System API**: This is a system API.
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci| Name      | Value        | Description          |
25e41f4b71Sopenharmony_ci| ---------- | ---------- | -------------- |
26e41f4b71Sopenharmony_ci| MEDIA_DATA | 0x00000001 | Media data.|
27e41f4b71Sopenharmony_ci| ALL_DATA   | 0xffffffff | All encrypted data.    |
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci## screenLockFileManager.acquireAccess
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciacquireAccess(dataType: DataType): AccessStatus
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ciRequests the permission to access a specified type of sensitive data on the lock screen. This API returns the result synchronously. Generally, sensitive data cannot be accessed once the screen is locked. However, you can call this API to access sensitive data of the specified type on the lock screen.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**System API**: This is a system API.
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_MEDIA_DATA or ohos.permission.ACCESS_SCREEN_LOCK_ALL_DATA
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.ScreenLockFileManager
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci**Parameters**
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci| Name | Type  | Mandatory| Description                      |
44e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | ---------------------------- |
45e41f4b71Sopenharmony_ci| dataType | [DataType](#datatype) | Yes  | Type of sensitive data that is accessible on the lock screen.|
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci**Return value**
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci| Type                                                       | Description                                 |
50e41f4b71Sopenharmony_ci| ----------------------------------------------------------- | ------------------------------------- |
51e41f4b71Sopenharmony_ci| [AccessStatus](js-apis-screenLockFileManager.md#accessstatus) | Sensitive data access status.|
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**Error codes**
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [ohos.screenLockFileManager](errorcode-screenLockFileManager.md).
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
58e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
59e41f4b71Sopenharmony_ci| 201      | Permission verification failed, usually returned by VerifyAccessToken. |
60e41f4b71Sopenharmony_ci| 202      | Permission verification failed, application which is not a system application uses system API. |
61e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
62e41f4b71Sopenharmony_ci| 801 | The specified SystemCapability name was not found. |
63e41f4b71Sopenharmony_ci| 29300001 | Invalid parameter. |
64e41f4b71Sopenharmony_ci| 29300002 | The system ability work abnormally. |
65e41f4b71Sopenharmony_ci| 29300003 | The application is not enabled the data protection under lock screen. |
66e41f4b71Sopenharmony_ci| 29300004 | File access is denied. |
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci**Example**
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci```ts
71e41f4b71Sopenharmony_ci// Request the permission to access media data on the lock screen.
72e41f4b71Sopenharmony_ciimport { screenLockFileManager } from '@kit.AbilityKit';
73e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
74e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_citry {
77e41f4b71Sopenharmony_ci    let acquireStatus = screenLockFileManager.acquireAccess(screenLockFileManager.DataType.MEDIA_DATA);
78e41f4b71Sopenharmony_ci    if (acquireStatus === screenLockFileManager.AccessStatus.ACCESS_GRANTED) {
79e41f4b71Sopenharmony_ci        hilog.info(0x0000, 'testTag', 'acquireAccess successfully.');
80e41f4b71Sopenharmony_ci    }
81e41f4b71Sopenharmony_ci} catch (err) {
82e41f4b71Sopenharmony_ci    let message = (err as BusinessError).message;
83e41f4b71Sopenharmony_ci    hilog.error(0x0000, 'testTag', 'acquireAccess failed: %{public}s', message);
84e41f4b71Sopenharmony_ci}
85e41f4b71Sopenharmony_ci```
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci## screenLockFileManager.releaseAccess
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_cireleaseAccess(dataType: DataType): ReleaseStatus
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ciRevokes the permission to access a specified type of sensitive data on the lock screen. This API returns the result synchronously.
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**System API**: This is a system API.
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_MEDIA_DATA or ohos.permission.ACCESS_SCREEN_LOCK_ALL_DATA
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.ScreenLockFileManager
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci**Parameters**
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci| Name | Type  | Mandatory| Description                      |
102e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | ---------------------------- |
103e41f4b71Sopenharmony_ci| dataType | [DataType](#datatype) | Yes  | Type of sensitive data that is accessible on the lock screen.|
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci**Return value**
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci| Type                                                        | Description                          |
108e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------ |
109e41f4b71Sopenharmony_ci| [ReleaseStatus](js-apis-screenLockFileManager.md#releasestatus) | Type of the operation used to revoke the permission to access sensitive data on the lock screen.|
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci**Error codes**
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [ohos.screenLockFileManager](errorcode-screenLockFileManager.md).
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
116e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
117e41f4b71Sopenharmony_ci| 201      | Permission verification failed, usually returned by VerifyAccessToken. |
118e41f4b71Sopenharmony_ci| 202      | Permission verification failed, application which is not a system application uses system API. |
119e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
120e41f4b71Sopenharmony_ci| 801      | The specified SystemCapability name was not found.           |
121e41f4b71Sopenharmony_ci| 29300001 | Invalid parameter.                                           |
122e41f4b71Sopenharmony_ci| 29300002 | The system ability work abnormally.                          |
123e41f4b71Sopenharmony_ci| 29300003 | The application is not enabled the data protection under lock screen. |
124e41f4b71Sopenharmony_ci| 29300005 | File access was not acquired.                                |
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci**Example**
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci```ts
129e41f4b71Sopenharmony_ci// Revoke the permission to access media data on the lock screen.
130e41f4b71Sopenharmony_ciimport { screenLockFileManager } from '@kit.AbilityKit';
131e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
132e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_citry {
135e41f4b71Sopenharmony_ci    let releaseStatus = screenLockFileManager.releaseAccess(screenLockFileManager.DataType.MEDIA_DATA);
136e41f4b71Sopenharmony_ci    if (releaseStatus === screenLockFileManager.ReleaseStatus.RELEASE_GRANTED) {
137e41f4b71Sopenharmony_ci        hilog.info(0x0000, 'testTag', 'releaseAccess successfully.');
138e41f4b71Sopenharmony_ci    }
139e41f4b71Sopenharmony_ci} catch (err) {
140e41f4b71Sopenharmony_ci    let message = (err as BusinessError).message;
141e41f4b71Sopenharmony_ci    hilog.error(0x0000, 'testTag', 'releaseAccess failed: %{public}s', message);
142e41f4b71Sopenharmony_ci}
143e41f4b71Sopenharmony_ci```
144