1e41f4b71Sopenharmony_ci# @ohos.dlpPermission (数据防泄漏)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci数据防泄漏(DLP)是系统提供的系统级的数据防泄漏解决方案,提供跨设备的文件的权限管理、加密存储、授权访问等能力。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci> - @ohos.dlpPermission归属的Kit已由'DataLossPreventionKit'变更为'DataProtectionKit',建议开发者使用新模块名'@kit.DataProtectionKit'完成模块导入。如果使用'@kit.DataLossPreventionKit'导入,仅能调用改名前的接口,无法使用新增接口。
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## 导入模块
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## dlpPermission.isDLPFile
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciisDLPFile(fd: number): Promise<boolean>
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci根据文件的fd,查询该文件是否是DLP文件。使用Promise方式异步返回结果。
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**参数:**
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
27e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
28e41f4b71Sopenharmony_ci| fd | number | 是 | 文件的fd(file descriptor, 文件描述符)。 |
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci**返回值:**
31e41f4b71Sopenharmony_ci| 类型 | 说明 |
32e41f4b71Sopenharmony_ci| -------- | -------- |
33e41f4b71Sopenharmony_ci| Promise<boolean> | Promise对象。返回true表示是DLP文件,返回false表示非DLP文件。 |
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**错误码:**
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
40e41f4b71Sopenharmony_ci| -------- | -------- |
41e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
42e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
43e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**示例:**
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci```ts
48e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
49e41f4b71Sopenharmony_ciimport { fileIo } from '@kit.CoreFileKit';
50e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
53e41f4b71Sopenharmony_cilet file = fileIo.openSync(uri);
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_citry {
56e41f4b71Sopenharmony_ci  let res = dlpPermission.isDLPFile(file.fd); // 是否加密DLP文件
57e41f4b71Sopenharmony_ci  console.info('res', res);
58e41f4b71Sopenharmony_ci} catch (err) {
59e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
60e41f4b71Sopenharmony_ci}
61e41f4b71Sopenharmony_cifileIo.closeSync(file);
62e41f4b71Sopenharmony_ci```
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci## dlpPermission.isDLPFile
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ciisDLPFile(fd: number, callback: AsyncCallback<boolean>): void
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci根据文件的fd,查询该文件是否是DLP文件。使用callback方式异步返回结果。
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**参数:**
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
75e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
76e41f4b71Sopenharmony_ci| fd | number | 是 | 文件的fd。 |
77e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示是DLP文件,返回false表示非DLP文件。 |
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**错误码:**
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
84e41f4b71Sopenharmony_ci| -------- | -------- |
85e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
86e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
87e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci**示例:**
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci```ts
92e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
93e41f4b71Sopenharmony_ciimport { fileIo } from '@kit.CoreFileKit';
94e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
97e41f4b71Sopenharmony_cilet file = fileIo.openSync(uri);
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_citry {
100e41f4b71Sopenharmony_ci  dlpPermission.isDLPFile(file.fd, (err, res) => {
101e41f4b71Sopenharmony_ci    if (err != undefined) {
102e41f4b71Sopenharmony_ci      console.error('isDLPFile error,', err.code, err.message);
103e41f4b71Sopenharmony_ci    } else {
104e41f4b71Sopenharmony_ci      console.info('res', res);
105e41f4b71Sopenharmony_ci    }
106e41f4b71Sopenharmony_ci    fileIo.closeSync(file);
107e41f4b71Sopenharmony_ci  });
108e41f4b71Sopenharmony_ci} catch (err) {
109e41f4b71Sopenharmony_ci  console.error('isDLPFile error,', (err as BusinessError).code, (err as BusinessError).message);
110e41f4b71Sopenharmony_ci  fileIo.closeSync(file);
111e41f4b71Sopenharmony_ci}
112e41f4b71Sopenharmony_ci```
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci## dlpPermission.getDLPPermissionInfo
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_cigetDLPPermissionInfo(): Promise<DLPPermissionInfo>
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci查询当前DLP沙箱的权限信息。使用Promise方式异步返回结果。
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**返回值:**
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci| 类型 | 说明 |
125e41f4b71Sopenharmony_ci| -------- | -------- |
126e41f4b71Sopenharmony_ci| Promise<[DLPPermissionInfo](#dlppermissioninfo)> | Promise对象。返回查询的DLP文件的权限信息,无异常则表明查询成功。 |
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**错误码:**
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
133e41f4b71Sopenharmony_ci| -------- | -------- |
134e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
135e41f4b71Sopenharmony_ci| 19100006 | No permission to call this API, which is available only for DLP sandbox applications. |
136e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**示例:**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci```ts
141e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
142e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_citry {
145e41f4b71Sopenharmony_ci  dlpPermission.isInSandbox().then((inSandbox) => { // 是否在沙箱内
146e41f4b71Sopenharmony_ci    if (inSandbox) {
147e41f4b71Sopenharmony_ci      let res: Promise<dlpPermission.DLPPermissionInfo> = dlpPermission.getDLPPermissionInfo(); // 获取当前权限信息
148e41f4b71Sopenharmony_ci      console.info('res', JSON.stringify(res));
149e41f4b71Sopenharmony_ci    }
150e41f4b71Sopenharmony_ci  });
151e41f4b71Sopenharmony_ci} catch (err) {
152e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
153e41f4b71Sopenharmony_ci}
154e41f4b71Sopenharmony_ci```
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci## dlpPermission.getDLPPermissionInfo
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_cigetDLPPermissionInfo(callback: AsyncCallback&lt;DLPPermissionInfo&gt;): void
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci查询当前DLP沙箱的权限信息。使用callback方式异步返回结果。
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci**参数:**
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
167e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
168e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;[DLPPermissionInfo](#dlppermissioninfo)&gt; | 是 | 回调函数。err为undefine时表示查询成功;否则为错误对象。 |
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**错误码:**
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
175e41f4b71Sopenharmony_ci| -------- | -------- |
176e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
177e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
178e41f4b71Sopenharmony_ci| 19100006 | No permission to call this API, which is available only for DLP sandbox applications. |
179e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci**示例:**
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci```ts
184e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
185e41f4b71Sopenharmony_ciimport { fileIo } from '@kit.CoreFileKit';
186e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_citry {
189e41f4b71Sopenharmony_ci  dlpPermission.isInSandbox().then((inSandbox) => { // 是否在沙箱内
190e41f4b71Sopenharmony_ci    if (inSandbox) {
191e41f4b71Sopenharmony_ci      dlpPermission.getDLPPermissionInfo((err, res) => {
192e41f4b71Sopenharmony_ci        if (err != undefined) {
193e41f4b71Sopenharmony_ci          console.error('getDLPPermissionInfo error,', err.code, err.message);
194e41f4b71Sopenharmony_ci        } else {
195e41f4b71Sopenharmony_ci          console.info('res', JSON.stringify(res));
196e41f4b71Sopenharmony_ci        }
197e41f4b71Sopenharmony_ci      }); // 获取当前权限信息
198e41f4b71Sopenharmony_ci    }
199e41f4b71Sopenharmony_ci  });
200e41f4b71Sopenharmony_ci} catch (err) {
201e41f4b71Sopenharmony_ci  console.error('getDLPPermissionInfo error,', (err as BusinessError).code, (err as BusinessError).message);
202e41f4b71Sopenharmony_ci}
203e41f4b71Sopenharmony_ci```
204e41f4b71Sopenharmony_ci
205e41f4b71Sopenharmony_ci## dlpPermission.getOriginalFileName
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_cigetOriginalFileName(fileName: string): string
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci获取指定DLP文件名的原始文件名。接口为同步接口。
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci**参数:**
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
216e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
217e41f4b71Sopenharmony_ci| fileName | string | 是 | 指定要查询的文件名。 |
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci**返回值:**
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci| 类型 | 说明 |
222e41f4b71Sopenharmony_ci| -------- | -------- |
223e41f4b71Sopenharmony_ci| string | 返回DLP文件的原始文件名。例如:DLP文件名为test.txt.dlp,则返回的原始文件名为test.txt。 |
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci**错误码:**
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
230e41f4b71Sopenharmony_ci| -------- | -------- |
231e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
232e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci**示例:**
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci```ts
237e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
238e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_citry {
241e41f4b71Sopenharmony_ci  let res = dlpPermission.getOriginalFileName('test.txt.dlp'); // 获取原始文件名
242e41f4b71Sopenharmony_ci  console.info('res', res);
243e41f4b71Sopenharmony_ci} catch (err) {
244e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
245e41f4b71Sopenharmony_ci}
246e41f4b71Sopenharmony_ci```
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci## dlpPermission.getDLPSuffix
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_cigetDLPSuffix(): string
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci获取DLP文件扩展名。接口为同步接口。
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci**返回值:**
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci| 类型 | 说明 |
259e41f4b71Sopenharmony_ci| -------- | -------- |
260e41f4b71Sopenharmony_ci| string | 返回DLP文件扩展名。例如:原文件"text.txt",返回拓展名为".dlp",加密后的DLP文件名为"test.txt.dlp"。 |
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci**错误码:**
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
265e41f4b71Sopenharmony_ci
266e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
267e41f4b71Sopenharmony_ci| -------- | -------- |
268e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ci**示例:**
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci```ts
273e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
274e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
275e41f4b71Sopenharmony_ci
276e41f4b71Sopenharmony_citry {
277e41f4b71Sopenharmony_ci  let res = dlpPermission.getDLPSuffix(); // 获取DLP拓展名
278e41f4b71Sopenharmony_ci  console.info('res', res);
279e41f4b71Sopenharmony_ci} catch (err) {
280e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
281e41f4b71Sopenharmony_ci}
282e41f4b71Sopenharmony_ci```
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ci## dlpPermission.on('openDLPFile')
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_cion(type: 'openDLPFile', listener: Callback&lt;AccessedDLPFileInfo&gt;): void
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci监听打开DLP文件。在当前应用的沙箱应用打开DLP文件时,通知当前应用。
289e41f4b71Sopenharmony_ci
290e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
291e41f4b71Sopenharmony_ci
292e41f4b71Sopenharmony_ci**参数:**
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
295e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
296e41f4b71Sopenharmony_ci| type | 'openDLPFile' | 是 | 监听事件类型。固定值为'openDLPFile':打开DLP文件事件。 |
297e41f4b71Sopenharmony_ci| listener | Callback&lt;[AccessedDLPFileInfo](#accesseddlpfileinfo)&gt; | 是 | DLP文件打开事件的回调。在当前应用的沙箱应用打开DLP文件时,通知当前应用。 |
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci**错误码:**
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
304e41f4b71Sopenharmony_ci| -------- | -------- |
305e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
306e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
307e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. |
308e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci**示例:**
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci```ts
313e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
314e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_citry {
317e41f4b71Sopenharmony_ci  dlpPermission.on('openDLPFile', (info: dlpPermission.AccessedDLPFileInfo) => {
318e41f4b71Sopenharmony_ci    console.info('openDlpFile event', info.uri, info.lastOpenTime)
319e41f4b71Sopenharmony_ci  }); // 订阅
320e41f4b71Sopenharmony_ci} catch (err) {
321e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
322e41f4b71Sopenharmony_ci}
323e41f4b71Sopenharmony_ci```
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ci## dlpPermission.off('openDLPFile')
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_cioff(type: 'openDLPFile', listener?: Callback&lt;AccessedDLPFileInfo&gt;): void
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci取消监听打开DLP文件。在当前应用的沙箱应用打开DLP文件时,取消通知当前应用。
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci**参数:**
334e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
335e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
336e41f4b71Sopenharmony_ci| type | 'openDLPFile' | 是 | 监听事件类型。固定值为'openDLPFile':打开DLP文件事件。 |
337e41f4b71Sopenharmony_ci| listener | Callback&lt;[AccessedDLPFileInfo](#accesseddlpfileinfo)&gt; | 否 | DLP文件被打开的事件的回调。在当前应用的沙箱应用打开DLP文件时,取消通知当前应用。默认为空,表示取消该类型事件的所有回调。 |
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci**错误码:**
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
344e41f4b71Sopenharmony_ci| -------- | -------- |
345e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
346e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
347e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. |
348e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
349e41f4b71Sopenharmony_ci
350e41f4b71Sopenharmony_ci**示例:**
351e41f4b71Sopenharmony_ci
352e41f4b71Sopenharmony_ci```ts
353e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
354e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_citry {
357e41f4b71Sopenharmony_ci  dlpPermission.off('openDLPFile', (info: dlpPermission.AccessedDLPFileInfo) => {
358e41f4b71Sopenharmony_ci    console.info('openDlpFile event', info.uri, info.lastOpenTime)
359e41f4b71Sopenharmony_ci  }); // 取消订阅
360e41f4b71Sopenharmony_ci} catch (err) {
361e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
362e41f4b71Sopenharmony_ci}
363e41f4b71Sopenharmony_ci```
364e41f4b71Sopenharmony_ci
365e41f4b71Sopenharmony_ci## dlpPermission.isInSandbox
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ciisInSandbox(): Promise&lt;boolean&gt;
368e41f4b71Sopenharmony_ci
369e41f4b71Sopenharmony_ci查询当前应用是否运行在DLP沙箱环境。使用Promise方式异步返回结果。
370e41f4b71Sopenharmony_ci
371e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_ci**返回值:**
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci| 类型 | 说明 |
376e41f4b71Sopenharmony_ci| -------- | -------- |
377e41f4b71Sopenharmony_ci| Promise&lt;boolean&gt; | Promise对象。返回当前应用是否运行在沙箱中。 |
378e41f4b71Sopenharmony_ci
379e41f4b71Sopenharmony_ci**错误码:**
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
384e41f4b71Sopenharmony_ci| -------- | -------- |
385e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
386e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
387e41f4b71Sopenharmony_ci
388e41f4b71Sopenharmony_ci**示例:**
389e41f4b71Sopenharmony_ci
390e41f4b71Sopenharmony_ci```ts
391e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
392e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_citry {
395e41f4b71Sopenharmony_ci  let inSandbox = dlpPermission.isInSandbox(); // 是否在沙箱内
396e41f4b71Sopenharmony_ci  console.info('res', inSandbox);
397e41f4b71Sopenharmony_ci} catch (err) {
398e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
399e41f4b71Sopenharmony_ci}
400e41f4b71Sopenharmony_ci```
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci## dlpPermission.isInSandbox
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ciisInSandbox(callback: AsyncCallback&lt;boolean&gt;): void
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci查询当前应用是否运行在DLP沙箱环境。使用callback方式异步返回结果。
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci**参数:**
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
413e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
414e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。err为undefine时表示查询成功;否则为错误对象。 |
415e41f4b71Sopenharmony_ci
416e41f4b71Sopenharmony_ci**错误码:**
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
419e41f4b71Sopenharmony_ci
420e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
421e41f4b71Sopenharmony_ci| -------- | -------- |
422e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
423e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
424e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
425e41f4b71Sopenharmony_ci
426e41f4b71Sopenharmony_ci**示例:**
427e41f4b71Sopenharmony_ci
428e41f4b71Sopenharmony_ci```ts
429e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
430e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_citry {
433e41f4b71Sopenharmony_ci  dlpPermission.isInSandbox((err, data) => {
434e41f4b71Sopenharmony_ci    if (err) {
435e41f4b71Sopenharmony_ci      console.error('isInSandbox error,', err.code, err.message);
436e41f4b71Sopenharmony_ci    } else {
437e41f4b71Sopenharmony_ci      console.info('isInSandbox, data', JSON.stringify(data));
438e41f4b71Sopenharmony_ci    }
439e41f4b71Sopenharmony_ci  }); // 是否在沙箱内
440e41f4b71Sopenharmony_ci} catch (err) {
441e41f4b71Sopenharmony_ci  console.error('isInSandbox error,', (err as BusinessError).code, (err as BusinessError).message);
442e41f4b71Sopenharmony_ci}
443e41f4b71Sopenharmony_ci```
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_ci## dlpPermission.getDLPSupportedFileTypes
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_cigetDLPSupportedFileTypes(): Promise&lt;Array&lt;string&gt;&gt;
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_ci查询当前可支持权限设置和校验的文件扩展名类型列表。使用Promise方式异步返回结果。
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci**返回值:**
454e41f4b71Sopenharmony_ci
455e41f4b71Sopenharmony_ci| 类型 | 说明 |
456e41f4b71Sopenharmony_ci| -------- | -------- |
457e41f4b71Sopenharmony_ci| Promise&lt;Array&lt;string&gt;&gt; | Promise对象。返回当前可支持权限设置和校验的文件扩展名类型列表。 |
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci**错误码:**
460e41f4b71Sopenharmony_ci
461e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
464e41f4b71Sopenharmony_ci| -------- | -------- |
465e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
466e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_ci**示例:**
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci```ts
471e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
472e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_citry {
475e41f4b71Sopenharmony_ci  let res = dlpPermission.getDLPSupportedFileTypes(); // 获取支持DLP的文件类型
476e41f4b71Sopenharmony_ci  console.info('res', JSON.stringify(res));
477e41f4b71Sopenharmony_ci} catch (err) {
478e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
479e41f4b71Sopenharmony_ci}
480e41f4b71Sopenharmony_ci```
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci## dlpPermission.getDLPSupportedFileTypes
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_cigetDLPSupportedFileTypes(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
485e41f4b71Sopenharmony_ci
486e41f4b71Sopenharmony_ci查询当前可支持权限设置和校验的文件扩展名类型列表。使用callback方式异步返回结果。
487e41f4b71Sopenharmony_ci
488e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
489e41f4b71Sopenharmony_ci
490e41f4b71Sopenharmony_ci**参数:**
491e41f4b71Sopenharmony_ci
492e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
493e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
494e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是 | 回调函数。err为undefine时表示查询成功;否则为错误对象。 |
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci**错误码:**
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
499e41f4b71Sopenharmony_ci
500e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
501e41f4b71Sopenharmony_ci| -------- | -------- |
502e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
503e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
504e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
505e41f4b71Sopenharmony_ci
506e41f4b71Sopenharmony_ci**示例:**
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_ci```ts
509e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
510e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
511e41f4b71Sopenharmony_ci
512e41f4b71Sopenharmony_citry {
513e41f4b71Sopenharmony_ci  dlpPermission.getDLPSupportedFileTypes((err, res) => {
514e41f4b71Sopenharmony_ci    if (err != undefined) {
515e41f4b71Sopenharmony_ci      console.error('getDLPSupportedFileTypes error,', err.code, err.message);
516e41f4b71Sopenharmony_ci    } else {
517e41f4b71Sopenharmony_ci      console.info('res', JSON.stringify(res));
518e41f4b71Sopenharmony_ci    }
519e41f4b71Sopenharmony_ci  }); // 获取支持DLP的文件类型
520e41f4b71Sopenharmony_ci} catch (err) {
521e41f4b71Sopenharmony_ci  console.error('getDLPSupportedFileTypes error,', (err as BusinessError).code, (err as BusinessError).message);
522e41f4b71Sopenharmony_ci}
523e41f4b71Sopenharmony_ci```
524e41f4b71Sopenharmony_ci
525e41f4b71Sopenharmony_ci## dlpPermission.setRetentionState
526e41f4b71Sopenharmony_ci
527e41f4b71Sopenharmony_cisetRetentionState(docUris: Array&lt;string&gt;): Promise&lt;void&gt;
528e41f4b71Sopenharmony_ci
529e41f4b71Sopenharmony_ci打开DLP文件时自动安装沙箱,关闭DLP文件时自动卸载沙箱。设置沙箱保留状态时DLP文件关闭时自动卸载暂时失效。使用Promise方式异步返回结果。
530e41f4b71Sopenharmony_ci
531e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
532e41f4b71Sopenharmony_ci
533e41f4b71Sopenharmony_ci**参数:**
534e41f4b71Sopenharmony_ci
535e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
536e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
537e41f4b71Sopenharmony_ci| docUris | Array&lt;string&gt; | 是 | 表示需要设置保留状态的文件uri列表。 |
538e41f4b71Sopenharmony_ci
539e41f4b71Sopenharmony_ci**返回值:**
540e41f4b71Sopenharmony_ci
541e41f4b71Sopenharmony_ci| 类型 | 说明 |
542e41f4b71Sopenharmony_ci| -------- | -------- |
543e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
544e41f4b71Sopenharmony_ci
545e41f4b71Sopenharmony_ci**错误码:**
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
548e41f4b71Sopenharmony_ci
549e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
550e41f4b71Sopenharmony_ci| -------- | -------- |
551e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
552e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
553e41f4b71Sopenharmony_ci| 19100006 | No permission to call this API, which is available only for DLP sandbox applications. |
554e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
555e41f4b71Sopenharmony_ci
556e41f4b71Sopenharmony_ci**示例:**
557e41f4b71Sopenharmony_ci
558e41f4b71Sopenharmony_ci```ts
559e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
560e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
561e41f4b71Sopenharmony_ci
562e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
563e41f4b71Sopenharmony_citry {
564e41f4b71Sopenharmony_ci  dlpPermission.isInSandbox().then((inSandbox) => { // 是否在沙箱内
565e41f4b71Sopenharmony_ci    if (inSandbox) {
566e41f4b71Sopenharmony_ci      dlpPermission.setRetentionState([uri]); // 设置沙箱保留
567e41f4b71Sopenharmony_ci    }
568e41f4b71Sopenharmony_ci  });
569e41f4b71Sopenharmony_ci} catch (err) {
570e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
571e41f4b71Sopenharmony_ci}
572e41f4b71Sopenharmony_ci```
573e41f4b71Sopenharmony_ci
574e41f4b71Sopenharmony_ci## dlpPermission.setRetentionState
575e41f4b71Sopenharmony_ci
576e41f4b71Sopenharmony_cisetRetentionState(docUris: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
577e41f4b71Sopenharmony_ci
578e41f4b71Sopenharmony_ci打开DLP文件时自动安装沙箱,关闭DLP文件时自动卸载沙箱。设置沙箱保留状态时DLP文件关闭时自动卸载暂时失效。使用callback方式异步返回结果。
579e41f4b71Sopenharmony_ci
580e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
581e41f4b71Sopenharmony_ci
582e41f4b71Sopenharmony_ci**参数:**
583e41f4b71Sopenharmony_ci
584e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
585e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
586e41f4b71Sopenharmony_ci| docUris | Array&lt;string&gt; | 是 | 表示需要设置保留状态的文件uri列表。 |
587e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。err为undefine时表示设置成功;否则为错误对象。 |
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ci**错误码:**
590e41f4b71Sopenharmony_ci
591e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
592e41f4b71Sopenharmony_ci
593e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
594e41f4b71Sopenharmony_ci| -------- | -------- |
595e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
596e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
597e41f4b71Sopenharmony_ci| 19100006 | No permission to call this API, which is available only for DLP sandbox applications. |
598e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
599e41f4b71Sopenharmony_ci
600e41f4b71Sopenharmony_ci**示例:**
601e41f4b71Sopenharmony_ci
602e41f4b71Sopenharmony_ci```ts
603e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
604e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
605e41f4b71Sopenharmony_ci
606e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
607e41f4b71Sopenharmony_citry {
608e41f4b71Sopenharmony_ci  dlpPermission.setRetentionState([uri], (err, res) => {
609e41f4b71Sopenharmony_ci    if (err != undefined) {
610e41f4b71Sopenharmony_ci      console.error('setRetentionState error,', err.code, err.message);
611e41f4b71Sopenharmony_ci    } else {
612e41f4b71Sopenharmony_ci      console.info('setRetentionState success');
613e41f4b71Sopenharmony_ci      console.info('res', JSON.stringify(res));
614e41f4b71Sopenharmony_ci    }
615e41f4b71Sopenharmony_ci  }); // 设置沙箱保留
616e41f4b71Sopenharmony_ci} catch (err) {
617e41f4b71Sopenharmony_ci  console.error('setRetentionState error,', (err as BusinessError).code, (err as BusinessError).message);
618e41f4b71Sopenharmony_ci}
619e41f4b71Sopenharmony_ci```
620e41f4b71Sopenharmony_ci
621e41f4b71Sopenharmony_ci## dlpPermission.cancelRetentionState
622e41f4b71Sopenharmony_ci
623e41f4b71Sopenharmony_cicancelRetentionState(docUris: Array&lt;string&gt;): Promise&lt;void&gt;
624e41f4b71Sopenharmony_ci
625e41f4b71Sopenharmony_ci取消沙箱保留状态即恢复DLP文件关闭时自动卸载沙箱策略。使用Promise方式异步返回结果。
626e41f4b71Sopenharmony_ci
627e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
628e41f4b71Sopenharmony_ci
629e41f4b71Sopenharmony_ci**参数:**
630e41f4b71Sopenharmony_ci
631e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
632e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
633e41f4b71Sopenharmony_ci| docUris | Array&lt;string&gt; | 是 | 表示需要设置保留状态的文件uri列表。 |
634e41f4b71Sopenharmony_ci
635e41f4b71Sopenharmony_ci**返回值:**
636e41f4b71Sopenharmony_ci
637e41f4b71Sopenharmony_ci| 类型 | 说明 |
638e41f4b71Sopenharmony_ci| -------- | -------- |
639e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
640e41f4b71Sopenharmony_ci
641e41f4b71Sopenharmony_ci**错误码:**
642e41f4b71Sopenharmony_ci
643e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
644e41f4b71Sopenharmony_ci
645e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
646e41f4b71Sopenharmony_ci| -------- | -------- |
647e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
648e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
649e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
650e41f4b71Sopenharmony_ci
651e41f4b71Sopenharmony_ci**示例:**
652e41f4b71Sopenharmony_ci
653e41f4b71Sopenharmony_ci```ts
654e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
655e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
658e41f4b71Sopenharmony_citry {
659e41f4b71Sopenharmony_ci  dlpPermission.cancelRetentionState([uri]); // 取消沙箱保留
660e41f4b71Sopenharmony_ci} catch (err) {
661e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
662e41f4b71Sopenharmony_ci}
663e41f4b71Sopenharmony_ci```
664e41f4b71Sopenharmony_ci
665e41f4b71Sopenharmony_ci## dlpPermission.cancelRetentionState
666e41f4b71Sopenharmony_ci
667e41f4b71Sopenharmony_cicancelRetentionState(docUris: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
668e41f4b71Sopenharmony_ci
669e41f4b71Sopenharmony_ci取消沙箱保留状态即恢复DLP文件关闭时自动卸载沙箱策略。使用callback方式异步返回结果。
670e41f4b71Sopenharmony_ci
671e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
672e41f4b71Sopenharmony_ci
673e41f4b71Sopenharmony_ci**参数:**
674e41f4b71Sopenharmony_ci
675e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
676e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
677e41f4b71Sopenharmony_ci| docUris | Array&lt;string&gt; | 是 | 表示需要设置保留状态的文件uri列表。 |
678e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。err为undefine时表示设置成功;否则为错误对象。 |
679e41f4b71Sopenharmony_ci
680e41f4b71Sopenharmony_ci**错误码:**
681e41f4b71Sopenharmony_ci
682e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
683e41f4b71Sopenharmony_ci
684e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
685e41f4b71Sopenharmony_ci| -------- | -------- |
686e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
687e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
688e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
689e41f4b71Sopenharmony_ci
690e41f4b71Sopenharmony_ci**示例:**
691e41f4b71Sopenharmony_ci
692e41f4b71Sopenharmony_ci```ts
693e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
694e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
695e41f4b71Sopenharmony_ci
696e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
697e41f4b71Sopenharmony_citry {
698e41f4b71Sopenharmony_ci  dlpPermission.cancelRetentionState([uri], (err, res) => {
699e41f4b71Sopenharmony_ci    if (err != undefined) {
700e41f4b71Sopenharmony_ci      console.error('cancelRetentionState error,', err.code, err.message);
701e41f4b71Sopenharmony_ci    } else {
702e41f4b71Sopenharmony_ci      console.info('cancelRetentionState success');
703e41f4b71Sopenharmony_ci    }
704e41f4b71Sopenharmony_ci  }); // 取消沙箱保留
705e41f4b71Sopenharmony_ci} catch (err) {
706e41f4b71Sopenharmony_ci  console.error('cancelRetentionState error,', (err as BusinessError).code, (err as BusinessError).message);
707e41f4b71Sopenharmony_ci}
708e41f4b71Sopenharmony_ci```
709e41f4b71Sopenharmony_ci
710e41f4b71Sopenharmony_ci## dlpPermission.getRetentionSandboxList
711e41f4b71Sopenharmony_ci
712e41f4b71Sopenharmony_cigetRetentionSandboxList(bundleName?: string): Promise&lt;Array&lt;RetentionSandboxInfo&gt;&gt;
713e41f4b71Sopenharmony_ci
714e41f4b71Sopenharmony_ci查询指定应用的保留沙箱信息列表。使用Promise方式异步返回结果。
715e41f4b71Sopenharmony_ci
716e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
717e41f4b71Sopenharmony_ci
718e41f4b71Sopenharmony_ci**参数:**
719e41f4b71Sopenharmony_ci
720e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
721e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
722e41f4b71Sopenharmony_ci| bundleName | string | 否 | 指定应用包名。默认为空,查询当前应用的保留沙箱信息列表。 |
723e41f4b71Sopenharmony_ci
724e41f4b71Sopenharmony_ci**返回值:**
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_ci| 类型 | 说明 |
727e41f4b71Sopenharmony_ci| -------- | -------- |
728e41f4b71Sopenharmony_ci| Promise&lt;Array&lt;[RetentionSandboxInfo](#retentionsandboxinfo)&gt;&gt; | Promise对象。返回查询的沙箱信息列表。 |
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ci**错误码:**
731e41f4b71Sopenharmony_ci
732e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
735e41f4b71Sopenharmony_ci| -------- | -------- |
736e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
737e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
738e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. |
739e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
740e41f4b71Sopenharmony_ci
741e41f4b71Sopenharmony_ci**示例:**
742e41f4b71Sopenharmony_ci
743e41f4b71Sopenharmony_ci```ts
744e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
745e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
746e41f4b71Sopenharmony_ci
747e41f4b71Sopenharmony_citry {
748e41f4b71Sopenharmony_ci  let res: Promise<Array<dlpPermission.RetentionSandboxInfo>> = dlpPermission.getRetentionSandboxList(); // 获取沙箱保留列表
749e41f4b71Sopenharmony_ci  console.info('res', JSON.stringify(res))
750e41f4b71Sopenharmony_ci} catch (err) {
751e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
752e41f4b71Sopenharmony_ci}
753e41f4b71Sopenharmony_ci```
754e41f4b71Sopenharmony_ci
755e41f4b71Sopenharmony_ci## dlpPermission.getRetentionSandboxList
756e41f4b71Sopenharmony_ci
757e41f4b71Sopenharmony_cigetRetentionSandboxList(bundleName: string, callback: AsyncCallback&lt;Array&lt;RetentionSandboxInfo&gt;&gt;): void
758e41f4b71Sopenharmony_ci
759e41f4b71Sopenharmony_ci查询指定应用的保留沙箱信息列表。使用callback方式异步返回结果。
760e41f4b71Sopenharmony_ci
761e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
762e41f4b71Sopenharmony_ci
763e41f4b71Sopenharmony_ci**参数:**
764e41f4b71Sopenharmony_ci
765e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
766e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
767e41f4b71Sopenharmony_ci| bundleName | string | 是 | 指定应用包名。 |
768e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;Array&lt;[RetentionSandboxInfo](#retentionsandboxinfo)&gt;&gt; | 是 | 回调函数。err为undefine时表示查询成功;否则为错误对象。 |
769e41f4b71Sopenharmony_ci
770e41f4b71Sopenharmony_ci**错误码:**
771e41f4b71Sopenharmony_ci
772e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
773e41f4b71Sopenharmony_ci
774e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
775e41f4b71Sopenharmony_ci| -------- | -------- |
776e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
777e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
778e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. |
779e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
780e41f4b71Sopenharmony_ci
781e41f4b71Sopenharmony_ci**示例:**
782e41f4b71Sopenharmony_ci
783e41f4b71Sopenharmony_ci```ts
784e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
785e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
786e41f4b71Sopenharmony_ci
787e41f4b71Sopenharmony_citry {
788e41f4b71Sopenharmony_ci  dlpPermission.getRetentionSandboxList("bundleName", (err, res) => {
789e41f4b71Sopenharmony_ci    if (err != undefined) {
790e41f4b71Sopenharmony_ci      console.error('getRetentionSandboxList error,', err.code, err.message);
791e41f4b71Sopenharmony_ci    } else {
792e41f4b71Sopenharmony_ci      console.info('res', JSON.stringify(res));
793e41f4b71Sopenharmony_ci    }
794e41f4b71Sopenharmony_ci  }); // 获取沙箱保留列表
795e41f4b71Sopenharmony_ci} catch (err) {
796e41f4b71Sopenharmony_ci  console.error('getRetentionSandboxList error,', (err as BusinessError).code, (err as BusinessError).message);
797e41f4b71Sopenharmony_ci}
798e41f4b71Sopenharmony_ci```
799e41f4b71Sopenharmony_ci
800e41f4b71Sopenharmony_ci## dlpPermission.getRetentionSandboxList
801e41f4b71Sopenharmony_ci
802e41f4b71Sopenharmony_cigetRetentionSandboxList(callback: AsyncCallback&lt;Array&lt;RetentionSandboxInfo&gt;&gt;): void
803e41f4b71Sopenharmony_ci
804e41f4b71Sopenharmony_ci查询指定应用的保留沙箱信息列表。使用callback方式异步返回结果。
805e41f4b71Sopenharmony_ci
806e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
807e41f4b71Sopenharmony_ci
808e41f4b71Sopenharmony_ci**参数:**
809e41f4b71Sopenharmony_ci
810e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
811e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
812e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;Array&lt;[RetentionSandboxInfo](#retentionsandboxinfo)&gt;&gt; | 是 | 回调函数。err为undefine时表示查询成功;否则为错误对象。 |
813e41f4b71Sopenharmony_ci
814e41f4b71Sopenharmony_ci**错误码:**
815e41f4b71Sopenharmony_ci
816e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
817e41f4b71Sopenharmony_ci
818e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
819e41f4b71Sopenharmony_ci| -------- | -------- |
820e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
821e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
822e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. |
823e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
824e41f4b71Sopenharmony_ci
825e41f4b71Sopenharmony_ci**示例:**
826e41f4b71Sopenharmony_ci
827e41f4b71Sopenharmony_ci```ts
828e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
829e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
830e41f4b71Sopenharmony_ci
831e41f4b71Sopenharmony_citry {
832e41f4b71Sopenharmony_ci  dlpPermission.getRetentionSandboxList((err, res) => {
833e41f4b71Sopenharmony_ci    if (err != undefined) {
834e41f4b71Sopenharmony_ci      console.error('getRetentionSandboxList error,', err.code, err.message);
835e41f4b71Sopenharmony_ci    } else {
836e41f4b71Sopenharmony_ci      console.info('res', JSON.stringify(res));
837e41f4b71Sopenharmony_ci    }
838e41f4b71Sopenharmony_ci  }); // 获取沙箱保留列表
839e41f4b71Sopenharmony_ci} catch (err) {
840e41f4b71Sopenharmony_ci  console.error('getRetentionSandboxList error,', (err as BusinessError).code, (err as BusinessError).message);
841e41f4b71Sopenharmony_ci}
842e41f4b71Sopenharmony_ci```
843e41f4b71Sopenharmony_ci
844e41f4b71Sopenharmony_ci## dlpPermission.getDLPFileAccessRecords
845e41f4b71Sopenharmony_ci
846e41f4b71Sopenharmony_cigetDLPFileAccessRecords(): Promise&lt;Array&lt;AccessedDLPFileInfo&gt;&gt;
847e41f4b71Sopenharmony_ci
848e41f4b71Sopenharmony_ci查询最近访问的DLP文件列表。使用Promise方式异步返回结果。
849e41f4b71Sopenharmony_ci
850e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
851e41f4b71Sopenharmony_ci
852e41f4b71Sopenharmony_ci**返回值:**
853e41f4b71Sopenharmony_ci
854e41f4b71Sopenharmony_ci| 类型 | 说明 |
855e41f4b71Sopenharmony_ci| -------- | -------- |
856e41f4b71Sopenharmony_ci| Promise&lt;Array&lt;[AccessedDLPFileInfo](#accesseddlpfileinfo)&gt;&gt; | Promise对象。返回最近访问的DLP文件列表。 |
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_ci**错误码:**
859e41f4b71Sopenharmony_ci
860e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
861e41f4b71Sopenharmony_ci
862e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
863e41f4b71Sopenharmony_ci| -------- | -------- |
864e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
865e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. |
866e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
867e41f4b71Sopenharmony_ci
868e41f4b71Sopenharmony_ci**示例:**
869e41f4b71Sopenharmony_ci
870e41f4b71Sopenharmony_ci```ts
871e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
872e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
873e41f4b71Sopenharmony_ci
874e41f4b71Sopenharmony_citry {
875e41f4b71Sopenharmony_ci  let res: Promise<Array<dlpPermission.AccessedDLPFileInfo>> = dlpPermission.getDLPFileAccessRecords(); // 获取DLP访问列表
876e41f4b71Sopenharmony_ci  console.info('res', JSON.stringify(res))
877e41f4b71Sopenharmony_ci} catch (err) {
878e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
879e41f4b71Sopenharmony_ci}
880e41f4b71Sopenharmony_ci```
881e41f4b71Sopenharmony_ci
882e41f4b71Sopenharmony_ci## dlpPermission.getDLPFileAccessRecords
883e41f4b71Sopenharmony_ci
884e41f4b71Sopenharmony_cigetDLPFileAccessRecords(callback: AsyncCallback&lt;Array&lt;AccessedDLPFileInfo&gt;&gt;): void
885e41f4b71Sopenharmony_ci
886e41f4b71Sopenharmony_ci查询最近访问的DLP文件列表。使用callback方式异步返回结果。
887e41f4b71Sopenharmony_ci
888e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
889e41f4b71Sopenharmony_ci
890e41f4b71Sopenharmony_ci**参数:**
891e41f4b71Sopenharmony_ci
892e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
893e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
894e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;Array&lt;[AccessedDLPFileInfo](#accesseddlpfileinfo)&gt;&gt; | 是 | 回调函数。err为undefine时表示查询成功;否则为错误对象。 |
895e41f4b71Sopenharmony_ci
896e41f4b71Sopenharmony_ci**错误码:**
897e41f4b71Sopenharmony_ci
898e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
899e41f4b71Sopenharmony_ci
900e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
901e41f4b71Sopenharmony_ci| -------- | -------- |
902e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
903e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
904e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. |
905e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
906e41f4b71Sopenharmony_ci
907e41f4b71Sopenharmony_ci**示例:**
908e41f4b71Sopenharmony_ci
909e41f4b71Sopenharmony_ci```ts
910e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
911e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
912e41f4b71Sopenharmony_ci
913e41f4b71Sopenharmony_citry {
914e41f4b71Sopenharmony_ci  dlpPermission.getDLPFileAccessRecords((err, res) => {
915e41f4b71Sopenharmony_ci    if (err != undefined) {
916e41f4b71Sopenharmony_ci      console.error('getDLPFileAccessRecords error,', err.code, err.message);
917e41f4b71Sopenharmony_ci    } else {
918e41f4b71Sopenharmony_ci      console.info('res', JSON.stringify(res));
919e41f4b71Sopenharmony_ci    }
920e41f4b71Sopenharmony_ci  }); // 获取DLP访问列表
921e41f4b71Sopenharmony_ci} catch (err) {
922e41f4b71Sopenharmony_ci  console.error('getDLPFileAccessRecords error,', (err as BusinessError).code, (err as BusinessError).message);
923e41f4b71Sopenharmony_ci}
924e41f4b71Sopenharmony_ci```
925e41f4b71Sopenharmony_ci
926e41f4b71Sopenharmony_ci## dlpPermission.startDLPManagerForResult<sup>11+</sup>
927e41f4b71Sopenharmony_ci
928e41f4b71Sopenharmony_cistartDLPManagerForResult(context: common.UIAbilityContext, want: Want): Promise&lt;DLPManagerResult&gt;
929e41f4b71Sopenharmony_ci
930e41f4b71Sopenharmony_ci在当前UIAbility界面以无边框形式打开DLP权限管理应用。使用Promise方式异步返回结果。
931e41f4b71Sopenharmony_ci
932e41f4b71Sopenharmony_ci**模型约束:** 此接口仅可在Stage模型下使用。
933e41f4b71Sopenharmony_ci
934e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
935e41f4b71Sopenharmony_ci
936e41f4b71Sopenharmony_ci**参数:**
937e41f4b71Sopenharmony_ci
938e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
939e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
940e41f4b71Sopenharmony_ci| context | [common.UIAbilityContext](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | 是 | 当前窗口UIAbility上下文。 |
941e41f4b71Sopenharmony_ci| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 请求对象。 |
942e41f4b71Sopenharmony_ci
943e41f4b71Sopenharmony_ci**返回值:**
944e41f4b71Sopenharmony_ci
945e41f4b71Sopenharmony_ci| 类型 | 说明 |
946e41f4b71Sopenharmony_ci| -------- | -------- |
947e41f4b71Sopenharmony_ci| Promise&lt;[DLPManagerResult](#dlpmanagerresult11)&gt; | Promise对象。打开DLP权限管理应用并退出后的结果。 |
948e41f4b71Sopenharmony_ci
949e41f4b71Sopenharmony_ci**错误码:**
950e41f4b71Sopenharmony_ci
951e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
952e41f4b71Sopenharmony_ci
953e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
954e41f4b71Sopenharmony_ci| -------- | -------- |
955e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
956e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
957e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
958e41f4b71Sopenharmony_ci| 19100016 | uri missing in want. |
959e41f4b71Sopenharmony_ci| 19100017 | displayName missing in want. |
960e41f4b71Sopenharmony_ci
961e41f4b71Sopenharmony_ci**示例:**
962e41f4b71Sopenharmony_ci
963e41f4b71Sopenharmony_ci```ts
964e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
965e41f4b71Sopenharmony_ciimport { common, UIAbility, AbilityConstant, Want } from '@kit.AbilityKit';
966e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
967e41f4b71Sopenharmony_ci
968e41f4b71Sopenharmony_citry {
969e41f4b71Sopenharmony_ci  let context = getContext() as common.UIAbilityContext; // 获取当前UIAbilityContext
970e41f4b71Sopenharmony_ci  let want: Want = {
971e41f4b71Sopenharmony_ci    "uri": "file://docs/storage/Users/currentUser/Desktop/1.txt",
972e41f4b71Sopenharmony_ci    "parameters": {
973e41f4b71Sopenharmony_ci      "displayName": "1.txt"
974e41f4b71Sopenharmony_ci    }
975e41f4b71Sopenharmony_ci  }; // 请求参数
976e41f4b71Sopenharmony_ci  dlpPermission.startDLPManagerForResult(context, want).then((res) => {
977e41f4b71Sopenharmony_ci    console.info('res.resultCode', res.resultCode);
978e41f4b71Sopenharmony_ci    console.info('res.want', JSON.stringify(res.want));
979e41f4b71Sopenharmony_ci  }); // 打开DLP权限管理应用
980e41f4b71Sopenharmony_ci} catch (err) {
981e41f4b71Sopenharmony_ci  console.error('error', err.code, err.message); // 失败报错
982e41f4b71Sopenharmony_ci}
983e41f4b71Sopenharmony_ci```
984e41f4b71Sopenharmony_ci
985e41f4b71Sopenharmony_ci## dlpPermission.setSandboxAppConfig<sup>11+<sup>
986e41f4b71Sopenharmony_cisetSandboxAppConfig(configInfo: string): Promise&lt;void&gt;
987e41f4b71Sopenharmony_ci
988e41f4b71Sopenharmony_ci设置沙箱应用配置信息,使用Promise方式异步返回结果。
989e41f4b71Sopenharmony_ci
990e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
991e41f4b71Sopenharmony_ci
992e41f4b71Sopenharmony_ci**参数:**
993e41f4b71Sopenharmony_ci
994e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
995e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
996e41f4b71Sopenharmony_ci| configInfo | string | 是 | 沙箱应用配置信息。 |
997e41f4b71Sopenharmony_ci
998e41f4b71Sopenharmony_ci**返回值:**
999e41f4b71Sopenharmony_ci
1000e41f4b71Sopenharmony_ci| 类型 | 说明 |
1001e41f4b71Sopenharmony_ci| -------- | -------- |
1002e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
1003e41f4b71Sopenharmony_ci
1004e41f4b71Sopenharmony_ci**错误码:**
1005e41f4b71Sopenharmony_ci
1006e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1007e41f4b71Sopenharmony_ci
1008e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
1009e41f4b71Sopenharmony_ci| -------- | -------- |
1010e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1011e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
1012e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. |
1013e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
1014e41f4b71Sopenharmony_ci| 19100018 | Not authorized application. |
1015e41f4b71Sopenharmony_ci
1016e41f4b71Sopenharmony_ci**示例:**
1017e41f4b71Sopenharmony_ci
1018e41f4b71Sopenharmony_ci```ts
1019e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
1020e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1021e41f4b71Sopenharmony_ci
1022e41f4b71Sopenharmony_citry {
1023e41f4b71Sopenharmony_ci  dlpPermission.setSandboxAppConfig('configInfo'); // 设置沙箱应用配置信息
1024e41f4b71Sopenharmony_ci} catch (err) {
1025e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
1026e41f4b71Sopenharmony_ci}
1027e41f4b71Sopenharmony_ci```
1028e41f4b71Sopenharmony_ci
1029e41f4b71Sopenharmony_ci## dlpPermission.cleanSandboxAppConfig<sup>11+<sup>
1030e41f4b71Sopenharmony_cicleanSandboxAppConfig(): Promise&lt;void&gt;
1031e41f4b71Sopenharmony_ci
1032e41f4b71Sopenharmony_ci清理沙箱应用配置信息,使用Promise方式异步返回结果。
1033e41f4b71Sopenharmony_ci
1034e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
1035e41f4b71Sopenharmony_ci
1036e41f4b71Sopenharmony_ci**返回值:**
1037e41f4b71Sopenharmony_ci
1038e41f4b71Sopenharmony_ci| 类型 | 说明 |
1039e41f4b71Sopenharmony_ci| -------- | -------- |
1040e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
1041e41f4b71Sopenharmony_ci
1042e41f4b71Sopenharmony_ci**错误码:**
1043e41f4b71Sopenharmony_ci
1044e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1045e41f4b71Sopenharmony_ci
1046e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
1047e41f4b71Sopenharmony_ci| -------- | -------- |
1048e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
1049e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. |
1050e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
1051e41f4b71Sopenharmony_ci| 19100018 | Not authorized application. |
1052e41f4b71Sopenharmony_ci
1053e41f4b71Sopenharmony_ci**示例:**
1054e41f4b71Sopenharmony_ci
1055e41f4b71Sopenharmony_ci```ts
1056e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
1057e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1058e41f4b71Sopenharmony_ci
1059e41f4b71Sopenharmony_citry {
1060e41f4b71Sopenharmony_ci  dlpPermission.cleanSandboxAppConfig(); // 清理沙箱应用配置信息
1061e41f4b71Sopenharmony_ci} catch (err) {
1062e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
1063e41f4b71Sopenharmony_ci}
1064e41f4b71Sopenharmony_ci```
1065e41f4b71Sopenharmony_ci
1066e41f4b71Sopenharmony_ci## dlpPermission.getSandboxAppConfig<sup>11+<sup>
1067e41f4b71Sopenharmony_cigetSandboxAppConfig(): Promise&lt;string&gt;
1068e41f4b71Sopenharmony_ci
1069e41f4b71Sopenharmony_ci获取沙箱应用配置信息,使用Promise方式异步返回结果
1070e41f4b71Sopenharmony_ci
1071e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
1072e41f4b71Sopenharmony_ci
1073e41f4b71Sopenharmony_ci**返回值:**
1074e41f4b71Sopenharmony_ci| 类型 | 说明 |
1075e41f4b71Sopenharmony_ci| -------- | -------- |
1076e41f4b71Sopenharmony_ci| Promise&lt;string&gt; | Promise对象。返回沙箱应用配置信息。 |
1077e41f4b71Sopenharmony_ci
1078e41f4b71Sopenharmony_ci**错误码:**
1079e41f4b71Sopenharmony_ci
1080e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1081e41f4b71Sopenharmony_ci
1082e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
1083e41f4b71Sopenharmony_ci| -------- | -------- |
1084e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. |
1085e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
1086e41f4b71Sopenharmony_ci| 19100018 | Not authorized application. |
1087e41f4b71Sopenharmony_ci
1088e41f4b71Sopenharmony_ci**示例:**
1089e41f4b71Sopenharmony_ci
1090e41f4b71Sopenharmony_ci```ts
1091e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
1092e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1093e41f4b71Sopenharmony_ci
1094e41f4b71Sopenharmony_citry {
1095e41f4b71Sopenharmony_ci  dlpPermission.getSandboxAppConfig().then((res) => {
1096e41f4b71Sopenharmony_ci    console.info('res', JSON.stringify(res));
1097e41f4b71Sopenharmony_ci  }); // 获取沙箱应用配置信息
1098e41f4b71Sopenharmony_ci} catch (err) {
1099e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
1100e41f4b71Sopenharmony_ci}
1101e41f4b71Sopenharmony_ci```
1102e41f4b71Sopenharmony_ci
1103e41f4b71Sopenharmony_ci## dlpPermission.isDLPFeatureProvided<sup>12+<sup>
1104e41f4b71Sopenharmony_ciisDLPFeatureProvided(): Promise&lt;boolean&gt;
1105e41f4b71Sopenharmony_ci
1106e41f4b71Sopenharmony_ci查询当前系统是否提供DLP特性,使用Promise方式异步返回结果
1107e41f4b71Sopenharmony_ci
1108e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
1109e41f4b71Sopenharmony_ci
1110e41f4b71Sopenharmony_ci**返回值:**
1111e41f4b71Sopenharmony_ci| 类型 | 说明 |
1112e41f4b71Sopenharmony_ci| -------- | -------- |
1113e41f4b71Sopenharmony_ci| Promise&lt;boolean&gt; | Promise对象。返回当前系统是否提供DLP特性。 |
1114e41f4b71Sopenharmony_ci
1115e41f4b71Sopenharmony_ci**错误码:**
1116e41f4b71Sopenharmony_ci
1117e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1118e41f4b71Sopenharmony_ci
1119e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
1120e41f4b71Sopenharmony_ci| -------- | -------- |
1121e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. |
1122e41f4b71Sopenharmony_ci
1123e41f4b71Sopenharmony_ci**示例:**
1124e41f4b71Sopenharmony_ci
1125e41f4b71Sopenharmony_ci```ts
1126e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit';
1127e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1128e41f4b71Sopenharmony_ci
1129e41f4b71Sopenharmony_cidlpPermission.isDLPFeatureProvided().then((res) => {
1130e41f4b71Sopenharmony_ci  console.info('res', JSON.stringify(res));
1131e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1132e41f4b71Sopenharmony_ci  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
1133e41f4b71Sopenharmony_ci});
1134e41f4b71Sopenharmony_ci```
1135e41f4b71Sopenharmony_ci
1136e41f4b71Sopenharmony_ci## ActionFlagType
1137e41f4b71Sopenharmony_ci
1138e41f4b71Sopenharmony_ci可以对DLP文件进行的操作类型枚举。例如:DLP沙箱应用可以根据是否具有操作权限,对其按钮进行置灰
1139e41f4b71Sopenharmony_ci
1140e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
1141e41f4b71Sopenharmony_ci
1142e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 |
1143e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
1144e41f4b71Sopenharmony_ci| ACTION_VIEW | 0x00000001 | 表示文件的查看权限。 |
1145e41f4b71Sopenharmony_ci| ACTION_SAVE | 0x00000002 | 表示文件的保存权限。 |
1146e41f4b71Sopenharmony_ci| ACTION_SAVE_AS | 0x00000004 | 表示文件的另存为权限。 |
1147e41f4b71Sopenharmony_ci| ACTION_EDIT | 0x00000008 | 表示文件的编辑权限。 |
1148e41f4b71Sopenharmony_ci| ACTION_SCREEN_CAPTURE | 0x00000010 | 表示文件的截屏权限。 |
1149e41f4b71Sopenharmony_ci| ACTION_SCREEN_SHARE | 0x00000020 | 表示文件的共享屏幕权限。 |
1150e41f4b71Sopenharmony_ci| ACTION_SCREEN_RECORD | 0x00000040 | 表示文件的录屏权限。 |
1151e41f4b71Sopenharmony_ci| ACTION_COPY | 0x00000080 | 表示文件的复制权限。 |
1152e41f4b71Sopenharmony_ci| ACTION_PRINT | 0x00000100 | 表示文件的打印权限。 |
1153e41f4b71Sopenharmony_ci| ACTION_EXPORT | 0x00000200 | 表示文件的导出权限。 |
1154e41f4b71Sopenharmony_ci| ACTION_PERMISSION_CHANGE | 0x00000400 | 表示文件的修改文件权限。 |
1155e41f4b71Sopenharmony_ci
1156e41f4b71Sopenharmony_ci## DLPFileAccess
1157e41f4b71Sopenharmony_ci
1158e41f4b71Sopenharmony_ciDLP文件授权类型的枚举。
1159e41f4b71Sopenharmony_ci
1160e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
1161e41f4b71Sopenharmony_ci
1162e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 |
1163e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
1164e41f4b71Sopenharmony_ci| NO_PERMISSION | 0 | 表示无文件权限。 |
1165e41f4b71Sopenharmony_ci| READ_ONLY | 1 | 表示文件的只读权限。 |
1166e41f4b71Sopenharmony_ci| CONTENT_EDIT | 2 | 表示文件的编辑权限。 |
1167e41f4b71Sopenharmony_ci| FULL_CONTROL | 3 | 表示文件的完全控制权限。 |
1168e41f4b71Sopenharmony_ci
1169e41f4b71Sopenharmony_ci## DLPPermissionInfo
1170e41f4b71Sopenharmony_ci
1171e41f4b71Sopenharmony_ci表示DLP文件的权限信息。
1172e41f4b71Sopenharmony_ci
1173e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
1174e41f4b71Sopenharmony_ci
1175e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 |
1176e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
1177e41f4b71Sopenharmony_ci| dlpFileAccess | [DLPFileAccess](#dlpfileaccess) | 是 | 否 | 表示DLP文件针对用户的授权类型,例如:只读 |
1178e41f4b71Sopenharmony_ci| flags | number | 是 | 否 | 表示DLP文件的详细操作权限,是不同[ActionFlagType](#actionflagtype)的组合。 |
1179e41f4b71Sopenharmony_ci
1180e41f4b71Sopenharmony_ci## AccessedDLPFileInfo
1181e41f4b71Sopenharmony_ci
1182e41f4b71Sopenharmony_ci表示被打开的DLP文件的信息。
1183e41f4b71Sopenharmony_ci
1184e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
1185e41f4b71Sopenharmony_ci
1186e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 |
1187e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
1188e41f4b71Sopenharmony_ci| uri | string | 是 | 否 | 表示DLP文件的uri。 |
1189e41f4b71Sopenharmony_ci| lastOpenTime | number | 是 | 否 | 表示DLP文件最近打开时间。 |
1190e41f4b71Sopenharmony_ci
1191e41f4b71Sopenharmony_ci## DLPManagerResult<sup>11+</sup>
1192e41f4b71Sopenharmony_ci
1193e41f4b71Sopenharmony_ci表示打开DLP权限管理应用的结果。
1194e41f4b71Sopenharmony_ci
1195e41f4b71Sopenharmony_ci**模型约束:** 此接口仅可在Stage模型下使用。
1196e41f4b71Sopenharmony_ci
1197e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
1198e41f4b71Sopenharmony_ci
1199e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 |
1200e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
1201e41f4b71Sopenharmony_ci| resultCode | number | 是 | 否 | 表示打开DLP权限管理应用并退出后返回的结果码。 |
1202e41f4b71Sopenharmony_ci| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 否 | 表示打开DLP权限管理应用并退出后返回的数据。 |
1203e41f4b71Sopenharmony_ci
1204e41f4b71Sopenharmony_ci## RetentionSandboxInfo
1205e41f4b71Sopenharmony_ci
1206e41f4b71Sopenharmony_ci保留沙箱的沙箱信息。
1207e41f4b71Sopenharmony_ci
1208e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.DataLossPrevention
1209e41f4b71Sopenharmony_ci
1210e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 |
1211e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
1212e41f4b71Sopenharmony_ci| appIndex | number | 是 | 否 | 表示DLP沙箱应用索引。 |
1213e41f4b71Sopenharmony_ci| bundleName | string | 是 | 否 | 表示应用包名。 |
1214e41f4b71Sopenharmony_ci| docUris | Array&lt;string&gt; | 是 | 否 | 表示DLP文件的URI列表。 |
1215e41f4b71Sopenharmony_ci
1216