文件分级管控-更新安全管控策略
HarmonyOS 5.0.3(15) 版本支持PC/2in1设备,提供了Enterprise Data Guard Kit,用于下发和执行安全管控策略。该版本API级别为API 15 Release,开发者可以通过Callback或Promise方式更新安全管控策略。开发步骤包括导入模块、初始化FileGuard对象、调用updatePolicy接口更新策略,并通过回调或Promise处理结果。
·
HarmonyOS 5.0.3(15) 版本的配套文档,该版本API能力级别为API 15 Release


场景介绍
支持设备PC/2in1
Enterprise Data Guard Kit为应用提供下发管控策略的能力,相关策略会被分发到内核各管控模块中执行。
接口说明
支持设备PC/2in1
详细接口说明可参考接口文档。
| 接口名 | 描述 |
|---|---|
| updatePolicy(policy: string, callback: AsyncCallback): void | 使用Callback方式更新安全管控策略。 |
| updatePolicy(policy: string): Promise | 使用Promise方式更新安全管控策略。 |
开发步骤
支持设备PC/2in1
- 导入模块。
import { fileGuard } from '@kit.EnterpriseDataGuardKit';
- 初始化FileGuard对象guard,调用接口updatePolicy,更新安全管控策略。
- 通过回调函数方式,更新安全管控策略。
import { BusinessError } from '@kit.BasicServicesKit';
function updatePolicyCallback() {
let guard: fileGuard.FileGuard = new fileGuard.FileGuard();
let policy: string = '{' +
'"net_intercept_toggle":0,' +
'"boundary":["10.10.0.0-10.10.255.255.255","0.0.0.0-1.1.1.1"],' +
'"netsegment_trustlist":["10.10.0.0-10.10.255.255.255"],' +
'"netsegment_blocklist":["0.0.0.0-1.1.1.1"],' +
'"default_policy":0' +
'}';
guard.updatePolicy(policy, (err: BusinessError) => {
if (err) {
console.error(`Failed to update policy. Code: ${err.code}, message: ${err.message}.`);
} else {
console.info(`Succeeded in updating policy.`);
}
});
}
- 通过Promise方式,更新安全管控策略。
import { BusinessError } from '@kit.BasicServicesKit';
function updatePolicyPromise() {
let guard: fileGuard.FileGuard = new fileGuard.FileGuard();
let policy: string = '{' +
'"net_intercept_toggle":0,' +
'"boundary":["10.10.0.0-10.10.255.255.255","0.0.0.0-1.1.1.1"],' +
'"netsegment_trustlist":["10.10.0.0-10.10.255.255.255"],' +
'"netsegment_blocklist":["0.0.0.0-1.1.1.1"],' +
'"default_policy":0' +
'}';
guard.updatePolicy(policy).then(() => {
console.info(`Succeeded in updating policy.`);
}).catch((err: BusinessError) => {
console.error(`Failed to update policy. Code: ${err.code}, message: ${err.message}.`);
});
}
- 调用函数,查看打印信息。

更多推荐

所有评论(0)