• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.dlpPermission (数据防泄漏)(系统接口)
2<!--Kit: Data Protection Kit-->
3<!--Subsystem: Security-->
4<!--Owner: @winnieHuYu-->
5<!--Designer: @lucky-jinduo-->
6<!--Tester: @nacyli-->
7<!--Adviser: @zengyawen-->
8
9数据防泄漏(DLP)是系统提供的系统级的数据防泄漏解决方案,提供跨设备的文件的权限管理、加密存储、授权访问等能力。
10
11> **说明:**
12>
13> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.dlpPermission (数据防泄漏)](js-apis-dlppermission.md)。
15
16## 导入模块
17
18```ts
19import { dlpPermission } from '@kit.DataProtectionKit';
20```
21
22## dlpPermission.getDLPGatheringPolicy
23
24getDLPGatheringPolicy(): Promise&lt;GatheringPolicyType&gt;
25
26查询DLP沙箱聚合策略。使用Promise方式异步返回结果。
27
28**系统接口:** 此接口为系统接口。
29
30**需要权限:** ohos.permission.ACCESS_DLP_FILE
31
32**系统能力:** SystemCapability.Security.DataLossPrevention
33
34**返回值:**
35
36| 类型 | 说明 |
37| -------- | -------- |
38| Promise&lt;[GatheringPolicyType](#gatheringpolicytype)&gt; | Promise对象。返回当前DLP沙箱聚合策略。 |
39
40**错误码:**
41
42以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
43
44| 错误码ID | 错误信息 |
45| -------- | -------- |
46| 201 | Permission denied. |
47| 202 | Non-system applications use system APIs. |
48| 19100001 | Invalid parameter value. |
49| 19100011 | The system ability works abnormally. |
50
51**示例:**
52
53```ts
54import { dlpPermission } from '@kit.DataProtectionKit';
55import { BusinessError } from '@kit.BasicServicesKit';
56
57async function ExampleFunction() {
58  try {
59    let res: dlpPermission.GatheringPolicyType = await dlpPermission.getDLPGatheringPolicy(); // 获取沙箱聚合策略。
60    console.info('res', JSON.stringify(res));
61  } catch (err) {
62    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
63  }
64}
65```
66
67## dlpPermission.getDLPGatheringPolicy
68
69getDLPGatheringPolicy(callback: AsyncCallback&lt;GatheringPolicyType&gt;): void
70
71查询DLP沙箱聚合策略。使用callback方式异步返回结果。
72
73**系统接口:** 此接口为系统接口。
74
75**需要权限:** ohos.permission.ACCESS_DLP_FILE
76
77**系统能力:** SystemCapability.Security.DataLossPrevention
78
79**参数:**
80
81| 参数名 | 类型 | 必填 | 说明 |
82| -------- | -------- | -------- | -------- |
83| callback | AsyncCallback&lt;[GatheringPolicyType](#gatheringpolicytype)&gt; | 是 | 回调函数。err为undefine时表示查询成功;否则为错误对象。 |
84
85**错误码:**
86
87以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
88
89| 错误码ID | 错误信息 |
90| -------- | -------- |
91| 201 | Permission denied. |
92| 202 | Non-system applications use system APIs. |
93| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
94| 19100001 | Invalid parameter value. |
95| 19100011 | The system ability works abnormally. |
96
97**示例:**
98
99```ts
100import { dlpPermission } from '@kit.DataProtectionKit';
101import { BusinessError } from '@kit.BasicServicesKit';
102
103try {
104  dlpPermission.getDLPGatheringPolicy((err, res) => {
105    if (err !== undefined) {
106      console.error('getDLPGatheringPolicy error,', err.code, err.message);
107    } else {
108      console.info('res', JSON.stringify(res));
109    }
110  }); // 获取沙箱聚合策略。
111} catch (err) {
112  console.error('getDLPGatheringPolicy error,', (err as BusinessError).code, (err as BusinessError).message);
113}
114```
115
116## dlpPermission.installDLPSandbox
117
118installDLPSandbox(bundleName: string, access: DLPFileAccess, userId: number, uri: string): Promise&lt;DLPSandboxInfo&gt;
119
120安装一个应用的DLP沙箱。使用Promise方式异步返回结果返回应用沙箱信息。
121
122**系统接口:** 此接口为系统接口。
123
124**需要权限:** ohos.permission.ACCESS_DLP_FILE
125
126**系统能力:** SystemCapability.Security.DataLossPrevention
127
128**参数:**
129
130| 参数名 | 类型 | 必填 | 说明 |
131| -------- | -------- | -------- | -------- |
132| bundleName | string | 是 | 应用包名。最小7字节,最大128字节。 |
133| access | [DLPFileAccess](js-apis-dlppermission.md#dlpfileaccess) | 是 | DLP文件授权类型。 |
134| userId | number | 是 | 当前的用户ID,通过账号子系统获取的OS账号ID,默认主用户ID:100。 |
135| uri | string | 是 | DLP文件的URI。不超过4095字节。 |
136
137**返回值:**
138
139| 类型 | 说明 |
140| -------- | -------- |
141| Promise&lt;[DLPSandboxInfo](#dlpsandboxinfo)&gt; | Promise对象。安装沙箱应用,返回应用沙箱信息。 |
142
143**错误码:**
144
145以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
146
147| 错误码ID | 错误信息 |
148| -------- | -------- |
149| 201 | Permission denied. |
150| 202 | Non-system applications use system APIs. |
151| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
152| 19100001 | Invalid parameter value. |
153| 19100011 | The system ability works abnormally. |
154
155**示例:**
156
157```ts
158import { dlpPermission } from '@kit.DataProtectionKit';
159import { BusinessError } from '@kit.BasicServicesKit';
160
161async function ExampleFunction() {
162  try {
163    let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
164    let res: dlpPermission.DLPSandboxInfo =
165      await dlpPermission.installDLPSandbox('com.ohos.note', dlpPermission.DLPFileAccess.READ_ONLY, 100,
166        uri); // 安装DLP沙箱。
167    console.info('res', JSON.stringify(res));
168  } catch (err) {
169    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
170  }
171}
172```
173
174## dlpPermission.installDLPSandbox
175
176installDLPSandbox(bundleName: string, access: DLPFileAccess, userId: number, uri:string, callback: AsyncCallback&lt;DLPSandboxInfo&gt;): void
177
178安装一个应用的DLP沙箱。使用callback方式异步返回应用沙箱信息。
179
180**系统接口:** 此接口为系统接口。
181
182**需要权限:** ohos.permission.ACCESS_DLP_FILE
183
184**系统能力:** SystemCapability.Security.DataLossPrevention
185
186**参数:**
187
188| 参数名 | 类型 | 必填 | 说明 |
189| -------- | -------- | -------- | -------- |
190| bundleName | string | 是 | 应用包名。最小7字节,最大128字节。 |
191| access | [DLPFileAccess](js-apis-dlppermission.md#dlpfileaccess) | 是 | DLP文件授权类型。 |
192| userId | number | 是 | 当前的用户ID,通过账号子系统获取的系账号ID,默认主用户ID:100。 |
193| uri | string | 是 | DLP文件的URI。不超过4095字节。 |
194| callback | AsyncCallback&lt;[DLPSandboxInfo](#dlpsandboxinfo)&gt; | 是 | 获取应用沙箱信息的回调。 |
195
196**错误码:**
197
198以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
199
200| 错误码ID | 错误信息 |
201| -------- | -------- |
202| 201 | Permission denied. |
203| 202 | Non-system applications use system APIs. |
204| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
205| 19100001 | Invalid parameter value. |
206| 19100011 | The system ability works abnormally. |
207
208**示例:**
209
210```ts
211import { dlpPermission } from '@kit.DataProtectionKit';
212import { BusinessError } from '@kit.BasicServicesKit';
213
214let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
215try {
216  dlpPermission.installDLPSandbox('com.ohos.note', dlpPermission.DLPFileAccess.READ_ONLY, 100, uri, (err, res) => {
217    if (err !== undefined) {
218      console.error('installDLPSandbox error,', err.code, err.message);
219    } else {
220      console.info('res', JSON.stringify(res));
221    }
222  }); // 安装DLP沙箱。
223} catch (err) {
224  console.error('installDLPSandbox error,', (err as BusinessError).code, (err as BusinessError).message);
225}
226```
227
228## dlpPermission.uninstallDLPSandbox
229
230uninstallDLPSandbox(bundleName: string, userId: number, appIndex: number): Promise&lt;void&gt;
231
232卸载一个应用的DLP沙箱。使用Promise方式异步返回结果。
233
234**系统接口:** 此接口为系统接口。
235
236**需要权限:** ohos.permission.ACCESS_DLP_FILE
237
238**系统能力:** SystemCapability.Security.DataLossPrevention
239
240**参数:**
241
242| 参数名 | 类型 | 必填 | 说明 |
243| -------- | -------- | -------- | -------- |
244| bundleName | string | 是 | 应用包名。最小7字节,最大128字节。 |
245| userId | number | 是 | 当前的用户ID,通过账号子系统获取的系统账号ID,默认主用户ID:100。 |
246| appIndex | number | 是 | DLP沙箱号。 |
247
248**返回值:**
249
250| 类型 | 说明 |
251| -------- | -------- |
252| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
253
254**错误码:**
255
256以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
257
258| 错误码ID | 错误信息 |
259| -------- | -------- |
260| 201 | Permission denied. |
261| 202 | Non-system applications use system APIs. |
262| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
263| 19100001 | Invalid parameter value. |
264| 19100011 | The system ability works abnormally. |
265
266**示例:**
267
268```ts
269import { dlpPermission } from '@kit.DataProtectionKit';
270import { BusinessError } from '@kit.BasicServicesKit';
271
272async function ExampleFunction() {
273  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
274  try {
275    let res = await dlpPermission.installDLPSandbox('com.ohos.note', dlpPermission.DLPFileAccess.READ_ONLY, 100, uri);
276    console.info('res', JSON.stringify(res));
277    await dlpPermission.uninstallDLPSandbox('com.ohos.note', 100, res.appIndex); // 卸载DLP沙箱。
278  } catch (err) {
279    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
280  }
281}
282```
283
284## dlpPermission.uninstallDLPSandbox
285
286uninstallDLPSandbox(bundleName: string, userId: number, appIndex: number, callback: AsyncCallback&lt;void&gt;): void
287
288卸载一个应用的DLP沙箱。使用callback方式异步返回结果。
289
290**系统接口:** 此接口为系统接口。
291
292**需要权限:** ohos.permission.ACCESS_DLP_FILE
293
294**系统能力:** SystemCapability.Security.DataLossPrevention
295
296**参数:**
297
298| 参数名 | 类型 | 必填 | 说明 |
299| -------- | -------- | -------- | -------- |
300| bundleName | string | 是 | 应用包名。最小7字节,最大128字节。 |
301| userId | number | 是 | 当前的用户ID,通过账号子系统获取的系统账号ID,默认主用户ID:100。 |
302| appIndex | number | 是 | DLP沙箱号,即installDLPSandbox接口调用成功后的返回值。 |
303| callback | AsyncCallback&lt;void&gt; | 是 | 获取卸载结果的回调。 |
304
305**错误码:**
306
307以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
308
309| 错误码ID | 错误信息 |
310| -------- | -------- |
311| 201 | Permission denied. |
312| 202 | Non-system applications use system APIs. |
313| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
314| 19100001 | Invalid parameter value. |
315| 19100011 | The system ability works abnormally. |
316
317**示例:**
318
319```ts
320import { dlpPermission } from '@kit.DataProtectionKit';
321import { BusinessError } from '@kit.BasicServicesKit';
322
323async function ExampleFunction() {
324  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
325  try {
326    let res = await dlpPermission.installDLPSandbox('com.ohos.note', dlpPermission.DLPFileAccess.READ_ONLY, 100,
327      uri) // 安装DLP沙箱。
328    console.info('res', JSON.stringify(res));
329    dlpPermission.uninstallDLPSandbox('com.ohos.note', 100, res.appIndex, (err, res) => {
330      if (err !== undefined) {
331        console.error('uninstallDLPSandbox error,', err.code, err.message);
332      } else {
333        console.info('res', JSON.stringify(res));
334      }
335    });
336  } catch (err) {
337    console.error('uninstallDLPSandbox error,', (err as BusinessError).code, (err as BusinessError).message);
338  }
339}
340```
341
342## dlpPermission.on('uninstallDLPSandbox')
343
344on(type: 'uninstallDLPSandbox', listener: Callback&lt;DLPSandboxState&gt;): void
345
346注册监听DLP沙箱卸载事件。
347
348**系统接口:** 此接口为系统接口。
349
350**需要权限:** ohos.permission.ACCESS_DLP_FILE
351
352**系统能力:** SystemCapability.Security.DataLossPrevention
353
354**参数:**
355| 参数名 | 类型 | 必填 | 说明 |
356| -------- | -------- | -------- | -------- |
357| type | 'uninstallDLPSandbox' | 是 | 监听事件类型。固定值为'uninstallDLPSandbox':DLP沙箱卸载事件。 |
358| listener | Callback&lt;[DLPSandboxState](#dlpsandboxstate)&gt; | 是 | 沙箱应用卸载事件的回调。 |
359
360**错误码:**
361
362以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
363
364| 错误码ID | 错误信息 |
365| -------- | -------- |
366| 201 | Permission denied. |
367| 202 | Non-system applications use system APIs. |
368| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
369| 19100001 | Invalid parameter value. |
370| 19100011 | The system ability works abnormally. |
371
372**示例:**
373
374```ts
375import { dlpPermission } from '@kit.DataProtectionKit';
376import { BusinessError } from '@kit.BasicServicesKit';
377
378try {
379  dlpPermission.on('uninstallDLPSandbox', (info: dlpPermission.DLPSandboxState) => {
380    console.info('uninstallDLPSandbox event', info.appIndex, info.bundleName)
381  }); // 订阅。
382} catch (err) {
383  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错
384}
385```
386
387## dlpPermission.off('uninstallDLPSandbox')
388
389off(type: 'uninstallDLPSandbox', listener?: Callback&lt;DLPSandboxState&gt;): void
390
391取消监听DLP沙箱卸载事件。
392
393**系统接口:** 此接口为系统接口。
394
395**需要权限:** ohos.permission.ACCESS_DLP_FILE
396
397**系统能力:** SystemCapability.Security.DataLossPrevention
398
399**参数:**
400| 参数名 | 类型 | 必填 | 说明 |
401| -------- | -------- | -------- | -------- |
402| type | 'uninstallDLPSandbox' | 是 | 监听事件类型。固定值为'uninstallDLPSandbox':DLP沙箱卸载事件。 |
403| listener | Callback&lt;[DLPSandboxState](#dlpsandboxstate)&gt; | 否 | 沙箱应用卸载事件的回调。默认为空,表示取消该类型事件的所有回调。 |
404
405**错误码:**
406
407以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
408
409| 错误码ID | 错误信息 |
410| -------- | -------- |
411| 201 | Permission denied. |
412| 202 | Non-system applications use system APIs. |
413| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
414| 19100001 | Invalid parameter value. |
415| 19100011 | The system ability works abnormally. |
416
417**示例:**
418
419```ts
420import { dlpPermission } from '@kit.DataProtectionKit';
421import { BusinessError } from '@kit.BasicServicesKit';
422
423try {
424  dlpPermission.off('uninstallDLPSandbox', (info: dlpPermission.DLPSandboxState) => {
425    console.info('uninstallDLPSandbox event', info.appIndex, info.bundleName)
426  }); // 取消订阅。
427} catch (err) {
428  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
429}
430```
431
432## DLPFile
433
434管理DLPFile的实例,表示一个DLP文件对象,需要通过[generateDLPFile](#dlppermissiongeneratedlpfile)/[openDLPFile](#dlppermissionopendlpfile11)获取DLPFile的示例。
435
436### 属性
437
438**系统接口:** 此接口为系统接口。
439
440**系统能力:** SystemCapability.Security.DataLossPrevention
441
442| 名称 | 类型 | 只读 | 可选 | 说明 |
443| -------- | -------- | -------- | -------- | -------- |
444| dlpProperty | [DLPProperty](#dlpproperty) | 否 | 否 | 表示DLP文件授权相关信息。 |
445
446### addDLPLinkFile
447
448addDLPLinkFile(linkFileName: string): Promise&lt;void&gt;
449
450在FUSE文件系统(Filesystem in Userspace)添加link文件(FUSE文件系统中映射到密文的虚拟文件,对该文件的读写操作会同步到DLP文件)。使用Promise方式异步返回结果。
451
452**系统接口:** 此接口为系统接口。
453
454**需要权限:** ohos.permission.ACCESS_DLP_FILE
455
456**系统能力:** SystemCapability.Security.DataLossPrevention
457
458**参数:**
459
460| 参数名 | 类型 | 必填 | 说明 |
461| -------- | -------- | -------- | -------- |
462| linkFileName | string | 是 | 用于fuse文件系统的link文件名。不超过255字节。 |
463
464**返回值:**
465
466| 类型 | 说明 |
467| -------- | -------- |
468| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
469
470**错误码:**
471
472以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
473
474| 错误码ID | 错误信息 |
475| -------- | -------- |
476| 201 | Permission denied. |
477| 202 | Non-system applications use system APIs. |
478| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
479| 19100001 | Invalid parameter value. |
480| 19100009 | Failed to operate the DLP file. |
481| 19100011 | The system ability works abnormally. |
482
483**示例:**
484
485```ts
486import { dlpPermission } from '@kit.DataProtectionKit';
487import { fileIo } from '@kit.CoreFileKit';
488import { bundleManager } from '@kit.AbilityKit';
489import { BusinessError } from '@kit.BasicServicesKit';
490
491async function ExampleFunction() {
492  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
493  let file: number | undefined = undefined;
494  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
495  let appId = '';
496  let bundleName = 'com.ohos.note';
497  let userId = 100;
498  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
499
500  try {
501    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
502    appId = data.signatureInfo.appId;
503  } catch (err) {
504    console.error('error', err.code, err.message);
505    return;
506  }
507
508  try {
509    file = fileIo.openSync(uri).fd;
510    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
511    await dlpFile.addDLPLinkFile('test.txt.dlp.link'); // 添加link文件。
512  } catch (err) {
513    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
514  } finally {
515    dlpFile?.closeDLPFile(); // 关闭DLP对象。
516    if (file) {
517      fileIo.closeSync(file);
518    }
519  }
520}
521```
522
523### addDLPLinkFile
524
525addDLPLinkFile(linkFileName: string, callback: AsyncCallback&lt;void&gt;): void
526
527在FUSE中添加link文件,使用callback方式异步返回结果。
528
529**系统接口:** 此接口为系统接口。
530
531**需要权限:** ohos.permission.ACCESS_DLP_FILE
532
533**系统能力:** SystemCapability.Security.DataLossPrevention
534
535**参数:**
536
537| 参数名 | 类型 | 必填 | 说明 |
538| -------- | -------- | -------- | -------- |
539| linkFileName | string | 是 | 用于fuse文件系统的link文件名。不超过255字节。 |
540| callback | AsyncCallback&lt;void&gt; | 是 | 获取添加结果的回调。 |
541
542**错误码:**
543
544以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
545
546| 错误码ID | 错误信息 |
547| -------- | -------- |
548| 201 | Permission denied. |
549| 202 | Non-system applications use system APIs. |
550| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
551| 19100001 | Invalid parameter value. |
552| 19100009 | Failed to operate the DLP file. |
553| 19100011 | The system ability works abnormally. |
554
555**示例:**
556
557```ts
558import { dlpPermission } from '@kit.DataProtectionKit';
559import { fileIo } from '@kit.CoreFileKit';
560import { bundleManager } from '@kit.AbilityKit';
561import { BusinessError } from '@kit.BasicServicesKit';
562
563async function ExampleFunction() {
564  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
565  let file: number | undefined = undefined;
566  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
567  let appId = '';
568  let bundleName = 'com.ohos.note';
569  let userId = 100;
570  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
571
572  try {
573    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
574    appId = data.signatureInfo.appId;
575  } catch (err) {
576    console.error('error', err.code, err.message);
577  }
578
579  try {
580    file = fileIo.openSync(uri).fd;
581    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
582    dlpFile.addDLPLinkFile('test.txt.dlp.link', async (err, res) => {
583      if (err !== undefined) {
584        console.error('addDLPLinkFile error,', err.code, err.message);
585      } else {
586        console.info('res', JSON.stringify(res));
587      }
588      await dlpFile?.closeDLPFile(); // 关闭DLP对象。
589      fileIo.closeSync(file);
590    });
591  } catch (err) {
592    console.error('addDLPLinkFile error,', (err as BusinessError).code, (err as BusinessError).message);
593    await dlpFile?.closeDLPFile(); // 关闭DLP对象。
594    if (file) {
595      fileIo.closeSync(file);
596    }
597  }
598}
599```
600
601### stopFuseLink
602
603stopFuseLink(): Promise&lt;void&gt;
604
605停止FUSE关联读写。使用Promise方式异步返回结果。
606
607**系统接口:** 此接口为系统接口。
608
609**需要权限:** ohos.permission.ACCESS_DLP_FILE
610
611**系统能力:** SystemCapability.Security.DataLossPrevention
612
613**返回值:**
614
615| 类型 | 说明 |
616| -------- | -------- |
617| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
618
619**错误码:**
620
621以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
622
623| 错误码ID | 错误信息 |
624| -------- | -------- |
625| 201 | Permission denied. |
626| 202 | Non-system applications use system APIs. |
627| 19100001 | Invalid parameter value. |
628| 19100009 | Failed to operate the DLP file. |
629| 19100011 | The system ability works abnormally. |
630
631**示例:**
632
633```ts
634import { dlpPermission } from '@kit.DataProtectionKit';
635import { fileIo } from '@kit.CoreFileKit';
636import { bundleManager } from '@kit.AbilityKit';
637import { BusinessError } from '@kit.BasicServicesKit';
638
639async function ExampleFunction() {
640  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
641  let file: number | undefined = undefined;
642  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
643  let appId = '';
644  let bundleName = 'com.ohos.note';
645  let userId = 100;
646  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
647
648  try {
649    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
650    appId = data.signatureInfo.appId;
651  } catch (err) {
652    console.error('error', err.code, err.message);
653  }
654
655  try {
656    file = fileIo.openSync(uri).fd;
657    dlpFile = await dlpPermission.openDLPFile(file, appId) // 打开DLP文件。
658    dlpFile.addDLPLinkFile('test.txt.dlp.link'); // 添加link文件。
659    dlpFile.stopFuseLink(); // 暂停link读写。
660  } catch (err) {
661    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
662  } finally {
663    dlpFile?.closeDLPFile(); // 关闭DLP对象。
664    if (file) {
665      fileIo.closeSync(file);
666    }
667  }
668}
669```
670
671### stopFuseLink
672
673stopFuseLink(callback: AsyncCallback&lt;void&gt;): void
674
675停止FUSE关联读写,使用callback方式异步返回结果。
676
677**系统接口:** 此接口为系统接口。
678
679**需要权限:** ohos.permission.ACCESS_DLP_FILE
680
681**系统能力:** SystemCapability.Security.DataLossPrevention
682
683**参数:**
684
685| 参数名 | 类型 | 必填 | 说明 |
686| -------- | -------- | -------- | -------- |
687| callback | AsyncCallback&lt;void&gt; | 是 | 获取停止结果的回调。 |
688
689**错误码:**
690
691以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
692
693| 错误码ID | 错误信息 |
694| -------- | -------- |
695| 201 | Permission denied. |
696| 202 | Non-system applications use system APIs. |
697| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
698| 19100001 | Invalid parameter value. |
699| 19100009 | Failed to operate the DLP file. |
700| 19100011 | The system ability works abnormally. |
701
702**示例:**
703
704```ts
705import { dlpPermission } from '@kit.DataProtectionKit';
706import { fileIo } from '@kit.CoreFileKit';
707import { bundleManager } from '@kit.AbilityKit';
708import { BusinessError } from '@kit.BasicServicesKit';
709
710async function ExampleFunction() {
711  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
712  let file: number | undefined = undefined;
713  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
714  let appId = '';
715  let bundleName = 'com.ohos.note';
716  let userId = 100;
717  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
718
719  try {
720    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
721    appId = data.signatureInfo.appId;
722  } catch (err) {
723    console.error('error', err.code, err.message);
724  }
725
726  try {
727    file = fileIo.openSync(uri).fd;
728    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
729    await dlpFile.addDLPLinkFile('test.txt.dlp.link'); // 添加link文件。
730    dlpFile.stopFuseLink(async (err, res) => {
731      if (err !== undefined) {
732        console.error('stopFuseLink error,', err.code, err.message);
733      } else {
734        console.info('res', JSON.stringify(res));
735      }
736      await dlpFile?.closeDLPFile(); // 关闭DLP对象。
737      fileIo.closeSync(file);
738    });
739  } catch (err) {
740    console.error('stopFuseLink error,', (err as BusinessError).code, (err as BusinessError).message);
741    await dlpFile?.closeDLPFile(); // 关闭DLP对象。
742    if (file) {
743      fileIo.closeSync(file);
744    }
745  }
746}
747```
748
749### resumeFuseLink
750
751resumeFuseLink(): Promise&lt;void&gt;
752
753恢复FUSE关联读写。使用Promise方式异步返回结果。
754
755**系统接口:** 此接口为系统接口。
756
757**需要权限:** ohos.permission.ACCESS_DLP_FILE
758
759**系统能力:** SystemCapability.Security.DataLossPrevention
760
761**返回值:**
762
763| 类型 | 说明 |
764| -------- | -------- |
765| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
766
767**错误码:**
768
769以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
770
771| 错误码ID | 错误信息 |
772| -------- | -------- |
773| 201 | Permission denied. |
774| 202 | Non-system applications use system APIs. |
775| 19100001 | Invalid parameter value. |
776| 19100009 | Failed to operate the DLP file. |
777| 19100011 | The system ability works abnormally. |
778
779**示例:**
780
781```ts
782import { dlpPermission } from '@kit.DataProtectionKit';
783import { fileIo } from '@kit.CoreFileKit';
784import { bundleManager } from '@kit.AbilityKit';
785import { BusinessError } from '@kit.BasicServicesKit';
786
787async function ExampleFunction() {
788  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
789  let file: number | undefined = undefined;
790  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
791  let appId = '';
792  let bundleName = 'com.ohos.note';
793  let userId = 100;
794  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
795
796  try {
797    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
798    appId = data.signatureInfo.appId;
799  } catch (err) {
800    console.error('error', err.code, err.message);
801  }
802
803  try {
804    file = fileIo.openSync(uri).fd;
805    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
806    await dlpFile.addDLPLinkFile('test.txt.dlp.link'); // 添加link文件。
807    await dlpFile.stopFuseLink(); // 暂停link读写。
808    await dlpFile.resumeFuseLink(); // 恢复link读写。
809  } catch (err) {
810    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
811  } finally {
812    dlpFile?.closeDLPFile(); // 关闭DLP对象。
813    if (file) {
814      fileIo.closeSync(file);
815    }
816  }
817}
818```
819
820### resumeFuseLink
821
822resumeFuseLink(callback: AsyncCallback&lt;void&gt;): void
823
824恢复FUSE关联读写,使用callback方式异步返回结果。
825
826**系统接口:** 此接口为系统接口。
827
828**需要权限:** ohos.permission.ACCESS_DLP_FILE
829
830**系统能力:** SystemCapability.Security.DataLossPrevention
831
832**参数:**
833
834| 参数名 | 类型 | 必填 | 说明 |
835| -------- | -------- | -------- | -------- |
836| callback | AsyncCallback&lt;void&gt; | 是 | 获取恢复结果的回调。 |
837
838**错误码:**
839
840以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
841
842| 错误码ID | 错误信息 |
843| -------- | -------- |
844| 201 | Permission denied. |
845| 202 | Non-system applications use system APIs. |
846| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
847| 19100001 | Invalid parameter value. |
848| 19100009 | Failed to operate the DLP file. |
849| 19100011 | The system ability works abnormally. |
850
851**示例:**
852
853```ts
854import { dlpPermission } from '@kit.DataProtectionKit';
855import { fileIo } from '@kit.CoreFileKit';
856import { bundleManager } from '@kit.AbilityKit';
857import { BusinessError } from '@kit.BasicServicesKit';
858
859async function ExampleFunction() {
860  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
861  let file: number | undefined = undefined;
862  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
863  let appId = '';
864  let bundleName = 'com.ohos.note';
865  let userId = 100;
866  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
867
868  try {
869    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
870    appId = data.signatureInfo.appId;
871  } catch (err) {
872    console.error('error', err.code, err.message);
873  }
874
875  try {
876    file = fileIo.openSync(uri).fd;
877    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
878    await dlpFile.addDLPLinkFile('test.txt.dlp.link'); // 添加link文件。
879    await dlpFile.stopFuseLink(); // 暂停link读写。
880    dlpFile.resumeFuseLink(async (err, res) => {
881      if (err !== undefined) {
882        console.error('resumeFuseLink error,', err.code, err.message);
883      } else {
884        console.info('res', JSON.stringify(res));
885      }
886      await dlpFile?.closeDLPFile(); // 关闭DLP对象。
887      fileIo.closeSync(file);
888    });
889  } catch (err) {
890    console.error('resumeFuseLink error,', (err as BusinessError).code, (err as BusinessError).message);
891    await dlpFile?.closeDLPFile(); // 关闭DLP对象。
892    if (file) {
893      fileIo.closeSync(file);
894    }
895  }
896}
897```
898
899### replaceDLPLinkFile
900
901replaceDLPLinkFile(linkFileName: string): Promise&lt;void&gt;
902
903替换link文件。使用Promise方式异步返回结果。
904
905**系统接口:** 此接口为系统接口。
906
907**需要权限:** ohos.permission.ACCESS_DLP_FILE
908
909**系统能力:** SystemCapability.Security.DataLossPrevention
910
911**参数:**
912
913| 参数名 | 类型 | 必填 | 说明 |
914| -------- | -------- | -------- | -------- |
915| linkFileName | string | 是 | 用于fuse文件系统的link文件名。不超过255字节。 |
916
917**返回值:**
918
919| 类型 | 说明 |
920| -------- | -------- |
921| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
922
923**错误码:**
924
925以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
926
927| 错误码ID | 错误信息 |
928| -------- | -------- |
929| 201 | Permission denied. |
930| 202 | Non-system applications use system APIs. |
931| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
932| 19100001 | Invalid parameter value. |
933| 19100009 | Failed to operate the DLP file. |
934| 19100011 | The system ability works abnormally. |
935
936**示例:**
937
938```ts
939import { dlpPermission } from '@kit.DataProtectionKit';
940import { fileIo } from '@kit.CoreFileKit';
941import { bundleManager } from '@kit.AbilityKit';
942import { BusinessError } from '@kit.BasicServicesKit';
943
944async function ExampleFunction() {
945  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
946  let file: number | undefined = undefined;
947  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
948  let appId = '';
949  let bundleName = 'com.ohos.note';
950  let userId = 100;
951  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
952
953  try {
954    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
955    appId = data.signatureInfo.appId;
956  } catch (err) {
957    console.error('error', err.code, err.message);
958  }
959
960  try {
961    file = fileIo.openSync(uri).fd;
962    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
963    await dlpFile.addDLPLinkFile('test.txt.dlp.link'); // 添加link文件。
964    await dlpFile.stopFuseLink(); // 暂停link读写。
965    await dlpFile.replaceDLPLinkFile('test_new.txt.dlp.link'); // 替换link文件。
966    await dlpFile.resumeFuseLink(); // 恢复link读写。
967  } catch (err) {
968    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
969  } finally {
970    await dlpFile?.closeDLPFile(); // 关闭DLP对象。
971    if (file) {
972      fileIo.closeSync(file);
973    }
974  }
975}
976```
977
978### replaceDLPLinkFile
979
980replaceDLPLinkFile(linkFileName: string, callback: AsyncCallback&lt;void&gt;): void
981
982替换link文件,使用callback方式异步返回结果。
983
984**系统接口:** 此接口为系统接口。
985
986**需要权限:** ohos.permission.ACCESS_DLP_FILE
987
988**系统能力:** SystemCapability.Security.DataLossPrevention
989
990**参数:**
991
992| 参数名 | 类型 | 必填 | 说明 |
993| -------- | -------- | -------- | -------- |
994| linkFileName | string | 是 | 用于fuse文件系统的link文件名。不超过255字节。 |
995| callback | AsyncCallback&lt;void&gt; | 是 | 获取替换结果的回调。 |
996
997**错误码:**
998
999以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1000
1001| 错误码ID | 错误信息 |
1002| -------- | -------- |
1003| 201 | Permission denied. |
1004| 202 | Non-system applications use system APIs. |
1005| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1006| 19100001 | Invalid parameter value. |
1007| 19100009 | Failed to operate the DLP file. |
1008| 19100011 | The system ability works abnormally. |
1009
1010**示例:**
1011
1012```ts
1013import { dlpPermission } from '@kit.DataProtectionKit';
1014import { fileIo } from '@kit.CoreFileKit';
1015import { bundleManager } from '@kit.AbilityKit';
1016import { BusinessError } from '@kit.BasicServicesKit';
1017
1018async function ExampleFunction() {
1019  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1020  let file: number | undefined = undefined;
1021  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
1022  let appId = '';
1023  let bundleName = 'com.ohos.note';
1024  let userId = 100;
1025  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
1026
1027  try {
1028    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
1029    appId = data.signatureInfo.appId;
1030  } catch (err) {
1031    console.error('error', err.code, err.message);
1032  }
1033
1034  try {
1035    file = fileIo.openSync(uri).fd;
1036    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
1037    await dlpFile.addDLPLinkFile('test.txt.dlp.link'); // 添加link文件。
1038    await dlpFile.stopFuseLink(); // 暂停link读写。
1039    dlpFile.replaceDLPLinkFile('test_new.txt.dlp.link', async (err, res) => { // 替换link文件。
1040      if (err !== undefined) {
1041        console.error('replaceDLPLinkFile error,', err.code, err.message);
1042      } else {
1043        console.info('res', JSON.stringify(res));
1044        await dlpFile?.resumeFuseLink(); // 恢复link读写。
1045      }
1046      await dlpFile?.closeDLPFile(); // 关闭DLP对象。
1047      fileIo.closeSync(file);
1048    });
1049  } catch (err) {
1050    console.error('error,', (err as BusinessError).code, (err as BusinessError).message);
1051    await dlpFile?.closeDLPFile(); // 关闭DLP对象。
1052    if (file) {
1053      fileIo.closeSync(file);
1054    }
1055  }
1056}
1057```
1058
1059### deleteDLPLinkFile
1060
1061deleteDLPLinkFile(linkFileName: string): Promise&lt;void&gt;
1062
1063删除fuse文件系统中创建的link文件。使用Promise方式异步返回结果。
1064
1065**系统接口:** 此接口为系统接口。
1066
1067**需要权限:** ohos.permission.ACCESS_DLP_FILE
1068
1069**系统能力:** SystemCapability.Security.DataLossPrevention
1070
1071**参数:**
1072
1073| 参数名 | 类型 | 必填 | 说明 |
1074| -------- | -------- | -------- | -------- |
1075| linkFileName | string | 是 | 用于fuse文件系统的link文件名。不超过255字节。 |
1076
1077**返回值:**
1078
1079| 类型 | 说明 |
1080| -------- | -------- |
1081| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
1082
1083**错误码:**
1084
1085以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1086
1087| 错误码ID | 错误信息 |
1088| -------- | -------- |
1089| 201 | Permission denied. |
1090| 202 | Non-system applications use system APIs. |
1091| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1092| 19100001 | Invalid parameter value. |
1093| 19100009 | Failed to operate the DLP file. |
1094| 19100011 | The system ability works abnormally. |
1095
1096**示例:**
1097
1098```ts
1099import { dlpPermission } from '@kit.DataProtectionKit';
1100import { fileIo } from '@kit.CoreFileKit';
1101import { bundleManager } from '@kit.AbilityKit';
1102import { BusinessError } from '@kit.BasicServicesKit';
1103
1104async function ExampleFunction() {
1105  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1106  let file: number | undefined = undefined;
1107  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
1108  let appId = '';
1109  let bundleName = 'com.ohos.note';
1110  let userId = 100;
1111  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
1112
1113  try {
1114    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
1115    appId = data.signatureInfo.appId;
1116  } catch (err) {
1117    console.error('error', err.code, err.message);
1118  }
1119
1120  try {
1121    file = fileIo.openSync(uri).fd;
1122    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
1123    await dlpFile.addDLPLinkFile('test.txt.dlp.link'); // 添加link文件。
1124    await dlpFile.deleteDLPLinkFile('test.txt.dlp.link'); // 删除link文件。
1125  } catch (err) {
1126    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
1127  } finally {
1128    await dlpFile?.closeDLPFile(); // 关闭DLP对象。
1129    if (file) {
1130      fileIo.closeSync(file);
1131    }
1132  }
1133}
1134```
1135
1136### deleteDLPLinkFile
1137
1138deleteDLPLinkFile(linkFileName: string, callback: AsyncCallback&lt;void&gt;): void
1139
1140删除link文件,使用callback方式异步返回结果。
1141
1142**系统接口:** 此接口为系统接口。
1143
1144**需要权限:** ohos.permission.ACCESS_DLP_FILE
1145
1146**系统能力:** SystemCapability.Security.DataLossPrevention
1147
1148**参数:**
1149
1150| 参数名 | 类型 | 必填 | 说明 |
1151| -------- | -------- | -------- | -------- |
1152| linkFileName | string | 是 | 用于fuse文件系统的link文件名。不超过255字节。 |
1153| callback | AsyncCallback&lt;void&gt; | 是 | 获取删除结果的回调。 |
1154
1155**错误码:**
1156
1157以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1158
1159| 错误码ID | 错误信息 |
1160| -------- | -------- |
1161| 201 | Permission denied. |
1162| 202 | Non-system applications use system APIs. |
1163| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1164| 19100001 | Invalid parameter value. |
1165| 19100009 | Failed to operate the DLP file. |
1166| 19100011 | The system ability works abnormally. |
1167
1168**示例:**
1169
1170```ts
1171import { dlpPermission } from '@kit.DataProtectionKit';
1172import { fileIo } from '@kit.CoreFileKit';
1173import { bundleManager } from '@kit.AbilityKit';
1174import { BusinessError } from '@kit.BasicServicesKit';
1175
1176async function ExampleFunction() {
1177  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1178  let file: number | undefined = undefined;
1179  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
1180  let appId = '';
1181  let bundleName = 'com.ohos.note';
1182  let userId = 100;
1183  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
1184
1185  try {
1186    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
1187    appId = data.signatureInfo.appId;
1188  } catch (err) {
1189    console.error('error', err.code, err.message);
1190  }
1191
1192  try {
1193    file = fileIo.openSync(uri).fd;
1194    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
1195    await dlpFile.addDLPLinkFile('test.txt.dlp.link'); // 添加link文件。
1196    dlpFile.deleteDLPLinkFile('test.txt.dlp.link', async (err, res) => { // 删除link文件。
1197      if (err !== undefined) {
1198        console.error('deleteDLPLinkFile error,', err.code, err.message);
1199      } else {
1200        console.info('res', JSON.stringify(res));
1201      }
1202      await dlpFile?.closeDLPFile(); // 关闭DLP对象。
1203      fileIo.closeSync(file);
1204    });
1205  } catch (err) {
1206    console.error('error,', (err as BusinessError).code, (err as BusinessError).message);
1207    await dlpFile?.closeDLPFile(); // 关闭DLP对象。
1208    if (file) {
1209      fileIo.closeSync(file);
1210    }
1211  }
1212}
1213```
1214
1215### recoverDLPFile
1216
1217recoverDLPFile(plaintextFd: number): Promise&lt;void&gt;
1218
1219移除DLP文件的权限控制,恢复成明文文件。使用Promise方式异步返回结果。
1220
1221**系统接口:** 此接口为系统接口。
1222
1223**需要权限:** ohos.permission.ACCESS_DLP_FILE
1224
1225**系统能力:** SystemCapability.Security.DataLossPrevention
1226
1227**参数:**
1228
1229| 参数名 | 类型 | 必填 | 说明 |
1230| -------- | -------- | -------- | -------- |
1231| plaintextFd | number | 是 | 目标明文文件的fd。 |
1232
1233**返回值:**
1234
1235| 类型 | 说明 |
1236| -------- | -------- |
1237| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
1238
1239**错误码:**
1240
1241以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1242
1243| 错误码ID | 错误信息 |
1244| -------- | -------- |
1245| 201 | Permission denied. |
1246| 202 | Non-system applications use system APIs. |
1247| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1248| 19100001 | Invalid parameter value. |
1249| 19100002 | Credential task error. |
1250| 19100003 | Credential task time out. |
1251| 19100004 | Credential service error. |
1252| 19100005 | Credential authentication server error. |
1253| 19100008 | The file is not a DLP file. |
1254| 19100009 | Failed to operate the DLP file. |
1255| 19100010 | The DLP file is read only. |
1256| 19100011 | The system ability works abnormally. |
1257
1258**示例:**
1259
1260```ts
1261import { dlpPermission } from '@kit.DataProtectionKit';
1262import { fileIo } from '@kit.CoreFileKit';
1263import { bundleManager } from '@kit.AbilityKit';
1264import { BusinessError } from '@kit.BasicServicesKit';
1265
1266async function ExampleFunction() {
1267  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1268  let file: number | undefined = undefined;
1269  let destFile: number | undefined = undefined;
1270  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
1271  let appId = '';
1272  let bundleName = 'com.ohos.note';
1273  let userId = 100;
1274  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
1275
1276  try {
1277    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
1278    appId = data.signatureInfo.appId;
1279  } catch (err) {
1280    console.error('error', err.code, err.message);
1281  }
1282
1283  try {
1284    file = fileIo.openSync(uri).fd;
1285    destFile = fileIo.openSync('destUri').fd;
1286    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
1287    await dlpFile.recoverDLPFile(destFile); // 还原DLP文件。
1288  } catch (err) {
1289    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
1290  } finally {
1291    dlpFile?.closeDLPFile(); // 关闭DLP对象。
1292    if (file) {
1293      fileIo.closeSync(file);
1294    }
1295    if (destFile) {
1296      fileIo.closeSync(destFile);
1297    }
1298  }
1299}
1300```
1301
1302### recoverDLPFile
1303
1304recoverDLPFile(plaintextFd: number, callback: AsyncCallback&lt;void&gt;): void
1305
1306移除DLP文件的权限控制,恢复成明文文件,使用callback方式异步返回结果。
1307
1308**系统接口:** 此接口为系统接口。
1309
1310**需要权限:** ohos.permission.ACCESS_DLP_FILE
1311
1312**系统能力:** SystemCapability.Security.DataLossPrevention
1313
1314**参数:**
1315
1316| 参数名 | 类型 | 必填 | 说明 |
1317| -------- | -------- | -------- | -------- |
1318| plaintextFd | number | 是 | 目标明文文件的fd。 |
1319| callback | AsyncCallback&lt;void&gt; | 是 | 获取恢复结果的回调。 |
1320
1321**错误码:**
1322
1323以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1324
1325| 错误码ID | 错误信息 |
1326| -------- | -------- |
1327| 201 | Permission denied. |
1328| 202 | Non-system applications use system APIs. |
1329| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1330| 19100001 | Invalid parameter value. |
1331| 19100002 | Credential task error. |
1332| 19100003 | Credential task time out. |
1333| 19100004 | Credential service error. |
1334| 19100005 | Credential authentication server error. |
1335| 19100008 | The file is not a DLP file. |
1336| 19100009 | Failed to operate the DLP file. |
1337| 19100010 | The DLP file is read only. |
1338| 19100011 | The system ability works abnormally. |
1339
1340**示例:**
1341
1342```ts
1343import { dlpPermission } from '@kit.DataProtectionKit';
1344import { fileIo } from '@kit.CoreFileKit';
1345import { bundleManager } from '@kit.AbilityKit';
1346import { BusinessError } from '@kit.BasicServicesKit';
1347
1348async function ExampleFunction() {
1349  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1350  let file: number | undefined = undefined;
1351  let destFile: number | undefined = undefined;
1352  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
1353  let appId = '';
1354  let bundleName = 'com.ohos.note';
1355  let userId = 100;
1356  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
1357
1358  try {
1359    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
1360    appId = data.signatureInfo.appId;
1361  } catch (err) {
1362    console.error('error', err.code, err.message);
1363  }
1364
1365  try {
1366    file = fileIo.openSync(uri).fd;
1367    destFile = fileIo.openSync('destUri').fd;
1368    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
1369    dlpFile.recoverDLPFile(destFile, async (err, res) => { // 还原DLP文件。
1370      if (err !== undefined) {
1371        console.error('recoverDLPFile error,', err.code, err.message);
1372      } else {
1373        console.info('res', JSON.stringify(res));
1374      }
1375      await dlpFile?.closeDLPFile(); // 关闭DLP对象。
1376      fileIo.closeSync(file);
1377      fileIo.closeSync(destFile);
1378    });
1379  } catch (err) {
1380    console.error('error,', (err as BusinessError).code, (err as BusinessError).message);
1381    await dlpFile?.closeDLPFile(); // 关闭DLP对象。
1382    if (file) {
1383      fileIo.closeSync(file);
1384    }
1385    if (destFile) {
1386      fileIo.closeSync(destFile);
1387    }
1388  }
1389}
1390```
1391
1392### closeDLPFile
1393
1394closeDLPFile(): Promise&lt;void&gt;
1395
1396关闭DLPFile,释放对象。使用Promise方式异步返回结果。
1397
1398**系统接口:** 此接口为系统接口。
1399
1400**需要权限:** ohos.permission.ACCESS_DLP_FILE
1401
1402**系统能力:** SystemCapability.Security.DataLossPrevention
1403
1404> **说明:**
1405>
1406> dlpFile不再使用,应该关闭释放内存,且对象不应继续使用。
1407
1408**返回值:**
1409
1410| 类型 | 说明 |
1411| -------- | -------- |
1412| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
1413
1414**错误码:**
1415
1416以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1417
1418| 错误码ID | 错误信息 |
1419| -------- | -------- |
1420| 201 | Permission denied. |
1421| 202 | Non-system applications use system APIs. |
1422| 19100001 | Invalid parameter value. |
1423| 19100009 | Failed to operate the DLP file. |
1424| 19100011 | The system ability works abnormally. |
1425
1426**示例:**
1427
1428```ts
1429import { dlpPermission } from '@kit.DataProtectionKit';
1430import { fileIo } from '@kit.CoreFileKit';
1431import { bundleManager } from '@kit.AbilityKit';
1432import { BusinessError } from '@kit.BasicServicesKit';
1433
1434async function ExampleFunction() {
1435  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1436  let file: number | undefined = undefined;
1437  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
1438  let appId = '';
1439  let bundleName = 'com.ohos.note';
1440  let userId = 100;
1441  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
1442
1443  try {
1444    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
1445    appId = data.signatureInfo.appId;
1446  } catch (err) {
1447    console.error('error', err.code, err.message);
1448  }
1449
1450  try {
1451    file = fileIo.openSync(uri).fd;
1452    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
1453  } catch (err) {
1454    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
1455  } finally {
1456    dlpFile?.closeDLPFile(); // 关闭DLP对象。
1457    if (file) {
1458      fileIo.closeSync(file);
1459    }
1460  }
1461}
1462```
1463
1464### closeDLPFile
1465
1466closeDLPFile(callback: AsyncCallback&lt;void&gt;): void
1467
1468关闭DLPFile,释放对象,使用callback方式异步返回结果。
1469
1470**系统接口:** 此接口为系统接口。
1471
1472**需要权限:** ohos.permission.ACCESS_DLP_FILE
1473
1474**系统能力:** SystemCapability.Security.DataLossPrevention
1475
1476> **说明:**
1477>
1478> dlpFile不再使用,应该关闭释放内存,且对象不应继续使用。
1479
1480**参数:**
1481
1482| 参数名 | 类型 | 必填 | 说明 |
1483| -------- | -------- | -------- | -------- |
1484| callback | AsyncCallback&lt;void&gt; | 是 | 获取关闭结果的回调。 |
1485
1486**错误码:**
1487
1488以下错误码的详细介绍请参见[DLP服务错误码](errorcode-dlp.md)。
1489
1490| 错误码ID | 错误信息 |
1491| -------- | -------- |
1492| 201 | Permission denied. |
1493| 202 | Non-system applications use system APIs. |
1494| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. |
1495| 19100001 | Invalid parameter value. |
1496| 19100009 | Failed to operate the DLP file. |
1497| 19100011 | The system ability works abnormally. |
1498
1499**示例:**
1500
1501```ts
1502import { dlpPermission } from '@kit.DataProtectionKit';
1503import { fileIo } from '@kit.CoreFileKit';
1504import { bundleManager } from '@kit.AbilityKit';
1505import { BusinessError } from '@kit.BasicServicesKit';
1506
1507async function ExampleFunction() {
1508  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1509  let file: number | undefined = undefined;
1510  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
1511  let appId = '';
1512  let bundleName = 'com.ohos.note';
1513  let userId = 100;
1514  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
1515
1516  try {
1517    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
1518    appId = data.signatureInfo.appId;
1519  } catch (err) {
1520    console.error('error', err.code, err.message);
1521  }
1522
1523  try {
1524    file = fileIo.openSync(uri).fd;
1525    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
1526    dlpFile.closeDLPFile((err, res) => { // 关闭DLP文件。
1527      if (err !== undefined) {
1528        console.error('closeDLPFile error,', err.code, err.message);
1529      } else {
1530        console.info('res', JSON.stringify(res));
1531      }
1532      fileIo.closeSync(file);
1533    });
1534  } catch (err) {
1535    console.error('error,', (err as BusinessError).code, (err as BusinessError).message);
1536    if (file) {
1537      fileIo.closeSync(file);
1538    }
1539  }
1540}
1541```
1542
1543## dlpPermission.generateDLPFile
1544
1545generateDLPFile(plaintextFd: number, ciphertextFd: number, property: DLPProperty): Promise&lt;DLPFile&gt;
1546
1547将明文文件加密生成权限受控文件,仅在授权列表内的用户可以打开,授权又分为完全控制权限和只读权限。获取DLPFile管理对象,使用Promise方式异步返回结果。
1548
1549**系统接口:** 此接口为系统接口。
1550
1551**需要权限:** ohos.permission.ACCESS_DLP_FILE
1552
1553**系统能力:** SystemCapability.Security.DataLossPrevention
1554
1555**参数:**
1556
1557| 参数名 | 类型 | 必填 | 说明 |
1558| -------- | -------- | -------- | -------- |
1559| plaintextFd | number | 是 | 待加密明文文件的fd。 |
1560| ciphertextFd | number | 是 | 目标加密文件的fd。 |
1561| property | [DLPProperty](#dlpproperty) | 是 | 授权用户信息:授权用户列表、owner账号、联系人账号。 |
1562
1563**返回值:**
1564
1565| 类型 | 说明 |
1566| -------- | -------- |
1567| Promise&lt;[DLPFile](#dlpfile)&gt; | Promise对象。返回对象表示成功生成DLP文件,返回null表示失败。 |
1568
1569**错误码:**
1570
1571以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[DLP服务错误码](errorcode-dlp.md)。
1572
1573| 错误码ID | 错误信息 |
1574| -------- | -------- |
1575| 201 | Permission denied. |
1576| 202 | Non-system applications use system APIs. |
1577| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1578| 19100001 | Invalid parameter value. |
1579| 19100002 | Credential service busy due to too many tasks or duplicate tasks. |
1580| 19100003 | Credential task time out. |
1581| 19100004 | Credential service error. |
1582| 19100005 | Credential authentication server error. |
1583| 19100009 | Failed to operate the DLP file. |
1584| 19100011 | The system ability works abnormally. |
1585
1586**示例:**
1587
1588```ts
1589import { dlpPermission } from '@kit.DataProtectionKit';
1590import { fileIo } from '@kit.CoreFileKit';
1591import { BusinessError } from '@kit.BasicServicesKit';
1592
1593async function ExampleFunction() {
1594  let dlpUri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1595  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt';
1596  let file: number | undefined = undefined;
1597  let dlp: number | undefined = undefined;
1598  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
1599
1600  try {
1601    file = fileIo.openSync(uri).fd;
1602    dlp = fileIo.openSync(dlpUri).fd;
1603    let dlpProperty: dlpPermission.DLPProperty = {
1604      ownerAccount: 'zhangsan',
1605      ownerAccountType: dlpPermission.AccountType.DOMAIN_ACCOUNT,
1606      authUserList: [],
1607      contactAccount: 'zhangsan',
1608      offlineAccess: true,
1609      ownerAccountID: 'xxxxxxx',
1610      everyoneAccessList: []
1611    };
1612    dlpFile = await dlpPermission.generateDLPFile(file, dlp, dlpProperty); // 生成DLP文件。
1613  } catch (err) {
1614    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
1615  } finally {
1616    dlpFile?.closeDLPFile(); // 关闭DLP对象。
1617    if (file) {
1618      fileIo.closeSync(file);
1619    }
1620    if (dlp) {
1621      fileIo.closeSync(dlp);
1622    }
1623  }
1624}
1625```
1626
1627## dlpPermission.generateDLPFile
1628
1629generateDLPFile(plaintextFd: number, ciphertextFd: number, property: DLPProperty, callback: AsyncCallback&lt;DLPFile&gt;): void
1630
1631DLP管理应用调用该接口,将明文文件加密生成权限受控文件,仅在授权列表内的用户可以打开,授权又分为完全控制权限和只读权限。获取DLPFile管理对象,使用callback方式异步返回结果。
1632
1633**系统接口:** 此接口为系统接口。
1634
1635**需要权限:** ohos.permission.ACCESS_DLP_FILE
1636
1637**系统能力:** SystemCapability.Security.DataLossPrevention
1638
1639**参数:**
1640
1641| 参数名 | 类型 | 必填 | 说明 |
1642| -------- | -------- | -------- | -------- |
1643| plaintextFd | number | 是 | 待加密明文文件的fd。 |
1644| ciphertextFd | number | 是 | 目标加密文件的fd。 |
1645| property | [DLPProperty](#dlpproperty) | 是 | 授权用户信息:授权用户列表、owner账号、联系人账号。 |
1646| callback | AsyncCallback&lt;[DLPFile](#dlpfile)&gt; | 是 | 回调函数。返回DLPFile对象。 |
1647
1648**错误码:**
1649
1650以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[DLP服务错误码](errorcode-dlp.md)。
1651
1652| 错误码ID | 错误信息 |
1653| -------- | -------- |
1654| 201 | Permission denied. |
1655| 202 | Non-system applications use system APIs. |
1656| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1657| 19100001 | Invalid parameter value. |
1658| 19100002 | Credential service busy due to too many tasks or duplicate tasks. |
1659| 19100003 | Credential task time out. |
1660| 19100004 | Credential service error. |
1661| 19100005 | Credential authentication server error. |
1662| 19100009 | Failed to operate the DLP file. |
1663| 19100011 | The system ability works abnormally. |
1664
1665**示例:**
1666
1667```ts
1668import { dlpPermission } from '@kit.DataProtectionKit';
1669import { fileIo } from '@kit.CoreFileKit';
1670import { BusinessError } from '@kit.BasicServicesKit';
1671
1672let dlpUri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1673let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt';
1674let file: number | undefined = undefined;
1675let dlp: number | undefined = undefined;
1676
1677try {
1678  file = fileIo.openSync(uri).fd;
1679  dlp = fileIo.openSync(dlpUri).fd;
1680  let dlpProperty: dlpPermission.DLPProperty = {
1681    ownerAccount: 'zhangsan',
1682    ownerAccountType: dlpPermission.AccountType.DOMAIN_ACCOUNT,
1683    authUserList: [],
1684    contactAccount: 'zhangsan',
1685    offlineAccess: true,
1686    ownerAccountID: 'xxxxxxx',
1687    everyoneAccessList: []
1688  };
1689  dlpPermission.generateDLPFile(file, dlp, dlpProperty, (err, res) => { // 生成DLP文件。
1690    if (err !== undefined) {
1691      console.error('generateDLPFile error,', err.code, err.message);
1692    } else {
1693      console.info('res', JSON.stringify(res));
1694    }
1695    fileIo.closeSync(file);
1696    fileIo.closeSync(dlp);
1697  });
1698} catch (err) {
1699  console.error('error,', (err as BusinessError).code, (err as BusinessError).message);
1700  if (file) {
1701    fileIo.closeSync(file);
1702  }
1703  if (dlp) {
1704    fileIo.closeSync(dlp);
1705  }
1706}
1707```
1708
1709## dlpPermission.openDLPFile<sup>11+</sup>
1710
1711openDLPFile(ciphertextFd: number, appId: string): Promise&lt;DLPFile&gt;
1712
1713打开DLP文件。获取DLPFile管理对象,使用Promise方式异步返回结果。
1714
1715**系统接口:** 此接口为系统接口。
1716
1717**需要权限:** ohos.permission.ACCESS_DLP_FILE
1718
1719**系统能力:** SystemCapability.Security.DataLossPrevention
1720
1721**参数:**
1722
1723| 参数名 | 类型 | 必填 | 说明 |
1724| -------- | -------- | -------- | -------- |
1725| ciphertextFd | number | 是 | 加密文件的fd。 |
1726| appId | string | 是 | 调用方身份。最小8字节,最大1024字节。 |
1727
1728**返回值:**
1729
1730| 类型 | 说明 |
1731| -------- | -------- |
1732| Promise&lt;[DLPFile](#dlpfile)&gt; | Promise对象。返回对象表示打开生成DLP文件,返回null表示失败。 |
1733
1734**错误码:**
1735
1736以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[DLP服务错误码](errorcode-dlp.md)。
1737
1738| 错误码ID | 错误信息 |
1739| -------- | -------- |
1740| 201 | Permission denied. |
1741| 202 | Non-system applications use system APIs. |
1742| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1743| 19100001 | Invalid parameter value. |
1744| 19100002 | Credential service busy due to too many tasks or duplicate tasks. |
1745| 19100003 | Credential task time out. |
1746| 19100004 | Credential service error. |
1747| 19100005 | Credential authentication server error. |
1748| 19100008 | The file is not a DLP file. |
1749| 19100009 | Failed to operate the DLP file. |
1750| 19100011 | The system ability works abnormally. |
1751| 19100018 | The application is not authorized. |
1752| 19100019 | The DLP file has expired. |
1753| 19100020 | No network connection. |
1754
1755**示例:**
1756
1757```ts
1758import { dlpPermission } from '@kit.DataProtectionKit';
1759import { fileIo } from '@kit.CoreFileKit';
1760import { bundleManager } from '@kit.AbilityKit';
1761import { BusinessError } from '@kit.BasicServicesKit';
1762
1763async function ExampleFunction() {
1764  let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1765  let file: number | undefined = undefined;
1766  let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
1767  let appId = '';
1768  let bundleName = 'com.ohos.note';
1769  let userId = 100;
1770  let dlpFile: dlpPermission.DLPFile | undefined = undefined;
1771
1772  try {
1773    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
1774    appId = data.signatureInfo.appId;
1775  } catch (err) {
1776    console.error('error', err.code, err.message);
1777  }
1778
1779  try {
1780    file = fileIo.openSync(uri).fd;
1781    dlpFile = await dlpPermission.openDLPFile(file, appId); // 打开DLP文件。
1782  } catch (err) {
1783    console.error('error', (err as BusinessError).code, (err as BusinessError).message); // 失败报错。
1784    dlpFile?.closeDLPFile(); // 关闭DLP对象。
1785  } finally {
1786    if (file) {
1787      fileIo.closeSync(file);
1788    }
1789  }
1790}
1791```
1792
1793## dlpPermission.openDLPFile<sup>11+</sup>
1794
1795openDLPFile(ciphertextFd: number, appId: string, callback: AsyncCallback&lt;DLPFile&gt;): void
1796
1797DLP管理应用调用该接口,打开DLP文件。获取DLPFile管理对象,使用callback方式异步返回结果。
1798
1799**系统接口:** 此接口为系统接口。
1800
1801**需要权限:** ohos.permission.ACCESS_DLP_FILE
1802
1803**系统能力:** SystemCapability.Security.DataLossPrevention
1804
1805**参数:**
1806
1807| 参数名 | 类型 | 必填 | 说明 |
1808| -------- | -------- | -------- | -------- |
1809| ciphertextFd | number | 是 | 加密文件的fd。 |
1810| appId | string | 是 | 调用方身份。最小8字节,最大1024字节。 |
1811| callback | AsyncCallback&lt;[DLPFile](#dlpfile)&gt; | 是 | 回调函数。返回DLPFile对象。 |
1812
1813**错误码:**
1814
1815以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[DLP服务错误码](errorcode-dlp.md)。
1816
1817| 错误码ID | 错误信息 |
1818| -------- | -------- |
1819| 201 | Permission denied. |
1820| 202 | Non-system applications use system APIs. |
1821| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1822| 19100001 | Invalid parameter value. |
1823| 19100002 | Credential service busy due to too many tasks or duplicate tasks. |
1824| 19100003 | Credential task time out. |
1825| 19100004 | Credential service error. |
1826| 19100005 | Credential authentication server error. |
1827| 19100008 | The file is not a DLP file. |
1828| 19100009 | Failed to operate the DLP file. |
1829| 19100011 | The system ability works abnormally. |
1830| 19100018 | The application is not authorized. |
1831| 19100019 | The DLP file has expired. |
1832| 19100020 | No network connection. |
1833
1834**示例:**
1835
1836```ts
1837import { dlpPermission } from '@kit.DataProtectionKit';
1838import { fileIo } from '@kit.CoreFileKit';
1839import { bundleManager } from '@kit.AbilityKit';
1840import { BusinessError } from '@kit.BasicServicesKit';
1841
1842let uri = 'file://docs/storage/Users/currentUser/Desktop/test.txt.dlp';
1843let file: number | undefined = undefined;
1844let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
1845let appId = '';
1846let bundleName = 'com.ohos.note';
1847let userId = 100;
1848
1849try{
1850  let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
1851  appId = data.signatureInfo.appId;
1852} catch (err) {
1853  console.error('error', err.code, err.message);
1854}
1855
1856try {
1857  file = fileIo.openSync(uri).fd;
1858  dlpPermission.openDLPFile(file, appId, (err, res) => { // 打开DLP文件。
1859    if (err !== undefined) {
1860      console.error('openDLPFile error,', err.code, err.message);
1861    } else {
1862      console.info('res', JSON.stringify(res));
1863    }
1864    if (file) {
1865      fileIo.closeSync(file);
1866    }
1867  });
1868} catch (err) {
1869  console.error('error,', (err as BusinessError).code, (err as BusinessError).message);
1870  if (file) {
1871    fileIo.closeSync(file);
1872  }
1873}
1874```
1875
1876## dlpPermission.generateDlpFileForEnterprise<sup>20+</sup>
1877
1878generateDLPFileForEnterprise(plaintextFd: number, dlpFd: number, property: DLPProperty, customProperty: CustomProperty): Promise&lt;void&gt;
1879
1880获取DLPFile管理对象。使用Promise异步回调。
1881>**说明:**
1882>
1883> 使用该接口可以将明文文件加密生成权限受控文件,仅拥有完全控制权限的用户可以打开。
1884
1885**系统接口:** 此接口为系统接口。
1886
1887**需要权限:** ohos.permission.ENTERPEISE_ACCESS_DLP_FILE
1888
1889**系统能力:** SystemCapability.Security.DataLossPrevention
1890
1891**参数:**
1892
1893| 参数名 | 类型 | 必填 | 说明 |
1894| -------- | -------- | -------- | -------- |
1895| plaintextFd | number | 是 | 明文文件的fd。 |
1896| dlpFd | number | 是 | 加密文件的fd。 |
1897| property | [DLPProperty](#dlpproperty) | 是 | DLP文件通用策略。 |
1898| customProperty | [CustomProperty](#customproperty20) | 是 | 企业定制策略。 |
1899
1900**返回值:**
1901
1902| 类型 | 说明 |
1903| -------- | -------- |
1904| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
1905
1906**错误码:**
1907
1908以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[DLP服务错误码](errorcode-dlp.md)。
1909
1910| 错误码ID | 错误信息 |
1911| -------- | -------- |
1912| 201 | Permission denied. |
1913| 202 | Non-system applications use system APIs. |
1914| 19100001 | Invalid parameter value. |
1915| 19100002 | Credential service busy due to too many tasks or duplicate tasks. |
1916| 19100003 | Credential task time out. |
1917| 19100004 | Credential service error. |
1918| 19100005 | Credential authentication server error. |
1919| 19100009 | Failed to operate the DLP file. |
1920| 19100011 | The system ability works abnormally. |
1921
1922**示例:**
1923
1924```ts
1925import { dlpPermission } from '@kit.DataProtectionKit';
1926import { fileIo } from '@kit.CoreFileKit';
1927import { BusinessError } from '@kit.BasicServicesKit';
1928
1929async function ExampleFunction(plainFilePath: string, dlpFilePath: string) {
1930  let plaintextFd: number | undefined = undefined;
1931  let dlpFd: number | undefined = undefined;
1932  try {
1933    plaintextFd = fileIo.openSync(plainFilePath, fileIo.OpenMode.READ_ONLY).fd;
1934    dlpFd = fileIo.openSync(dlpFilePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE).fd;
1935    let dlpProperty: dlpPermission.DLPProperty = {
1936      ownerAccount: 'zhangsan',
1937      ownerAccountType: dlpPermission.AccountType.DOMAIN_ACCOUNT,
1938      authUserList: [],
1939      contactAccount: 'zhangsan',
1940      offlineAccess: true,
1941      ownerAccountID: 'xxxxxxx',
1942      everyoneAccessList: []
1943    };
1944    let customProperty: dlpPermission.CustomProperty = {
1945      enterprise: 'customProperty'
1946    };
1947    await dlpPermission.generateDlpFileForEnterprise(plaintextFd, dlpFd, dlpProperty, customProperty);
1948    console.info('Successfully generate DLP file for enterprise.');
1949  } catch(err) {
1950    console.error('error,', (err as BusinessError).code, (err as BusinessError).message);
1951  } finally {
1952    if (dlpFd) {
1953      fileIo.closeSync(dlpFd);
1954    }
1955    if (plaintextFd) {
1956      fileIo.closeSync(plaintextFd);
1957    }
1958  }
1959}
1960```
1961
1962## dlpPermission.decryptDlpFile<sup>20+</sup>
1963
1964decryptDlpFile(dlpFd: number, plaintextFd: number): Promise&lt;void&gt;
1965
1966将DLP文件解密生成明文文件。使用Promise异步回调。
1967>**说明:**
1968>
1969> 仅拥有完全控制权限的用户可以解密DLP文件。
1970
1971**系统接口:** 此接口为系统接口。
1972
1973**需要权限:** ohos.permission.ENTERPEISE_ACCESS_DLP_FILE
1974
1975**系统能力:** SystemCapability.Security.DataLossPrevention
1976
1977**参数:**
1978
1979| 参数名 | 类型 | 必填 | 说明 |
1980| -------- | -------- | -------- | -------- |
1981| dlpFd | number | 是 | 待解密文件的fd。 |
1982| plaintextFd | number | 是 | 目标解密文件的fd。 |
1983
1984**返回值:**
1985
1986| 类型 | 说明 |
1987| -------- | -------- |
1988| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
1989
1990**错误码:**
1991
1992以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[DLP服务错误码](errorcode-dlp.md)。
1993
1994| 错误码ID | 错误信息 |
1995| -------- | -------- |
1996| 201 | Permission denied. |
1997| 202 | Non-system applications use system APIs. |
1998| 19100001 | Invalid parameter value. |
1999| 19100002 | Credential service busy due to too many tasks or duplicate tasks. |
2000| 19100003 | Credential task time out. |
2001| 19100004 | Credential service error. |
2002| 19100005 | Credential authentication server error. |
2003| 19100008 | The file is not a DLP file. |
2004| 19100009 | Failed to operate the DLP file. |
2005| 19100011 | The system ability works abnormally. |
2006| 19100013 | The user does not have the permission. |
2007
2008**示例:**
2009
2010```ts
2011import { dlpPermission } from '@kit.DataProtectionKit';
2012import { fileIo } from '@kit.CoreFileKit';
2013import { BusinessError } from '@kit.BasicServicesKit';
2014
2015async function ExampleFunction(plainFilePath: string, dlpFilePath: string) {
2016  let plaintextFd: number | undefined = undefined;
2017  let dlpFd: number | undefined = undefined;
2018  try {
2019    plaintextFd = fileIo.openSync(plainFilePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE).fd;
2020    dlpFd = fileIo.openSync(dlpFilePath, fileIo.OpenMode.READ_ONLY).fd;
2021    await dlpPermission.decryptDlpFile(dlpFd, plaintextFd);
2022    console.info('Successfully decrypt DLP file.');
2023  } catch(err) {
2024    console.error('error,', (err as BusinessError).code, (err as BusinessError).message);
2025  } finally {
2026    if (dlpFd) {
2027      fileIo.closeSync(dlpFd);
2028    }
2029    if (plaintextFd) {
2030      fileIo.closeSync(plaintextFd);
2031    }
2032  }
2033}
2034```
2035
2036## dlpPermission.queryDlpPolicy<sup>20+</sup>
2037
2038queryDlpPolicy(dlpFd: number): Promise&lt;string&gt;
2039
2040在DLP文件中解析文件头,获取DLP明文策略。使用Promise异步回调。
2041
2042**系统接口:** 此接口为系统接口。
2043
2044**需要权限:** ohos.permission.ENTERPEISE_ACCESS_DLP_FILE
2045
2046**系统能力:** SystemCapability.Security.DataLossPrevention
2047
2048**参数:**
2049
2050| 参数名 | 类型 | 必填 | 说明 |
2051| -------- | -------- | -------- | -------- |
2052| dlpFd | number | 是 | 待解密文件的fd。 |
2053
2054**返回值:**
2055
2056| 类型 | 说明 |
2057| -------- | -------- |
2058| Promise&lt;string&gt; | Promise对象,返回当前DLP策略的json字符串。 |
2059
2060**错误码:**
2061
2062以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[DLP服务错误码](errorcode-dlp.md)。
2063
2064| 错误码ID | 错误信息 |
2065| -------- | -------- |
2066| 201 | Permission denied. |
2067| 202 | Non-system applications use system APIs. |
2068| 19100001 | Invalid parameter value. |
2069| 19100002 | Credential service busy due to too many tasks or duplicate tasks. |
2070| 19100003 | Credential task time out. |
2071| 19100004 | Credential service error. |
2072| 19100005 | Credential authentication server error. |
2073| 19100008 | The file is not a DLP file. |
2074| 19100009 | Failed to operate the DLP file. |
2075| 19100011 | The system ability works abnormally. |
2076| 19100013 | The user does not have the permission. |
2077
2078**示例:**
2079
2080```ts
2081import { dlpPermission } from '@kit.DataProtectionKit';
2082import { fileIo } from '@kit.CoreFileKit';
2083import { BusinessError } from '@kit.BasicServicesKit';
2084
2085async function ExampleFunction(dlpFilePath: string) {
2086  let dlpFd : number | undefined = undefined;
2087  try {
2088    dlpFd = fileIo.openSync(dlpFilePath, fileIo.OpenMode.READ_ONLY).fd;
2089    let policy: string = await dlpPermission.queryDlpPolicy(dlpFd);
2090    console.info('DLP policy:' + policy);
2091  } catch(err) {
2092    console.error('error,', (err as BusinessError).code, (err as BusinessError).message);
2093  } finally {
2094    if (dlpFd) {
2095      fileIo.closeSync(dlpFd);
2096    }
2097  }
2098}
2099```
2100
2101## DLPSandboxInfo
2102
2103表示DLP沙箱的信息。
2104
2105**系统接口:** 此接口为系统接口。
2106
2107**系统能力:** SystemCapability.Security.DataLossPrevention
2108
2109| 名称 | 类型 | 可读 | 可写 | 说明 |
2110| -------- | -------- | -------- | -------- | -------- |
2111| appIndex | number | 是 | 否 | 表示DLP沙箱应用索引。 |
2112| tokenID | number | 是 | 否 | 表示DLP沙箱应用的tokenID。 |
2113
2114## DLPSandboxState
2115
2116DLP沙箱身份。
2117
2118**系统接口:** 此接口为系统接口。
2119
2120**系统能力:** SystemCapability.Security.DataLossPrevention
2121
2122| 名称 | 类型 | 可读 | 可写 | 说明 |
2123| -------- | -------- | -------- | -------- | -------- |
2124| bundleName | string | 是 | 否 | 表示应用包名。最小7字节,最大128字节。 |
2125| appIndex | number | 是 | 否 | 表示DLP沙箱应用索引。 |
2126
2127## AccountType
2128
2129授权账号类型的枚举。
2130
2131**系统接口:** 此接口为系统接口。
2132
2133**系统能力:** SystemCapability.Security.DataLossPrevention
2134
2135| 名称 | 值 | 说明 |
2136| -------- | -------- | -------- |
2137| CLOUD_ACCOUNT | 1 | 表示云账号。 |
2138| DOMAIN_ACCOUNT | 2 | 表示域账号。 |
2139
2140## ActionType<sup>20+</sup>
2141
2142表示在文件设定的权限时间到期后所执行的动作,默认为NOT_OPEN。
2143
2144**系统接口:** 此接口为系统接口。
2145
2146**系统能力:** SystemCapability.Security.DataLossPrevention
2147
2148| 名称 | 值 | 说明 |
2149| -------- | -------- | -------- |
2150| NOT_OPEN | 0 | 表示超过权限管控时间后,用户无权限打开DLP文件。 |
2151| OPEN | 1 | 表示超过权限管控时间后,登录账号的用户拥有编辑权限。 |
2152
2153## AuthUser
2154
2155表示授权用户数据。
2156
2157**系统接口:** 此接口为系统接口。
2158
2159**系统能力:** SystemCapability.Security.DataLossPrevention
2160
2161| 名称 | 类型 | 只读 | 可选 | 说明 |
2162| -------- | -------- | -------- | -------- | -------- |
2163| authAccount | string | 否 | 否 | 表示被授权用户账号。不超过255字节。 |
2164| authAccountType | [AccountType](#accounttype) | 否 | 否 | 表示被授权用户账号类型。 |
2165| dlpFileAccess | [DLPFileAccess](js-apis-dlppermission.md#dlpfileaccess) | 否 | 否 | 表示被授予的权限。 |
2166| permExpiryTime | number | 否 | 否 | 表示授权到期时间。 |
2167
2168## CustomProperty<sup>20+</sup>
2169
2170表示自定义策略。
2171
2172**系统接口:** 此接口为系统接口。
2173
2174**系统能力:** SystemCapability.Security.DataLossPrevention
2175
2176| 名称 | 类型 | 只读 | 可选 | 说明 |
2177| -------- | -------- | -------- | -------- | -------- |
2178| enterprise | string | 否 | 否 | 表示企业定制策略的json字符串。长度不超过4M(单位:兆)。 |
2179
2180## DLPProperty
2181
2182表示授权相关信息。
2183
2184**系统接口:** 此接口为系统接口。
2185
2186**系统能力:** SystemCapability.Security.DataLossPrevention
2187
2188| 名称 | 类型 | 只读 | 可选 | 说明 |
2189| -------- | -------- | -------- | -------- | -------- |
2190| ownerAccount | string | 否 | 否 | 表示权限设置者账号。不超过255字节。 |
2191| ownerAccountID | string | 否 | 否 | 表示权限设置者账号的ID。不超过255字节。 |
2192| ownerAccountType | [AccountType](#accounttype) | 否 | 否 | 表示权限设置者账号类型。 |
2193| authUserList | Array&lt;[AuthUser](#authuser)&gt; | 否 | 是 | 表示授权用户列表,默认为空。 |
2194| contactAccount | string | 否 | 否 | 表示联系人账号。不超过255字节。 |
2195| offlineAccess | boolean | 否 | 否 | 表示是否是离线打开。true表示允许离线打开,false表示不可离线打开。 |
2196| everyoneAccessList | Array&lt;[DLPFileAccess](js-apis-dlppermission.md#dlpfileaccess)&gt; | 否 | 是 | 表示授予所有人的权限,默认为空。 |
2197| expireTime<sup>11+</sup> | number | 否 | 是 | 表示文件权限到期时间戳,默认为空。 |
2198| actionUponExpiry<sup>20+</sup> | [ActionType](#actiontype20) | 否 | 是 | 表示到期后文件是否允许打开(打开后拥有编辑权限),仅在expireTime不为空时生效。 |
2199
2200## GatheringPolicyType
2201
2202DLP沙箱聚合策略类型的枚举。沙箱聚合表示同一权限类型的DLP文件,在同一个沙箱内打开,例如在同一个沙箱内使用不同tab页打开;沙箱非聚合表示不同DLP文件在不同沙箱打开。
2203
2204**系统能力:** SystemCapability.Security.DataLossPrevention
2205
2206**系统接口:** 此接口为系统接口。
2207
2208**参数:**
2209
2210| 名称 | 值 | 说明 |
2211| -------- | -------- | -------- |
2212| GATHERING | 1 | 表示沙箱聚合。 |
2213| NON_GATHERING | 2 | 表示沙箱非聚合。 |