1e41f4b71Sopenharmony_ci# @ohos.dlpPermission (DLP) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciData 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. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - 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. 8e41f4b71Sopenharmony_ci> - 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. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Modules to Import 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci```ts 13e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## dlpPermission.isDLPFile 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciisDLPFile(fd: number): Promise<boolean> 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ciChecks whether a file is a DLP file based on the file descriptor (FD). This API uses a promise to return the result. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**Parameters** 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 27e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 28e41f4b71Sopenharmony_ci| fd | number | Yes | FD of the file to check. | 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**Return value** 31e41f4b71Sopenharmony_ci| Type | Description | 32e41f4b71Sopenharmony_ci| -------- | -------- | 33e41f4b71Sopenharmony_ci| Promise<boolean> | Promise used to return the result. The value **true** means the file is a DLP file; the value **false** means the opposite. | 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci**Error codes** 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci| ID | Error Message | 40e41f4b71Sopenharmony_ci| -------- | -------- | 41e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 42e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 43e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**Example** 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci```ts 48e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 49e41f4b71Sopenharmony_ciimport { fileIo } from '@kit.CoreFileKit'; 50e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp"; 53e41f4b71Sopenharmony_cilet file = fileIo.openSync(uri); 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_citry { 56e41f4b71Sopenharmony_ci let res = dlpPermission.isDLPFile(file.fd); // Check whether the file is a DLP file. 57e41f4b71Sopenharmony_ci console.info('res', res); 58e41f4b71Sopenharmony_ci} catch (err) { 59e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 60e41f4b71Sopenharmony_ci} 61e41f4b71Sopenharmony_cifileIo.closeSync(file); 62e41f4b71Sopenharmony_ci``` 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci## dlpPermission.isDLPFile 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ciisDLPFile(fd: number, callback: AsyncCallback<boolean>): void 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ciChecks whether a file is a DLP file based on the FD. This API uses an asynchronous callback to return the result. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**Parameters** 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 75e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 76e41f4b71Sopenharmony_ci| fd | number | Yes | FD of the file to check. | 77e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result.<br>The value **true** means the file is a DLP file; the value **false** means the opposite. | 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**Error codes** 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci| ID | Error Message | 84e41f4b71Sopenharmony_ci| -------- | -------- | 85e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 86e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 87e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**Example** 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci```ts 92e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 93e41f4b71Sopenharmony_ciimport { fileIo } from '@kit.CoreFileKit'; 94e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp"; 97e41f4b71Sopenharmony_cilet file = fileIo.openSync(uri); 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_citry { 100e41f4b71Sopenharmony_ci dlpPermission.isDLPFile(file.fd, (err, res) => { 101e41f4b71Sopenharmony_ci if (err != undefined) { 102e41f4b71Sopenharmony_ci console.error('isDLPFile error,', err.code, err.message); 103e41f4b71Sopenharmony_ci } else { 104e41f4b71Sopenharmony_ci console.info('res', res); 105e41f4b71Sopenharmony_ci } 106e41f4b71Sopenharmony_ci fileIo.closeSync(file); 107e41f4b71Sopenharmony_ci }); 108e41f4b71Sopenharmony_ci} catch (err) { 109e41f4b71Sopenharmony_ci console.error('isDLPFile error,', (err as BusinessError).code, (err as BusinessError).message); 110e41f4b71Sopenharmony_ci fileIo.closeSync(file); 111e41f4b71Sopenharmony_ci} 112e41f4b71Sopenharmony_ci``` 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci## dlpPermission.getDLPPermissionInfo 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_cigetDLPPermissionInfo(): Promise<DLPPermissionInfo> 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ciObtains the permission information of this DLP file. This API uses a promise to return the result. 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci**Return value** 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci| Type | Description | 125e41f4b71Sopenharmony_ci| -------- | -------- | 126e41f4b71Sopenharmony_ci| Promise<[DLPPermissionInfo](#dlppermissioninfo)> | Promise used to return the permission information about the DLP file. The operation is successful if no error is reported. | 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**Error codes** 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci| ID | Error Message | 133e41f4b71Sopenharmony_ci| -------- | -------- | 134e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 135e41f4b71Sopenharmony_ci| 19100006 | No permission to call this API, which is available only for DLP sandbox applications. | 136e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**Example** 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci```ts 141e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 142e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_citry { 145e41f4b71Sopenharmony_ci dlpPermission.isInSandbox().then((inSandbox) => {// Check whether the application is running in a sandbox. 146e41f4b71Sopenharmony_ci if (inSandbox) { 147e41f4b71Sopenharmony_ci let res: Promise<dlpPermission.DLPPermissionInfo> = dlpPermission.getDLPPermissionInfo(); // Obtain the permission information. 148e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)); 149e41f4b71Sopenharmony_ci } 150e41f4b71Sopenharmony_ci }); 151e41f4b71Sopenharmony_ci} catch (err) { 152e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 153e41f4b71Sopenharmony_ci} 154e41f4b71Sopenharmony_ci``` 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci## dlpPermission.getDLPPermissionInfo 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_cigetDLPPermissionInfo(callback: AsyncCallback<DLPPermissionInfo>): void 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ciObtains the permission information of this DLP file. This API uses an asynchronous callback to return the result. 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci**Parameters** 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 167e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 168e41f4b71Sopenharmony_ci| callback | AsyncCallback<[DLPPermissionInfo](#dlppermissioninfo)> | Yes | Callback invoked to return the result.<br>If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci**Error codes** 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci| ID | Error Message | 175e41f4b71Sopenharmony_ci| -------- | -------- | 176e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 177e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 178e41f4b71Sopenharmony_ci| 19100006 | No permission to call this API, which is available only for DLP sandbox applications. | 179e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci**Example** 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci```ts 184e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 185e41f4b71Sopenharmony_ciimport { fileIo } from '@kit.CoreFileKit'; 186e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_citry { 189e41f4b71Sopenharmony_ci dlpPermission.isInSandbox().then((inSandbox) => {// Check whether the application is running in a sandbox. 190e41f4b71Sopenharmony_ci if (inSandbox) { 191e41f4b71Sopenharmony_ci dlpPermission.getDLPPermissionInfo((err, res) => { 192e41f4b71Sopenharmony_ci if (err != undefined) { 193e41f4b71Sopenharmony_ci console.error('getDLPPermissionInfo error,', err.code, err.message); 194e41f4b71Sopenharmony_ci } else { 195e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)); 196e41f4b71Sopenharmony_ci } 197e41f4b71Sopenharmony_ci }); // Obtain the permission information. 198e41f4b71Sopenharmony_ci } 199e41f4b71Sopenharmony_ci }); 200e41f4b71Sopenharmony_ci} catch (err) { 201e41f4b71Sopenharmony_ci console.error('getDLPPermissionInfo error,', (err as BusinessError).code, (err as BusinessError).message); 202e41f4b71Sopenharmony_ci} 203e41f4b71Sopenharmony_ci``` 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci## dlpPermission.getOriginalFileName 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_cigetOriginalFileName(fileName: string): string 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ciObtains the original file name of a DLP file. This API returns the result synchronously. 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci**Parameters** 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 216e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 217e41f4b71Sopenharmony_ci| fileName | string | Yes | Name of the target file. | 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci**Return value** 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci| Type | Description | 222e41f4b71Sopenharmony_ci| -------- | -------- | 223e41f4b71Sopenharmony_ci| string | Original 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**. | 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**Error codes** 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci| ID | Error Message | 230e41f4b71Sopenharmony_ci| -------- | -------- | 231e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 232e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci**Example** 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci```ts 237e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 238e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_citry { 241e41f4b71Sopenharmony_ci let res = dlpPermission.getOriginalFileName('test.txt.dlp'); // Obtain the original file name. 242e41f4b71Sopenharmony_ci console.info('res', res); 243e41f4b71Sopenharmony_ci} catch (err) { 244e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 245e41f4b71Sopenharmony_ci} 246e41f4b71Sopenharmony_ci``` 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci## dlpPermission.getDLPSuffix 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_cigetDLPSuffix(): string 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ciObtains the DLP file name extension. This API returns the result synchronously. 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci**Return value** 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci| Type | Description | 259e41f4b71Sopenharmony_ci| -------- | -------- | 260e41f4b71Sopenharmony_ci| string | DLP 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**. | 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci**Error codes** 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci| ID | Error Message | 267e41f4b71Sopenharmony_ci| -------- | -------- | 268e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci**Example** 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci```ts 273e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 274e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_citry { 277e41f4b71Sopenharmony_ci let res = dlpPermission.getDLPSuffix(); // Obtain the DLP file name extension. 278e41f4b71Sopenharmony_ci console.info('res', res); 279e41f4b71Sopenharmony_ci} catch (err) { 280e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 281e41f4b71Sopenharmony_ci} 282e41f4b71Sopenharmony_ci``` 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci## dlpPermission.on('openDLPFile') 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_cion(type: 'openDLPFile', listener: Callback<AccessedDLPFileInfo>): void 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ciSubscribes to a DLP file open event. The application will be notified when the DLP file is opened. 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci**Parameters** 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 295e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 296e41f4b71Sopenharmony_ci| type | 'openDLPFile' | Yes | Event type. It has a fixed value of **openDLPFile**, which indicates the DLP file open event. | 297e41f4b71Sopenharmony_ci| listener | Callback<[AccessedDLPFileInfo](#accesseddlpfileinfo)> | Yes | Callback invoked when a DLP file is opened. A notification will be sent to the application. | 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ci**Error codes** 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci| ID | Error Message | 304e41f4b71Sopenharmony_ci| -------- | -------- | 305e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 306e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 307e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. | 308e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci**Example** 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci```ts 313e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 314e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_citry { 317e41f4b71Sopenharmony_ci dlpPermission.on('openDLPFile', (info: dlpPermission.AccessedDLPFileInfo) => { 318e41f4b71Sopenharmony_ci console.info('openDlpFile event', info.uri, info.lastOpenTime) 319e41f4b71Sopenharmony_ci // Subscribe to the DLP file open event. 320e41f4b71Sopenharmony_ci} catch (err) { 321e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 322e41f4b71Sopenharmony_ci} 323e41f4b71Sopenharmony_ci``` 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci## dlpPermission.off('openDLPFile') 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_cioff(type: 'openDLPFile', listener?: Callback<AccessedDLPFileInfo>): void 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ciUnsubscribes from the DLP file open event. The application will not be notified when a DLP file is opened. 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci**Parameters** 334e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 335e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 336e41f4b71Sopenharmony_ci| type | 'openDLPFile' | Yes | Event type. It has a fixed value of **openDLPFile**, which indicates the DLP file open event. | 337e41f4b71Sopenharmony_ci| listener | Callback<[AccessedDLPFileInfo](#accesseddlpfileinfo)> | No | Callback 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. | 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci**Error codes** 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci| ID | Error Message | 344e41f4b71Sopenharmony_ci| -------- | -------- | 345e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 346e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 347e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. | 348e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci**Example** 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ci```ts 353e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 354e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_citry { 357e41f4b71Sopenharmony_ci dlpPermission.off('openDLPFile', (info: dlpPermission.AccessedDLPFileInfo) => { 358e41f4b71Sopenharmony_ci console.info('openDlpFile event', info.uri, info.lastOpenTime) 359e41f4b71Sopenharmony_ci // Unsubscribe from the DLP file open events. 360e41f4b71Sopenharmony_ci} catch (err) { 361e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 362e41f4b71Sopenharmony_ci} 363e41f4b71Sopenharmony_ci``` 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci## dlpPermission.isInSandbox 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ciisInSandbox(): Promise<boolean> 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ciChecks whether this application is running in a DLP sandbox environment. This API uses a promise to return the result. 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci**Return value** 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci| Type | Description | 376e41f4b71Sopenharmony_ci| -------- | -------- | 377e41f4b71Sopenharmony_ci| Promise<boolean> | Promise used to return the result. | 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci**Error codes** 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci| ID | Error Message | 384e41f4b71Sopenharmony_ci| -------- | -------- | 385e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 386e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci**Example** 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ci```ts 391e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 392e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_citry { 395e41f4b71Sopenharmony_ci let inSandbox = dlpPermission.isInSandbox(); // Check whether the application is running in a sandbox. 396e41f4b71Sopenharmony_ci console.info('res', inSandbox); 397e41f4b71Sopenharmony_ci} catch (err) { 398e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 399e41f4b71Sopenharmony_ci} 400e41f4b71Sopenharmony_ci``` 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci## dlpPermission.isInSandbox 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ciisInSandbox(callback: AsyncCallback<boolean>): void 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ciChecks whether this application is running in a DLP sandbox environment. This API uses an asynchronous callback to return the result. 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci**Parameters** 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 413e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 414e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result.<br>If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci**Error codes** 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci| ID | Error Message | 421e41f4b71Sopenharmony_ci| -------- | -------- | 422e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 423e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 424e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci**Example** 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci```ts 429e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 430e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_citry { 433e41f4b71Sopenharmony_ci dlpPermission.isInSandbox((err, data) => { 434e41f4b71Sopenharmony_ci if (err) { 435e41f4b71Sopenharmony_ci console.error('isInSandbox error,', err.code, err.message); 436e41f4b71Sopenharmony_ci } else { 437e41f4b71Sopenharmony_ci console.info('isInSandbox, data', JSON.stringify(data)); 438e41f4b71Sopenharmony_ci } 439e41f4b71Sopenharmony_ci }); // Check whether the application is running in the sandbox. 440e41f4b71Sopenharmony_ci} catch (err) { 441e41f4b71Sopenharmony_ci console.error('isInSandbox error,', (err as BusinessError).code, (err as BusinessError).message); 442e41f4b71Sopenharmony_ci} 443e41f4b71Sopenharmony_ci``` 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci## dlpPermission.getDLPSupportedFileTypes 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_cigetDLPSupportedFileTypes(): Promise<Array<string>> 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ciObtains the file name extension types that support DLP. This API uses a promise to return the result. 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_ci**Return value** 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ci| Type | Description | 456e41f4b71Sopenharmony_ci| -------- | -------- | 457e41f4b71Sopenharmony_ci| Promise<Array<string>> | Promise used to return the file name extension types obtained. | 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci**Error codes** 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci| ID | Error Message | 464e41f4b71Sopenharmony_ci| -------- | -------- | 465e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 466e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci**Example** 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci```ts 471e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 472e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 473e41f4b71Sopenharmony_ci 474e41f4b71Sopenharmony_citry { 475e41f4b71Sopenharmony_ci let res = dlpPermission.getDLPSupportedFileTypes(); // Obtain the file types that support DLP. 476e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)); 477e41f4b71Sopenharmony_ci} catch (err) { 478e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 479e41f4b71Sopenharmony_ci} 480e41f4b71Sopenharmony_ci``` 481e41f4b71Sopenharmony_ci 482e41f4b71Sopenharmony_ci## dlpPermission.getDLPSupportedFileTypes 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_cigetDLPSupportedFileTypes(callback: AsyncCallback<Array<string>>): void 485e41f4b71Sopenharmony_ci 486e41f4b71Sopenharmony_ciObtains the file name extension types that support DLP. This API uses an asynchronous callback to return the result. 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ci**Parameters** 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 493e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 494e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the result.<br>If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 495e41f4b71Sopenharmony_ci 496e41f4b71Sopenharmony_ci**Error codes** 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ci| ID | Error Message | 501e41f4b71Sopenharmony_ci| -------- | -------- | 502e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 503e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 504e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 505e41f4b71Sopenharmony_ci 506e41f4b71Sopenharmony_ci**Example** 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ci```ts 509e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 510e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 511e41f4b71Sopenharmony_ci 512e41f4b71Sopenharmony_citry { 513e41f4b71Sopenharmony_ci dlpPermission.getDLPSupportedFileTypes((err, res) => { 514e41f4b71Sopenharmony_ci if (err != undefined) { 515e41f4b71Sopenharmony_ci console.error('getDLPSupportedFileTypes error,', err.code, err.message); 516e41f4b71Sopenharmony_ci } else { 517e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)); 518e41f4b71Sopenharmony_ci } 519e41f4b71Sopenharmony_ci }); // Obtain the file types that support DLP. 520e41f4b71Sopenharmony_ci} catch (err) { 521e41f4b71Sopenharmony_ci console.error('getDLPSupportedFileTypes error,', (err as BusinessError).code, (err as BusinessError).message); 522e41f4b71Sopenharmony_ci} 523e41f4b71Sopenharmony_ci``` 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_ci## dlpPermission.setRetentionState 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_cisetRetentionState(docUris: Array<string>): Promise<void> 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ciSets the sandbox retention state. This API uses a promise to return the result. 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ciA 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. 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci**Parameters** 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 538e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 539e41f4b71Sopenharmony_ci| docUris | Array<string> | Yes | URIs of the files to be set with the retention state. | 540e41f4b71Sopenharmony_ci 541e41f4b71Sopenharmony_ci**Return value** 542e41f4b71Sopenharmony_ci 543e41f4b71Sopenharmony_ci| Type | Description | 544e41f4b71Sopenharmony_ci| -------- | -------- | 545e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value. | 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_ci**Error codes** 548e41f4b71Sopenharmony_ci 549e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 550e41f4b71Sopenharmony_ci 551e41f4b71Sopenharmony_ci| ID | Error Message | 552e41f4b71Sopenharmony_ci| -------- | -------- | 553e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 554e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 555e41f4b71Sopenharmony_ci| 19100006 | No permission to call this API, which is available only for DLP sandbox applications. | 556e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci**Example** 559e41f4b71Sopenharmony_ci 560e41f4b71Sopenharmony_ci```ts 561e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 562e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp"; 565e41f4b71Sopenharmony_citry { 566e41f4b71Sopenharmony_ci dlpPermission.isInSandbox().then((inSandbox) => {// Check whether the application is running in a sandbox. 567e41f4b71Sopenharmony_ci if (inSandbox) { 568e41f4b71Sopenharmony_ci dlpPermission.setRetentionState([uri]); // Set the retention state for a sandbox application. 569e41f4b71Sopenharmony_ci } 570e41f4b71Sopenharmony_ci }); 571e41f4b71Sopenharmony_ci} catch (err) { 572e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 573e41f4b71Sopenharmony_ci} 574e41f4b71Sopenharmony_ci``` 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci## dlpPermission.setRetentionState 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_cisetRetentionState(docUris: Array<string>, callback: AsyncCallback<void>): void 579e41f4b71Sopenharmony_ci 580e41f4b71Sopenharmony_ciSets the sandbox retention state. This API uses an asynchronous callback to return the result. 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_ciA 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. 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci**Parameters** 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 589e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 590e41f4b71Sopenharmony_ci| docUris | Array<string> | Yes | URIs of the files to be set with the retention state. | 591e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.<br>If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_ci**Error codes** 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_ci| ID | Error Message | 598e41f4b71Sopenharmony_ci| -------- | -------- | 599e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 600e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 601e41f4b71Sopenharmony_ci| 19100006 | No permission to call this API, which is available only for DLP sandbox applications. | 602e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_ci**Example** 605e41f4b71Sopenharmony_ci 606e41f4b71Sopenharmony_ci```ts 607e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 608e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp"; 611e41f4b71Sopenharmony_citry { 612e41f4b71Sopenharmony_ci dlpPermission.setRetentionState([uri], (err, res) => { 613e41f4b71Sopenharmony_ci if (err != undefined) { 614e41f4b71Sopenharmony_ci console.error('setRetentionState error,', err.code, err.message); 615e41f4b71Sopenharmony_ci } else { 616e41f4b71Sopenharmony_ci console.info('setRetentionState success'); 617e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)); 618e41f4b71Sopenharmony_ci } 619e41f4b71Sopenharmony_ci }); // Set the sandbox retention state. 620e41f4b71Sopenharmony_ci} catch (err) { 621e41f4b71Sopenharmony_ci console.error('setRetentionState error,', (err as BusinessError).code, (err as BusinessError).message); 622e41f4b71Sopenharmony_ci} 623e41f4b71Sopenharmony_ci``` 624e41f4b71Sopenharmony_ci 625e41f4b71Sopenharmony_ci## dlpPermission.cancelRetentionState 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_cicancelRetentionState(docUris: Array<string>): Promise<void> 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ciCancels 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. 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ci**Parameters** 634e41f4b71Sopenharmony_ci 635e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 636e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 637e41f4b71Sopenharmony_ci| docUris | Array<string> | Yes| URIs of the files whose retention state is to be canceled.| 638e41f4b71Sopenharmony_ci 639e41f4b71Sopenharmony_ci**Return value** 640e41f4b71Sopenharmony_ci 641e41f4b71Sopenharmony_ci| Type | Description | 642e41f4b71Sopenharmony_ci| -------- | -------- | 643e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value. | 644e41f4b71Sopenharmony_ci 645e41f4b71Sopenharmony_ci**Error codes** 646e41f4b71Sopenharmony_ci 647e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 648e41f4b71Sopenharmony_ci 649e41f4b71Sopenharmony_ci| ID | Error Message | 650e41f4b71Sopenharmony_ci| -------- | -------- | 651e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 652e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 653e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ci**Example** 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci```ts 658e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 659e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 660e41f4b71Sopenharmony_ci 661e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp"; 662e41f4b71Sopenharmony_citry { 663e41f4b71Sopenharmony_ci dlpPermission.cancelRetentionState([uri]); // Cancel the retention state for a sandbox application. 664e41f4b71Sopenharmony_ci} catch (err) { 665e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 666e41f4b71Sopenharmony_ci} 667e41f4b71Sopenharmony_ci``` 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_ci## dlpPermission.cancelRetentionState 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_cicancelRetentionState(docUris: Array<string>, callback: AsyncCallback<void>): void 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ciCancels 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. 674e41f4b71Sopenharmony_ci 675e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 676e41f4b71Sopenharmony_ci 677e41f4b71Sopenharmony_ci**Parameters** 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 680e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 681e41f4b71Sopenharmony_ci| docUris | Array<string> | Yes| URIs of the files whose retention state is to be canceled.| 682e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.<br>If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 683e41f4b71Sopenharmony_ci 684e41f4b71Sopenharmony_ci**Error codes** 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 687e41f4b71Sopenharmony_ci 688e41f4b71Sopenharmony_ci| ID | Error Message | 689e41f4b71Sopenharmony_ci| -------- | -------- | 690e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 691e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 692e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 693e41f4b71Sopenharmony_ci 694e41f4b71Sopenharmony_ci**Example** 695e41f4b71Sopenharmony_ci 696e41f4b71Sopenharmony_ci```ts 697e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 698e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_cilet uri = "file://docs/storage/Users/currentUser/Desktop/test.txt.dlp"; 701e41f4b71Sopenharmony_citry { 702e41f4b71Sopenharmony_ci dlpPermission.cancelRetentionState([uri], (err, res) => { 703e41f4b71Sopenharmony_ci if (err != undefined) { 704e41f4b71Sopenharmony_ci console.error('cancelRetentionState error,', err.code, err.message); 705e41f4b71Sopenharmony_ci } else { 706e41f4b71Sopenharmony_ci console.info('cancelRetentionState success'); 707e41f4b71Sopenharmony_ci } 708e41f4b71Sopenharmony_ci }); // Cancel the sandbox retention state. 709e41f4b71Sopenharmony_ci} catch (err) { 710e41f4b71Sopenharmony_ci console.error('cancelRetentionState error,', (err as BusinessError).code, (err as BusinessError).message); 711e41f4b71Sopenharmony_ci} 712e41f4b71Sopenharmony_ci``` 713e41f4b71Sopenharmony_ci 714e41f4b71Sopenharmony_ci## dlpPermission.getRetentionSandboxList 715e41f4b71Sopenharmony_ci 716e41f4b71Sopenharmony_cigetRetentionSandboxList(bundleName?: string): Promise<Array<RetentionSandboxInfo>> 717e41f4b71Sopenharmony_ci 718e41f4b71Sopenharmony_ciObtains the sandbox applications in the retention state of an application. This API uses a promise to return the result. 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 721e41f4b71Sopenharmony_ci 722e41f4b71Sopenharmony_ci**Parameters** 723e41f4b71Sopenharmony_ci 724e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 725e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 726e41f4b71Sopenharmony_ci| bundleName | string | No | Bundle name of the application. By default, this parameter is left empty, which obtains the sandbox retention information about the current application. | 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_ci**Return value** 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ci| Type | Description | 731e41f4b71Sopenharmony_ci| -------- | -------- | 732e41f4b71Sopenharmony_ci| Promise<Array<[RetentionSandboxInfo](#retentionsandboxinfo)>> | Promise used to return the sandbox retention information obtained. | 733e41f4b71Sopenharmony_ci 734e41f4b71Sopenharmony_ci**Error codes** 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_ci| ID | Error Message | 739e41f4b71Sopenharmony_ci| -------- | -------- | 740e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 741e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 742e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. | 743e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci**Example** 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci```ts 748e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 749e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_citry { 752e41f4b71Sopenharmony_ci let res: Promise<Array<dlpPermission.RetentionSandboxInfo>> = dlpPermission.getRetentionSandboxList(); // Obtain all the sandbox applications in the retention state. 753e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)) 754e41f4b71Sopenharmony_ci} catch (err) { 755e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 756e41f4b71Sopenharmony_ci} 757e41f4b71Sopenharmony_ci``` 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci## dlpPermission.getRetentionSandboxList 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_cigetRetentionSandboxList(bundleName: string, callback: AsyncCallback<Array<RetentionSandboxInfo>>): void 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ciObtains the sandbox applications in the retention state of an application. This API uses an asynchronous callback to return the result. 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ci**Parameters** 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 770e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 771e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name of the application. | 772e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[RetentionSandboxInfo](#retentionsandboxinfo)>> | Yes | Callback invoked to return the result.<br>If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 773e41f4b71Sopenharmony_ci 774e41f4b71Sopenharmony_ci**Error codes** 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ci| ID | Error Message | 779e41f4b71Sopenharmony_ci| -------- | -------- | 780e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 781e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 782e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. | 783e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 784e41f4b71Sopenharmony_ci 785e41f4b71Sopenharmony_ci**Example** 786e41f4b71Sopenharmony_ci 787e41f4b71Sopenharmony_ci```ts 788e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 789e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 790e41f4b71Sopenharmony_ci 791e41f4b71Sopenharmony_citry { 792e41f4b71Sopenharmony_ci dlpPermission.getRetentionSandboxList("bundleName", (err, res) => { 793e41f4b71Sopenharmony_ci if (err != undefined) { 794e41f4b71Sopenharmony_ci console.error('getRetentionSandboxList error,', err.code, err.message); 795e41f4b71Sopenharmony_ci } else { 796e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)); 797e41f4b71Sopenharmony_ci } 798e41f4b71Sopenharmony_ci }); // Obtain the sandbox retention information. 799e41f4b71Sopenharmony_ci} catch (err) { 800e41f4b71Sopenharmony_ci console.error('getRetentionSandboxList error,', (err as BusinessError).code, (err as BusinessError).message); 801e41f4b71Sopenharmony_ci} 802e41f4b71Sopenharmony_ci``` 803e41f4b71Sopenharmony_ci 804e41f4b71Sopenharmony_ci## dlpPermission.getRetentionSandboxList 805e41f4b71Sopenharmony_ci 806e41f4b71Sopenharmony_cigetRetentionSandboxList(callback: AsyncCallback<Array<RetentionSandboxInfo>>): void 807e41f4b71Sopenharmony_ci 808e41f4b71Sopenharmony_ciObtains the sandbox applications in the retention state of this application. This API uses an asynchronous callback to return the result. 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 811e41f4b71Sopenharmony_ci 812e41f4b71Sopenharmony_ci**Parameters** 813e41f4b71Sopenharmony_ci 814e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 815e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 816e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[RetentionSandboxInfo](#retentionsandboxinfo)>> | Yes | Callback invoked to return the result.<br>If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ci**Error codes** 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_ci| ID | Error Message | 823e41f4b71Sopenharmony_ci| -------- | -------- | 824e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 825e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 826e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. | 827e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 828e41f4b71Sopenharmony_ci 829e41f4b71Sopenharmony_ci**Example** 830e41f4b71Sopenharmony_ci 831e41f4b71Sopenharmony_ci```ts 832e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 833e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_citry { 836e41f4b71Sopenharmony_ci dlpPermission.getRetentionSandboxList((err, res) => { 837e41f4b71Sopenharmony_ci if (err != undefined) { 838e41f4b71Sopenharmony_ci console.error('getRetentionSandboxList error,', err.code, err.message); 839e41f4b71Sopenharmony_ci } else { 840e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)); 841e41f4b71Sopenharmony_ci } 842e41f4b71Sopenharmony_ci }); // Obtain the sandbox retention information. 843e41f4b71Sopenharmony_ci} catch (err) { 844e41f4b71Sopenharmony_ci console.error('getRetentionSandboxList error,', (err as BusinessError).code, (err as BusinessError).message); 845e41f4b71Sopenharmony_ci} 846e41f4b71Sopenharmony_ci``` 847e41f4b71Sopenharmony_ci 848e41f4b71Sopenharmony_ci## dlpPermission.getDLPFileAccessRecords 849e41f4b71Sopenharmony_ci 850e41f4b71Sopenharmony_cigetDLPFileAccessRecords(): Promise<Array<AccessedDLPFileInfo>> 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ciObtains the list of DLP files that are accessed recently. This API uses a promise to return the result. 853e41f4b71Sopenharmony_ci 854e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 855e41f4b71Sopenharmony_ci 856e41f4b71Sopenharmony_ci**Return value** 857e41f4b71Sopenharmony_ci 858e41f4b71Sopenharmony_ci| Type | Description | 859e41f4b71Sopenharmony_ci| -------- | -------- | 860e41f4b71Sopenharmony_ci| Promise<Array<[AccessedDLPFileInfo](#accesseddlpfileinfo)>> | Promise used to return the list of recently accessed files obtained. | 861e41f4b71Sopenharmony_ci 862e41f4b71Sopenharmony_ci**Error codes** 863e41f4b71Sopenharmony_ci 864e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 865e41f4b71Sopenharmony_ci 866e41f4b71Sopenharmony_ci| ID | Error Message | 867e41f4b71Sopenharmony_ci| -------- | -------- | 868e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 869e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. | 870e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 871e41f4b71Sopenharmony_ci 872e41f4b71Sopenharmony_ci**Example** 873e41f4b71Sopenharmony_ci 874e41f4b71Sopenharmony_ci```ts 875e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 876e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 877e41f4b71Sopenharmony_ci 878e41f4b71Sopenharmony_citry { 879e41f4b71Sopenharmony_ci let res: Promise<Array<dlpPermission.AccessedDLPFileInfo>> = dlpPermission.getDLPFileAccessRecords(); // Obtain the list of recently accessed DLP files. 880e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)) 881e41f4b71Sopenharmony_ci} catch (err) { 882e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 883e41f4b71Sopenharmony_ci} 884e41f4b71Sopenharmony_ci``` 885e41f4b71Sopenharmony_ci 886e41f4b71Sopenharmony_ci## dlpPermission.getDLPFileAccessRecords 887e41f4b71Sopenharmony_ci 888e41f4b71Sopenharmony_cigetDLPFileAccessRecords(callback: AsyncCallback<Array<AccessedDLPFileInfo>>): void 889e41f4b71Sopenharmony_ci 890e41f4b71Sopenharmony_ciObtains the list of DLP files that are accessed recently. This API uses an asynchronous callback to return the result. 891e41f4b71Sopenharmony_ci 892e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 893e41f4b71Sopenharmony_ci 894e41f4b71Sopenharmony_ci**Parameters** 895e41f4b71Sopenharmony_ci 896e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 897e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 898e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[AccessedDLPFileInfo](#accesseddlpfileinfo)>> | Yes | Callback invoked to return the result.<br>If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 899e41f4b71Sopenharmony_ci 900e41f4b71Sopenharmony_ci**Error codes** 901e41f4b71Sopenharmony_ci 902e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_ci| ID | Error Message | 905e41f4b71Sopenharmony_ci| -------- | -------- | 906e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 907e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 908e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. | 909e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 910e41f4b71Sopenharmony_ci 911e41f4b71Sopenharmony_ci**Example** 912e41f4b71Sopenharmony_ci 913e41f4b71Sopenharmony_ci```ts 914e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 915e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 916e41f4b71Sopenharmony_ci 917e41f4b71Sopenharmony_citry { 918e41f4b71Sopenharmony_ci dlpPermission.getDLPFileAccessRecords((err, res) => { 919e41f4b71Sopenharmony_ci if (err != undefined) { 920e41f4b71Sopenharmony_ci console.error('getDLPFileAccessRecords error,', err.code, err.message); 921e41f4b71Sopenharmony_ci } else { 922e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)); 923e41f4b71Sopenharmony_ci } 924e41f4b71Sopenharmony_ci }); // Obtain the list of recently accessed DLP files. 925e41f4b71Sopenharmony_ci} catch (err) { 926e41f4b71Sopenharmony_ci console.error('getDLPFileAccessRecords error,', (err as BusinessError).code, (err as BusinessError).message); 927e41f4b71Sopenharmony_ci} 928e41f4b71Sopenharmony_ci``` 929e41f4b71Sopenharmony_ci 930e41f4b71Sopenharmony_ci## dlpPermission.startDLPManagerForResult<sup>11+</sup> 931e41f4b71Sopenharmony_ci 932e41f4b71Sopenharmony_cistartDLPManagerForResult(context: common.UIAbilityContext, want: Want): Promise<DLPManagerResult> 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ciStarts the DLP manager application on the current UIAbility page in borderless mode. This API uses a promise to return the result. 935e41f4b71Sopenharmony_ci 936e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 937e41f4b71Sopenharmony_ci 938e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci**Parameters** 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 943e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 944e41f4b71Sopenharmony_ci| context | [common.UIAbilityContext](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | Yes | UIAbility context. | 945e41f4b71Sopenharmony_ci| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Object that requests the start of the DLP manager application. | 946e41f4b71Sopenharmony_ci 947e41f4b71Sopenharmony_ci**Return value** 948e41f4b71Sopenharmony_ci 949e41f4b71Sopenharmony_ci| Type | Description | 950e41f4b71Sopenharmony_ci| -------- | -------- | 951e41f4b71Sopenharmony_ci| Promise<[DLPManagerResult](#dlpmanagerresult11)> | Promise used to return the **DLPManagerResult** object. | 952e41f4b71Sopenharmony_ci 953e41f4b71Sopenharmony_ci**Error codes** 954e41f4b71Sopenharmony_ci 955e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 956e41f4b71Sopenharmony_ci 957e41f4b71Sopenharmony_ci| ID | Error Message | 958e41f4b71Sopenharmony_ci| -------- | -------- | 959e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 960e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 961e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 962e41f4b71Sopenharmony_ci| 19100016 | uri missing in want. | 963e41f4b71Sopenharmony_ci| 19100017 | displayName missing in want. | 964e41f4b71Sopenharmony_ci 965e41f4b71Sopenharmony_ci**Example** 966e41f4b71Sopenharmony_ci 967e41f4b71Sopenharmony_ci```ts 968e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 969e41f4b71Sopenharmony_ciimport { common, UIAbility, AbilityConstant, Want } from '@kit.AbilityKit'; 970e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 971e41f4b71Sopenharmony_ci 972e41f4b71Sopenharmony_citry { 973e41f4b71Sopenharmony_ci let context = getContext () as common.UIAbilityContext; // Obtain the UIAbility context. 974e41f4b71Sopenharmony_ci let want: Want = { 975e41f4b71Sopenharmony_ci "uri": "file://docs/storage/Users/currentUser/Desktop/1.txt", 976e41f4b71Sopenharmony_ci "parameters": { 977e41f4b71Sopenharmony_ci "displayName": "1.txt" 978e41f4b71Sopenharmony_ci } 979e41f4b71Sopenharmony_ci }; // Request parameters. 980e41f4b71Sopenharmony_ci dlpPermission.startDLPManagerForResult(context, want).then((res) => { 981e41f4b71Sopenharmony_ci console.info('res.resultCode', res.resultCode); 982e41f4b71Sopenharmony_ci console.info('res.want', JSON.stringify(res.want)); 983e41f4b71Sopenharmony_ci }); // Start the DLP manager application. 984e41f4b71Sopenharmony_ci} catch (err) { 985e41f4b71Sopenharmony_ci console.error('error', err.code, err.message); // Error reported if the operation fails. 986e41f4b71Sopenharmony_ci} 987e41f4b71Sopenharmony_ci``` 988e41f4b71Sopenharmony_ci 989e41f4b71Sopenharmony_ci## dlpPermission.setSandboxAppConfig<sup>11+<sup> 990e41f4b71Sopenharmony_cisetSandboxAppConfig(configInfo: string): Promise<void> 991e41f4b71Sopenharmony_ci 992e41f4b71Sopenharmony_ciSets sandbox application configuration. This API uses a promise to return the result. 993e41f4b71Sopenharmony_ci 994e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 995e41f4b71Sopenharmony_ci 996e41f4b71Sopenharmony_ci**Parameters** 997e41f4b71Sopenharmony_ci 998e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 999e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1000e41f4b71Sopenharmony_ci| configInfo | string | Yes | Sandbox application configuration. | 1001e41f4b71Sopenharmony_ci 1002e41f4b71Sopenharmony_ci**Return value** 1003e41f4b71Sopenharmony_ci 1004e41f4b71Sopenharmony_ci| Type | Description | 1005e41f4b71Sopenharmony_ci| -------- | -------- | 1006e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value. | 1007e41f4b71Sopenharmony_ci 1008e41f4b71Sopenharmony_ci**Error codes** 1009e41f4b71Sopenharmony_ci 1010e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 1011e41f4b71Sopenharmony_ci 1012e41f4b71Sopenharmony_ci| ID | Error Message | 1013e41f4b71Sopenharmony_ci| -------- | -------- | 1014e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1015e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 1016e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. | 1017e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 1018e41f4b71Sopenharmony_ci| 19100018 | Not authorized application. | 1019e41f4b71Sopenharmony_ci 1020e41f4b71Sopenharmony_ci**Example** 1021e41f4b71Sopenharmony_ci 1022e41f4b71Sopenharmony_ci```ts 1023e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 1024e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1025e41f4b71Sopenharmony_ci 1026e41f4b71Sopenharmony_citry { 1027e41f4b71Sopenharmony_ci dlpPermission.setSandboxAppConfig('configInfo'); // Set sandbox application configuration. 1028e41f4b71Sopenharmony_ci} catch (err) { 1029e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 1030e41f4b71Sopenharmony_ci} 1031e41f4b71Sopenharmony_ci``` 1032e41f4b71Sopenharmony_ci 1033e41f4b71Sopenharmony_ci## dlpPermission.cleanSandboxAppConfig<sup>11+<sup> 1034e41f4b71Sopenharmony_cicleanSandboxAppConfig(): Promise<void> 1035e41f4b71Sopenharmony_ci 1036e41f4b71Sopenharmony_ciCleans sandbox application configuration. This API uses a promise to return the result. 1037e41f4b71Sopenharmony_ci 1038e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 1039e41f4b71Sopenharmony_ci 1040e41f4b71Sopenharmony_ci**Return value** 1041e41f4b71Sopenharmony_ci 1042e41f4b71Sopenharmony_ci| Type | Description | 1043e41f4b71Sopenharmony_ci| -------- | -------- | 1044e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value. | 1045e41f4b71Sopenharmony_ci 1046e41f4b71Sopenharmony_ci**Error codes** 1047e41f4b71Sopenharmony_ci 1048e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 1049e41f4b71Sopenharmony_ci 1050e41f4b71Sopenharmony_ci| ID | Error Message | 1051e41f4b71Sopenharmony_ci| -------- | -------- | 1052e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 1053e41f4b71Sopenharmony_ci| 19100007 | No permission to call this API, which is available only for non-DLP sandbox applications. | 1054e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 1055e41f4b71Sopenharmony_ci| 19100018 | Not authorized application. | 1056e41f4b71Sopenharmony_ci 1057e41f4b71Sopenharmony_ci**Example** 1058e41f4b71Sopenharmony_ci 1059e41f4b71Sopenharmony_ci```ts 1060e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 1061e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1062e41f4b71Sopenharmony_ci 1063e41f4b71Sopenharmony_citry { 1064e41f4b71Sopenharmony_ci dlpPermission.cleanSandboxAppConfig(); // Clean sandbox application configuration. 1065e41f4b71Sopenharmony_ci} catch (err) { 1066e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 1067e41f4b71Sopenharmony_ci} 1068e41f4b71Sopenharmony_ci``` 1069e41f4b71Sopenharmony_ci 1070e41f4b71Sopenharmony_ci## dlpPermission.getSandboxAppConfig<sup>11+<sup> 1071e41f4b71Sopenharmony_cigetSandboxAppConfig(): Promise<string> 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ciObtains sandbox application configuration. This API uses a promise to return the result. 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ci**Return value** 1078e41f4b71Sopenharmony_ci| Type | Description | 1079e41f4b71Sopenharmony_ci| -------- | -------- | 1080e41f4b71Sopenharmony_ci| Promise<string> | Promise used to return the sandbox application configuration obtained. | 1081e41f4b71Sopenharmony_ci 1082e41f4b71Sopenharmony_ci**Error codes** 1083e41f4b71Sopenharmony_ci 1084e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 1085e41f4b71Sopenharmony_ci 1086e41f4b71Sopenharmony_ci| ID | Error Message | 1087e41f4b71Sopenharmony_ci| -------- | -------- | 1088e41f4b71Sopenharmony_ci| 19100001 | Invalid parameter value. | 1089e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 1090e41f4b71Sopenharmony_ci| 19100018 | Not authorized application. | 1091e41f4b71Sopenharmony_ci 1092e41f4b71Sopenharmony_ci**Example** 1093e41f4b71Sopenharmony_ci 1094e41f4b71Sopenharmony_ci```ts 1095e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 1096e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1097e41f4b71Sopenharmony_ci 1098e41f4b71Sopenharmony_citry { 1099e41f4b71Sopenharmony_ci dlpPermission.getSandboxAppConfig().then((res) => { 1100e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)); 1101e41f4b71Sopenharmony_ci }); // Obtain the sandbox application configuration. 1102e41f4b71Sopenharmony_ci} catch (err) { 1103e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 1104e41f4b71Sopenharmony_ci} 1105e41f4b71Sopenharmony_ci``` 1106e41f4b71Sopenharmony_ci 1107e41f4b71Sopenharmony_ci## dlpPermission.isDLPFeatureProvided<sup>12+<sup> 1108e41f4b71Sopenharmony_ciisDLPFeatureProvided(): Promise<boolean> 1109e41f4b71Sopenharmony_ci 1110e41f4b71Sopenharmony_ciQueries whether the current system provides the DLP feature. This API uses a promise to return the result. 1111e41f4b71Sopenharmony_ci 1112e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 1113e41f4b71Sopenharmony_ci 1114e41f4b71Sopenharmony_ci**Return value** 1115e41f4b71Sopenharmony_ci| Type | Description | 1116e41f4b71Sopenharmony_ci| -------- | -------- | 1117e41f4b71Sopenharmony_ci| Promise<boolean> | Promise used to return the result. | 1118e41f4b71Sopenharmony_ci 1119e41f4b71Sopenharmony_ci**Error codes** 1120e41f4b71Sopenharmony_ci 1121e41f4b71Sopenharmony_ciFor details about the error codes, see [DLP Service Error Codes](errorcode-dlp.md). 1122e41f4b71Sopenharmony_ci 1123e41f4b71Sopenharmony_ci| ID | Error Message | 1124e41f4b71Sopenharmony_ci| -------- | -------- | 1125e41f4b71Sopenharmony_ci| 19100011 | The system ability works abnormally. | 1126e41f4b71Sopenharmony_ci 1127e41f4b71Sopenharmony_ci**Example** 1128e41f4b71Sopenharmony_ci 1129e41f4b71Sopenharmony_ci```ts 1130e41f4b71Sopenharmony_ciimport { dlpPermission } from '@kit.DataProtectionKit'; 1131e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1132e41f4b71Sopenharmony_ci 1133e41f4b71Sopenharmony_cidlpPermission.isDLPFeatureProvided().then((res) => { 1134e41f4b71Sopenharmony_ci console.info('res', JSON.stringify(res)); 1135e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1136e41f4b71Sopenharmony_ci console.error('error', (err as BusinessError).code, (err as BusinessError).message); // Error reported if the operation fails. 1137e41f4b71Sopenharmony_ci}); 1138e41f4b71Sopenharmony_ci``` 1139e41f4b71Sopenharmony_ci 1140e41f4b71Sopenharmony_ci## ActionFlagType 1141e41f4b71Sopenharmony_ci 1142e41f4b71Sopenharmony_ciEnumerates the operations that can be performed on a DLP file. For example, the DLP sandbox application can dim its button based on this parameter. 1143e41f4b71Sopenharmony_ci 1144e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 1145e41f4b71Sopenharmony_ci 1146e41f4b71Sopenharmony_ci| Name | Value | Description | 1147e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 1148e41f4b71Sopenharmony_ci| ACTION_VIEW | 0x00000001 | View the file. | 1149e41f4b71Sopenharmony_ci| ACTION_SAVE | 0x00000002 | Save the file. | 1150e41f4b71Sopenharmony_ci| ACTION_SAVE_AS | 0x00000004 | Save the file as another file. | 1151e41f4b71Sopenharmony_ci| ACTION_EDIT | 0x00000008 | Edit the file. | 1152e41f4b71Sopenharmony_ci| ACTION_SCREEN_CAPTURE | 0x00000010 | Capture screenshots of the file. | 1153e41f4b71Sopenharmony_ci| ACTION_SCREEN_SHARE | 0x00000020 | Share the screen of the file. | 1154e41f4b71Sopenharmony_ci| ACTION_SCREEN_RECORD | 0x00000040 | Record the screen on which the file is open. | 1155e41f4b71Sopenharmony_ci| ACTION_COPY | 0x00000080 | Copy the file. | 1156e41f4b71Sopenharmony_ci| ACTION_PRINT | 0x00000100 | Print the file. | 1157e41f4b71Sopenharmony_ci| ACTION_EXPORT | 0x00000200 | Export the file. | 1158e41f4b71Sopenharmony_ci| ACTION_PERMISSION_CHANGE | 0x00000400 | Modify the permissions on the file. | 1159e41f4b71Sopenharmony_ci 1160e41f4b71Sopenharmony_ci## DLPFileAccess 1161e41f4b71Sopenharmony_ci 1162e41f4b71Sopenharmony_ciEnumerates the permissions on a DLP file. 1163e41f4b71Sopenharmony_ci 1164e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 1165e41f4b71Sopenharmony_ci 1166e41f4b71Sopenharmony_ci| Name | Value | Description | 1167e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 1168e41f4b71Sopenharmony_ci| NO_PERMISSION | 0 | The user has no permission on the file. | 1169e41f4b71Sopenharmony_ci| READ_ONLY | 1 | The user has only the permission to read the file. | 1170e41f4b71Sopenharmony_ci| CONTENT_EDIT | 2 | The user has the permission to edit the file. | 1171e41f4b71Sopenharmony_ci| FULL_CONTROL | 3 | The user has full control on the file. | 1172e41f4b71Sopenharmony_ci 1173e41f4b71Sopenharmony_ci## DLPPermissionInfo 1174e41f4b71Sopenharmony_ci 1175e41f4b71Sopenharmony_ciRepresents the permission information about a DLP file. 1176e41f4b71Sopenharmony_ci 1177e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 1178e41f4b71Sopenharmony_ci 1179e41f4b71Sopenharmony_ci| Name | Type | Readable | Writable | Description | 1180e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 1181e41f4b71Sopenharmony_ci| dlpFileAccess | [DLPFileAccess](#dlpfileaccess) | Yes | No | User permission on the DLP file, for example, read-only. | 1182e41f4b71Sopenharmony_ci| flags | number | Yes | No | Operations that can be performed on the DLP file. It is a combination of different [ActionFlagTypes](#actionflagtype). | 1183e41f4b71Sopenharmony_ci 1184e41f4b71Sopenharmony_ci## AccessedDLPFileInfo 1185e41f4b71Sopenharmony_ci 1186e41f4b71Sopenharmony_ciRepresents the information about a DLP file opened. 1187e41f4b71Sopenharmony_ci 1188e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 1189e41f4b71Sopenharmony_ci 1190e41f4b71Sopenharmony_ci| Name | Type | Readable | Writable | Description | 1191e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 1192e41f4b71Sopenharmony_ci| uri | string | Yes | No | URI of the DLP file. | 1193e41f4b71Sopenharmony_ci| lastOpenTime | number | Yes | No | Time when the file was last opened. | 1194e41f4b71Sopenharmony_ci 1195e41f4b71Sopenharmony_ci## DLPManagerResult<sup>11+</sup> 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ciRepresents information about the trigger of the DLP manager application. 1198e41f4b71Sopenharmony_ci 1199e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 1200e41f4b71Sopenharmony_ci 1201e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 1202e41f4b71Sopenharmony_ci 1203e41f4b71Sopenharmony_ci| Name | Type | Readable | Writable | Description | 1204e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 1205e41f4b71Sopenharmony_ci| resultCode | number | Yes | No | Result code returned after the DLP manager application is started and exits. | 1206e41f4b71Sopenharmony_ci| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | No | Data returned after the DLP manager application is started and exits. | 1207e41f4b71Sopenharmony_ci 1208e41f4b71Sopenharmony_ci## RetentionSandboxInfo 1209e41f4b71Sopenharmony_ci 1210e41f4b71Sopenharmony_ciRepresents the sandbox retention information. 1211e41f4b71Sopenharmony_ci 1212e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.DataLossPrevention 1213e41f4b71Sopenharmony_ci 1214e41f4b71Sopenharmony_ci| Name | Type | Readable | Writable | Description | 1215e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 1216e41f4b71Sopenharmony_ci| appIndex | number | Yes | No | Index of the DLP sandbox application. | 1217e41f4b71Sopenharmony_ci| bundleName | string | Yes | No | Bundle name of the application. | 1218e41f4b71Sopenharmony_ci| docUris | Array<string> | Yes | No | URI list of the DLP files. | 1219