• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.deviceControl(设备控制管理)(系统接口)
2<!--Kit: MDM Kit-->
3<!--Subsystem: Customization-->
4<!--Owner: @huanleima-->
5<!--Designer: @liuzuming-->
6<!--Tester: @lpw_work-->
7<!--Adviser: @Brilliantry_Rui-->
8
9本模块提供设备控制能力。
10
11> **说明**:
12>
13> 本模块首批接口从API version 10 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14>
15> 本模块接口仅可在Stage模型下使用。
16>
17> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-term.md#mdm应用设备管理应用)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin-2)后调用。
18>
19> 当前页面仅包含本模块的系统接口,其他公开接口参见。其他公开接口参见[@ohos.enterprise.deviceControl](js-apis-enterprise-deviceControl.md)。
20
21## 导入模块
22
23```ts
24import { deviceControl } from '@kit.MDMKit';
25```
26
27## deviceControl.resetFactory
28
29resetFactory(admin: Want, callback: AsyncCallback\<void>): void
30
31使设备恢复出厂设置。使用callback异步回调。
32
33**需要权限:** ohos.permission.ENTERPRISE_RESET_DEVICE
34
35**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
36
37**模型约束:** 此接口仅可在Stage模型下使用。
38
39**系统接口:** 此接口为系统接口。
40
41**参数:**
42
43| 参数名   | 类型                                  | 必填   | 说明      |
44| ----- | ----------------------------------- | ---- | ------- |
45| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 企业设备管理扩展组件。 |
46| callback | AsyncCallback\<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 |
47
48**错误码:**
49
50以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
51
52| 错误码ID | 错误信息                                                                      |
53| ------- | ---------------------------------------------------------------------------- |
54| 9200001 | The application is not an administrator application of the device.           |
55| 9200002 | The administrator application does not have permission to manage the device. |
56| 201 | Permission verification failed. The application does not have the permission required to call the API. |
57| 202 | Permission verification failed. A non-system application calls a system API. |
58| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
59
60**示例:**
61
62```ts
63import { deviceControl } from '@kit.MDMKit';
64import { Want } from '@kit.AbilityKit';
65
66let wantTemp: Want = {
67  // 需根据实际情况进行替换
68  bundleName: 'com.example.myapplication',
69  abilityName: 'EntryAbility'
70};
71
72deviceControl.resetFactory(wantTemp, (err) => {
73  if (err) {
74    console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`);
75    return;
76  }
77  console.log('Succeeded in resetting factory');
78})
79```
80
81## deviceControl.resetFactory
82
83resetFactory(admin: Want): Promise\<void>
84
85使设备恢复出厂设置。使用Promise异步回调。
86
87**需要权限:** ohos.permission.ENTERPRISE_RESET_DEVICE
88
89**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
90
91**模型约束:** 此接口仅可在Stage模型下使用。
92
93**系统接口:** 此接口为系统接口。
94
95**参数:**
96
97| 参数名   | 类型                                  | 必填   | 说明      |
98| ----- | ----------------------------------- | ---- | ------- |
99| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 企业设备管理扩展组件。 |
100
101**返回值:**
102
103| 类型   | 说明                                  |
104| ----- | ----------------------------------- |
105| Promise\<void> | 无返回结果的Promise对象。当恢复出厂设置失败时抛出错误对象。|
106
107**错误码:**
108
109以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
110
111| 错误码ID | 错误信息                                                                      |
112| ------- | ---------------------------------------------------------------------------- |
113| 9200001 | The application is not an administrator application of the device.            |
114| 9200002 | The administrator application does not have permission to manage the device. |
115| 201 | Permission verification failed. The application does not have the permission required to call the API. |
116| 202 | Permission verification failed. A non-system application calls a system API. |
117| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
118
119**示例:**
120
121```ts
122import { deviceControl } from '@kit.MDMKit';
123import { Want } from '@kit.AbilityKit';
124import { BusinessError } from '@kit.BasicServicesKit';
125
126let wantTemp: Want = {
127  // 需根据实际情况进行替换
128  bundleName: 'com.example.myapplication',
129  abilityName: 'EntryAbility'
130};
131
132deviceControl.resetFactory(wantTemp).then(() => {
133}).catch((err: BusinessError) => {
134  console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`);
135})
136```
137
138## deviceControl.shutdown<sup>11+</sup>
139
140shutdown(admin: Want): void
141
142使设备关机。
143
144**需要权限:** ohos.permission.ENTERPRISE_REBOOT
145
146**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
147
148**模型约束:** 此接口仅可在Stage模型下使用。
149
150**系统接口:** 此接口为系统接口。
151
152**参数:**
153
154| 参数名   | 类型                                  | 必填   | 说明      |
155| ----- | ----------------------------------- | ---- | ------- |
156| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 企业设备管理扩展组件。 |
157
158**错误码:**
159
160以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
161
162| 错误码ID | 错误信息                                                                      |
163| ------- | ---------------------------------------------------------------------------- |
164| 9200001 | The application is not an administrator application of the device.            |
165| 9200002 | The administrator application does not have permission to manage the device. |
166| 201 | Permission verification failed. The application does not have the permission required to call the API. |
167| 202 | Permission verification failed. A non-system application calls a system API. |
168| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
169
170**示例:**
171
172```ts
173import { deviceControl } from '@kit.MDMKit';
174import { Want } from '@kit.AbilityKit';
175
176let wantTemp: Want = {
177  // 需根据实际情况进行替换
178  bundleName: 'com.example.myapplication',
179  abilityName: 'EntryAbility'
180};
181
182try {
183  deviceControl.shutdown(wantTemp);
184} catch (err) {
185  console.error(`Failed to shutdown device. Code is ${err.code}, message is ${err.message}`);
186}
187```
188
189## deviceControl.reboot<sup>11+</sup>
190
191reboot(admin: Want): void
192
193使设备重启。
194
195**需要权限:** ohos.permission.ENTERPRISE_REBOOT
196
197**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
198
199**模型约束:** 此接口仅可在Stage模型下使用。
200
201**系统接口:** 此接口为系统接口。
202
203**参数:**
204
205| 参数名   | 类型                                  | 必填   | 说明      |
206| ----- | ----------------------------------- | ---- | ------- |
207| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 企业设备管理扩展组件。 |
208
209**错误码:**
210
211以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
212
213| 错误码ID | 错误信息                                                                      |
214| ------- | ---------------------------------------------------------------------------- |
215| 9200001 | The application is not an administrator application of the device.            |
216| 9200002 | The administrator application does not have permission to manage the device. |
217| 201 | Permission verification failed. The application does not have the permission required to call the API. |
218| 202 | Permission verification failed. A non-system application calls a system API. |
219| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
220
221**示例:**
222
223```ts
224import { deviceControl } from '@kit.MDMKit';
225import { Want } from '@kit.AbilityKit';
226
227let wantTemp: Want = {
228  // 需根据实际情况进行替换
229  bundleName: 'com.example.myapplication',
230  abilityName: 'EntryAbility'
231};
232
233try {
234  deviceControl.reboot(wantTemp);
235} catch (err) {
236  console.error(`Failed to reboot device. Code is ${err.code}, message is ${err.message}`);
237}
238```
239
240## deviceControl.lockScreen<sup>11+</sup>
241
242lockScreen(admin: Want): void
243
244使设备屏幕锁定。设置之后设备立即锁屏。
245
246**需要权限:** ohos.permission.ENTERPRISE_LOCK_DEVICE
247
248**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
249
250**模型约束:** 此接口仅可在Stage模型下使用。
251
252**系统接口:** 此接口为系统接口。
253
254**参数:**
255
256| 参数名   | 类型                                  | 必填   | 说明      |
257| ----- | ----------------------------------- | ---- | ------- |
258| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 企业设备管理扩展组件。 |
259
260**错误码:**
261
262以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
263
264| 错误码ID | 错误信息                                                                      |
265| ------- | ---------------------------------------------------------------------------- |
266| 9200001 | The application is not an administrator application of the device.            |
267| 9200002 | The administrator application does not have permission to manage the device. |
268| 201 | Permission verification failed. The application does not have the permission required to call the API. |
269| 202 | Permission verification failed. A non-system application calls a system API. |
270| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
271
272**示例:**
273
274```ts
275import { deviceControl } from '@kit.MDMKit';
276import { Want } from '@kit.AbilityKit';
277
278let wantTemp: Want = {
279  // 需根据实际情况进行替换
280  bundleName: 'com.example.myapplication',
281  abilityName: 'EntryAbility'
282};
283
284try {
285  deviceControl.lockScreen(wantTemp);
286} catch (err) {
287  console.error(`Failed to lock screen. Code is ${err.code}, message is ${err.message}`);
288}
289```