harmony 鸿蒙@ohos.enterprise.adminManager (admin权限管理)
@ohos.enterprise.adminManager (admin权限管理)
本模块为企业MDM应用提供admin权限管理能力,包括激活/解除激活admin权限、事件订阅、委托授权等。
说明:
本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
本模块接口仅对设备管理应用开放,具体请参考MDM Kit开发指南。
导入模块
import { adminManager } from '@kit.MDMKit';
adminManager.disableAdmin
disableAdmin(admin: Want, userId?: number): Promise<void>
将当前设备指定用户的设备管理应用解除激活。使用promise异步回调。
需要权限: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束:此接口仅可在Stage模型下使用。
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
userId | number | 否 | 用户ID,取值范围:大于等于0。 - 调用接口时,若传入userId,表示指定用户。 - 调用接口时,若未传入userId,表示当前用户。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。当解除激活设备管理应用失败时,会抛出错误对象。 |
错误码:
错误码ID | 错误信息 |
---|---|
9200005 | Failed to deactivate the administrator application of 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 { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
adminManager.disableAdmin(wantTemp, 100).catch((err: BusinessError) => {
console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`);
});
adminManager.subscribeManagedEventSync
subscribeManagedEventSync(admin: Want, managedEvents: Array<ManagedEvent>): void
订阅系统管理事件。
需要权限: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束:此接口仅可在Stage模型下使用。
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
managedEvents | Array<ManagedEvent> | 是 | 订阅事件数组。 |
错误码:
错误码ID | 错误信息 |
---|---|
9200001 | The application is not an administrator application of the device. |
9200008 | The specified system event is invalid. |
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 { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED];
try {
adminManager.subscribeManagedEventSync(wantTemp, events);
console.info('Succeeded in subscribing managed event.');
} catch (err) {
console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`);
}
adminManager.unsubscribeManagedEventSync
unsubscribeManagedEventSync(admin: Want, managedEvents: Array<ManagedEvent>): void
取消订阅系统管理事件。
需要权限: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束:此接口仅可在Stage模型下使用。
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
managedEvents | Array<ManagedEvent> | 是 | 取消订阅事件数组。 |
错误码:
错误码ID | 错误信息 |
---|---|
9200001 | The application is not an administrator application of the device. |
9200008 | The specified system event is invalid. |
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 { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED];
try {
adminManager.unsubscribeManagedEventSync(wantTemp, events);
console.info('Succeeded in unsubscribing managed event.');
} catch (err) {
console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`);
}
adminManager.setDelegatedPolicies14+
setDelegatedPolicies(admin: Want, bundleName: string, policies: Array<string>): void
委托其他应用来设置设备的管控策略。被委托的其他应用需申请委托策略对应接口所需权限。
需要权限: ohos.permission.ENTERPRISE_MANAGE_DELEGATED_POLICY
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束:此接口仅可在Stage模型下使用。
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
bundleName | string | 是 | 被委托应用包名。被委托应用仅支持分发类型为enterprise_normal(企业普通应用)和enterprise_mdm(企业MDM应用)两种类型,开发者可在Profile文件中查询分发类型字段app-distribution-type。 |
policies | Array<string> | 是 | 委托策略列表。 |
错误码:
错误码ID | 错误信息 |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
9200009 | Failed to grant the permission to the application. |
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 { Want } from '@kit.AbilityKit';
let admin: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let policies: Array<string> = ["disabled_hdc"];
try {
adminManager.setDelegatedPolicies(admin, "com.example.enterprise.xxx", policies);
console.info('Succeeded in setting delegated policies.');
} catch (err) {
console.error(`Failed to set delegated policies. Code: ${err.code}, message: ${err.message}`);
}
adminManager.getDelegatedPolicies14+
getDelegatedPolicies(admin: Want, bundleName: string): Array<string>
查询被委托应用可访问的策略列表。
需要权限: ohos.permission.ENTERPRISE_MANAGE_DELEGATED_POLICY
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束:此接口仅可在Stage模型下使用。
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
bundleName | string | 是 | 被委托应用包名。被委托应用仅支持分发类型为enterprise_normal(企业普通应用)和enterprise_mdm(企业MDM应用)两种类型,开发者可在Profile文件中查询分发类型字段app-distribution-type。 |
返回值:
类型 | 说明 |
---|---|
Array<string> | 委托策略列表。 |
错误码:
错误码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 { Want } from '@kit.AbilityKit';
let admin: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
try {
let policies: Array<string> = adminManager.getDelegatedPolicies(admin, "com.example.enterprise.xxx");
console.info(`Succeeded in getting delegated policies.${JSON.stringify(policies)}`);
} catch (err) {
console.error(`Failed to get delegated policies. Code: ${err.code}, message: ${err.message}`);
}
adminManager.getDelegatedBundleNames14+
getDelegatedBundleNames(admin: Want, policy: string): Array<string>
查询可以访问某个委托策略的被委托应用,输出被委托应用列表。
需要权限: ohos.permission.ENTERPRISE_MANAGE_DELEGATED_POLICY
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束:此接口仅可在Stage模型下使用。
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
policy | string | 是 | 委托策略。 |
返回值:
类型 | 说明 |
---|---|
Array<string> | 被委托应用列表。 |
错误码:
错误码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 { Want } from '@kit.AbilityKit';
let admin: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
try {
let bundleNames: Array<string> = adminManager.getDelegatedBundleNames(admin, "disabled_hdc");
console.info(`Succeeded in getting delegated bundles.${JSON.stringify(bundleNames)}`);
} catch (err) {
console.error(`Failed to get delegated bundles. Code: ${err.code}, message: ${err.message}`);
}
adminManager.startAdminProvision15+
startAdminProvision(admin: Want, type: AdminType, context: common.Context, parameters: Record<string, string>): void
设备管理应用拉起BYOD管理员激活页面进行激活。
需要权限: ohos.permission.START_PROVISIONING_MESSAGE
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
模型约束:此接口仅可在Stage模型下使用。
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
type | AdminType | 是 | 激活的设备管理应用类型,仅支持ADMIN_TYPE_BYOD类型。 |
context | common.Context | 是 | 管理应用的上下文信息。 |
parameters | Record<string, string> | 是 | 自定义参数信息,其中Key值必须包含:”activateId”。 |
错误码:
以下的错误码的详细介绍请参见通用错误码。
错误码ID | 错误信息 |
---|---|
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 { common, Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let recordParameters: Record<string, string> = {
"activateId": "activateId testValue",
"customizedInfo": "customizedInfo testValue"
};
const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
try {
console.info('context:' + JSON.stringify(context));
adminManager.startAdminProvision(wantTemp, adminManager.AdminType.ADMIN_TYPE_BYOD, context, recordParameters);
console.info('startAdminProvision::success');
} catch (error) {
console.error('startAdminProvision::errorCode: ' + error.code + ' errorMessage: ' + error.message);
}
ManagedEvent
可订阅的系统管理事件。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
名称 | 值 | 说明 |
---|---|---|
MANAGED_EVENT_BUNDLE_ADDED | 0 | 应用安装事件。 |
MANAGED_EVENT_BUNDLE_REMOVED | 1 | 应用卸载事件。 |
MANAGED_EVENT_APP_START | 2 | 应用启动事件。 |
MANAGED_EVENT_APP_STOP | 3 | 应用停止事件。 |
MANAGED_EVENT_SYSTEM_UPDATE | 4 | 系统更新事件。 |
MANAGED_EVENT_ACCOUNT_ADDED18+ | 5 | 账号新增事件。 |
MANAGED_EVENT_ACCOUNT_SWITCHED18+ | 6 | 账号切换事件。 |
MANAGED_EVENT_ACCOUNT_REMOVED18+ | 7 | 账号删除事件。 |
AdminType15+
设备管理应用的类型。
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
名称 | 值 | 说明 |
---|---|---|
ADMIN_TYPE_BYOD | 0x02 | BYOD设备管理应用。 |
附录
可委托策略列表
你可能感兴趣的鸿蒙文章
harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility(企业设备管理扩展能力)
harmony 鸿蒙@ohos.enterprise.accountManager(账户管理)(系统接口)
harmony 鸿蒙@ohos.enterprise.accountManager(账户管理)
harmony 鸿蒙@ohos.enterprise.adminManager(企业设备管理)(系统接口)
harmony 鸿蒙@ohos.enterprise.applicationManager(应用管理)(系统接口)
harmony 鸿蒙@ohos.enterprise.applicationManager(应用管理)
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦