harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management)

2023-02-03 浏览 (682)

@ohos.enterprise.adminManager (Enterprise Device Management)

The adminManager module provides enterprise device management capabilities so that devices have the custom capabilities required in enterprise settings.

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 used only in the stage model.

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

Modules to Import

import adminManager from '@ohos.enterprise.adminManager';

adminManager.enableAdmin

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

Enables a device administrator application for the current 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

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application to enable.
enterpriseInfoEnterpriseInfoYesEnterprise information of the device administrator application.
typeAdminTypeYesType of the device administrator application to enable.
callbackAsyncCallback<void>YesCallback 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.

IDError Message
9200003the administrator ability component is invalid.
9200004failed to enable the administrator application of the device.
9200007the system ability work abnormally.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let enterpriseInfo: adminManager.EnterpriseInfo = {
  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

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application to enable.
enterpriseInfoEnterpriseInfoYesEnterprise information of the device administrator application.
typeAdminTypeYesType of the device administrator application to enable.
userIdnumberYesUser ID, which must be greater than or equal to 0.
The default value is the user ID of the caller.
callbackAsyncCallback<void>YesCallback 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.

IDError Message
9200003the administrator ability component is invalid.
9200004failed to enable the administrator application of the device.
9200007the system ability work abnormally.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let enterpriseInfo: adminManager.EnterpriseInfo = {
  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

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application to enable.
enterpriseInfoEnterpriseInfoYesEnterprise information of the device administrator application.
typeAdminTypeYesType of the device administrator application to enable.
userIdnumberNoUser ID, which must be greater than or equal to 0.
- If userId is passed in, the application of the specified user is enabled.
- If userId is not passed in, the application of the current user is enabled.

Return value

TypeDescription
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.

IDError Message
9200003the administrator ability component is invalid.
9200004failed to enable the administrator application of the device.
9200007the system ability work abnormally.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let enterpriseInfo: adminManager.EnterpriseInfo = {
  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 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

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesCommon administrator application to disable.
callbackAsyncCallback<void>YesCallback 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.

IDError Message
9200005failed to disable the administrator application of the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};

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 administrator application for the specified user. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesCommon administrator application to disable.
userIdnumberYesUser ID, which must be greater than or equal to 0.
The default value is the user ID of the caller.
callbackAsyncCallback<void>YesCallback 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.

IDError Message
9200005failed to disable the administrator application of the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};

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.disableAdmin

disableAdmin(admin: Want, userId?: number): Promise<void>

Disables a common administrator application for the current or specified user. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesCommon administrator application to disable.
userIdnumberNoUser ID, which must be greater than or equal to 0.
- If userId is passed in, the application of the specified user is disabled.
- If userId is not passed in, the application of the current user is disabled.

Return value

TypeDescription
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.

IDError Message
9200005failed to disable the administrator application of the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};

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

adminManager.disableSuperAdmin

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

Disables a super administrator application for the administrator 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

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
bundleNameStringYesBundle name of the super administrator application to disable.
callbackAsyncCallback<void>YesCallback 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.

IDError Message
9200005failed to disable the administrator application of the device.

Example

import Want from '@ohos.app.ability.Want';
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 administrator application for the administrator 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

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
bundleNameStringYesBundle name of the super administrator application to disable.

Return value

TypeDescription
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.

IDError Message
9200005failed to disable the administrator application of the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
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

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application to check.
callbackAsyncCallback<boolean>YesCallback 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.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};

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

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application to check.
userIdnumberYesUser ID, which must be greater than or equal to 0.
The default value is the user ID of the caller.
callbackAsyncCallback<boolean>YesCallback 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.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};

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

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application to check.
userIdnumberNoUser ID, which must be greater than or equal to 0.
- If userId is passed in, the application of the specified user is checked.
- If userId is not passed in, the application of the current user is checked.

Return value

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

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};

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 administrator application of the administrator is enabled based on bundleName. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
bundleNameStringYesSuper administrator application to check.
callbackAsyncCallback<boolean>YesCallback 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.

Example

import Want from '@ohos.app.ability.Want';
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 administrator application of the administrator is enabled based on bundleName. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
bundleNameStringYesSuper administrator application to check.

Return value

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

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
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.setEnterpriseInfo

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

Sets enterprise information for a 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

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
enterpriseInfoEnterpriseInfoYesEnterprise information to set.
callbackAsyncCallback<void>;YesCallback 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.

IDError Message
9200001the application is not an administrator of the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let enterpriseInfo: adminManager.EnterpriseInfo = {
  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 enterprise information for a device administrator application. This API uses a promise to return the result.

Required permissions: ohos.permission.SET_ENTERPRISE_INFO

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
enterpriseInfoEnterpriseInfoYesEnterprise information to set.

Return value

TypeDescription
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.

IDError Message
9200001the application is not an administrator of the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let enterpriseInfo: adminManager.EnterpriseInfo = {
  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 a device administrator application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
callbackAsyncCallback<EnterpriseInfo>YesCallback 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.

IDError Message
9200001the application is not an administrator of the device.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

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 a device administrator application. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.

Return value

TypeDescription
Promise<EnterpriseInfo>Promise used to return the enterprise information obtained.

Error codes

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

IDError Message
9200001the application is not an administrator of the device.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

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 of a device administrator application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
managedEventsArray<ManagedEvent>YesArray of events to subscribe to.
callbackAsyncCallback<void>YesCallback 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.

IDError Message
9200001the application is not an administrator of the device.
9200008the specified system events enum is invalid.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};
let events: Array<adminManager.ManagedEvent> = [0, 1];

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 subscribe managed event');
});

adminManager.subscribeManagedEvent

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

Subscribes to system management events of a device administrator application. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
managedEventsArray<ManagedEvent>YesArray of events to subscribe to.

Return value

TypeDescription
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.

IDError Message
9200001the application is not an administrator of the device.
9200008the specified system events enum is invalid.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};
let events: Array<adminManager.ManagedEvent> = [0, 1];

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 of a device administrator application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
managedEventsArray<ManagedEvent>YesArray of events to unsubscribe from.
callbackAsyncCallback<void>YesCallback 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.

IDError Message
9200001the application is not an administrator of the device.
9200008the specified system events enum is invalid.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};
let events: Array<adminManager.ManagedEvent> = [0, 1];

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 unsubscribe managed event');
});

adminManager.unsubscribeManagedEvent

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

Unsubscribes from system management events of a device administrator application. This API uses a promise to return the result.

Required permissions: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
managedEventsArray<ManagedEvent>YesArray of events to unsubscribe from.

Return value

TypeDescription
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.

IDError Message
9200001the application is not an administrator of the device.
9200008the specified system events enum is invalid.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};
let events: Array<adminManager.ManagedEvent> = [0, 1];

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 rights to an application through the specified device administrator application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
bundleNamestringYesBundle name of the application to be authorized with the administrator rights.
callbackAsyncCallback<void>YesCallback 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.

IDError Message
9200001the application is not an administrator of the device.
9200002the administrator application does not have permission to manage the device.
9200009authorize permission to the application failed.

Example

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};
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 rights to an application through the specified device administrator application. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
bundleNamestringYesBundle name of the application to be authorized with the administrator rights.

Return value

TypeDescription
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.

IDError Message
9200001the application is not an administrator of the device.
9200002the administrator application does not have permission to manage the device.
9200009authorize permission to the application failed.

Example

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'bundleName',
  abilityName: 'abilityName',
};
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}`);
})

EnterpriseInfo

Represents the enterprise information of a device administrator application.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

NameTypeMandatoryDescription
namestringYesName of the enterprise.
descriptionstringYesDescription of the enterprise.

AdminType

Enumerates the types of device administrator applications.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

NameValueDescription
ADMIN_TYPE_NORMAL0x00Common administrator application.
ADMIN_TYPE_SUPER0x01Super administrator application.

ManagedEvent

Enumerates the system management events that can be subscribed to.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

System API: This is a system API.

NameValueDescription
MANAGED_EVENT_BUNDLE_ADDED0Application installed.
MANAGED_EVENT_BUNDLE_REMOVED1Application uninstalled.
MANAGED_EVENT_APP_START10+2Application started.
MANAGED_EVENT_APP_STOP10+3Application stopped.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/f1f7d2f40f134e23b34b46dd74cc6284