@ohos.enterprise.adminManager (Administrator Permission Management) (System API)

The adminManager module provides administrator permission management capabilities for enterprise MDM applications, including enabling or disabling administrator permissions, subscribing to events, delegating applications, and granting permissions.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

The APIs of this module can be called only by a device administrator application.

This topic describes only system APIs provided by the module. For details about its public APIs, see @ohos.enterprise.adminManager.

Modules to Import

import { adminManager } from '@kit.MDMKit';

adminManager.enableAdmin

enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, callback: AsyncCallback<void>): void

Enables a device administrator application. The super device administrator application can be activated only by the administrator. After the application is enabled, it cannot be uninstalled. The EnterpriseAdminExtensionAbility component of the application will automatically start upon device startup and user switching. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
enterpriseInfo EnterpriseInfo Yes Enterprise information of the device administrator application.
type AdminType Yes Type of the device administrator application to enable.
callback AsyncCallback<void> Yes Callback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
9200003 The administrator ability component is invalid.
9200004 Failed to activate the administrator application of the device.
9200007 The system ability works abnormally.
201 Permission verification failed. The application does not have the permission required to call the API.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
let enterpriseInfo: adminManager.EnterpriseInfo = {
  // Replace with actual values.
  name: 'enterprise name',
  description: 'enterprise description'
};

adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_SUPER, (err) => {
  if (err) {
    console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in enabling admin');
});

adminManager.enableAdmin

enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId: number, callback: AsyncCallback<void>): void

Enables a device administrator application for the specified user. The super device administrator application can be activated only by the administrator. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
enterpriseInfo EnterpriseInfo Yes Enterprise information of the device administrator application.
type AdminType Yes Type of the device administrator application to enable.
userId number Yes User ID, which must be greater than or equal to 0.
The default value is the user ID of the caller.
callback AsyncCallback<void> Yes Callback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
9200003 The administrator ability component is invalid.
9200004 Failed to activate the administrator application of the device.
9200007 The system ability works abnormally.
201 Permission verification failed. The application does not have the permission required to call the API.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
let enterpriseInfo: adminManager.EnterpriseInfo = {
  // Replace with actual values.
  name: 'enterprise name',
  description: 'enterprise description'
};

adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100, (err) => {
  if (err) {
    console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in enabling admin');
});

adminManager.enableAdmin

enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId?: number): Promise<void>

Enables a device administrator application for the current or specified user. The super device administrator application can be activated only by the administrator. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
enterpriseInfo EnterpriseInfo Yes Enterprise information of the device administrator application.
type AdminType Yes Type of the device administrator application to enable.
userId number No User ID, which must be greater than or equal to 0.
- If userId is passed in, this API applies to the specified user.
- If userId is not passed in, this API applies to the current user.

Return value

Type Description
Promise<void> Promise that returns no value. If the operation fails, an error object will be thrown.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
9200003 The administrator ability component is invalid.
9200004 Failed to activate the administrator application of the device.
9200007 The system ability works abnormally.
201 Permission verification failed. The application does not have the permission required to call the API.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
let enterpriseInfo: adminManager.EnterpriseInfo = {
  // Replace with actual values.
  name: 'enterprise name',
  description: 'enterprise description'
};

adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100).catch(
  (err: BusinessError) => {
    console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`);
  });

adminManager.disableAdmin

disableAdmin(admin: Want, callback: AsyncCallback<void>): void

Disables a common device administrator application for the current user. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
callback AsyncCallback<void> Yes Callback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};

adminManager.disableAdmin(wantTemp, (err) => {
  if (err) {
    console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in disabling admin');
});

adminManager.disableAdmin

disableAdmin(admin: Want, userId: number, callback: AsyncCallback<void>): void

Disables a common device administrator application for the user specified by userId. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
userId number Yes User ID, which must be greater than or equal to 0.
The default value is the user ID of the caller.
callback AsyncCallback<void> Yes Callback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};

adminManager.disableAdmin(wantTemp, 100, (err) => {
  if (err) {
    console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in disabling admin');
});

adminManager.disableSuperAdmin

disableSuperAdmin(bundleName: String, callback: AsyncCallback<void>): void

Disables a super device administrator application based on bundleName. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundleName String Yes Bundle name of the super device administrator application to disable.
callback AsyncCallback<void> Yes Callback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

// Replace with actual values.
let bundleName: string = 'com.example.myapplication';

adminManager.disableSuperAdmin(bundleName, (err) => {
  if (err) {
    console.error(`Failed to disable super admin. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in disabling super admin');
});

adminManager.disableSuperAdmin

disableSuperAdmin(bundleName: String): Promise<void>

Disables a super device administrator application based on bundleName. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundleName String Yes Bundle name of the super device administrator application to disable.

Return value

Type Description
Promise<void> Promise that returns no value. If the operation fails, an error object will be thrown.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

// Replace with actual values.
let bundleName: string = 'com.example.myapplication';

adminManager.disableSuperAdmin(bundleName).catch((err: BusinessError) => {
  console.error(`Failed to disable super admin. Code: ${err.code}, message: ${err.message}`);
});

adminManager.isAdminEnabled

isAdminEnabled(admin: Want, callback: AsyncCallback<boolean>): void

Checks whether a device administrator application of the current user is enabled. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
callback AsyncCallback<boolean> Yes Callback invoked to return the result. If the operation is successful, err is null and data is a Boolean value (true means that the device administrator application is enabled; and false means the opposite). If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};

adminManager.isAdminEnabled(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to query admin is enabled or not. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in querying admin is enabled or not, result : ${result}`);
});

adminManager.isAdminEnabled

isAdminEnabled(admin: Want, userId: number, callback: AsyncCallback<boolean>): void

Checks whether a device administrator application of the specified user is enabled. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
userId number Yes User ID, which must be greater than or equal to 0.
The default value is the user ID of the caller.
callback AsyncCallback<boolean> Yes Callback invoked to return the result. If the operation is successful, err is null and data is a Boolean value (true means that the device administrator application is enabled; and false means the opposite). If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};

// Replace parameters with actual values.
adminManager.isAdminEnabled(wantTemp, 100, (err, result) => {
  if (err) {
    console.error(`Failed to query admin is enabled. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in querying admin is enabled or not, result : ${result}`);
});

adminManager.isAdminEnabled

isAdminEnabled(admin: Want, userId?: number): Promise<boolean>

Checks whether a device administrator application of the current or specified user is enabled. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
userId number No User ID, which must be greater than or equal to 0.
- If userId is passed in, this API applies to the specified user.
- If userId is not passed in, this API applies to the current user.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means the device administrator application is enabled; the value false means the opposite.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};

// Replace parameters with actual values.
adminManager.isAdminEnabled(wantTemp, 100).then((result) => {
  console.info(`Succeeded in querying admin is enabled or not, result : ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to query admin is enabled or not. Code: ${err.code}, message: ${err.message}`);
});

adminManager.isSuperAdmin

isSuperAdmin(bundleName: String, callback: AsyncCallback<boolean>): void

Checks whether a super device administrator application is enabled based on bundleName. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundleName String Yes Super device administrator application.
callback AsyncCallback<boolean> Yes Callback invoked to return the result. If the operation is successful, err is null and data is a Boolean value (true means that the device administrator application is enabled; and false means the opposite). If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

// Replace with actual values.
let bundleName: string = 'com.example.myapplication';

adminManager.isSuperAdmin(bundleName, (err, result) => {
  if (err) {
    console.error(`Failed to query admin is super admin or not. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in querying admin is super admin or not, result : ${result}`);
});

adminManager.isSuperAdmin

isSuperAdmin(bundleName: String): Promise<boolean>

Checks whether a super device administrator application is enabled based on bundleName. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
bundleName String Yes Super device administrator application.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means the super device administrator application is enabled; the value false means the opposite.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

// Replace with actual values.
let bundleName: string = 'com.example.myapplication';

adminManager.isSuperAdmin(bundleName).then((result) => {
  console.info(`Succeeded in querying admin is super admin or not, result : ${result}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to query admin is super admin or not. Code: ${err.code}, message: ${err.message}`);
});

adminManager.getSuperAdmin12+

getSuperAdmin(): Promise<Want>

Obtains the super device administrator application of this administrator. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Return value

Type Description
Promise<Want> Promise used to return the super device administrator application obtained. If no super device administrator application is activated on the device, bundleName and abilityName in Want returned are empty strings.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
202 Permission verification failed. A non-system application calls a system API.

Example

import { adminManager } from '@kit.MDMKit';
import { BusinessError } from '@kit.BasicServicesKit';

adminManager.getSuperAdmin().then((result) => {
  console.info(`Succeeded in getting super admin :${JSON.stringify(result)}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get super admin. Code: ${err.code}, message: ${err.message}`);
})

adminManager.setEnterpriseInfo

setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo, callback: AsyncCallback<void>): void

Sets the enterprise information of the device administrator application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.SET_ENTERPRISE_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
enterpriseInfo EnterpriseInfo Yes Enterprise information of the device administrator application.
callback AsyncCallback<void> Yes Callback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
9200001 The application is not an administrator application of the device.
201 Permission verification failed. The application does not have the permission required to call the API.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
let enterpriseInfo: adminManager.EnterpriseInfo = {
  // Replace with actual values.
  name: 'enterprise name',
  description: 'enterprise description'
};

adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo, (err) => {
  if (err) {
    console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in setting enterprise info');
});

adminManager.setEnterpriseInfo

setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo): Promise<void>

Sets the enterprise information of the device administrator application. This API uses a promise to return the result.

Required permissions: ohos.permission.SET_ENTERPRISE_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
enterpriseInfo EnterpriseInfo Yes Enterprise information of the device administrator application.

Return value

Type Description
Promise<void> Promise that returns no value. If the operation fails, an error object will be thrown.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
9200001 The application is not an administrator application of the device.
201 Permission verification failed. The application does not have the permission required to call the API.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
let enterpriseInfo: adminManager.EnterpriseInfo = {
  // Replace with actual values.
  name: 'enterprise name',
  description: 'enterprise description'
};

adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo).catch((err: BusinessError) => {
  console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`);
});

adminManager.getEnterpriseInfo

getEnterpriseInfo(admin: Want, callback: AsyncCallback<EnterpriseInfo>): void

Obtains the enterprise information of the device administrator application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
callback AsyncCallback<EnterpriseInfo> Yes Callback invoked to return the result. If the operation is successful, err is null and data is the enterprise information of the device administrator application obtained. If the operation fails, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
9200001 The application is not an administrator application of the device.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};

adminManager.getEnterpriseInfo(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`);
});

adminManager.getEnterpriseInfo

getEnterpriseInfo(admin: Want): Promise<EnterpriseInfo>

Obtains the enterprise information of the device administrator application. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.

Return value

Type Description
Promise<EnterpriseInfo> Promise used to return the enterprise information of the device administrator application.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
9200001 The application is not an administrator application of the device.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};

adminManager.getEnterpriseInfo(wantTemp).then((result) => {
  console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`);
});

adminManager.subscribeManagedEvent

subscribeManagedEvent(admin: Want, managedEvents: Array<ManagedEvent>, callback: AsyncCallback<void>): void

Subscribes to system management events. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
managedEvents Array<ManagedEvent> Yes Array of events to subscribe to.
callback AsyncCallback<void> Yes Callback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
let events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED];

adminManager.subscribeManagedEvent(wantTemp, events, (err) => {
  if (err) {
    console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in subscribing managed event');
});

adminManager.subscribeManagedEvent

subscribeManagedEvent(admin: Want, managedEvents: Array<ManagedEvent>): Promise<void>

Subscribes to system management events. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
managedEvents Array<ManagedEvent> Yes Array of events to subscribe to.

Return value

Type Description
Promise<void> Promise that returns no value. When a system event fails to be subscribed to, an error object is thrown.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
let events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED];

adminManager.subscribeManagedEvent(wantTemp, events).then(() => {
}).catch((err: BusinessError) => {
  console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`);
})

adminManager.unsubscribeManagedEvent

unsubscribeManagedEvent(admin: Want, managedEvents: Array<ManagedEvent>, callback: AsyncCallback<void>): void

Unsubscribes from system management events. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
managedEvents Array<ManagedEvent> Yes Array of events to unsubscribe from.
callback AsyncCallback<void> Yes Callback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
let events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED];

adminManager.unsubscribeManagedEvent(wantTemp, events, (err) => {
  if (err) {
    console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Succeeded in unsubscribing managed event');
});

adminManager.unsubscribeManagedEvent

unsubscribeManagedEvent(admin: Want, managedEvents: Array<ManagedEvent>): Promise<void>

Unsubscribes from system management events. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
managedEvents Array<ManagedEvent> Yes Array of events to unsubscribe from.

Return value

Type Description
Promise<void> Promise that returns no value. An error object is thrown when the unsubscription of system management events fails.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
let events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED];

adminManager.unsubscribeManagedEvent(wantTemp, events).then(() => {
}).catch((err: BusinessError) => {
  console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`);
})

adminManager.authorizeAdmin10+

authorizeAdmin(admin: Want, bundleName: string, callback: AsyncCallback<void>): void

Authorizes the administrator permission to a specified application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
bundleName string Yes Bundle name of the application to be authorized with the administrator rights.
callback AsyncCallback<void> Yes Callback invoked to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
// Replace with actual values.
let bundleName: string = "com.example.application";

adminManager.authorizeAdmin(wantTemp, bundleName, (err) => {
  if (err) {
    console.error(`Failed to authorize permission to the application. Code: ${err.code}, message: ${err.message}`);
    return;
  }
  console.info('Successfully authorized permission to the application');
});

adminManager.authorizeAdmin10+

authorizeAdmin(admin: Want, bundleName: string): Promise<void>

Authorizes the administrator permission to a specified application. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
bundleName string Yes Bundle name of the application to be authorized with the administrator rights.

Return value

Type Description
Promise<void> Promise that returns no value. An error object is thrown when the permissions of a specified application administrator fail to be granted.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.
202 Permission verification failed. A non-system application calls a system API.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let wantTemp: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
// Replace with actual values.
let bundleName: string = "com.example.application";

adminManager.authorizeAdmin(wantTemp, bundleName).then(() => {
}).catch((err: BusinessError) => {
  console.error(`Failed to authorize permission to the application. Code: ${err.code}, message: ${err.message}`);
})

adminManager.getAdmins15+

getAdmins(): Promise<Array<Want>>

Queries all device administrator applications of the current user. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Return value

Type Description
Promise<Array<Want>> Promise that contains all activated device administrator applications.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Permission verification failed. A non-system application calls a system API.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

adminManager.getAdmins().then((result) => {
  console.info(`Succeeded in getting admins :${JSON.stringify(result)}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get admins. Code: ${err.code}, message: ${err.message}`);
})

adminManager.replaceSuperAdmin18+

replaceSuperAdmin(oldAdmin: Want, newAdmin: Want, isKeepPolicy: boolean): void

Replaces a specified application with a super device administrator application.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
oldAdmin Want Yes Old EnterpriseAdminExtensionAbility. Want must contain the ability name of the old EnterpriseAdminExtensionAbility and the bundle name of the application.
newAdmin Want Yes New EnterpriseAdminExtensionAbility. Want must contain the ability name of the new EnterpriseAdminExtensionAbility and the bundle name of the application.
isKeepPolicy boolean Yes A Boolean value indicates whether to retain the policy of the old EnterpriseAdminExtensionAbility. The value true means that the policy is retained, and the value false means the opposite.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
9200001 The application is not an administrator application of the device.
9200003 The administrator ability component is invalid.
9200011 Failed to replace the administrator application of the device.
201 Permission verification failed. The application does not have the permission required to call the API.
202 Permission verification failed. A non-system application calls a system API.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let oldAdmin: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
let newAdmin: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication_new',
  abilityName: 'NewEnterpriseAdminAbility'
};
try {
  adminManager.replaceSuperAdmin(oldAdmin, newAdmin, false);
  console.info(`Succeeded in replacing super admin.`);
} catch(err) {
  console.error(`Failed to replace super admin. Code: ${err.code}, message: ${err.message}`);
}

adminManager.setAdminRunningMode19+

setAdminRunningMode(admin: Want, mode: RunningMode): void

Sets the running mode of the device management application.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Device behavior differences: This API takes effect only on PCs/2-in-1 devices and does not work on other devices.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Parameters

Name Type Mandatory Description
admin Want Yes EnterpriseAdminExtensionAbility. Want must contain the ability name of the EnterpriseAdminExtensionAbility and the bundle name of the application.
mode RunningMode Yes Running mode.
The value DEFAULT means the application runs under the default user (user after the first device power-on). The value MULTI_USER means the application runs under multiple users at the same time.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
9200001 The application is not an administrator application of the device.
201 Permission verification failed. The application does not have the permission required to call the API.
202 Permission verification failed. A non-system application calls a system API.

Example

import { adminManager } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';

let admin: Want = {
  // Replace with actual values.
  bundleName: 'com.example.myapplication',
  abilityName: 'EnterpriseAdminAbility'
};
try {
  adminManager.setAdminRunningMode(admin, adminManager.RunningMode.MULTI_USER);
  console.info(`Succeeded in setting admin running mode.`);
} catch(err) {
  console.error(`Failed to set admin running mode. Code: ${err.code}, message: ${err.message}`);
}

adminManager.setDelegatedPolicies20+

setDelegatedPolicies(bundleName: string, accountId: number, policies: Array<string>): void

Delegates other applications to set device management policies. The applications must request the permissions required.

Required permissions: ohos.permission.ENTERPRISE_MANAGE_DELEGATED_POLICY

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Model restriction: This API can be used only in the stage model.

Parameters

Name Type Mandatory Description
bundleName String Yes Bundle name of the app to be delegated. The distribution type of the delegated app must be enterprise_normal or enterprise_mdm. You can call the bundleManager.getBundleInfoForSelf API to query the app BundleInfo. BundleInfo.appInfo.appDistributionType indicates the app distribution type.
accountId number Yes User ID, which must be greater than or equal to 0. You can use getOsAccountLocalId to obtain the user ID.
policies Array<string> Yes Delegation policy list.

Error codes

For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.

ID Error Message
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.

Example

import { adminManager } from '@kit.MDMKit';
import { common, Want } from '@kit.AbilityKit';

// Replace with actual values.
let bundleName = 'com.example.myapplication';
let userId = 100;
let policies: Array<string> = ["disabled_hdc"];

try {
  adminManager.setDelegatedPolicies(bundleName, userId, policies);
  console.info(`Succeeded in setting delegated policies.`);
} catch (err) {
  console.error(`Failed to set delegated policies. Code: ${err.code}, message: ${err.message}`);
}

EnterpriseInfo

Represents the enterprise information of a device administrator application.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Name Type Read-Only Optional Description
name string No No Name of the enterprise.
description string No No Description of the enterprise.

AdminType

Enumerates the types of device administrator applications.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Name Value Description
ADMIN_TYPE_NORMAL 0x00 Common device administrator application.
ADMIN_TYPE_SUPER 0x01 Super device administrator application.

RunningMode19+

Represents the running mode of a device administrator application.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Name Value Description
DEFAULT 0 Default user running mode, indicating that the application runs under the default user (user after the first device powered-on).
MULTI_USER 1 Multi-user running mode, indicating that the application runs under multiple users at the same time.