openharmony 鸿蒙 js-apis-dlppermission

2025-06-12 浏览 (1)

@ohos.dlpPermission (DLP)

Data loss prevention (DLP) is a system solution provided to prevent data disclosure. The dlpPermission module provides APIs for cross-device file access management, encrypted storage, and access authorization.

NOTE

  • The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The kit to which @ohos.dlpPermission belongs has been changed from DataLossPreventionKit to DataProtectionKit. You are advised to use the new module name @kit.DataProtectionKit to import the module. If @kit.DataLossPreventionKit is imported, only the APIs before the change can be called and the APIs after the change cannot be used.

Modules to Import

import { dlpPermission } from '@kit.DataProtectionKit';

dlpPermission.isDLPFile

isDLPFile(fd: number): Promise<boolean>

Checks whether a file is a DLP file based on the file descriptor (FD). This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
fdnumberYesFD of the file to check.

Return value

TypeDescription
Promise<boolean>Promise used to return the result. The value true means the file is a DLP file; the value false means the opposite.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
19100001Invalid parameter value.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { fileIo } from '@kit.CoreFileKit';
import { BusinessError } from '@kit.BasicServicesKit';

let uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
let file = fileIo.openSync(uri);

try {
  let res = dlpPermission.isDLPFile(file.fd);  // Check whether the file is a DLP file.
  console.info('res', res);
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}
fileIo.closeSync(file);

dlpPermission.isDLPFile

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

Checks whether a file is a DLP file based on the FD. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
fdnumberYesFD of the file to check.
callbackAsyncCallback<boolean>YesCallback invoked to return the result.
The value true means the file is a DLP file; the value false means the opposite.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
19100001Invalid parameter value.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { fileIo } from '@kit.CoreFileKit';
import { BusinessError } from '@kit.BasicServicesKit';

let uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
let file = fileIo.openSync(uri);

try {
  dlpPermission.isDLPFile(file.fd, (err, res) => {
    if (err != undefined) {
      console.error('isDLPFile error,', err.code, err.message);
    } else {
      console.info('res', res);
    }
    fileIo.closeSync(file);
  });
} catch (err) {
  console.error('isDLPFile error,', (err as BusinessError).code, (err as BusinessError).message);
  fileIo.closeSync(file);
}

dlpPermission.getDLPPermissionInfo

getDLPPermissionInfo(): Promise<DLPPermissionInfo>

Obtains the permission information of this DLP file. This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Return value

TypeDescription
Promise<DLPPermissionInfo>Promise used to return the permission information about the DLP file. The operation is successful if no error is reported.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
19100001Invalid parameter value.
19100006No permission to call this API, which is available only for DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.isInSandbox().then((inSandbox) => {// Check whether the application is running in a sandbox.
    if (inSandbox) {
      let res: Promise<dlpPermission.DLPPermissionInfo> = dlpPermission.getDLPPermissionInfo(); // Obtain the permission information.
      console.info('res', JSON.stringify(res));
    }
  });
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.getDLPPermissionInfo

getDLPPermissionInfo(callback: AsyncCallback<DLPPermissionInfo>): void

Obtains the permission information of this DLP file. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<DLPPermissionInfo>YesCallback invoked to return the result.
If the operation is successful, err is undefined. Otherwise, err is an error object.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Incorrect parameter types.
19100001Invalid parameter value.
19100006No permission to call this API, which is available only for DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { fileIo } from '@kit.CoreFileKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.isInSandbox().then((inSandbox) => {// Check whether the application is running in a sandbox.
    if (inSandbox) {
      dlpPermission.getDLPPermissionInfo((err, res) => {
        if (err != undefined) {
          console.error('getDLPPermissionInfo error,', err.code, err.message);
        } else {
          console.info('res', JSON.stringify(res));
        }
      }); // Obtain the permission information.
    }
  });
} catch (err) {
  console.error('getDLPPermissionInfo error,', (err as BusinessError).code, (err as BusinessError).message);
}

dlpPermission.getOriginalFileName

getOriginalFileName(fileName: string): string

Obtains the original file name of a DLP file. This API returns the result synchronously.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
fileNamestringYesName of the target file.

Return value

TypeDescription
stringOriginal name of the DLP file obtained. For example, if the DLP file name is test.txt.dlp, the original file name returned is test.txt.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
19100001Invalid parameter value.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let res = dlpPermission.getOriginalFileName('test.txt.dlp'); // Obtain the original file name.
  console.info('res', res);
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.getDLPSuffix

getDLPSuffix(): string

Obtains the DLP file name extension. This API returns the result synchronously.

System capability: SystemCapability.Security.DataLossPrevention

Return value

TypeDescription
stringDLP file name extension obtained. For example, if the original file is text.txt and the returned file name extension is .dlp, the DLP file name is test.txt.dlp.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let res = dlpPermission.getDLPSuffix(); // Obtain the DLP file name extension.
  console.info('res', res);
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.on('openDLPFile')

on(type: 'openDLPFile', listener: Callback<AccessedDLPFileInfo>): void

Subscribes to a DLP file open event. The application will be notified when the DLP file is opened.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
type'openDLPFile'YesEvent type. It has a fixed value of openDLPFile, which indicates the DLP file open event.
listenerCallback<AccessedDLPFileInfo>YesCallback invoked when a DLP file is opened. A notification will be sent to the application.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
19100001Invalid parameter value.
19100007No permission to call this API, which is available only for non-DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.on('openDLPFile', (info: dlpPermission.AccessedDLPFileInfo) => {
    console.info('openDlpFile event', info.uri, info.lastOpenTime)
  // Subscribe to the DLP file open event.
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.off('openDLPFile')

off(type: 'openDLPFile', listener?: Callback<AccessedDLPFileInfo>): void

Unsubscribes from the DLP file open event. The application will not be notified when a DLP file is opened.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
type'openDLPFile'YesEvent type. It has a fixed value of openDLPFile, which indicates the DLP file open event.
listenerCallback<AccessedDLPFileInfo>NoCallback for the DLP file open event. The application will not be notified when a DLP file is opened. By default, this parameter is left blank, which unregisters all callbacks for the file open event.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
19100001Invalid parameter value.
19100007No permission to call this API, which is available only for non-DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.off('openDLPFile', (info: dlpPermission.AccessedDLPFileInfo) => {
    console.info('openDlpFile event', info.uri, info.lastOpenTime)
  // Unsubscribe from the DLP file open events.
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.isInSandbox

isInSandbox(): Promise<boolean>

Checks whether this application is running in a DLP sandbox environment. This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
19100001Invalid parameter value.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let inSandbox = dlpPermission.isInSandbox(); // Check whether the application is running in a sandbox.
  console.info('res', inSandbox);
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.isInSandbox

isInSandbox(callback: AsyncCallback<boolean>): void

Checks whether this application is running in a DLP sandbox environment. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<boolean>YesCallback invoked to return the result.
If the operation is successful, err is undefined. Otherwise, err is an error object.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Incorrect parameter types.
19100001Invalid parameter value.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.isInSandbox((err, data) => {
    if (err) {
      console.error('isInSandbox error,', err.code, err.message);
    } else {
      console.info('isInSandbox, data', JSON.stringify(data));
    }
  }); // Check whether the application is running in the sandbox.
} catch (err) {
  console.error('isInSandbox error,', (err as BusinessError).code, (err as BusinessError).message);
}

dlpPermission.getDLPSupportedFileTypes

getDLPSupportedFileTypes(): Promise<Array<string>>

Obtains the file name extension types that support DLP. This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Return value

TypeDescription
Promise<Array<string>>Promise used to return the file name extension types obtained.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
19100001Invalid parameter value.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let res = dlpPermission.getDLPSupportedFileTypes(); // Obtain the file types that support DLP.
  console.info('res', JSON.stringify(res));
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.getDLPSupportedFileTypes

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

Obtains the file name extension types that support DLP. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<string>>YesCallback invoked to return the result.
If the operation is successful, err is undefined. Otherwise, err is an error object.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Incorrect parameter types.
19100001Invalid parameter value.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.getDLPSupportedFileTypes((err, res) => {
    if (err != undefined) {
      console.error('getDLPSupportedFileTypes error,', err.code, err.message);
    } else {
      console.info('res', JSON.stringify(res));
    }
  }); // Obtain the file types that support DLP.
} catch (err) {
  console.error('getDLPSupportedFileTypes error,', (err as BusinessError).code, (err as BusinessError).message);
}

dlpPermission.setRetentionState

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

Sets the sandbox retention state. This API uses a promise to return the result.

A sandbox application is automatically installed when a DLP file is opened, and automatically uninstalled when the DLP file is closed. Once the sandbox retention state is set for a DLP file, the sandbox application will not be automatically uninstalled when the DLP file is closed.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
docUrisArray<string>YesURIs of the files to be set with the retention state.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
19100001Invalid parameter value.
19100006No permission to call this API, which is available only for DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

let uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
try {
  dlpPermission.isInSandbox().then((inSandbox) => {// Check whether the application is running in a sandbox.
    if (inSandbox) {
      dlpPermission.setRetentionState([uri]); // Set the retention state for a sandbox application.
    }
  });
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.setRetentionState

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

Sets the sandbox retention state. This API uses an asynchronous callback to return the result.

A sandbox application is automatically installed when a DLP file is opened, and automatically uninstalled when the DLP file is closed. Once the sandbox retention state is set for a DLP file, the sandbox application will not be automatically uninstalled when the DLP file is closed.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
docUrisArray<string>YesURIs of the files to be set with the retention state.
callbackAsyncCallback<void>YesCallback invoked to return the result.
If the operation is successful, err is undefined. Otherwise, err is an error object.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
19100001Invalid parameter value.
19100006No permission to call this API, which is available only for DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

let uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
try {
  dlpPermission.setRetentionState([uri], (err, res) => {
    if (err != undefined) {
      console.error('setRetentionState error,', err.code, err.message);
    } else {
      console.info('setRetentionState success');
      console.info('res', JSON.stringify(res));
    }
  }); // Set the sandbox retention state.
} catch (err) {
  console.error('setRetentionState error,', (err as BusinessError).code, (err as BusinessError).message);
}

dlpPermission.cancelRetentionState

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

Cancels the sandbox retention state, that is, allows the sandbox application to be automatically uninstalled when the DLP file is closed. This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
docUrisArray<string>YesURIs of the files whose retention state is to be canceled.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
19100001Invalid parameter value.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

let uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
try {
  dlpPermission.cancelRetentionState([uri]); // Cancel the retention state for a sandbox application.
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.cancelRetentionState

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

Cancels the sandbox retention state, that is, allows the sandbox application to be automatically uninstalled when the DLP file is closed. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
docUrisArray<string>YesURIs of the files whose retention state is to be canceled.
callbackAsyncCallback<void>YesCallback invoked to return the result.
If the operation is successful, err is undefined. Otherwise, err is an error object.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
19100001Invalid parameter value.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

let uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp";
try {
  dlpPermission.cancelRetentionState([uri], (err, res) => {
    if (err != undefined) {
      console.error('cancelRetentionState error,', err.code, err.message);
    } else {
      console.info('cancelRetentionState success');
    }
  }); // Cancel the sandbox retention state.
} catch (err) {
  console.error('cancelRetentionState error,', (err as BusinessError).code, (err as BusinessError).message);
}

dlpPermission.getRetentionSandboxList

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

Obtains the sandbox applications in the retention state of an application. This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
bundleNamestringNoBundle name of the application. By default, this parameter is left empty, which obtains the sandbox retention information about the current application.

Return value

TypeDescription
Promise<Array<RetentionSandboxInfo>>Promise used to return the sandbox retention information obtained.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Incorrect parameter types.
19100001Invalid parameter value.
19100007No permission to call this API, which is available only for non-DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let res: Promise<Array<dlpPermission.RetentionSandboxInfo>> = dlpPermission.getRetentionSandboxList(); // Obtain all the sandbox applications in the retention state.
  console.info('res', JSON.stringify(res))
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.getRetentionSandboxList

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

Obtains the sandbox applications in the retention state of an application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.
callbackAsyncCallback<Array<RetentionSandboxInfo>>YesCallback invoked to return the result.
If the operation is successful, err is undefined. Otherwise, err is an error object.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Incorrect parameter types.
19100001Invalid parameter value.
19100007No permission to call this API, which is available only for non-DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.getRetentionSandboxList("bundleName", (err, res) => {
    if (err != undefined) {
      console.error('getRetentionSandboxList error,', err.code, err.message);
    } else {
      console.info('res', JSON.stringify(res));
    }
  }); // Obtain the sandbox retention information.
} catch (err) {
  console.error('getRetentionSandboxList error,', (err as BusinessError).code, (err as BusinessError).message);
}

dlpPermission.getRetentionSandboxList

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

Obtains the sandbox applications in the retention state of this application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<RetentionSandboxInfo>>YesCallback invoked to return the result.
If the operation is successful, err is undefined. Otherwise, err is an error object.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Incorrect parameter types.
19100001Invalid parameter value.
19100007No permission to call this API, which is available only for non-DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.getRetentionSandboxList((err, res) => {
    if (err != undefined) {
      console.error('getRetentionSandboxList error,', err.code, err.message);
    } else {
      console.info('res', JSON.stringify(res));
    }
  }); // Obtain the sandbox retention information.
} catch (err) {
  console.error('getRetentionSandboxList error,', (err as BusinessError).code, (err as BusinessError).message);
}

dlpPermission.getDLPFileAccessRecords

getDLPFileAccessRecords(): Promise<Array<AccessedDLPFileInfo>>

Obtains the list of DLP files that are accessed recently. This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Return value

TypeDescription
Promise<Array<AccessedDLPFileInfo>>Promise used to return the list of recently accessed files obtained.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
19100001Invalid parameter value.
19100007No permission to call this API, which is available only for non-DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let res: Promise<Array<dlpPermission.AccessedDLPFileInfo>> = dlpPermission.getDLPFileAccessRecords(); // Obtain the list of recently accessed DLP files.
  console.info('res', JSON.stringify(res))
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.getDLPFileAccessRecords

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

Obtains the list of DLP files that are accessed recently. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<AccessedDLPFileInfo>>YesCallback invoked to return the result.
If the operation is successful, err is undefined. Otherwise, err is an error object.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Incorrect parameter types.
19100001Invalid parameter value.
19100007No permission to call this API, which is available only for non-DLP sandbox applications.
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.getDLPFileAccessRecords((err, res) => {
    if (err != undefined) {
      console.error('getDLPFileAccessRecords error,', err.code, err.message);
    } else {
      console.info('res', JSON.stringify(res));
    }
  }); // Obtain the list of recently accessed DLP files.
} catch (err) {
  console.error('getDLPFileAccessRecords error,', (err as BusinessError).code, (err as BusinessError).message);
}

dlpPermission.startDLPManagerForResult11+

startDLPManagerForResult(context: common.UIAbilityContext, want: Want): Promise<DLPManagerResult>

Starts the DLP manager application on the current UIAbility page in borderless mode. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
contextcommon.UIAbilityContextYesUIAbility context.
wantWantYesObject that requests the start of the DLP manager application.

Return value

TypeDescription
Promise<DLPManagerResult>Promise used to return the DLPManagerResult object.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
19100001Invalid parameter value.
19100011The system ability works abnormally.
19100016uri missing in want.
19100017displayName missing in want.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { common, UIAbility, AbilityConstant, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let context = getContext () as common.UIAbilityContext; // Obtain the UIAbility context.
  let want: Want = {
    "uri": "file://docs/storage/Users/currentUser/Desktop/1.txt",
    "parameters": {
      "displayName": "1.txt"
    }
  }; // Request parameters.
  dlpPermission.startDLPManagerForResult(context, want).then((res) => {
    console.info('res.resultCode', res.resultCode);
    console.info('res.want', JSON.stringify(res.want));
  }); // Start the DLP manager application.
} catch (err) {
  console.error('error', err.code, err.message); // Error reported if the operation fails.
}

dlpPermission.setSandboxAppConfig11+

setSandboxAppConfig(configInfo: string): Promise<void>

Sets sandbox application configuration. This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Parameters

NameTypeMandatoryDescription
configInfostringYesSandbox application configuration.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
19100001Invalid parameter value.
19100007No permission to call this API, which is available only for non-DLP sandbox applications.
19100011The system ability works abnormally.
19100018Not authorized application.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.setSandboxAppConfig('configInfo'); // Set sandbox application configuration.
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.cleanSandboxAppConfig11+

cleanSandboxAppConfig(): Promise<void>

Cleans sandbox application configuration. This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
19100001Invalid parameter value.
19100007No permission to call this API, which is available only for non-DLP sandbox applications.
19100011The system ability works abnormally.
19100018Not authorized application.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.cleanSandboxAppConfig(); // Clean sandbox application configuration.
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.getSandboxAppConfig11+

getSandboxAppConfig(): Promise<string>

Obtains sandbox application configuration. This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Return value

TypeDescription
Promise<string>Promise used to return the sandbox application configuration obtained.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
19100001Invalid parameter value.
19100011The system ability works abnormally.
19100018Not authorized application.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  dlpPermission.getSandboxAppConfig().then((res) => {
    console.info('res', JSON.stringify(res));
  }); // Obtain the sandbox application configuration.
} catch (err) {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
}

dlpPermission.isDLPFeatureProvided12+

isDLPFeatureProvided(): Promise<boolean>

Queries whether the current system provides the DLP feature. This API uses a promise to return the result.

System capability: SystemCapability.Security.DataLossPrevention

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Error codes

For details about the error codes, see DLP Service Error Codes.

IDError Message
19100011The system ability works abnormally.

Example

import { dlpPermission } from '@kit.DataProtectionKit';
import { BusinessError } from '@kit.BasicServicesKit';

dlpPermission.isDLPFeatureProvided().then((res) => {
  console.info('res', JSON.stringify(res));
}).catch((err: BusinessError) => {
  console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails.
});

ActionFlagType

Enumerates the operations that can be performed on a DLP file. For example, the DLP sandbox application can dim its button based on this parameter.

System capability: SystemCapability.Security.DataLossPrevention

NameValueDescription
ACTION_VIEW0x00000001View the file.
ACTION_SAVE0x00000002Save the file.
ACTION_SAVE_AS0x00000004Save the file as another file.
ACTION_EDIT0x00000008Edit the file.
ACTION_SCREEN_CAPTURE0x00000010Capture screenshots of the file.
ACTION_SCREEN_SHARE0x00000020Share the screen of the file.
ACTION_SCREEN_RECORD0x00000040Record the screen on which the file is open.
ACTION_COPY0x00000080Copy the file.
ACTION_PRINT0x00000100Print the file.
ACTION_EXPORT0x00000200Export the file.
ACTION_PERMISSION_CHANGE0x00000400Modify the permissions on the file.

DLPFileAccess

Enumerates the permissions on a DLP file.

System capability: SystemCapability.Security.DataLossPrevention

NameValueDescription
NO_PERMISSION0The user has no permission on the file.
READ_ONLY1The user has only the permission to read the file.
CONTENT_EDIT2The user has the permission to edit the file.
FULL_CONTROL3The user has full control on the file.

DLPPermissionInfo

Represents the permission information about a DLP file.

System capability: SystemCapability.Security.DataLossPrevention

NameTypeReadableWritableDescription
dlpFileAccessDLPFileAccessYesNoUser permission on the DLP file, for example, read-only.
flagsnumberYesNoOperations that can be performed on the DLP file. It is a combination of different ActionFlagTypes.

AccessedDLPFileInfo

Represents the information about a DLP file opened.

System capability: SystemCapability.Security.DataLossPrevention

NameTypeReadableWritableDescription
uristringYesNoURI of the DLP file.
lastOpenTimenumberYesNoTime when the file was last opened.

DLPManagerResult11+

Represents information about the trigger of the DLP manager application.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Security.DataLossPrevention

NameTypeReadableWritableDescription
resultCodenumberYesNoResult code returned after the DLP manager application is started and exits.
wantWantYesNoData returned after the DLP manager application is started and exits.

RetentionSandboxInfo

Represents the sandbox retention information.

System capability: SystemCapability.Security.DataLossPrevention

NameTypeReadableWritableDescription
appIndexnumberYesNoIndex of the DLP sandbox application.
bundleNamestringYesNoBundle name of the application.
docUrisArray<string>YesNoURI list of the DLP files.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Data Protection Kit (Data Protection Service)

harmony 鸿蒙DlpPermissionApi

harmony 鸿蒙dlp_permission_api.h

harmony 鸿蒙DLP Service Error Codes

harmony 鸿蒙@ohos.dlpPermission (DLP) (System API)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/FHnpnf