1e41f4b71Sopenharmony_ci# @ohos.enterprise.deviceSettings (设备设置管理)(系统接口)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci本模块提供企业设备设置能力,包括获取设备息屏时间等。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> 本模块接口仅可在Stage模型下使用。
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-guide.md#功能介绍)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin)后调用,实现相应功能。
12e41f4b71Sopenharmony_ci> 
13e41f4b71Sopenharmony_ci> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.enterprise.deviceSettings](js-apis-enterprise-deviceSettings.md)。
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## 导入模块
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci```ts
18e41f4b71Sopenharmony_ciimport { deviceSettings } from '@kit.MDMKit';
19e41f4b71Sopenharmony_ci```
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## deviceSettings.setScreenOffTime<sup>11+</sup>
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_cisetScreenOffTime(admin: Want, time: number): void
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci以同步方法指定设备管理应用设置设备息屏时间。成功返回null,失败抛出对应异常。
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_SET_SCREENOFF_TIME
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**参数:**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| 参数名      | 类型                                       | 必填   | 说明                       |
34e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- |
35e41f4b71Sopenharmony_ci| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
36e41f4b71Sopenharmony_ci| time | number            | 是    | 设备息屏时间(单位:毫秒,建议参数与设备可选息屏时间保持一致)       |
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**错误码**:
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                                       |
43e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
44e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.            |
45e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
46e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
47e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
48e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci**示例:**
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci```ts
53e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
54e41f4b71Sopenharmony_cilet wantTemp: Want = {
55e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
56e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
57e41f4b71Sopenharmony_ci};
58e41f4b71Sopenharmony_citry {
59e41f4b71Sopenharmony_ci  deviceSettings.setScreenOffTime(wantTemp, 30000);
60e41f4b71Sopenharmony_ci  console.info(`Succeeded in setting screen off time`);
61e41f4b71Sopenharmony_ci} catch(err) {
62e41f4b71Sopenharmony_ci  console.error(`Failed to set screen off time. Code: ${err.code}, message: ${err.message}`);
63e41f4b71Sopenharmony_ci}
64e41f4b71Sopenharmony_ci```
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci## deviceSettings.getScreenOffTime
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_cigetScreenOffTime(admin: Want, callback: AsyncCallback&lt;number&gt;): void
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci指定设备管理应用获取设备息屏时间,使用callback异步回调。
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_GET_SETTINGS
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**参数:**
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci| 参数名      | 类型                                       | 必填   | 说明                       |
79e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- |
80e41f4b71Sopenharmony_ci| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
81e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt;            | 是    | 回调函数。当接口调用成功,err为null,data为设备息屏时间(单位:毫秒),否则err为错误对象。       |
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**错误码**:
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                                       |
88e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
89e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.            |
90e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
91e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
92e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
93e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci**示例:**
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci```ts
98e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
99e41f4b71Sopenharmony_cilet wantTemp: Want = {
100e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
101e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
102e41f4b71Sopenharmony_ci};
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_cideviceSettings.getScreenOffTime(wantTemp, (err, result) => {
105e41f4b71Sopenharmony_ci  if (err) {
106e41f4b71Sopenharmony_ci    console.error(`Failed to get screen off time. Code: ${err.code}, message: ${err.message}`);
107e41f4b71Sopenharmony_ci    return;
108e41f4b71Sopenharmony_ci  }
109e41f4b71Sopenharmony_ci  console.info(`Succeeded in getting screen off time, result : ${result}`);
110e41f4b71Sopenharmony_ci});
111e41f4b71Sopenharmony_ci```
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci## deviceSettings.getScreenOffTime
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_cigetScreenOffTime(admin: Want): Promise&lt;number&gt;
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci指定设备管理应用获取设备息屏时间,使用Promise异步回调。
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_GET_SETTINGS
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci**参数:**
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci| 参数名   | 类型                                  | 必填   | 说明      |
126e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- |
127e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**返回值:**
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci| 类型                   | 说明                      |
132e41f4b71Sopenharmony_ci| --------------------- | ------------------------- |
133e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回设备息屏时间(单位:毫秒)。  |
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci**错误码**:
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                                     |
140e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
141e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.            |
142e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
143e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
144e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
145e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci**示例:**
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci```ts
150e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
151e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
152e41f4b71Sopenharmony_cilet wantTemp: Want = {
153e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
154e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
155e41f4b71Sopenharmony_ci};
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_cideviceSettings.getScreenOffTime(wantTemp).then((result) => {
158e41f4b71Sopenharmony_ci  console.info(`Succeeded in getting screen off time, result : ${result}`);
159e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
160e41f4b71Sopenharmony_ci  console.error(`Failed to get screen off time. Code: ${err.code}, message: ${err.message}`);
161e41f4b71Sopenharmony_ci});
162e41f4b71Sopenharmony_ci```
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci## deviceSettings.installUserCertificate
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ciinstallUserCertificate(admin: Want, certificate: CertBlob, callback: AsyncCallback&lt;string&gt;): void
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci指定设备管理应用安装用户证书,使用callback异步回调。
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci**参数:**
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci| 参数名      | 类型                                       | 必填   | 说明                       |
177e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- |
178e41f4b71Sopenharmony_ci| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
179e41f4b71Sopenharmony_ci| certificate    | [CertBlob](#certblob)     | 是    | 证书信息。                  |
180e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;string&gt;            | 是    | 回调函数,当接口调用成功,err为null,否则为错误对象。      |
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci**错误码**:
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                                       |
187e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
188e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.            |
189e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
190e41f4b71Sopenharmony_ci| 9201001 | Failed to manage the certificate. |
191e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
192e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
193e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci**示例:**
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci```ts
198e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
199e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
200e41f4b71Sopenharmony_cilet wantTemp: Want = {
201e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
202e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
203e41f4b71Sopenharmony_ci};
204e41f4b71Sopenharmony_cilet certFileArray: Uint8Array = new Uint8Array();
205e41f4b71Sopenharmony_ci// The variable context needs to be initialized in MainAbility's onCreate callback function
206e41f4b71Sopenharmony_ci// test.cer needs to be placed in the rawfile directory
207e41f4b71Sopenharmony_cigetContext().resourceManager.getRawFileContent("test.cer").then((value) => {
208e41f4b71Sopenharmony_ci  certFileArray = value;
209e41f4b71Sopenharmony_ci  deviceSettings.installUserCertificate(wantTemp, { inData: certFileArray, alias: "cert_alias_xts" }, (err, result) => {
210e41f4b71Sopenharmony_ci    if (err) {
211e41f4b71Sopenharmony_ci      console.error(`Failed to install user certificate. Code: ${err.code}, message: ${err.message}`);
212e41f4b71Sopenharmony_ci    } else {
213e41f4b71Sopenharmony_ci      console.info(`Succeeded in installing user certificate, result : ${JSON.stringify(result)}`);
214e41f4b71Sopenharmony_ci    }
215e41f4b71Sopenharmony_ci  });
216e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
217e41f4b71Sopenharmony_ci  console.error(`Failed to get row file content. message: ${error.message}`);
218e41f4b71Sopenharmony_ci  return
219e41f4b71Sopenharmony_ci});
220e41f4b71Sopenharmony_ci```
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci## deviceSettings.installUserCertificate
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ciinstallUserCertificate(admin: Want, certificate: CertBlob): Promise&lt;string&gt;
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci指定设备管理应用安装用户证书,使用Promise异步回调。
227e41f4b71Sopenharmony_ci
228e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci**参数:**
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci| 参数名   | 类型                                  | 必填   | 说明      |
235e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- |
236e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
237e41f4b71Sopenharmony_ci| certificate    | [CertBlob](#certblob)     | 是    | 证书信息。                  |
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_ci**返回值:**
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ci| 类型                   | 说明                      |
242e41f4b71Sopenharmony_ci| --------------------- | ------------------------- |
243e41f4b71Sopenharmony_ci| Promise&lt;string&gt; | Promise对象,返回当前证书安装后的uri,用于卸载证书。 |
244e41f4b71Sopenharmony_ci
245e41f4b71Sopenharmony_ci**错误码**:
246e41f4b71Sopenharmony_ci
247e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
248e41f4b71Sopenharmony_ci
249e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                                     |
250e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
251e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.            |
252e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
253e41f4b71Sopenharmony_ci| 9201001 | Failed to manage the certificate. |
254e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
255e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
256e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci**示例:**
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ci```ts
261e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
262e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
263e41f4b71Sopenharmony_cilet wantTemp: Want = {
264e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
265e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
266e41f4b71Sopenharmony_ci};
267e41f4b71Sopenharmony_cilet certFileArray: Uint8Array = new Uint8Array();
268e41f4b71Sopenharmony_ci// The variable context needs to be initialized in MainAbility's onCreate callback function
269e41f4b71Sopenharmony_ci// test.cer needs to be placed in the rawfile directory
270e41f4b71Sopenharmony_cigetContext().resourceManager.getRawFileContent("test.cer").then((value) => {
271e41f4b71Sopenharmony_ci  certFileArray = value
272e41f4b71Sopenharmony_ci  deviceSettings.installUserCertificate(wantTemp, { inData: certFileArray, alias: "cert_alias_xts" })
273e41f4b71Sopenharmony_ci    .then((result) => {
274e41f4b71Sopenharmony_ci      console.info(`Succeeded in installing user certificate, result : ${JSON.stringify(result)}`);
275e41f4b71Sopenharmony_ci    }).catch((err: BusinessError) => {
276e41f4b71Sopenharmony_ci    console.error(`Failed to install user certificate. Code: ${err.code}, message: ${err.message}`);
277e41f4b71Sopenharmony_ci  })
278e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
279e41f4b71Sopenharmony_ci  console.error(`Failed to get row file content. message: ${error.message}`);
280e41f4b71Sopenharmony_ci  return
281e41f4b71Sopenharmony_ci});
282e41f4b71Sopenharmony_ci```
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ci## CertBlob
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci证书信息。
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
289e41f4b71Sopenharmony_ci
290e41f4b71Sopenharmony_ci| 名称         | 类型     | 必填 | 说明                            |
291e41f4b71Sopenharmony_ci| ----------- | --------| ----- | ------------------------------- |
292e41f4b71Sopenharmony_ci| inData | Uint8Array | 是 | 证书的二进制内容。 |
293e41f4b71Sopenharmony_ci| alias | string | 是 | 证书别名。 |
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci## deviceSettings.uninstallUserCertificate
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ciuninstallUserCertificate(admin: Want, certUri: string, callback: AsyncCallback&lt;void&gt;): void
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci指定设备管理应用卸载用户证书,使用callback异步回调。
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ci**参数:**
306e41f4b71Sopenharmony_ci
307e41f4b71Sopenharmony_ci| 参数名      | 类型                                       | 必填   | 说明                       |
308e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- |
309e41f4b71Sopenharmony_ci| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
310e41f4b71Sopenharmony_ci| certUri    | string    | 是    | 证书uri,由安装用户证书接口返回。                  |
311e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt;            | 是    | 回调函数,当接口调用成功,err为null,否则为错误对象。      |
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ci**错误码**:
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                                       |
318e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
319e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.            |
320e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
321e41f4b71Sopenharmony_ci| 9201001 | Failed to manage the certificate. |
322e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
323e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
324e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci**示例:**
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci```ts
329e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
330e41f4b71Sopenharmony_cilet wantTemp: Want = {
331e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
332e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
333e41f4b71Sopenharmony_ci};
334e41f4b71Sopenharmony_cilet aliasStr = "certName"
335e41f4b71Sopenharmony_cideviceSettings.uninstallUserCertificate(wantTemp, aliasStr, (err) => {
336e41f4b71Sopenharmony_ci  if (err) {
337e41f4b71Sopenharmony_ci    console.error(`Failed to uninstall user certificate. Code: ${err.code}, message: ${err.message}`);
338e41f4b71Sopenharmony_ci    return;
339e41f4b71Sopenharmony_ci  }
340e41f4b71Sopenharmony_ci  console.info(`Succeeded in uninstalling user certificate`);
341e41f4b71Sopenharmony_ci});
342e41f4b71Sopenharmony_ci```
343e41f4b71Sopenharmony_ci
344e41f4b71Sopenharmony_ci## deviceSettings.uninstallUserCertificate
345e41f4b71Sopenharmony_ci
346e41f4b71Sopenharmony_ciuninstallUserCertificate(admin: Want, certUri: string): Promise&lt;void&gt;
347e41f4b71Sopenharmony_ci
348e41f4b71Sopenharmony_ci指定设备管理应用卸载用户证书,使用Promise异步回调。
349e41f4b71Sopenharmony_ci
350e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_CERTIFICATE
351e41f4b71Sopenharmony_ci
352e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_ci**参数:**
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_ci| 参数名   | 类型                                  | 必填   | 说明      |
357e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- |
358e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
359e41f4b71Sopenharmony_ci| certUri    | string     | 是    | 证书uri,由安装用户证书接口返回。                  |
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci**返回值:**
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci| 类型                   | 说明                      |
364e41f4b71Sopenharmony_ci| --------------------- | ------------------------- |
365e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | 无返回结果的Promise对象。当指定设备管理应用卸载用户证书失败时会抛出错误对象。 |
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ci**错误码**:
368e41f4b71Sopenharmony_ci
369e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
370e41f4b71Sopenharmony_ci
371e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                                     |
372e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
373e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.            |
374e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
375e41f4b71Sopenharmony_ci| 9201001 | Failed to manage the certificate. |
376e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
377e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
378e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
379e41f4b71Sopenharmony_ci
380e41f4b71Sopenharmony_ci**示例:**
381e41f4b71Sopenharmony_ci
382e41f4b71Sopenharmony_ci```ts
383e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
384e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
385e41f4b71Sopenharmony_cilet wantTemp: Want = {
386e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
387e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
388e41f4b71Sopenharmony_ci};
389e41f4b71Sopenharmony_cilet aliasStr = "certName"
390e41f4b71Sopenharmony_cideviceSettings.uninstallUserCertificate(wantTemp, aliasStr).then(() => {
391e41f4b71Sopenharmony_ci  console.info(`Succeeded in uninstalling user certificate`);
392e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
393e41f4b71Sopenharmony_ci  console.error(`Failed to uninstall user certificate. Code is ${err.code}, message is ${err.message}`);
394e41f4b71Sopenharmony_ci});
395e41f4b71Sopenharmony_ci```
396e41f4b71Sopenharmony_ci
397e41f4b71Sopenharmony_ci## deviceSettings.setPowerPolicy<sup>11+</sup>
398e41f4b71Sopenharmony_ci
399e41f4b71Sopenharmony_cisetPowerPolicy(admin: Want, powerScene: PowerScene, powerPolicy: PowerPolicy): void
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ci以同步方法指定设备管理应用设置电源策略。成功返回null,失败抛出对应异常。
402e41f4b71Sopenharmony_ci
403e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SETTINGS
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
406e41f4b71Sopenharmony_ci
407e41f4b71Sopenharmony_ci**参数:**
408e41f4b71Sopenharmony_ci
409e41f4b71Sopenharmony_ci| 参数名      | 类型                                       | 必填   | 说明                       |
410e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- |
411e41f4b71Sopenharmony_ci| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
412e41f4b71Sopenharmony_ci| powerScene | [PowerScene](#powerscene11) | 是    | 电源策略场景,当前只支持超时场景。       |
413e41f4b71Sopenharmony_ci| powerPolicy | [PowerPolicy](#powerpolicy11) | 是    | 电源策略。       |
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ci**错误码**:
416e41f4b71Sopenharmony_ci
417e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                                       |
420e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
421e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.            |
422e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
423e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
424e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
425e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ci**示例:**
428e41f4b71Sopenharmony_ci
429e41f4b71Sopenharmony_ci```ts
430e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
431e41f4b71Sopenharmony_cilet wantTemp: Want = {
432e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
433e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
434e41f4b71Sopenharmony_ci};
435e41f4b71Sopenharmony_citry {
436e41f4b71Sopenharmony_ci  let delayTime = 0;
437e41f4b71Sopenharmony_ci  let powerScene: deviceSettings.PowerScene = deviceSettings.PowerScene.TIME_OUT;
438e41f4b71Sopenharmony_ci  let powerPolicyAction: deviceSettings.PowerPolicyAction = deviceSettings.PowerPolicyAction.AUTO_SUSPEND;
439e41f4b71Sopenharmony_ci  let powerPolicy: deviceSettings.PowerPolicy = {powerPolicyAction, delayTime};
440e41f4b71Sopenharmony_ci  deviceSettings.setPowerPolicy(wantTemp, powerScene, powerPolicy);
441e41f4b71Sopenharmony_ci  console.info(`Succeeded in setting power polilcy`);
442e41f4b71Sopenharmony_ci} catch (err) {
443e41f4b71Sopenharmony_ci  console.error(`Failed to set power policy. Code: ${err.code}, message: ${err.message}`);
444e41f4b71Sopenharmony_ci}
445e41f4b71Sopenharmony_ci```
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci## deviceSettings.getPowerPolicy<sup>11+</sup>
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_cigetPowerPolicy(admin: Want, powerScene: PowerScene): PowerPolicy
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci以同步方法指定设备管理应用获取电源策略。成功返回电源策略,失败抛出对应异常。
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SETTINGS
454e41f4b71Sopenharmony_ci
455e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
456e41f4b71Sopenharmony_ci
457e41f4b71Sopenharmony_ci**参数:**
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci| 参数名      | 类型                                       | 必填   | 说明                       |
460e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- |
461e41f4b71Sopenharmony_ci| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
462e41f4b71Sopenharmony_ci| powerScene | [PowerScene](#powerscene11) | 是    | 电源策略场景,当前只支持超时场景。       |
463e41f4b71Sopenharmony_ci
464e41f4b71Sopenharmony_ci**返回值:**
465e41f4b71Sopenharmony_ci
466e41f4b71Sopenharmony_ci| 类型   | 说明                                  | 说明                       |
467e41f4b71Sopenharmony_ci| ----- | ----------------------------------- |------------------------------- |
468e41f4b71Sopenharmony_ci| PowerPolicy | [PowerPolicy](#powerpolicy11) |   电源策略。       |
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci**错误码**:
471e41f4b71Sopenharmony_ci
472e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                                       |
475e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
476e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.            |
477e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device. |
478e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
479e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
480e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci**示例:**
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci```ts
485e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
486e41f4b71Sopenharmony_cilet wantTemp: Want = {
487e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
488e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
489e41f4b71Sopenharmony_ci};
490e41f4b71Sopenharmony_citry {
491e41f4b71Sopenharmony_ci  let powerScene: deviceSettings.PowerScene = deviceSettings.PowerScene.TIME_OUT;
492e41f4b71Sopenharmony_ci  let powerPolicy: deviceSettings.PowerPolicy = deviceSettings.getPowerPolicy(wantTemp, powerScene);
493e41f4b71Sopenharmony_ci  console.info(`Succeeded in getting power polilcy ${JSON.stringify(powerPolicy)}`);
494e41f4b71Sopenharmony_ci} catch (err) {
495e41f4b71Sopenharmony_ci  console.error(`Failed to get power policy. Code: ${err.code}, message: ${err.message}`);
496e41f4b71Sopenharmony_ci}
497e41f4b71Sopenharmony_ci```
498e41f4b71Sopenharmony_ci
499e41f4b71Sopenharmony_ci## PowerPolicy<sup>11+</sup>
500e41f4b71Sopenharmony_ci
501e41f4b71Sopenharmony_ci电源策略。
502e41f4b71Sopenharmony_ci
503e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
504e41f4b71Sopenharmony_ci
505e41f4b71Sopenharmony_ci| 名称         | 类型     | 必填 | 说明                            |
506e41f4b71Sopenharmony_ci| ----------- | --------| ----- | ------------------------------- |
507e41f4b71Sopenharmony_ci| powerPolicyAction | [PowerPolicyAction](#powerpolicyaction11) | 是 | 执行电源策略的动作。 |
508e41f4b71Sopenharmony_ci| delayTime | number | 是 | 延迟时间。 |
509e41f4b71Sopenharmony_ci
510e41f4b71Sopenharmony_ci## PowerScene<sup>11+</sup>
511e41f4b71Sopenharmony_ci
512e41f4b71Sopenharmony_ci执行电源策略的场景。
513e41f4b71Sopenharmony_ci
514e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
515e41f4b71Sopenharmony_ci
516e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 |
517e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
518e41f4b71Sopenharmony_ci| TIME_OUT | 0 | 超时场景。 |
519e41f4b71Sopenharmony_ci
520e41f4b71Sopenharmony_ci## PowerPolicyAction<sup>11+</sup>
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_ci执行电源策略的动作。
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 |
527e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
528e41f4b71Sopenharmony_ci| NONE | 0 | 不执行动作。 |
529e41f4b71Sopenharmony_ci| AUTO_SUSPEND | 1 | 自动进入睡眠。 |
530e41f4b71Sopenharmony_ci| FORCE_SUSPEND | 2 | 强制进入睡眠。 |
531e41f4b71Sopenharmony_ci| HIBERNATE | 3 | 进入休眠。(当前电源子系统暂不支持) |
532e41f4b71Sopenharmony_ci| SHUTDOWN | 4 | 关机。 |
533