@ohos.enterprise.deviceControl (Device Control Management)
The deviceControl module provides APIs for device control.
NOTE
The initial APIs of this module are supported since API version 12. 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 of this module can be called only by a device administrator application that is enabled. For details, see MDM Kit Development.
Modules to Import
import { deviceControl } from '@kit.MDMKit';
deviceControl.operateDevice
operateDevice(admin: Want, operate: string, addition?: string): void
Allows the specified device administrator application to operate devices.
Required permissions: ohos.permission.ENTERPRISE_OPERATE_DEVICE
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Model restriction: This API can be used only in the stage model.
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. |
| operate | string | Yes | Operation to be performed, which can be any of the following: - resetFactory: restore device factory settings. After this API is called, the device will be restored to factory settings immediately. Once the restoration is complete, all device data will be erased and cannot be restored. To protect against data loss caused by potential application attacks, enterprises should implement robust security measures for their applications. - reboot: restart devices. - shutDown: shut down devices. - lockScreen: lock device screens. Once this capability is used, the device screen will become inaccessible. It only supports lock screen text customization but does not allow for interactive function customization on the lock screen. To implement custom behaviors on the lock screen, you are advised to use the setAllowedKioskApps API to configure apps that support the Kiosk mode. |
| addition | string | No | Additional parameter for the operation. Currently, this parameter does not need to be passed in. |
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. |
| 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 { deviceControl } from '@kit.MDMKit';
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
// Replace it as required.
bundleName: 'com.example.myapplication',
abilityName: 'EnterpriseAdminAbility'
};
try {
// Replace the parameters as required.
deviceControl.operateDevice(wantTemp, 'resetFactory');
} catch (err) {
console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`);
}