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

  1. 导入模块。
import { fileGuard } from '@kit.EnterpriseDataGuardKit';
  1. 初始化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}.`);
  });
}
  1. 调用函数,查看打印信息。

在这里插入图片描述

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐