1# @ohos.ability.screenLockFileManager (锁屏敏感数据管理)
2
3敏感数据密钥在锁屏后会触发销毁,销毁后敏感数据无法读写,需解锁屏幕触发恢复敏感数据密钥后方可访问。本模块提供应用锁屏下敏感数据保护的能力,支持申请和释放锁屏下敏感数据访问权限等。
4
5> **说明:**
6> 本模块首批接口从API version 12 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
7
8## 导入模块
9
10```ts
11import { screenLockFileManager } from '@kit.AbilityKit';
12```
13
14## AccessStatus
15
16枚举,锁屏下敏感数据访问权限申请的状态。
17
18 **系统能力:** SystemCapability.Security.ScreenLockFileManager
19
20| 名称           | 值   | 说明                     |
21| -------------- | ---- | ------------------------ |
22| ACCESS_DENIED  | -1   | 拒绝授予锁屏下敏感数据访问。 |
23| ACCESS_GRANTED | 0    | 授予锁屏下敏感数据访问。     |
24
25
26## ReleaseStatus
27
28枚举,锁屏下敏感数据访问权限释放的状态。
29
30 **系统能力:** SystemCapability.Security.ScreenLockFileManager
31
32| 名称 | 值 | 说明 |
33|-----------------|----|----|
34| RELEASE_DENIED |  -1 | 拒绝锁屏下敏感数据访问释放。 |
35| RELEASE_GRANTED |  0  |  释放锁屏下敏感数据访问。  |
36
37## screenLockFileManager.acquireAccess
38
39acquireAccess(): AccessStatus
40
41以同步方法申请锁屏下应用敏感数据访问权限。锁屏后,敏感数据无法被访问,但可通过调用该方法,访问指定类型的敏感数据。
42
43**系统能力:** SystemCapability.Security.ScreenLockFileManager
44
45**返回值:**
46
47| 类型                                                        | 说明                                  |
48| ----------------------------------------------------------- | ------------------------------------- |
49| [AccessStatus](#accessstatus) | 锁屏下敏感数据访问权限申请的状态。 |
50
51**错误码:**
52
53以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.screenLockFileManager错误码](errorcode-screenLockFileManager.md)。
54
55| 错误码ID | 错误信息                                                     |
56| -------- | ------------------------------------------------------------ |
57| 801 | The specified SystemCapability name was not found. |
58| 29300002 | The system ability work abnormally. |
59| 29300003 | The application is not enabled the data protection under lock screen. |
60| 29300004 | File access is denied. |
61
62**示例:**
63
64```ts
65// 申请锁屏下应用敏感数据访问权限
66import { screenLockFileManager } from '@kit.AbilityKit';
67import { BusinessError } from '@kit.BasicServicesKit';
68import { hilog } from '@kit.PerformanceAnalysisKit';
69
70try {
71    let acquireStatus = screenLockFileManager.acquireAccess();
72    if (acquireStatus === screenLockFileManager.AccessStatus.ACCESS_GRANTED) {
73        hilog.info(0x0000, 'testTag', 'acquireAccess successfully.');
74    }
75} catch (err) {
76    let message = (err as BusinessError).message;
77    hilog.error(0x0000, 'testTag', 'acquireAccess failed: %{public}s', message);
78}
79```
80
81## screenLockFileManager.releaseAccess
82
83releaseAccess(): ReleaseStatus
84
85以同步方法取消锁屏下应用敏感数据访问权限。
86
87**系统能力:** SystemCapability.Security.ScreenLockFileManager
88
89**返回值:**
90
91| 类型                            | 说明                           |
92| ------------------------------- | ------------------------------ |
93| [ReleaseStatus](#releasestatus) | 锁屏下敏感数据访问权限释放的状态。 |
94
95**错误码:**
96
97以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.screenLockFileManager错误码](errorcode-screenLockFileManager.md)。
98
99| 错误码ID | 错误信息                                                     |
100| -------- | ------------------------------------------------------------ |
101| 801      | The specified SystemCapability name was not found.           |
102| 29300002 | The system ability work abnormally.                          |
103| 29300003 | The application is not enabled the data protection under lock screen. |
104| 29300005 | File access was not acquired. |
105
106**示例:**
107
108```ts
109// 释放锁屏下应用敏感数据访问权限
110import { screenLockFileManager } from '@kit.AbilityKit';
111import { BusinessError } from '@kit.BasicServicesKit';
112import { hilog } from '@kit.PerformanceAnalysisKit';
113
114try {
115    let releaseStatus = screenLockFileManager.releaseAccess();
116    if (releaseStatus === screenLockFileManager.ReleaseStatus.RELEASE_GRANTED) {
117        hilog.info(0x0000, 'testTag', 'releaseAccess successfully.');
118    }
119} catch (err) {
120    let message = (err as BusinessError).message;
121    hilog.error(0x0000, 'testTag', 'releaseAccess failed: %{public}s', message);
122}
123```