本模块提供系统管理能力,包括NTP时间服务器设置、OTA升级策略管理、系统更新管理、按键事件处理策略、日志收集、设备激活锁管理等功能。适用于企业设备管理场景,帮助企业管理员统一管控设备系统配置、升级策略和安全策略,提升企业设备管理效率和安全性。
本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
本模块接口仅可在Stage模型下使用。
本模块接口仅对设备管理应用开放,且调用接口前需激活设备管理应用,具体请参考MDM Kit开发指南。
setNTPServer(admin: Want, server: string): void
设置NTP(Network Time Protocol)时间服务器。设置成功后,系统将使用指定的NTP服务器进行时间同步,校准系统时间。适用于企业设备需要统一时间同步的场景,确保企业设备时间与标准时间保持一致,避免因时间不准确导致的业务问题,如日志时间戳不一致、证书验证失败等。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| server | string | 是 | NTP服务器地址(以","分隔,如"ntpserver1.com,ntpserver2.com"。最大长度96字节,包括null终止符(\0))。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
// 需根据实际情况进行替换
let server: string = "ntpserver.com";
try {
systemManager.setNTPServer(wantTemp, server);
console.info('Succeeded in setting NTPserver.');
} catch (err) {
console.error(`Failed to set ntp server. Code is ${err.code}, message is ${err.message}`);
} getNTPServer(admin: Want): string
获取NTP时间服务器信息。适用于需要查询当前设备配置的NTP服务器地址的场景,用于验证时间同步配置是否正确,或在进行策略调整前获取当前配置。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
返回值:
| 类型 | 说明 |
|---|---|
| string | string对象,返回NTP时间服务器信息。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
try {
let result: string = systemManager.getNTPServer(wantTemp);
console.info(`Succeeded in getting NTP server. result: ${result}`);
} catch (err) {
console.error(`Failed to get ntp server. Code is ${err.code}, message is ${err.message}`);
} setOtaUpdatePolicy(admin: Want, policy: OtaUpdatePolicy): void
设置升级策略。设置成功后,系统将按照指定的策略类型进行OTA升级处理,不同策略类型对应不同的升级行为。内网升级场景下,需要先调用systemManager.notifyUpdatePackages接口通知系统更新包,再调用该接口设置升级策略。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| policy | OtaUpdatePolicy | 是 | 升级策略。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
// 默认升级策略
let otaUpdatePolicy1: systemManager.OtaUpdatePolicy = {
"policyType": systemManager.PolicyType.DEFAULT,
"version": "version_1.0.0.0"
};
try {
systemManager.setOtaUpdatePolicy(wantTemp, otaUpdatePolicy1);
console.info('Succeeded in setting ota update policy.');
} catch (err) {
console.error(`Failed to set ota update policy. Code is ${err.code}, message is ${err.message}`);
}
// 禁止升级
let otaUpdatePolicy2: systemManager.OtaUpdatePolicy = {
"policyType": systemManager.PolicyType.PROHIBIT,
"version": "version_1.0.0.1"
};
try {
systemManager.setOtaUpdatePolicy(wantTemp, otaUpdatePolicy2);
console.info('Succeeded in setting ota update policy.');
} catch (err) {
console.error(`Failed to set ota update policy. Code is ${err.code}, message is ${err.message}`);
}
// 强制升级
let otaUpdatePolicy3: systemManager.OtaUpdatePolicy = {
"policyType": systemManager.PolicyType.UPDATE_TO_SPECIFIC_VERSION,
"version": "version_1.0.0.2",
"latestUpdateTime": 1716343200 // 时间戳
};
try {
systemManager.setOtaUpdatePolicy(wantTemp, otaUpdatePolicy3);
console.info('Succeeded in setting ota update policy.');
} catch (err) {
console.error(`Failed to set ota update policy. Code is ${err.code}, message is ${err.message}`);
}
// 指定时间窗口升级
let otaUpdatePolicy4: systemManager.OtaUpdatePolicy = {
"policyType": systemManager.PolicyType.WINDOWS,
"version": "version_1.0.0.3",
"installStartTime": 1716281049, // 时间戳
"installEndTime": 1716343200 // 时间戳
};
try {
systemManager.setOtaUpdatePolicy(wantTemp, otaUpdatePolicy4);
console.info('Succeeded in setting ota update policy.');
} catch (err) {
console.error(`Failed to set ota update policy. Code is ${err.code}, message is ${err.message}`);
}
// 延迟升级
let otaUpdatePolicy5: systemManager.OtaUpdatePolicy = {
"policyType": systemManager.PolicyType.POSTPONE,
"version": "version_1.0.0.4",
"delayUpdateTime": 5 // 单位(小时)
};
try {
systemManager.setOtaUpdatePolicy(wantTemp, otaUpdatePolicy5);
console.info('Succeeded in setting ota update policy.');
} catch (err) {
console.error(`Failed to set ota update policy. Code is ${err.code}, message is ${err.message}`);
}
// 禁用公网升级
let otaUpdatePolicy6: systemManager.OtaUpdatePolicy = {
"policyType": systemManager.PolicyType.DEFAULT,
"version": "version_1.0.0.5",
"disableSystemOtaUpdate": true
};
try {
systemManager.setOtaUpdatePolicy(wantTemp, otaUpdatePolicy6);
console.info('Succeeded in setting ota update policy.');
} catch (err) {
console.error(`Failed to set ota update policy. Code is ${err.code}, message is ${err.message}`);
} getOtaUpdatePolicy(admin: Want): OtaUpdatePolicy
查询升级策略。适用于需要获取当前设备OTA升级策略配置的场景,用于验证策略是否正确下发,或在进行策略调整前获取当前策略配置。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
返回值:
| 类型 | 说明 |
|---|---|
| OtaUpdatePolicy | OtaUpdatePolicy对象,返回升级策略。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
try {
let policy: systemManager.OtaUpdatePolicy = systemManager.getOtaUpdatePolicy(wantTemp);
console.info(`Succeeded in getting update policy: ${JSON.stringify(policy)}`);
} catch (err) {
console.error(`Failed to get update policy. Code is ${err.code}, message is ${err.message}`);
} notifyUpdatePackages(admin: Want, packageInfo: UpdatePackageInfo): Promise<void>
通知系统更新包信息。内网升级场景下,需要先调用该接口通知系统更新包,再调用systemManager.setOtaUpdatePolicy设置升级策略。使用Promise异步回调。
该接口比较耗时,当调用此接口后,后续如果在应用主线程调用其他同步接口时需要等待该接口异步返回。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| packageInfo | UpdatePackageInfo | 是 | 系统更新包信息。 说明: 传入的UpdatePackageInfo.packages.path必须是“update”开头的zip压缩包,传入其他形式的文件会报9201004错误码。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 无返回结果的Promise对象。当通知系统更新包失败时会抛出错误对象。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9201004 | The update packages do not exist or analyzing failed. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
示例:
import { systemManager } from '@kit.MDMKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { Want } from '@kit.AbilityKit';
import { fileIo } from '@kit.CoreFileKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
let notify: systemManager.NotifyDescription = {
// 需根据实际情况进行替换
"installTips": "installTips",
"installTipsDetail": "installTips detail"
};
let description: systemManager.PackageDescription = {
// 需根据实际情况进行替换
"notify": notify
};
let updatePackages: Array<systemManager.Package> = [];
// 应用沙箱路径,需根据实际情况进行替换
let fileDir = "/xxxx/xxxx/";
let path1: string = "update_sd_base.zip";
let path2: string = "update_sd_cust_xxxxx_all_cn.zip";
let path3: string = "update_sd_preload_xxxxx_all_cn_R1.zip";
let fd1: number = fileIo.openSync(fileDir + path1, fileIo.OpenMode.READ_ONLY).fd;
let fd2: number = fileIo.openSync(fileDir + "xxxxx/" + path2, fileIo.OpenMode.READ_ONLY).fd;
let fd3: number = fileIo.openSync(fileDir + "xxxxx/" + path3, fileIo.OpenMode.READ_ONLY).fd;
let package1: systemManager.Package = {
// 需根据实际情况进行替换
"type": systemManager.PackageType.FIRMWARE,
"path": path1,
"fd": fd1
};
let package2: systemManager.Package = {
// 需根据实际情况进行替换
"type": systemManager.PackageType.FIRMWARE,
"path": path2,
"fd": fd2
};
let package3: systemManager.Package = {
// 需根据实际情况进行替换
"type": systemManager.PackageType.FIRMWARE,
"path": path3,
"fd": fd3
};
updatePackages.push(package1);
updatePackages.push(package2);
updatePackages.push(package3);
let updatePackageInfo: systemManager.UpdatePackageInfo = {
// 需根据实际情况进行替换
"version" : "1.0",
"packages" : updatePackages,
"description" : description
};
systemManager.notifyUpdatePackages(wantTemp, updatePackageInfo).then(() => {
console.info('Succeeded in notifying update packages.');
}).catch ((error: BusinessError) => {
console.error(`Failed to notify update packages. Code is ${error.code},message is ${error.message}`);
}); getUpdateResult(admin: Want, version: string): Promise<UpdateResult>
获取系统更新结果。使用Promise异步回调。适用于需要检查系统更新是否成功的场景,帮助企业管理员了解设备升级状态,及时处理更新失败的情况,确保设备系统版本符合企业要求。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| version | string | 是 | 更新包版本号。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<UpdateResult> | Promise对象,返回系统更新结果。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
示例:
import { systemManager } from '@kit.MDMKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
systemManager.getUpdateResult(wantTemp, "1.0").then((result:systemManager.UpdateResult) => {
console.info(`Succeeded in getting update result: ${JSON.stringify(result)}`);
}).catch((error: BusinessError) => {
console.error(`Get update result failed. Code is ${error.code},message is ${error.message}`);
}); getUpdateAuthData(admin: Want): Promise<string>
获取系统更新的鉴权数据,用于校验系统更新信息。使用Promise异步回调。适用于内网升级场景,企业管理员可以通过鉴权数据验证系统更新包的合法性和完整性,防止恶意更新包,提升系统安全性。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<string> | Promise对象,返回系统更新的鉴权数据。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
示例:
import { systemManager } from '@kit.MDMKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
systemManager.getUpdateAuthData(wantTemp).then((result: string) => {
console.info(`Succeeded in getting update auth data: ${JSON.stringify(result)}`);
}).catch((error: BusinessError) => {
console.error(`Get update auth data failed. Code is ${error.code},message is ${error.message}`);
}); setOtaUpdateNonceEnable(admin: Want, isEnable: boolean): void
设置OTA更新时Nonce的启用状态(默认为启用状态)。启用后,系统将在OTA更新过程中校验Nonce的有效性,从而防止重放攻击,提升系统安全性。
起始版本: 26.0.0
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1企业设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| isEnable | boolean | 是 | true表示启用OTA更新Nonce,false表示禁用OTA更新Nonce。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200016 | Service timeout. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
// 需根据实际情况进行替换
let isEnable: boolean = true;
try {
systemManager.setOtaUpdateNonceEnable(wantTemp, isEnable);
console.info('Succeeded in setting OTA update Nonce enable.');
} catch (err) {
console.error(`Failed to set OTA update Nonce enable. Code is ${err.code}, message is ${err.message}`);
} isOtaUpdateNonceEnable(admin: Want): boolean
查询OTA更新Nonce是否启用。适用于需要验证设备OTA更新安全配置的场景,帮助企业管理员确认Nonce校验功能状态,保障系统更新安全性。
起始版本: 26.0.0
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 返回true表示OTA更新Nonce已启用,返回false表示OTA更新Nonce已禁用。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200016 | Service timeout. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
try {
let result: boolean = systemManager.isOtaUpdateNonceEnable(wantTemp);
console.info(`Succeeded in querying OTA update Nonce enable: ${result}`);
} catch (err) {
console.error(`Failed to query OTA update Nonce enable. Code is ${err.code}, message is ${err.message}`);
} setLocalHotaDomain(domain: string): void
设置设备本机HOTA(Huawei Over-the-Air)域名。设置成功后,系统将使用指定的HOTA域名进行升级。适用于企业内网升级场景,帮助企业管理员指定设备本机HOTA域名,使设备能够从企业指定的升级服务器获取升级包,避免通过公网升级,提升升级的安全性和可控性。调用本接口前,可通过common.isFeatureSupported接口(入参为common.ManagedFeature.LOCAL_HOTA_DOMAIN)查询设备是否支持本机HOTA域名特性。
HOTA域名使用流程:
适用场景:
当通过systemManager.setOtaUpdatePolicy接口将升级策略设置为禁止升级时,设备将禁止OTA升级,此场景下设置的本机HOTA域名无法生效。
在多个MDM应用场景下,遵循配置规则。
传入的domain需符合域名命名规则,校验规则如下:
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1企业设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| domain | string | 是 | 本机HOTA域名,具体校验规则详见接口说明。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 9200016 | Service timeout. |
| 9200018 | This device is not an enterprise device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { common, systemManager } from '@kit.MDMKit';
// 需根据实际情况进行替换
let domain: string = "https://www.hotaExample.com";
// 调用本接口前,先查询设备是否支持本机HOTA域名特性
let isSupported: boolean = common.isFeatureSupported(common.ManagedFeature.LOCAL_HOTA_DOMAIN);
if (isSupported) {
try {
systemManager.setLocalHotaDomain(domain);
console.info('Succeeded in setting local HOTA domain.');
} catch (err) {
console.error(`Failed to set local HOTA domain. Code is ${err.code}, message is ${err.message}`);
}
} else {
console.info('The local HOTA domain feature is not supported.');
} getLocalHotaDomain(): string
获取设备本机HOTA(Huawei Over-the-Air)域名。适用于需要查询当前设备配置的本机HOTA域名的场景。
适用场景:
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1企业设备中可正常调用,在其他设备中返回空字符串。
模型约束: 此接口仅可在Stage模型下使用。
返回值:
| 类型 | 说明 |
|---|---|
| string | 返回本机HOTA域名。当设备不支持该接口时,返回空字符串作为默认值。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200016 | Service timeout. |
| 9200018 | This device is not an enterprise device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
示例:
import { systemManager } from '@kit.MDMKit';
try {
let domain: string = systemManager.getLocalHotaDomain();
console.info(`Succeeded in getting local HOTA domain: ${domain}`);
} catch (err) {
console.error(`Failed to get local HOTA domain. Code is ${err.code}, message is ${err.message}`);
} addDisallowedNearLinkProtocols(admin: Want, protocols: Array<NearLinkProtocol>, accountId: number): void
为指定用户添加禁用的星闪协议名单。NearLink Kit(星闪服务)提供一种低功耗、高速率的短距离通信服务,支持星闪设备之间的连接、数据交互。具体请参考NearLink Kit。本接口对键盘、手写笔等系统服务和系统应用不生效。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| protocols | Array<NearLinkProtocol> | 是 | 星闪协议列表。 |
| accountId | number | 是 | 用户ID,取值范围:大于等于0。 accountId可以通过getOsAccountLocalId等接口来获取。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
// 需根据实际情况进行替换
let protocols: systemManager.NearLinkProtocol[] = [systemManager.NearLinkProtocol.SSAP,
systemManager.NearLinkProtocol.DATA_TRANSFER];
// 需根据实际情况进行替换
let accountId: number = 100;
try {
systemManager.addDisallowedNearLinkProtocols(wantTemp, protocols, accountId);
console.info('Succeeded in adding the disabled Starlink protocol list for the specified user.');
} catch (err) {
console.error(`Failed to add the disabled Starlink protocol list for the specified user. Code is ${err.code}, message is ${err.message}`);
} removeDisallowedNearLinkProtocols(admin: Want, protocols: Array<NearLinkProtocol>, accountId: number): void
为指定用户移除禁用的星闪协议名单。移除成功后,指定用户可以重新使用移除列表中的星闪协议进行通信,恢复相应的协议连接能力。使用场景:在企业设备管理场景下,管理员可通过此接口移除之前设置的星闪协议禁用策略,允许用户恢复使用星闪协议进行设备间通信。适用于需要恢复特定用户星闪通信能力的场景,帮助企业管理员灵活调整用户设备的星闪协议访问权限,满足不同业务场景的通信需求。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| protocols | Array<NearLinkProtocol> | 是 | 星闪协议列表。 |
| accountId | number | 是 | 用户ID,取值范围:大于等于0。 accountId可以通过getOsAccountLocalId等接口来获取。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
// 需根据实际情况进行替换
let protocols: systemManager.NearLinkProtocol[] = [systemManager.NearLinkProtocol.SSAP,
systemManager.NearLinkProtocol.DATA_TRANSFER];
// 需根据实际情况进行替换
let accountId: number = 100;
try {
systemManager.removeDisallowedNearLinkProtocols(wantTemp, protocols, accountId);
console.info('Succeeded in removing the disabled Starlink protocol list for the specified user.');
} catch (err) {
console.error(`Failed to remove the disabled Starlink protocol list for the specified user. Code is ${err.code}, message is ${err.message}`);
} getDisallowedNearLinkProtocols(admin: Want, accountId: number): Array<NearLinkProtocol>
获取指定用户下禁用的星闪协议名单。适用于需要查询用户当前星闪协议访问限制的场景,帮助企业管理员验证策略是否正确下发,或在进行策略调整前获取当前配置。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| accountId | number | 是 | 用户ID,取值范围:大于等于0。 accountId可以通过getOsAccountLocalId等接口来获取。 |
返回值:
| 类型 | 说明 |
|---|---|
| Array<NearLinkProtocol> | 指定用户下禁用的星闪协议名单。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
// 需根据实际情况进行替换
let accountId: number = 100;
try {
let result: systemManager.NearLinkProtocol[] = systemManager.getDisallowedNearLinkProtocols(wantTemp, accountId);
console.info(`Succeeded in querying the disabled Starlink protocol list for the specified user: ${result}`);
} catch (err) {
console.error(`Failed to query the disabled Starlink protocol list for the specified user. Code is ${err.code}, message is ${err.message}`);
} setInstallLocalEnterpriseAppEnabled(admin: Want, isEnable: boolean): void
设置是否支持本地安装企业应用。设置为支持安装后,具备本地安装能力的PC/2in1企业设备可本地双击应用安装包,安装签名证书分发类型为enterprise_normal的企业应用。调用此接口前,此设备必须通过HEM商用部署。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1企业设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| isEnable | boolean | 是 | 是否支持本地安装企业应用。true表示支持,false表示不支持。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
// 需根据实际情况进行替换
let isEnable: boolean = true;
try {
systemManager.setInstallLocalEnterpriseAppEnabled(wantTemp, isEnable);
console.info('Succeeded in setting InstallLocalEnterpriseAppEnabled.');
} catch (err) {
console.error(`Failed to set installLocalEnterpriseAppEnabled. Code is ${err.code}, message is ${err.message}`);
} getInstallLocalEnterpriseAppEnabled(admin: Want | null): boolean
查询是否支持本地安装企业应用。适用于需要验证设备本地安装企业应用功能是否开启的场景,帮助企业管理员确认策略配置状态,确保设备能够正常安装企业应用。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1企业设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | null | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 API version 24之前,调用本接口查询系统当前是否支持本地安装企业应用。当设备存在多个MDM应用时,传入admin查询对应admin设置的策略。从API version 24开始,admin新增支持传入null,传入null时查询整机实际生效的策略。 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 是否支持本地安装企业应用,true为支持,false为不支持。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
try {
let isEnable: boolean = systemManager.getInstallLocalEnterpriseAppEnabled(wantTemp);
console.info('Succeeded in getting installLocalEnterpriseAppEnabled.');
} catch (err) {
console.error(`Failed to get installLocalEnterpriseAppEnabled. Code is ${err.code}, message is ${err.message}`);
} setAutoUnlockAfterReboot(admin: Want, isAllowed: boolean): void
设置设备重启自动解锁,仅针对无锁屏密码设备生效。适用于企业无人值守设备或需要快速重启恢复服务的场景,避免因手动解锁导致的设备停机时间,提升设备运维效率和业务连续性。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| isAllowed | boolean | 是 | true表示设备重启后自动解锁,false表示设备重启后不自动解锁。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { Want } from '@kit.AbilityKit';
import { systemManager } from '@kit.MDMKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
let isAllowed: boolean = true;
try {
systemManager.setAutoUnlockAfterReboot(wantTemp, isAllowed);
console.info('Succeeded in setting setAutoUnlockAfterReboot.');
} catch (err) {
console.error(`Failed to set auto unlock after reboot. Code is ${err.code}, message is ${err.message}`);
} getAutoUnlockAfterReboot(admin: Want): boolean
获取设备是否重启自动解锁。适用于需要验证设备重启解锁策略是否正确配置的场景,帮助企业管理员确认设备自动解锁功能状态。
本接口通过传入Want查询对应企业设备管理应用设置的策略,如需查询实际生效的策略,请使用systemManager.getAutoUnlockAfterReboot接口。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 返回true表示设备重启后自动解锁,返回false表示设备重启后不自动解锁。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { Want } from '@kit.AbilityKit';
import { systemManager } from '@kit.MDMKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
try {
let result: boolean = systemManager.getAutoUnlockAfterReboot(wantTemp);
console.info(`Succeeded in getting auto unlock after reboot. result: ${result}`);
} catch (err) {
console.error(`Failed to get auto unlock after reboot. Code is ${err.code}, message is ${err.message}`);
} getAutoUnlockAfterReboot(admin: Want | null): boolean
获取设备是否重启自动解锁。适用于需要验证设备重启解锁策略是否正确配置的场景,帮助企业管理员确认设备自动解锁功能状态。
起始版本: 26.0.0
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | null | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 当设备存在多个MDM应用时,传入Want时查询对应企业设备管理应用设置的策略,传入null时查询实际生效的策略。 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 返回true表示设备重启后自动解锁,返回false表示设备重启后不自动解锁。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
try {
// 参数需根据实际情况进行替换
systemManager.getAutoUnlockAfterReboot(null);
console.info('Succeeded in getting auto unlock after reboot.');
} catch (err) {
console.error(`Failed to get auto unlock after reboot. Code is ${err.code}, message is ${err.message}`);
} addKeyEventPolicies(admin: Want, keyPolicies: Array<KeyEventPolicy>): void
添加按键事件处理策略。系统触发按键事件时,若匹配下发的按键事件策略,将通过EnterpriseAdminExtensionAbility.onKeyEvent回调通知MDM应用,并携带匹配策略的按键事件信息。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在Phone和Tablet设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| keyPolicies | Array<KeyEventPolicy> | 是 | 按键策略。支持物理按键(电源键、音量加、音量减),导航键(回退、主页、最近打开)。物理键支持任意组合为组合键,导航键不支持组合。组合键事件响应详见按键事件回调onKeyEvent接口。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200010 | A conflict policy has been configured. |
| 9200012 | Parameter verification failed. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { Want } from '@kit.AbilityKit';
import { systemManager } from '@kit.MDMKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
let keypolicy: Array<systemManager.KeyEventPolicy> = [
{
"keyCode": systemManager.KeyCode.POWER,
"keyPolicy": systemManager.KeyPolicy.CUSTOM
},
{
"keyCode": systemManager.KeyCode.VOLUME_UP,
"keyPolicy": systemManager.KeyPolicy.CUSTOM
}
];
try {
systemManager.addKeyEventPolicies(wantTemp, keypolicy);
console.info('Succeeded in adding key event policies.');
} catch (err) {
console.error(`Failed to add key event policies. Code is ${err.code}, message is ${err.message}`);
} removeKeyEventPolicies(admin: Want, keyCodes: Array<KeyCode>): void
删除按键事件处理策略。删除成功后,系统将恢复对指定按键事件的默认处理行为。适用于需要恢复按键默认行为的场景,帮助企业管理员灵活调整设备按键响应策略,满足不同业务场景的需求。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在Phone和Tablet设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| keyCodes | Array<KeyCode> | 是 | 按键编码。支持一次删除多条按键策略,删除不支持按键时返回9200012错误码。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { Want } from '@kit.AbilityKit';
import { systemManager } from '@kit.MDMKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
let keyCodes: Array<systemManager.KeyCode> = [
systemManager.KeyCode.POWER, systemManager.KeyCode.VOLUME_UP
];
try {
systemManager.removeKeyEventPolicies(wantTemp, keyCodes);
console.info('Succeeded in removing key event policies.');
} catch (err) {
console.error(`Failed to remove key event policies. Code is ${err.code}, message is ${err.message}`);
} getKeyEventPolicies(admin: Want): Array<KeyEventPolicy>
获取按键事件处理策略。适用于需要查询当前按键事件处理策略配置的场景,帮助企业管理员验证策略是否正确下发,或在进行策略调整前获取当前配置。
本接口通过传入Want查询对应企业设备管理应用设置的策略,如需查询实际生效的策略,请使用systemManager.getKeyEventPolicies接口。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在Phone和Tablet设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
返回值:
| 类型 | 说明 |
|---|---|
| Array<KeyEventPolicy> | 返回当前配置的按键事件策略列表。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { Want } from '@kit.AbilityKit';
import { systemManager } from '@kit.MDMKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
let result: Array<systemManager.KeyEventPolicy> = [];
try {
result = systemManager.getKeyEventPolicies(wantTemp);
console.info('Succeeded in getting key event policies.');
} catch (err) {
console.error(`Failed to get key event policies. Code is ${err.code}, message is ${err.message}`);
} getKeyEventPolicies(admin: Want | null): Array<KeyEventPolicy>
获取按键事件处理策略。适用于需要查询当前按键事件处理策略配置的场景,帮助企业管理员验证策略是否正确下发,或在进行策略调整前获取当前配置。
起始版本: 26.0.0
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在Phone和Tablet设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | null | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 当设备存在多个MDM应用时,传入Want时查询对应企业设备管理应用设置的策略,传入null时查询实际生效的策略。 |
返回值:
| 类型 | 说明 |
|---|---|
| Array<KeyEventPolicy> | 返回当前配置的按键事件策略列表。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
let result: Array<systemManager.KeyEventPolicy> = [];
try {
// 参数需根据实际情况进行替换
result = systemManager.getKeyEventPolicies(null);
console.info('Succeeded in getting key event policies.');
} catch (err) {
console.error(`Failed to get key event policies. Code is ${err.code}, message is ${err.message}`);
} startCollectLog(admin: Want): Promise<void>
开始收集设备上已生成并存储至硬盘的FaultType类型的faultlog日志,不支持收集未存储至硬盘的faultlog日志、应用业务日志和系统运行日志。使用Promise异步回调。
在多个MDM应用场景下,允许多个MDM应用调用,不同MDM应用在不同用户下收集的日志分开保存,互不影响。同一时间只允许一个MDM应用启动日志收集任务,在任务执行完成前调用本接口会返回错误码9201009,任务执行完成后,允许其他MDM应用调用。
需要权限: ohos.permission.ENTERPRISE_READ_LOG
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 无返回结果的Promise对象。当收集日志任务创建失败时,会抛出错误对象。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9201009 | Collecting logs, please try again later. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { systemManager } from '@kit.MDMKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
systemManager.startCollectLog(wantTemp).then(() => {
console.info('Succeeded in starting collect log');
}).catch((err: BusinessError) => {
console.error(`Failed to start collect log. Code: ${err.code}, message: ${err.message}`);
}); finishLogCollected(admin: Want): void
删除本MDM应用在当前用户下收集到的设备日志。
在应用调用startCollectLog开始收集日志后,收到EnterpriseAdminExtensionAbility.onLogCollected回调时,建议立即拷贝或者处理日志,并调用此接口删除收集到的日志。
若不调用本接口,设备日志会占用系统存储空间,不影响下一次调用startCollectLog启动日志收集任务。
需要权限: ohos.permission.ENTERPRISE_READ_LOG
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { Want } from '@kit.AbilityKit';
import { systemManager } from '@kit.MDMKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
try {
systemManager.finishLogCollected(wantTemp);
console.info('Succeeded in finishing log collected.');
} catch (err) {
console.error(`Failed to finish log collected. Code is ${err.code}, message is ${err.message}`);
} setActivationLockDisabled(admin: Want, isDisabled: boolean, credential?: string): Promise<void>
禁用/启用设备激活锁。使用Promise异步回调。设备激活锁被禁用后,将无法使用查找设备功能。该功能只适用于特定设备(只支持PC/2in1企业设备)。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| isDisabled | boolean | 是 | 是否禁用激活锁。true表示禁用,false表示启用。 |
| credential | string | 否 | 禁用凭据。当设置禁用时该参数必须填写有效凭据,设置启用时为空。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 无返回结果的Promise对象。当设置禁用/启用失败时,会抛出错误对象。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 9200016 | Service timeout. |
| 9201011 | The credential of the activation lock is invalid. |
| 9201012 | Failed to enable or disable the activation lock. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { systemManager } from '@kit.MDMKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
// 需根据实际情况进行替换
let credential: string = "XXX";
let isDisabled: boolean = true;
systemManager.setActivationLockDisabled(wantTemp, isDisabled, credential).then(() => {
console.info('Succeeded in setting activation lock status.');
}).catch((err: BusinessError) => {
console.error(`Failed to set activation lock status. Code: ${err.code}, message: ${err.message}`);
}); isActivationLockDisabled(admin: Want): Promise<boolean>
获取设备激活锁禁用状态。使用Promise异步回调。适用于需要验证设备激活锁功能状态的场景,帮助企业管理员确认设备的安全配置,特别是在设备转让或回收时需要了解激活锁状态。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<boolean> | Promise对象,返回当前设备激活锁的禁用状态。返回true表示设备激活锁处于禁用状态,查找设备功能无法使用;返回false表示设备激活锁处于启用状态,可以正常使用设备查找功能。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200016 | Service timeout. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { systemManager } from '@kit.MDMKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
systemManager.isActivationLockDisabled(wantTemp).then(result => {
console.info(`Succeeded in getting activation lock status: ${JSON.stringify(result)}`);
}).catch((err: BusinessError) => {
console.error(`Failed to set activation lock status. Code: ${err.code}, message: ${err.message}`);
}); setInstallLocalEnterpriseAppEnabledForAccount(admin: Want, isEnable: boolean, accountId: number): void
设置指定用户下是否支持本地安装企业应用。在具备本地安装能力的PC/2in1企业设备上下发支持本地企业应用策略后,用户可以在桌面或者文件管理器直接双击企业应用安装包,即可直接安装企业应用。调用此接口前,此设备必须通过HEM商用部署。
仅支持enterprise_normal或enterprise_mdm签名类型的企业应用。
满足以下任意条件,PC/2in1企业设备在当前用户下即支持本地安装企业应用:
已通过setInstallLocalEnterpriseAppEnabled开启离线安装器;
已通过本接口设置当前用户支持本地安装企业应用。
在多个MDM应用场景下,遵循从严管控规则。任意一个MDM应用设置支持本地安装企业应用,则综合策略即为支持本地安装企业应用。
本地安装能力依赖华为应用市场。仅7.2.1.300及以上版本的应用市场支持安装MDM应用(分发类型为enterprise_mdm的应用);仅7.1.6.300及以上版本的应用市场支持普通企业应用(分发类型为enterprise_normal的应用)。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1企业设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 |
| isEnable | boolean | 是 | 是否支持本地安装企业应用。true表示支持,false表示不支持。 |
| accountId | number | 是 | 用户ID,取值范围:大于等于0。 accountId可以通过getOsAccountLocalId等接口来获取。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
// 需根据实际情况进行替换
let isEnable: boolean = true;
let accountId: number = 100;
try {
systemManager.setInstallLocalEnterpriseAppEnabledForAccount(wantTemp, isEnable, accountId);
console.info('Succeeded in setting InstallLocalEnterpriseAppEnabledForAccount.');
} catch (err) {
console.error(`Failed to set installLocalEnterpriseAppEnabledForAccount. Code is ${err.code}, message is ${err.message}`);
} getInstallLocalEnterpriseAppEnabledForAccount(admin: Want | null, accountId: number): boolean
查询指定用户是否支持本地安装企业应用。适用于需要验证特定用户本地安装企业应用功能是否开启的场景,帮助企业管理员确认策略配置状态,确保用户能够正常安装企业应用。
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1企业设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| admin | Want | null | 是 | 企业设备管理扩展组件。Want中必须包含企业设备管理扩展能力的abilityName和所在应用的bundleName。 当设备存在多个MDM应用时,传入admin查询对应admin设置的策略。传入null时查询整机实际生效的策略。 |
| accountId | number | 是 | 用户ID,取值范围:大于等于0。 accountId可以通过getOsAccountLocalId等接口来获取。 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 是否支持本地安装企业应用,true为支持,false为不支持。当admin为null时,查询系统当前是否支持本地安装企业应用。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// 需根据实际情况进行替换
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
// 需根据实际情况进行替换
let accountId: number = 100;
try {
let isEnable: boolean = systemManager.getInstallLocalEnterpriseAppEnabledForAccount(wantTemp, accountId);
console.info('Succeeded in getting installLocalEnterpriseAppEnabled.');
} catch (err) {
console.error(`Failed to get installLocalEnterpriseAppEnabled. Code is ${err.code}, message is ${err.message}`);
} addAllowedPrinterIPAddressesForDevice(ipAddresses: Array<string>): void
为当前设备添加基于IP的网络打印机白名单策略。设置该策略后,只有IP在白名单内的网络打印机允许打印,不在白名单内的网络打印机无法打印。
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| ipAddresses | Array<string> | 是 | IP地址(IPv4和IPv6,只允许输入完整标准格式的地址)。最多可设置100个IP地址 (白名单内已设置60条IP,最多再设置40条)。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200010 | A conflict policy has been configured. |
| 9200012 | Parameter verification failed. |
| 9200016 | Service timeout. |
| 9200019 | The policy list has exceeded the limit. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
// 需要根据实际情况替换
const ipArray: Array<string> = ['192.1.1.1', '2001:0db8:0000:0000:0000:0000:1428:57ab'];
try {
systemManager.addAllowedPrinterIPAddressesForDevice(ipArray);
console.info('Succeeded in adding the allowed printer IP Addresses for the device.');
} catch (err) {
console.error(`Failed to add the allowed printer IP Addresses for the device. Code is ${err.code}, message is ${err.message}`);
} removeAllowedPrinterIPAddressesForDevice(ipAddresses: Array<string>): void
为当前设备移除基于IP管控的网络打印机白名单。移除成功后,当白名单为空时,所有网络打印机均不受本策略管控;当白名单不为空时,已从白名单中移除IP的网络打印机将无法打印。
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| ipAddresses | Array<string> | 是 | IP地址(IPv4和IPv6,只允许输入完整标准格式的地址)。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 9200016 | Service timeout. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
// 需要根据实际情况替换
const ipArray: Array<string> = ['192.1.1.1', '2001:0db8:0000:0000:0000:0000:1428:57ab'];
try {
systemManager.removeAllowedPrinterIPAddressesForDevice(ipArray);
console.info('Succeeded in removing the allowed printer IP Addresses for the device.');
} catch (err) {
console.error(`Failed to remove the allowed printer IP Addresses for the device. Code is ${err.code}, message is ${err.message}`);
} getAllowedPrinterIPAddressesForDevice(queryPolicy?: common.QueryPolicy): Array<string>
获取设备基于IP管控的网络打印机白名单。
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常返回白名单数组,在其他设备中返回空数组。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| queryPolicy | common.QueryPolicy | 否 | 获取的策略。类型为SELF和ALL,不传时,等效于SELF。 |
返回值:
| 类型 | 说明 |
|---|---|
| Array<string> | 基于IP管控的网络打印机白名单。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200016 | Service timeout. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
示例:
import { common, systemManager } from '@kit.MDMKit';
try {
let result: string[] = systemManager.getAllowedPrinterIPAddressesForDevice(common.QueryPolicy.ALL);
console.info(`Succeeded in querying the allowed printer IP Addresses for the device.`);
} catch (err) {
console.error(`Failed to query the allowed printer IP Addresses for the device. Code is ${err.code}, message is ${err.message}`);
} addAllowedPrinterIPAddressesForAccount(ipAddresses: Array<string>): void
为当前用户添加基于IP的网络打印机白名单策略。设置该策略后,只有IP在白名单内的网络打印机允许打印,不在白名单内的网络打印机无法打印。
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| ipAddresses | Array<string> | 是 | IP地址(IPv4和IPv6,只允许输入完整标准格式的地址)。最多可设置100个IP地址 (白名单内已设置60条IP,最多再设置40条)。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200010 | A conflict policy has been configured. |
| 9200012 | Parameter verification failed. |
| 9200016 | Service timeout. |
| 9200019 | The policy list has exceeded the limit. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
// 需要根据实际情况替换
const ipArray: Array<string> = ['192.1.1.1', '2001:0db8:0000:0000:0000:0000:1428:57ab'];
try {
systemManager.addAllowedPrinterIPAddressesForAccount(ipArray);
console.info('Succeeded in adding the allowed printer IP Addresses for current user.');
} catch (err) {
console.error(`Failed to add the allowed printer IP Addresses for current user. Code is ${err.code}, message is ${err.message}`);
} removeAllowedPrinterIPAddressesForAccount(ipAddresses: Array<string>): void
为当前用户移除基于IP管控的网络打印机白名单。移除成功后,当白名单为空时,所有网络打印机均不受本策略管控;当白名单不为空时,已从白名单中移除IP的网络打印机将无法打印。
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| ipAddresses | Array<string> | 是 | IP地址(IPv4和IPv6,只允许输入完整标准格式的地址)。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 9200016 | Service timeout. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
// 需要根据实际情况替换
const ipArray: Array<string> = ['192.1.1.1', '2001:0db8:0000:0000:0000:0000:1428:57ab'];
try {
systemManager.removeAllowedPrinterIPAddressesForAccount(ipArray);
console.info('Succeeded in removing the allowed printer IP Addresses for current user.');
} catch (err) {
console.error(`Failed to remove the allowed printer IP Addresses for current user. Code is ${err.code}, message is ${err.message}`);
} getAllowedPrinterIPAddressesForAccount(queryPolicy?: common.QueryPolicy): Array<string>
获取当前用户基于IP管控的网络打印机白名单。
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在PC/2in1设备中可正常返回白名单数组,在其他设备中返回空数组。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| queryPolicy | common.QueryPolicy | 否 | 获取的策略。类型为SELF和ALL,不传时,等效于SELF。 |
返回值:
| 类型 | 说明 |
|---|---|
| Array<string> | 当前用户基于IP管控的网络打印机白名单。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200016 | Service timeout. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
示例:
import { common, systemManager } from '@kit.MDMKit';
try {
let result: string[] = systemManager.getAllowedPrinterIPAddressesForAccount(common.QueryPolicy.SELF);
console.info(`Succeeded in querying the allowed printer IP Addresses for current user.`);
} catch (err) {
console.error(`Failed to query the allowed printer IP Addresses for current user. Code is ${err.code}, message is ${err.message}`);
} createExactTimer(config: ExactTimerConfig): Promise<number>
创建精确定时器。适用于企业设备需要精确定时执行任务的场景,例如定时巡检、定时数据上报、定时策略下发等,帮助企业管理员实现设备任务的自动化定时执行。使用Promise异步回调。
该接口需与systemManager.destroyExactTimer接口配合使用,否则会导致内存泄漏。
当设备管理应用被取消激活或进程终止时,EDM服务会自动销毁该设备管理应用创建的所有定时器。
若创建的定时器名称与已存在的定时器名称相同,则先前的同名定时器将被自动停止并销毁,新创建的定时器将被分配新的定时器ID,与被销毁的定时器ID不同。
单个设备管理应用最多可创建5个同时生效的定时器,超出上限时返回9201053错误码。
应用进程长时间后台运行时可能被系统冻结或终止,导致定时器被销毁,可通过addFreezeExemptedApps接口将应用添加至防冻结名单以避免此问题。
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在Phone和Tablet中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| config | ExactTimerConfig | 是 | 定时器初始化配置,包括是否为循环定时器、触发间隔、回调和名称。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<number> | Promise对象,返回定时器ID。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 9200016 | Service timeout. |
| 9201053 | The number of timers has reached the upper limit. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { BusinessError } from '@kit.BasicServicesKit';
let config: systemManager.ExactTimerConfig = {
name: 'timer1',
repeat: true,
interval: 5000,
callback: () => {
console.info('Timer expired.');
}
};
systemManager.createExactTimer(config).then((timerId: number) => {
console.info(`Succeeded in creating exact timer, timerId: ${timerId}.`);
}).catch((err: BusinessError) => {
console.error(`Failed to create exact timer. Code: ${err.code}, message: ${err.message}`);
}); startExactTimer(timer: number, triggerTime: number): Promise<void>
启动精确定时器。定时器到期时将触发创建定时器时配置的回调函数。对于循环定时器,到达触发时间后,将按配置的interval周期性触发回调;对于单次定时器,到达触发时间后触发一次回调。适用于启动定时任务的场景。使用Promise异步回调。
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在Phone和Tablet中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| timer | number | 是 | 定时器ID,由systemManager.createExactTimer接口获取。 |
| triggerTime | number | 是 | 定时器触发时间,单位:毫秒。该值为目标触发时刻的系统启动后经过时间,需在当前系统启动后经过的时间基础上加上期望的延迟时长。例如,期望5秒后触发定时器,可通过systemDateTime.getUptime(传入TimeType.STARTUP)获取当前系统启动后经过的时间,再加上5s。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 无返回结果的Promise对象。当启动定时器失败时,会抛出错误对象。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200012 | Parameter verification failed. |
| 9200016 | Service timeout. |
| 9201054 | The specified timer does not exist or does not belong to the current administrator. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { systemDateTime } from '@kit.BasicServicesKit';
// 需根据实际情况进行替换,timerId由createExactTimer接口获取
let timerId: number = 1;
// 10秒后开始触发定时器
let triggerTime: number = systemDateTime.getUptime(systemDateTime.TimeType.STARTUP) + 10000;
systemManager.startExactTimer(timerId, triggerTime).then(() => {
console.info('Succeeded in starting exact timer.');
}).catch((err: BusinessError) => {
console.error(`Failed to start exact timer. Code: ${err.code}, message: ${err.message}`);
}); stopExactTimer(timer: number): Promise<void>
停止精确定时器。停止后定时器将不再触发回调,但定时器资源不会被释放,可通过systemManager.startExactTimer接口重新启动。适用于暂停定时任务的场景。使用Promise异步回调。
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在Phone和Tablet中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| timer | number | 是 | 定时器ID,由systemManager.createExactTimer接口获取。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 无返回结果的Promise对象。当停止定时器失败时,会抛出错误对象。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200016 | Service timeout. |
| 9201054 | The specified timer does not exist or does not belong to the current administrator. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { BusinessError } from '@kit.BasicServicesKit';
// 需根据实际情况进行替换,timerId由createExactTimer接口获取
let timerId: number = 1;
systemManager.stopExactTimer(timerId).then(() => {
console.info('Succeeded in stopping exact timer.');
}).catch((err: BusinessError) => {
console.error(`Failed to stop exact timer. Code: ${err.code}, message: ${err.message}`);
}); destroyExactTimer(timer: number): Promise<void>
销毁精确定时器。销毁后定时器资源将被释放,定时器ID将失效,无法再用于启动或停止定时器。适用于不再需要定时任务的场景,帮助企业管理员及时释放系统资源。使用Promise异步回调。
起始版本: 26.0.1
需要权限: ohos.permission.ENTERPRISE_MANAGE_SYSTEM
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
设备行为差异: 该接口在Phone和Tablet中可正常调用,在其他设备中返回801错误码。
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| timer | number | 是 | 定时器ID,由systemManager.createExactTimer接口获取。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 无返回结果的Promise对象。当销毁定时器失败时,会抛出错误对象。 |
错误码:
| 错误码ID | 错误信息 |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 9200016 | Service timeout. |
| 9201054 | The specified timer does not exist or does not belong to the current administrator. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 801 | Capability not supported. Failed to call the API due to limited device capabilities. |
示例:
import { systemManager } from '@kit.MDMKit';
import { BusinessError } from '@kit.BasicServicesKit';
// 需根据实际情况进行替换,timerId由createExactTimer接口获取
let timerId: number = 1;
systemManager.destroyExactTimer(timerId).then(() => {
console.info('Succeeded in destroying exact timer.');
}).catch((err: BusinessError) => {
console.error(`Failed to destroy exact timer. Code: ${err.code}, message: ${err.message}`);
}); 待更新的系统版本信息。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| versionName | string | 否 | 否 | 待更新的系统版本名称。 |
| firstReceivedTime | number | 否 | 否 | 第一次收到系统更新包的时间(单位:秒)。 |
| packageType | string | 否 | 否 | 待更新的系统更新包类型,类型分为normal和patch类型。 |
升级策略。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| policyType | PolicyType | 否 | 否 | 表示升级策略类型。 |
| version | string | 否 | 否 | 表示待升级软件版本号。 |
| latestUpdateTime | number | 否 | 是 | 表示最晚升级时间(时间戳)。 |
| delayUpdateTime | number | 否 | 是 | 表示延迟升级时间(单位:小时)。 |
| installStartTime | number | 否 | 是 | 表示指定安装窗口起始时间(时间戳)。 |
| installEndTime | number | 否 | 是 | 表示指定安装窗口结束时间(时间戳)。 |
| disableSystemOtaUpdate20+ | boolean | 否 | 是 | 表示是否禁用在公网环境下升级。true表示禁用公网升级,false表示不禁用公网升级。如果作为systemManager.setOtaUpdatePolicy的入参,该字段可缺省,缺省时保持当前配置不变。当前配置可通过systemManager.getOtaUpdatePolicy接口获取。禁用公网升级后,可以采用内网升级。推荐使用restrictions.setDisallowedPolicy禁用公网升级。 |
升级策略类型枚举。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| DEFAULT | 0 | 默认升级策略。周期弹框提醒用户升级。周期从24小时开始逐渐延长。 |
| PROHIBIT | 1 | 禁止升级策略。 |
| UPDATE_TO_SPECIFIC_VERSION | 2 | 强制升级策略。需指定最晚升级时间(latestUpdateTime)参数。1. 距离最晚升级时间大于48小时未升级,提醒弹框每24小时常规提醒一次。2. 距离最晚升级时间小于48小时未升级,每隔X小时周期提醒安装升级,消息处于通知中心,且不可移除。3. 超过最晚升级时间还未升级,弹出闲时强制升级提醒。 |
| WINDOWS | 3 | 指定时间窗口升级策略。需指定时间窗口参数(installStartTime、installEndTime)。时间窗口必须大于5分钟。1. 配置时间窗口[A,B],获取到窗口中的随机升级时间C,到达时间后满足空闲条件,自动升级。2. 配置时间窗口[A,B],获取到窗口中的随机升级时间C,到达时间后不满足空闲条件,B-C大于半小时,在C和B之间重新刷新一个随机时间D,到达D时间后满足空闲条件,自动升级。3. 配置时间窗口[A,B],获取到窗口中的随机升级时间C,到达时间后不满足空闲条件,B-C大于半小时,在C和B之间重新刷新一个随机时间D,到达D时间后不满足空闲条件,24小时后再检测,即窗口任务推迟到下一个[A,B]窗口。4. 配置时间[A,B],获取到窗口中的随机升级时间C,到达时间后不满足空闲条件,B-C小于或等于半小时,24小时后再检测,即窗口任务推迟到下一个[A,B]窗口。 |
| POSTPONE | 4 | 延迟升级策略。延迟指定时间(delayUpdateTime)后进入DEFAULT模式,周期提示用户升级。 |
系统更新包信息。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| version | string | 否 | 否 | 系统更新包版本号。 |
| packages | Array<Package> | 否 | 否 | 系统更新包详情。 |
| description | PackageDescription | 否 | 是 | 系统更新包描述信息。 |
| authInfo19+ | string | 否 | 是 | 系统更新包的鉴权信息。 |
系统更新包详情。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| type | PackageType | 否 | 否 | 系统更新包类型。 |
| path | string | 否 | 否 | 系统更新包文件路径。若传入fd参数,该参数传入更新包文件名。 |
| fd | number | 否 | 是 | 系统更新包文件句柄。当前不支持只传入path参数,需要传入fd。 |
系统更新包描述信息。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| notify | NotifyDescription | 否 | 是 | 企业自定义更新通知说明。 |
企业自定义更新通知说明。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| installTips | string | 否 | 是 | 企业自定义更新提示。 |
| installTipsDetail | string | 否 | 是 | 企业自定义更新提示详情。 |
系统更新结果信息。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| version | string | 否 | 否 | 系统当前版本号。 |
| status | UpdateStatus | 否 | 否 | 系统更新状态。 |
| errorInfo | ErrorInfo | 否 | 否 | 系统更新错误信息。 |
系统更新错误信息。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| code | number | 否 | 否 | 错误码。 |
| message | string | 否 | 否 | 错误描述信息。 |
系统更新包类型。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| FIRMWARE | 1 | 固件。 |
系统更新状态。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| NO_UPDATE_PACKAGE | -4 | 指定版本系统更新包不存在。 |
| UPDATE_WAITING | -3 | 系统更新包等待安装中。 |
| UPDATING | -2 | 正在更新。 |
| UPDATE_FAILURE | -1 | 更新失败。 |
| UPDATE_SUCCESS | 0 | 更新成功。 |
星闪协议枚举。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| SSAP | 0 | SSAP(SparkLink Service Access Protocol)协议。具体请参考SSAP协议。 |
| DATA_TRANSFER | 1 | 数据传输协议。具体请参考Data Transfer协议。 |
按键事件处理策略。按键事件发生时,仅拦截响应已下发按键事件处理策略的按键。对于未下发按键事件处理策略的按键事件,系统执行原先的响应逻辑。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
按键编码。添加按键事件处理策略addKeyEventPolicies、删除按键事件处理策略removeKeyEventPolicies、获取按键事件处理策略getKeyEventPolicies和按键事件回调onKeyEvent接口通过按键编码映射到设备对应实际按键。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| POWER | 0 | 电源键。 |
| VOLUME_UP | 1 | 音量加。 |
| VOLUME_DOWN | 2 | 音量减。 |
| BACK | 3 | 导航键-回退。 |
| HOME | 4 | 导航键-主页。 |
| RECENT | 5 | 导航键-最近打开。 |
按键策略。MDM应用下发按键策略的按键编码与系统按键事件匹配后的系统行为。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| INTERCEPTION | 0 | 拦截消息。设置后仅会拦截当前按键事件,系统不会再处理该事件,按键回调接口也不会响应按键事件。例如:下发电源键拦截策略后,按电源键无任何响应,无法关机,无法锁屏,仅影响开机状态下电源键事件,关机时可通过电源键正常开机。 |
| CUSTOM | 1 | 拦截并转发消息。 设置后会拦截当前按键事件,系统不会再处理该事件,同时通过EnterpriseAdminExtensionAbility.onKeyEvent回调接口将发生的按键事件通知给MDM应用,通知MDM应用处理该事件的过程不会阻塞系统后续的其他事件处理。 |
按键事件。EnterpriseAdminExtensionAbility.onKeyEvent按键事件回调触发时,传递当前按键事件信息。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
按键动作。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| UNKNOWN | -1 | 除按下和抬起动作以外,其他按键动作。 |
| DOWN | 0 | 按键按下动作。 |
| UP | 1 | 按键抬起动作。 |
其他按键信息。当前KeyCode事件发生时,其他已被按下的按键信息。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| keyCode | KeyCode | 否 | 否 | 按键编码。 |
| pressed | boolean | 否 | 否 | 按键动作。按键是否被按下。true:按下;false:抬起 |
| downTime | number | 否 | 否 | 按键动作发生时间,系统开机后微秒级时间戳。导航按键不支持组合扩展,发生时间显示为0。 |
精确定时器初始化配置。创建精确定时器systemManager.createExactTimer接口的入参,用于配置定时器名称、是否循环触发、触发间隔和到期回调函数。
起始版本: 26.0.1
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
起始版本: 26.0.1
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| name | string | 否 | 否 | 定时器名称。最大长度为64字节,不能为空。 |
| repeat | boolean | 否 | 否 | 是否为循环定时器。true表示循环定时器,false表示单次定时器。 |
| interval | number | 否 | 否 | 定时器触发时间间隔。循环定时器时,interval最小值为1000ms,最大值为86400000ms;单次定时器时,该值为0。单位:毫秒(ms)。 |