We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesSystemSecurityData Protection KitDLP ServiceDLP Service Development (ArkTS)

DLP Service Development (ArkTS)

The Data Loss Prevention (DLP) service is a system solution provided to prevent leakage of sensitive data. It provides a file format called DLP. A DLP file consists of the original file in ciphertext and the authorization credential, and ".dlp" is added to the end of the original file name (including the file name extension), for example, test.docx.dlp.

A DLP file can be accessed only after successful device-cloud authentication (network connection required). The permissions for a DLP file include the following:

  • Read-only: The user can only view the file.

  • Edit: The user can read and write the file, but cannot change the permission on the file.

  • Full control: The user can read and write the file, change the permission on the file, and restore the plaintext of the file.

When an application accesses a DLP file, the system automatically installs a dual application, a copy based on the current application. Both can run at the same time without affecting each other. The dual application is running in a sandbox, which restricts external access to prevent data leakage. For simplicity, the dual application running in a sandbox is referred to as sandbox application. Each time a DLP file is opened, a sandbox application is generated. The sandbox applications are also isolated from each other. When an application is closed, its sandbox application will be automatically uninstalled and the temporary data generated in the sandbox directory will be cleared.

Normally, the application is unaware of the sandbox and accesses the file in plaintext, like accessing a common file. However, the DLP sandbox restricts the application from accessing external resources (such as the network, clipboard, screenshot capturing, screen recording, and Bluetooth). For better user experience, you need to adapt your application to service requirements. For example, for a read-only file, you'd better hide the Save button and disable automatic Internet access.

Sandbox Restrictions

The sandbox also restricts the permissions granted to the application based on the permission on the DLP file.

Expand
Application Permission Description Read-Only Edit/Full Control
ohos.permission.USE_BLUETOOTH Allows an application to use Bluetooth. Forbidden Forbidden
ohos.permission.INTERNET Allows an application to access the Internet. Forbidden Forbidden
ohos.permission.DISTRIBUTED_DATASYNC Allows an application to exchange user data (such as images, music, videos, and application data) with another device. Forbidden Forbidden
ohos.permission.WRITE_MEDIA Allows an application to read and write media files, such as videos, audio clips, and images. Forbidden Allowed
ohos.permission.NFC_TAG Allows an application to use NFC. Forbidden Allowed

Available APIs

Expand
API Description

isDLPFile(fd: number): Promise<boolean>

isDLPFile(fd: number, callback: AsyncCallback<boolean>): void

Checks whether a file is a DLP file.

getDLPPermissionInfo(): Promise<DLPPermissionInfo>

getDLPPermissionInfo(callback: AsyncCallback<DLPPermissionInfo>): void

Obtains the DLP permission information of this sandbox application.
getOriginalFileName(fileName: string): string Obtains the original name of a DLP file.
getDLPSuffix(): string Obtains the file name extension of this DLP file.
on(type: 'openDLPFile', listener: Callback<AccessedDLPFileInfo>): void Subscribes to the DLP file open event.
off(type: 'openDLPFile', listener?: Callback<AccessedDLPFileInfo>): void Unsubscribes from the DLP file open event.

isInSandbox(): Promise<boolean>

isInSandbox(callback: AsyncCallback<boolean>): void

Checks whether this application is a sandbox application.

getDLPSupportedFileTypes(): Promise<Array<string>>

getDLPSupportedFileTypes(callback: AsyncCallback<Array<string>>): void

Obtains the file name extension types that can be appended with .dlp.

setRetentionState(docUris: Array<string>): Promise<void>

setRetentionState(docUris: Array<string>, callback: AsyncCallback<void>): void

Sets the sandbox application retention state. If the retention state is set, the sandbox application will not be automatically uninstalled after being closed.

cancelRetentionState(docUris: Array<string>): Promise<void>

cancelRetentionState(docUris: Array<string>, callback: AsyncCallback<void>): void

Cancels the sandbox application retention state.

getRetentionSandboxList(bundleName?: string): Promise<Array<RetentionSandboxInfo>>

getRetentionSandboxList(bundleName: string, callback: AsyncCallback<Array<RetentionSandboxInfo>>): void

getRetentionSandboxList(callback: AsyncCallback<Array<RetentionSandboxInfo>>): void

Obtains the sandbox applications in the retention state.

getDLPFileAccessRecords(): Promise<Array<AccessedDLPFileInfo>>

getDLPFileAccessRecords(callback: AsyncCallback<Array<AccessedDLPFileInfo>>): void

Obtains the recently accessed DLP files.
setSandboxAppConfig(configInfo: string): Promise<void> Sets sandbox application configuration.
getSandboxAppConfig(): Promise<string> Obtains the sandbox application configuration.
cleanSandboxAppConfig(): Promise<void> Clears the sandbox application configuration.
startDLPManagerForResult(context: common.UIAbilityContext, want: Want): Promise<DLPManagerResult> Starts the DLP manager application on the current UIAbility page in borderless mode (available only for the stage model).

How to Develop

DLP is a system-level data protection solution that can be integrated into your application with minor adaptation or without adaptation.

When a DLP file is opened using the default application or a specified application, the DLP framework:

  1. Installs a sandbox application for your application.

  2. Binds a Filesystem in Userspace (FUSE) file to the DLP file.

  3. Shares the FUSE file with the DLP sandbox application.

This allows the sandbox application to seamlessly access the decrypted content of the DLP file, without aware of the encryption and decryption process.

To incorporate the DLP feature (support opening of DLP files) to a third-party application, perform the following adaptation.

Prerequisites

Before you start, ensure that the following conditions are met:

  • Your application supports one or more of the following file types:

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. ".doc", ".docm", ".docx", ".dot", ".dotm", ".dotx", ".odp", ".odt", ".pdf", ".pot", ".potm", ".potx", ".ppa",
    2. ".ppam", ".pps", ".ppsm", ".ppsx", ".ppt", ".pptm", ".pptx", ".rtf", ".txt", ".wps", ".xla", ".xlam", ".xls",
    3. ".xlsb", ".xlsm", ".xlsx", ".xlt", ".xltm", ".xltx", ".xlw", ".xml", ".xps"
  • The application must have ohos.want.action.viewData or ohos.want.action.editData configured under skills in the module.json5 file.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. "skills":[
    2. {
    3. "entities":[
    4. ...
    5. ],
    6. "actions":[
    7. ...
    8. "ohos.want.action.viewData"
    9. ]
    10. }
    11. ]
  • The device supports domain accounts.

Importing Modules

Import the dlpPermission module.

Collapse
Word wrap
Dark theme
Copy code
  1. import { dlpPermission } from '@kit.DataProtectionKit';

Opening the FUSE File

Generally, an application can open the FUSE file without adaptation if it can open the files mentioned in Prerequisites and there is no restriction on the Want parameter.

When a DLP file is opened, a sandbox application will be installed for the application. The sandbox application receives a Want request and parses the fields in the request.

Collapse
Word wrap
Dark theme
Copy code
  1. import Want from '@ohos.app.ability.Want';
  2. interface DLPUriObj {
  3. name: string
  4. };
  5. interface DLPWriteable {
  6. name:boolean
  7. };
  8. interface DLPNameObj {
  9. dateModified: string,
  10. displayName: string,
  11. relativePath: string,
  12. };
  13. interface DLPLinkNameObj {
  14. name: string
  15. };
  16. function getParams(want: Want) {
  17. // Receive the parameters passed after the DLP file is opened.
  18. let dlpFuseUri: string = want.uri? want.uri : ''; // URI of the FUSE file, which stores the decrypted plaintext.
  19. let dlpFuseWriteable: boolean = (want.parameters?.linkFileWriteable as DLPWriteable).name; // Whether the FUSE file is writeable.
  20. let dlpUri: string = (want.parameters?.dlpUri as DLPUriObj).name; // URI of the DLP file.
  21. let dlpName: string = (want.parameters?.fileAsset as DLPNameObj).displayName; // DLP file name.
  22. let dlpFuseName: string = (want.parameters?.linkFileName as DLPLinkNameObj).name; // FUSE file name.
  23. }

The sandbox application opens the FUSE file based on want.uri, obtains the FD, and then obtains the content of the FUSE file based on the FD.

Collapse
Word wrap
Dark theme
Copy code
  1. import fileIo from '@ohos.fileio';
  2. import fs from '@ohos.file.fs';
  3. import util from '@ohos.util';
  4. function readFileContent(dlpFuseUri:string): string {
  5. let content: string = '';
  6. let file: fs.File;
  7. try {
  8. file = fs.openSync(dlpFuseUri, fs.OpenMode.READ_ONLY); // Open the FUSE file and obtain the FD.
  9. this.commonFd = file.fd;
  10. } catch (err) {
  11. console.error('openSync failed. ' + err);
  12. return content;
  13. }
  14. try {
  15. let buffer = new ArrayBuffer(4096);
  16. let readOut = fs.readSync(this.commonFd, buffer, { // Read the file content.
  17. offset: 0
  18. });
  19. content = bufferToString(buffer); // Convert the file content to a string.
  20. } catch (err) {
  21. console.error('readSync failed. ' + err);
  22. }
  23. fileIo.closeSync(this.commonFd); // Close the file.
  24. return content;
  25. }
  26. function bufferToString(buffer: ArrayBuffer): string {
  27. let textDecoder = new util.TextDecoder('utf-8', {
  28. ignoreBOM: true
  29. });
  30. let resultPut = textDecoder.decodeWithStream(new Uint8Array(buffer), {
  31. stream: true
  32. });
  33. return resultPut;
  34. }

If the FUSE file is readable and writeable, you can also update the FUSE file content.

Collapse
Word wrap
Dark theme
Copy code
  1. import fs from '@ohos.file.fs';
  2. function writeFileContent(dlpFuseUri: string, content: string): void {
  3. let file: fs.File = fs.openSync(dlpFuseUri, fs.OpenMode.READ_WRITE); // Open the FUSE file in read/write mode.
  4. let writeLen: number = fs.writeSync(file.fd, content); // Write data to the FUSE file.
  5. fs.closeSync(file); // Close the file.
  6. }

Setting the UI Based on the DLP File Permission

Use getDLPPermissionInfo to obtain the user permission and operations allowed for the login domain account on the DLP file. The operations allowed vary with the user permission.

Collapse
Word wrap
Dark theme
Copy code
  1. import { dlpPermission } from '@kit.DataProtectionKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. dlpPermission.getDLPPermissionInfo().then((data: dlpPermission.DLPPermissionInfo)=> {
  4. let userAccess: dlpPermission.DLPPermissionInfo.DLPFileAccess = data.dlpFileAccess; // User permission on the DLP file, which can be read-only, edit, or full control.
  5. let isEditable: number = data.flags & dlpPermission.DLPPermissionInfo.ACTION_EDIT; // Operations allowed on the DLP file.
  6. }).catch((err: BusinessError) => {
  7. console.error('getDLPPermissionInfo: ' + JSON.stringify(err));
  8. });

In DLPPermissionInfo returned by getDLPPermissionInfo, dlpFileAccess indicates the user permission and flags is the bitwise combination of the operations allowed. You can determine the allowed operations based on ActionFlagType and disable the related buttons on the UI.

Sharing Data Between an Application and Its Sandbox Application

Since the sandbox application is isolated from the application, its data is different from that of the application. To share data between them, you can use the data sharing mechanism provided by the DLP framework. For example, the application and its sandbox application can share the configuration for determining whether the privacy statement window has been displayed.

Generally, the configuration can be written and read in any of the following sequences:

  • The application writes the configuration and then reads the configuration.

  • The application writes the configuration, and the sandbox application reads the configuration.

  • The sandbox application writes the configuration and then reads the configuration.

  • The sandbox application writes the configuration, and the application reads the configuration.

Constraints

  • Each time the API for setting the configuration is called, the settings overwrite the previous ones.

  • To prevent data leakage, the configuration written by a sandbox application must be completed before the FUSE file content is read.

Procedure

  1. Set the configuration information.

    Convert the configuration information to the string type and call setSandboxAppConfig to set the configuration information for the sandbox application.

    Both an application and its sandbox application can call this API. However, the DLP sandbox application can call this API only before reading the DLP file content.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { dlpPermission } from '@kit.DataProtectionKit';
    2. import { BusinessError } from '@kit.BasicServicesKit';
    3. async function setSandboxAppConfig() {
    4. try {
    5. await dlpPermission.setSandboxAppConfig('configInfo'); // Set configuration information.
    6. } catch (err) {
    7. console.error('setSandboxAppConfig error, ', (err as BusinessError).code, (err as BusinessError).message); // Throw an error if the operation fails.
    8. }
    9. }
  2. Clear the configuration information.

    Call cleanSandboxAppConfig to clear all configuration of the sandbox application.

    This API can be called only by a common application.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { dlpPermission } from '@kit.DataProtectionKit';
    2. import { BusinessError } from '@kit.BasicServicesKit';
    3. async function cleanSandboxAppConfig() {
    4. try {
    5. await dlpPermission.cleanSandboxAppConfig(); // Clear configuration information.
    6. } catch (err) {
    7. console.error('cleanSandboxAppConfig error, ', (err as BusinessError).code, (err as BusinessError).message); // Throw an error if the operation fails.
    8. }
    9. }
  3. Obtain configuration information.

    Call getSandboxAppConfig to obtain configuration of the sandbox application.

    Both an application and its sandbox application can call this API.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { dlpPermission } from '@kit.DataProtectionKit';
    2. import { BusinessError } from '@kit.BasicServicesKit';
    3. async function getSandboxAppConfig() {
    4. try {
    5. let res:string = await dlpPermission.getSandboxAppConfig(); // Obtain configuration information.
    6. } catch (err) {
    7. console.error('getSandboxAppConfig error, ', (err as BusinessError).code, (err as BusinessError).message); // Throw an error if the operation fails.
    8. }
    9. }

Updating the DLP File Access Record

You can use the APIs provided by the DLP framework to obtain information about the recently accessed DLP files. Scenarios include the following:

  • The application is not started and cannot detect the DLP files accessed by the sandbox application.

    If DLP files are accessed only by the sandbox application, the application can call getDLPFileAccessRecords() to obtain information about the DLP files accessed by the sandbox application when started.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { dlpPermission } from '@kit.DataProtectionKit';
    2. import { BusinessError } from '@kit.BasicServicesKit';
    3. async function getDLPFileAccessRecords() {
    4. try {
    5. let res:Array<dlpPermission.AccessedDLPFileInfo> = await dlpPermission.getDLPFileAccessRecords(); // Obtain a list of recently accessed DLP files.
    6. console.info('res', JSON.stringify(res))
    7. } catch (err) {
    8. console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Throw an error if the operation fails.
    9. }
    10. }
  • The application is started and can detect the DLP files accessed by the sandbox application.

    The application can subscribe to the DLP file open event.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
    2. import { dlpPermission } from '@kit.DataProtectionKit';
    3. import { BusinessError } from '@kit.BasicServicesKit';
    4. export default class TestAbility extends UIAbility {
    5. onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    6. this.subscribe();
    7. }
    8. onDestroy(): void {
    9. this.unSubscribe();
    10. }
    11. event(info: dlpPermission.AccessedDLPFileInfo) {
    12. console.info('openDlpFile event', info.uri, info.lastOpenTime)
    13. }
    14. unSubscribe() {
    15. try {
    16. dlpPermission.off('openDLPFile', this.event); // Unsubscribe from the DLP file open event.
    17. } catch (err) {
    18. console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Throw an error if the operation fails.
    19. }
    20. }
    21. subscribe() {
    22. try {
    23. dlpPermission.on('openDLPFile', this.event); // Subscribe to the DLP file open event.
    24. } catch (err) {
    25. console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Throw an error if the operation fails.
    26. }
    27. }
    28. }

Opening a DLP File in an Application

You can select a DLP file in the list of recently accessed files or using a file Picker and open it as follows:

  1. Set Want as follows:

    Set action to ohos.want.action.viewData.

    Set bundleName and abilityName to the bundle name and ability name of the application that attempts to open the DLP file, respectively.

    Set uri to the URI of the DLP file to open.

    Set fileName in Parameters to the name of the DLP file.

  2. Obtain UIAbilityContext.

  3. Call startAbility of the context to pass in the Want parameter and open the DLP file.

Collapse
Word wrap
Dark theme
Copy code
  1. import { Want } from '@kit.AbilityKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. import common from '@ohos.app.ability.common';
  4. function openDlpFile(dlpUri: string, fileName: string) {
  5. let want: Want = {
  6. "action": "ohos.want.action.viewData",
  7. "bundleName": "com.example.example_bundle_name",
  8. "abilityName": "exampleAbility",
  9. "uri": dlpUri,
  10. "parameters": {
  11. "fileName": {
  12. "name": fileName
  13. }
  14. }
  15. }
  16. let context = getContext() as common.UIAbilityContext; // Obtain UIAbilityContext.
  17. try {
  18. console.log('openDLPFile:' + JSON.stringify(want));
  19. console.log('openDLPFile: delegator:' + JSON.stringify(context));
  20. context.startAbility(want);
  21. } catch (err) {
  22. console.error('openDLPFile startAbility failed', (err as BusinessError).code, (err as BusinessError).message);
  23. return;
  24. }
  25. }

Setting the DLP File Permission in an Application

You can integrate the permission settings button into an application. When opening a common file, you can click the button to open the modal permission settings page of the DLPManager application and generate a DLP file. You can also view the allowed operations for the opened DLP file via the sandbox application.

  • Setting the permission in an application

    Start the DLP manager application in borderless mode.

    • The dlpPermission.startDLPManagerForResult() API can be called only in the UIAbility context and supports only the stage model.
    • In the Want parameter, uri is the URI of a common file, and parameters.displayName is the file name. The two parameters are mandatory.
    • Call dlpPermission.startDLPManagerForResult to open the permission settings page of the DLP manager application, enter the domain account information, and click Save. In the file Picker started, select the directory for saving the DLP file.

    Sample code:

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { common, Want } from '@kit.AbilityKit';
    2. import { BusinessError } from '@kit.BasicServicesKit';
    3. import { dlpPermission } from '@kit.DataLossPreventionKit';
    4. try {
    5. let fileUri: string = "file://docs/storage/Users/currentUser/test.txt";
    6. let fileName: string = "test.txt";
    7. let context = getContext() as common.UIAbilityContext; // Obtain UIAbilityContext.
    8. let want: Want = {
    9. 'uri': fileUri,
    10. 'parameters': {
    11. 'displayName': fileName
    12. }
    13. }; // Request parameters.
    14. dlpPermission.startDLPManagerForResult(context, want).then((res: dlpPermission.DLPManagerResult) => {
    15. console.info('startDLPManagerForResult res.resultCode:' + res.resultCode);
    16. console.info('startDLPManagerForResult res.want:' + JSON.stringify(res.want));
    17. }); // Start the DLPManager application to set permissions.
    18. } catch (err) {
    19. console.error('startDLPManagerForResult error:' + (err as BusinessError).code + (err as BusinessError).message);
    20. }
  • Modifying, obtaining, and removing the DLP permission in a sandbox application

    • If the current account is the user who creates the DLP file, the user can modify the DLP file permission and remove the DLP protection (making the file become a common file). You can call the following code to start the permission settings page of the DLP manager application, and choose Change Encryption or Cancel Encryption. If the current account has the read-only or edit permission on the DLP file, you can call the following code to view the permission of the current user.

      Collapse
      Word wrap
      Dark theme
      Copy code
      1. import { common, Want } from '@kit.AbilityKit';
      2. import { BusinessError } from '@kit.BasicServicesKit';
      3. import { dlpPermission } from '@kit.DataLossPreventionKit';
      4. try {
      5. let fileUri: string = "file://docs/storage/Users/currentUser/test.txt.dlp";// URI of the DLP file.
      6. let fileName: string = "test.txt.dlp";
      7. let context = getContext() as common.UIAbilityContext; // Obtain UIAbilityContext.
      8. let want: Want = {
      9. 'uri': fileUri,
      10. 'parameters': {
      11. 'displayName': fileName
      12. }
      13. }; // Request parameters.
      14. dlpPermission.startDLPManagerForResult(context, want).then((res: dlpPermission.DLPManagerResult) => {
      15. console.info('startDLPManagerForResult res.resultCode:' + res.resultCode);
      16. console.info('startDLPManagerForResult res.want:' + JSON.stringify(res.want));
      17. }); // Start the DLPManager application to set permissions.
      18. } catch (err) {
      19. console.error('startDLPManagerForResult error:' + (err as BusinessError).code + (err as BusinessError).message);
      20. }
    • Call getDLPPermissionInfo to obtain the DLP file permission information of the current user. For details about the permission restrictions of the sandbox application, see Sandbox Restrictions.

      Collapse
      Word wrap
      Dark theme
      Copy code
      1. import { dlpPermission } from '@kit.DataProtectionKit';
      2. import { BusinessError } from '@kit.BasicServicesKit';
      3. dlpPermission.getDLPPermissionInfo().then((data:dlpPermission.DLPPermissionInfo)=> {
      4. console.log('getDLPPermissionInfo, result: ' + JSON.stringify(data));
      5. }).catch((err: BusinessError) => {
      6. console.error('getDLPPermissionInfo: ' + JSON.stringify(err));
      7. });

Other DLP Capabilities

  • Checking whether a file is a DLP file

    Check whether the file specified by the FD is a DLP file. If yes, you can open the file by following the instructions provided in Opening a DLP File.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { dlpPermission } from '@kit.DataProtectionKit';
    2. import { fileIo } from '@kit.CoreFileKit';
    3. import { BusinessError } from '@kit.BasicServicesKit';
    4. let uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
    5. let file = fileIo.openSync(uri);
    6. try {
    7. let res: boolean = dlpPermission.isDLPFile (file.fd); // Check whether the file is a DLP file.
    8. console.info('res', res);
    9. } catch (err) {
    10. console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Throw an error if the operation fails.
    11. }
    12. fileIo.closeSync(file);
  • Checking whether this application is a sandbox application

    Call isInSandbox to check whether this application is a DLP sandbox application. If yes, you can disable or hide corresponding buttons on the UI. For details, see Setting the UI Based on the DLP File Permission. If the DLP file permission is Read-only, you can disable the edit and save entries. If the DLP file permission is Edit, disable the permission settings entry.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. import { dlpPermission } from '@kit.DataProtectionKit';
    2. import { BusinessError } from '@kit.BasicServicesKit';
    3. dlpPermission.isInSandbox().then((data: boolean)=> {
    4. console.log('isInSandbox, result: ' + JSON.stringify(data));
    5. }).catch((err: BusinessError) => {
    6. console.error('isInSandbox: ' + JSON.stringify(err));
    7. });
  • Setting the retention state for a sandbox application

    A sandbox application in the retention state will not be automatically uninstalled when the sandbox application is closed. Then, the sandbox application will be uninstalled only after the retention state is canceled and the sandbox application is closed.

    • Call setRetentionState to set the retention state of a sandbox application. You need to pass in the URIs of the DLP files opened in this sandbox. This API can be called only by a sandbox application.

      Collapse
      Word wrap
      Dark theme
      Copy code
      1. import { dlpPermission } from '@kit.DataProtectionKit';
      2. import { BusinessError } from '@kit.BasicServicesKit';
      3. async function setRetentionSandboxList() {
      4. let docUris: Array<string>=["file://docs/storage/Users/currentUser/Desktop/test.txt.dlp"]
      5. try {
      6. await dlpPermission.setRetentionState (docUris); // Set the sandbox retention state.
      7. } catch (err) {
      8. console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Throw an error if the operation fails.
      9. }
      10. }
    • Call cancelRetentionState to cancel the sandbox retention state. This API can be called only by a sandbox application.

      Collapse
      Word wrap
      Dark theme
      Copy code
      1. import { dlpPermission } from '@kit.DataProtectionKit';
      2. import { BusinessError } from '@kit.BasicServicesKit';
      3. async function setRetentionSandboxList() {
      4. let docUris: Array<string>=["file://docs/storage/Users/currentUser/Desktop/test.txt.dlp"]
      5. try {
      6. await dlpPermission.cancelRetentionState (docUris); // Cancel the retention state of the sandbox application.
      7. } catch (err) {
      8. console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Throw an error if the operation fails.
      9. }
      10. }
    • Call getRetentionSandboxList to obtain the sandbox retention information. This API can be called by a common application and its sandbox application.

      Collapse
      Word wrap
      Dark theme
      Copy code
      1. import { dlpPermission } from '@kit.DataProtectionKit';
      2. import { BusinessError } from '@kit.BasicServicesKit';
      3. async function getRetentionSandboxList() {
      4. try {
      5. let res:Array<dlpPermission.RetentionSandboxInfo> = await dlpPermission.getRetentionSandboxList(); // Obtain retention information of the sandbox application.
      6. console.info('res', JSON.stringify(res))
      7. } catch (err) {
      8. console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Throw an error if the operation fails.
      9. }
      10. }

FAQs

What should I do if the application can open a common file but cannot open the FUSE file?

  • Check for specific restrictions on Want.

  • Check whether the read-only FUSE file is opened with the read/write permission.

Search in Guides
Enter a keyword.