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