1# @ohos.enterprise.adminManager (企业设备管理) 2 3本模块提供企业设备管理能力,使设备具备企业场景下所需的定制能力。 4 5> **说明:** 6> 7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9> 本模块接口仅对[设备管理应用](enterpriseDeviceManagement-overview.md#基本概念)开放,实现相应功能。 10 11## 导入模块 12 13```ts 14import adminManager from '@ohos.enterprise.adminManager'; 15``` 16 17## adminManager.enableAdmin 18 19enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, callback: AsyncCallback\<void>): void 20 21激活当前用户下指定的设备管理应用,其中超级设备管理应用仅能在管理员用户下被激活。使用callback异步回调。 22 23**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 24 25**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 26 27**系统API**: 此接口为系统接口。 28 29**模型约束**: 此接口仅可在Stage模型下使用。 30 31**参数**: 32 33| 参数名 | 类型 | 必填 | 说明 | 34| -------------- | ----------------------------------- | ---- | ------------------ | 35| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 36| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | 是 | 设备管理应用的企业信息。 | 37| type | [AdminType](#admintype) | 是 | 激活的设备管理应用类型。 | 38| callback | AsyncCallback\<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 39 40**错误码**: 41 42以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 43 44| 错误码ID | 错误信息 | 45| ------- | --------------------------------------------------------------- | 46| 9200003 | the administrator ability component is invalid. | 47| 9200004 | failed to enable the administrator application of the device. | 48| 9200007 | the system ability work abnormally. | 49 50**示例**: 51 52```ts 53import Want from '@ohos.app.ability.Want'; 54let wantTemp: Want = { 55 bundleName: 'com.example.myapplication', 56 abilityName: 'EntryAbility', 57}; 58let enterpriseInfo: adminManager.EnterpriseInfo = { 59 name: 'enterprise name', 60 description: 'enterprise description' 61} 62 63adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_SUPER, (err) => { 64 if (err) { 65 console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`); 66 return; 67 } 68 console.info('Succeeded in enabling admin'); 69}); 70``` 71 72## adminManager.enableAdmin 73 74enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId: number, callback: AsyncCallback\<void>): void 75 76激活指定用户(通过userId指定)下指定的设备管理应用,其中超级管理应用仅能在管理员用户下被激活。使用callback异步回调。 77 78**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 79 80**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 81 82**系统API**: 此接口为系统接口。 83 84**模型约束**: 此接口仅可在Stage模型下使用。 85 86**参数**: 87 88| 参数名 | 类型 | 必填 | 说明 | 89| -------------- | ----------------------------------- | ---- | ---------------------------- | 90| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 91| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | 是 | 设备管理应用的企业信息。 | 92| type | [AdminType](#admintype) | 是 | 激活的设备管理应用类型。 | 93| userId | number | 是 | 用户ID,指定具体用户,取值范围:大于等于0。<br>默认值:调用方所在用户。 | 94| callback | AsyncCallback\<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 95 96**错误码**: 97 98以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 99 100| 错误码ID | 错误信息 | 101| ------- | --------------------------------------------------------------- | 102| 9200003 | the administrator ability component is invalid. | 103| 9200004 | failed to enable the administrator application of the device. | 104| 9200007 | the system ability work abnormally. | 105 106**示例**: 107 108```ts 109import Want from '@ohos.app.ability.Want'; 110let wantTemp: Want = { 111 bundleName: 'com.example.myapplication', 112 abilityName: 'EntryAbility', 113}; 114let enterpriseInfo: adminManager.EnterpriseInfo = { 115 name: 'enterprise name', 116 description: 'enterprise description' 117} 118 119adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100, (err) => { 120 if (err) { 121 console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`); 122 return; 123 } 124 console.info('Succeeded in enabling admin'); 125}); 126``` 127 128## adminManager.enableAdmin 129 130enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId?: number): Promise\<void> 131 132激活当前/指定用户下指定的设备管理应用,其中超级管理应用仅能在管理员用户下被激活。使用promise异步回调。 133 134**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 135 136**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 137 138**系统API**: 此接口为系统接口。 139 140**模型约束**: 此接口仅可在Stage模型下使用。 141 142**参数**: 143 144| 参数名 | 类型 | 必填 | 说明 | 145| -------------- | ----------------------------------- | ---- | ---------------------------- | 146| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 147| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | 是 | 设备管理应用的企业信息。 | 148| type | [AdminType](#admintype) | 是 | 激活的设备管理应用类型。 | 149| userId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。| 150 151**返回值:** 152 153| 类型 | 说明 | 154| ----------------- | ----------------- | 155| Promise\<void> | 无返回结果的Promise对象。当激活设备管理应用失败时,会抛出错误对象。 | 156 157**错误码**: 158 159以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 160 161| 错误码ID | 错误信息 | 162| ------- | --------------------------------------------------------------- | 163| 9200003 | the administrator ability component is invalid. | 164| 9200004 | failed to enable the administrator application of the device. | 165| 9200007 | the system ability work abnormally. | 166 167**示例**: 168 169```ts 170import Want from '@ohos.app.ability.Want'; 171import { BusinessError } from '@ohos.base'; 172let wantTemp: Want = { 173 bundleName: 'com.example.myapplication', 174 abilityName: 'EntryAbility', 175}; 176let enterpriseInfo: adminManager.EnterpriseInfo = { 177 name: 'enterprise name', 178 description: 'enterprise description' 179} 180 181adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100).catch( 182 (err: BusinessError) => { 183 console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`); 184 }); 185``` 186 187## adminManager.disableAdmin 188 189disableAdmin(admin: Want, callback: AsyncCallback\<void>): void 190 191将当前用户下指定的普通设备管理应用去激活。使用callback异步回调。 192 193**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 194 195**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 196 197**系统API**: 此接口为系统接口。 198 199**模型约束**: 此接口仅可在Stage模型下使用。 200 201**参数**: 202 203| 参数名 | 类型 | 必填 | 说明 | 204| -------- | ----------------------------------- | ---- | ------------------- | 205| admin | [Want](js-apis-app-ability-want.md) | 是 | 普通设备管理应用。 | 206| callback | AsyncCallback\<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 207 208**错误码**: 209 210以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 211 212| 错误码ID | 错误信息 | 213| ------- | ----------------------------------------------------------------- | 214| 9200005 | failed to disable the administrator application of the device. | 215 216**示例**: 217 218```ts 219import Want from '@ohos.app.ability.Want'; 220let wantTemp: Want = { 221 bundleName: 'bundleName', 222 abilityName: 'abilityName', 223}; 224 225adminManager.disableAdmin(wantTemp, (err) => { 226 if (err) { 227 console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); 228 return; 229 } 230 console.info('Succeeded in disabling admin'); 231}); 232``` 233 234## adminManager.disableAdmin 235 236disableAdmin(admin: Want, userId: number, callback: AsyncCallback\<void>): void 237 238将指定用户(通过userId指定)下指定的普通管理应用去激活。使用callback异步回调。 239 240**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 241 242**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 243 244**系统API**: 此接口为系统接口。 245 246**模型约束**: 此接口仅可在Stage模型下使用。 247 248**参数**: 249 250| 参数名 | 类型 | 必填 | 说明 | 251| -------- | ----------------------------------- | ---- | ---------------------------- | 252| admin | [Want](js-apis-app-ability-want.md) | 是 | 普通设备管理应用。 | 253| userId | number | 是 | 用户ID,指定具体用户,取值范围:大于等于0。<br>默认值:当前用户。 | 254| callback | AsyncCallback\<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 255 256**错误码**: 257 258以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 259 260| 错误码ID | 错误信息 | 261| ------- | ----------------------------------------------------------------- | 262| 9200005 | failed to disable the administrator application of the device. | 263 264**示例**: 265 266```ts 267import Want from '@ohos.app.ability.Want'; 268let wantTemp: Want = { 269 bundleName: 'bundleName', 270 abilityName: 'abilityName', 271}; 272 273adminManager.disableAdmin(wantTemp, 100, (err) => { 274 if (err) { 275 console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); 276 return; 277 } 278 console.info('Succeeded in disabling admin'); 279}); 280``` 281 282## adminManager.disableAdmin 283 284disableAdmin(admin: Want, userId?: number): Promise\<void> 285 286将当前/指定用户下指定的普通管理应用去激活。使用promise异步回调。 287 288**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 289 290**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 291 292**系统API**: 此接口为系统接口。 293 294**模型约束**: 此接口仅可在Stage模型下使用。 295 296**参数**: 297 298| 参数名 | 类型 | 必填 | 说明 | 299| ------ | ----------------------------------- | ---- | ---------------------------- | 300| admin | [Want](js-apis-app-ability-want.md) | 是 | 普通设备管理应用。 | 301| userId | number | 否 | 用户ID, 取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。| 302 303**返回值:** 304 305| 类型 | 说明 | 306| ----------------- | ----------------- | 307| Promise\<void> | 无返回结果的Promise对象。当去激活普通管理应用失败时,会抛出错误对象。 | 308 309**错误码**: 310 311以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 312 313| 错误码ID | 错误信息 | 314| ------- | ----------------------------------------------------------------- | 315| 9200005 | failed to disable the administrator application of the device. | 316 317**示例**: 318 319```ts 320import Want from '@ohos.app.ability.Want'; 321import { BusinessError } from '@ohos.base'; 322let wantTemp: Want = { 323 bundleName: 'bundleName', 324 abilityName: 'abilityName', 325}; 326 327adminManager.disableAdmin(wantTemp, 100).catch((err: BusinessError) => { 328 console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); 329}); 330``` 331 332## adminManager.disableSuperAdmin 333 334disableSuperAdmin(bundleName: String, callback: AsyncCallback\<void>): void 335 336根据bundleName将管理员用户下的超级设备管理应用去激活。使用callback异步回调。 337 338**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 339 340**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 341 342**系统API**: 此接口为系统接口。 343 344**模型约束**: 此接口仅可在Stage模型下使用。 345 346**参数**: 347 348| 参数名 | 类型 | 必填 | 说明 | 349| ---------- | ----------------------- | ---- | ------------------- | 350| bundleName | String | 是 | 超级设备管理应用的包名。 | 351| callback | AsyncCallback\<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 352 353**错误码**: 354 355以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 356 357| 错误码ID | 错误信息 | 358| ------- | ----------------------------------------------------------------- | 359| 9200005 | failed to disable the administrator application of the device. | 360 361**示例**: 362 363```ts 364import Want from '@ohos.app.ability.Want'; 365let bundleName: string = 'com.example.myapplication'; 366 367adminManager.disableSuperAdmin(bundleName, (err) => { 368 if (err) { 369 console.error(`Failed to disable super admin. Code: ${err.code}, message: ${err.message}`); 370 return; 371 } 372 console.info('Succeeded in disabling super admin'); 373}); 374``` 375 376## adminManager.disableSuperAdmin 377 378disableSuperAdmin(bundleName: String): Promise\<void> 379 380根据bundleName将管理员用户下的超级设备管理应用去激活。使用promise异步回调。 381 382**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 383 384**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 385 386**系统API**: 此接口为系统接口。 387 388**模型约束**: 此接口仅可在Stage模型下使用。 389 390**参数**: 391 392| 参数名 | 类型 | 必填 | 说明 | 393| ---------- | ------ | ---- | ------------ | 394| bundleName | String | 是 | 超级设备管理应用的包名。 | 395 396**返回值:** 397 398| 类型 | 说明 | 399| ----------------- | ----------------- | 400| Promise\<void> | 无返回结果的Promise对象。当去激活超级设备管理应用失败时,会抛出错误对象。 | 401 402**错误码**: 403 404以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 405 406| 错误码ID | 错误信息 | 407| ------- | ----------------------------------------------------------------- | 408| 9200005 | failed to disable the administrator application of the device. | 409 410**示例**: 411 412```ts 413import Want from '@ohos.app.ability.Want'; 414import { BusinessError } from '@ohos.base'; 415let bundleName: string = 'com.example.myapplication'; 416 417adminManager.disableSuperAdmin(bundleName).catch((err: BusinessError) => { 418 console.error(`Failed to disable super admin. Code: ${err.code}, message: ${err.message}`); 419}); 420``` 421 422## adminManager.isAdminEnabled 423 424isAdminEnabled(admin: Want, callback: AsyncCallback\<boolean>): void 425 426查询当前用户下指定的设备管理应用是否被激活。使用callback异步回调。 427 428**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 429 430**系统API**: 此接口为系统接口。 431 432**模型约束**: 此接口仅可在Stage模型下使用。 433 434**参数**: 435 436| 参数名 | 类型 | 必填 | 说明 | 437| -------- | ----------------------------------- | ---- | -------------------- | 438| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 439| callback | AsyncCallback\<boolean> | 是 | 回调函数,当接口调用成功,err为null,data为boolean值,true表示当前用户下指定的设备管理应用被激活,false表示当前用户下指定的设备管理应用未激活,否则err为错误对象。 | 440 441**示例**: 442 443```ts 444import Want from '@ohos.app.ability.Want'; 445let wantTemp: Want = { 446 bundleName: 'bundleName', 447 abilityName: 'abilityName', 448}; 449 450adminManager.isAdminEnabled(wantTemp, (err, result) => { 451 if (err) { 452 console.error(`Failed to query admin is enabled or not. Code: ${err.code}, message: ${err.message}`); 453 return; 454 } 455 console.info(`Succeeded in querying admin is enabled or not, result : ${result}`); 456}); 457``` 458 459## adminManager.isAdminEnabled 460 461isAdminEnabled(admin: Want, userId: number, callback: AsyncCallback\<boolean>): void 462 463查询指定用户(通过userId指定)下指定的设备管理应用是否被激活。使用callback异步回调。 464 465**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 466 467**系统API**: 此接口为系统接口。 468 469**模型约束**: 此接口仅可在Stage模型下使用。 470 471**参数**: 472 473| 参数名 | 类型 | 必填 | 说明 | 474| -------- | ----------------------------------- | ---- | ---------------------------- | 475| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 476| userId | number | 是 | 用户ID,指定具体用户,取值范围:大于等于0。<br> 默认值:当前用户。 | 477| callback | AsyncCallback\<boolean> | 是 | 回调函数,当接口调用成功,err为null,data为boolean值,true表示当前用户下指定的设备管理应用被激活,false表示当前用户下指定的设备管理应用未激活,否则err为错误对象。 | 478 479**示例**: 480 481```ts 482import Want from '@ohos.app.ability.Want'; 483let wantTemp: Want = { 484 bundleName: 'bundleName', 485 abilityName: 'abilityName', 486}; 487 488adminManager.isAdminEnabled(wantTemp, 100, (err, result) => { 489 if (err) { 490 console.error(`Failed to query admin is enabled. Code: ${err.code}, message: ${err.message}`); 491 return; 492 } 493 console.info(`Succeeded in querying admin is enabled or not, result : ${result}`); 494}); 495``` 496 497## adminManager.isAdminEnabled 498 499isAdminEnabled(admin: Want, userId?: number): Promise\<boolean> 500 501查询当前/指定用户下指定的设备管理应用是否被激活。使用promise异步回调。 502 503**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 504 505**系统API**: 此接口为系统接口。 506 507**模型约束**: 此接口仅可在Stage模型下使用。 508 509**参数**: 510 511| 参数名 | 类型 | 必填 | 说明 | 512| ------ | ----------------------------------- | ---- | ---------------------------- | 513| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 514| userId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 | 515 516**返回值:** 517 518| 类型 | 说明 | 519| ----------------- | ------------------- | 520| Promise\<boolean> | Promise对象, 返回true表示指定的设备管理应用被激活,返回false表示指定的设备管理应用未激活。| 521 522**示例**: 523 524```ts 525import Want from '@ohos.app.ability.Want'; 526import { BusinessError } from '@ohos.base'; 527let wantTemp: Want = { 528 bundleName: 'bundleName', 529 abilityName: 'abilityName', 530}; 531 532adminManager.isAdminEnabled(wantTemp, 100).then((result) => { 533 console.info(`Succeeded in querying admin is enabled or not, result : ${result}`); 534}).catch((err: BusinessError) => { 535 console.error(`Failed to query admin is enabled or not. Code: ${err.code}, message: ${err.message}`); 536}); 537``` 538 539## adminManager.isSuperAdmin 540 541isSuperAdmin(bundleName: String, callback: AsyncCallback\<boolean>): void 542 543根据bundleName查询管理员用户下的超级设备管理应用是否被激活。使用callback异步回调。 544 545**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 546 547**系统API**: 此接口为系统接口。 548 549**模型约束**: 此接口仅可在Stage模型下使用。 550 551**参数**: 552 553| 参数名 | 类型 | 必填 | 说明 | 554| ---------- | ----------------------- | ---- | -------------------- | 555| bundleName | String | 是 | 超级设备管理应用。 | 556| callback | AsyncCallback\<boolean> | 是 | 回调函数,当接口调用成功,err为null,data为boolean类型值,true表示当前用户下指定的设备管理应用被激活,false表示当前用户下指定的设备管理应用未激活,否则err为错误对象。 | 557 558**示例**: 559 560```ts 561import Want from '@ohos.app.ability.Want'; 562let bundleName: string = 'com.example.myapplication'; 563 564adminManager.isSuperAdmin(bundleName, (err, result) => { 565 if (err) { 566 console.error(`Failed to query admin is super admin or not. Code: ${err.code}, message: ${err.message}`); 567 return; 568 } 569 console.info(`Succeeded in querying admin is super admin or not, result : ${result}`); 570}); 571``` 572 573## adminManager.isSuperAdmin 574 575isSuperAdmin(bundleName: String): Promise\<boolean> 576 577根据bundleName查询管理员用户下的超级设备管理应用是否被激活。使用promise异步回调。 578 579**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 580 581**系统API**: 此接口为系统接口。 582 583**模型约束**: 此接口仅可在Stage模型下使用。 584 585**参数**: 586 587| 参数名 | 类型 | 必填 | 说明 | 588| ---------- | ------ | ---- | --------- | 589| bundleName | String | 是 | 超级设备管理应用。 | 590 591**返回值:** 592 593| 错误码ID | 错误信息 | 594| ----------------- | ------------------- | 595| Promise\<boolean> | Promise对象, 返回true表示指定的超级设备管理应用被激活,返回false表示指定的超级设备管理应用未激活。 | 596 597**示例**: 598 599```ts 600import Want from '@ohos.app.ability.Want'; 601import { BusinessError } from '@ohos.base'; 602let bundleName: string = 'com.example.myapplication'; 603 604adminManager.isSuperAdmin(bundleName).then((result) => { 605 console.info(`Succeeded in querying admin is super admin or not, result : ${result}`); 606}).catch((err: BusinessError) => { 607 console.error(`Failed to query admin is super admin or not. Code: ${err.code}, message: ${err.message}`); 608}); 609``` 610 611## adminManager.setEnterpriseInfo 612 613setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo, callback: AsyncCallback\<void>;): void 614 615设置指定的设备管理应用的企业信息。使用callback异步回调。 616 617**需要权限:** ohos.permission.SET_ENTERPRISE_INFO 618 619**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 620 621**系统API**: 此接口为系统接口。 622 623**模型约束**: 此接口仅可在Stage模型下使用。 624 625**参数:** 626 627| 参数名 | 类型 | 必填 | 说明 | 628| -------------- | ----------------------------------- | ---- | ---------------------- | 629| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 630| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | 是 | 设备管理应用的企业信息。 | 631| callback | AsyncCallback\<void>; | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 632 633**错误码**: 634 635以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 636 637| 错误码ID | 错误信息 | 638| ------- | ----------------------------------------------------- | 639| 9200001 | the application is not an administrator of the device. | 640 641**示例:** 642 643```ts 644import Want from '@ohos.app.ability.Want'; 645let wantTemp: Want = { 646 bundleName: 'com.example.myapplication', 647 abilityName: 'EntryAbility', 648}; 649let enterpriseInfo: adminManager.EnterpriseInfo = { 650 name: 'enterprise name', 651 description: 'enterprise description' 652} 653 654adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo, (err) => { 655 if (err) { 656 console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`); 657 return; 658 } 659 console.info('Succeeded in setting enterprise info'); 660}); 661``` 662 663## adminManager.setEnterpriseInfo 664 665setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo): Promise\<void>; 666 667设置指定的设备管理应用的企业信息。使用promise异步回调。 668 669**需要权限:** ohos.permission.SET_ENTERPRISE_INFO 670 671**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 672 673**系统API**: 此接口为系统接口。 674 675**模型约束**: 此接口仅可在Stage模型下使用。 676 677**参数:** 678 679| 参数名 | 类型 | 必填 | 说明 | 680| -------------- | ----------------------------------- | ---- | ------------ | 681| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用 | 682| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | 是 | 设备管理应用的企业信息 | 683 684**返回值:** 685 686| 类型 | 说明 | 687| ----------------- | --------------------- | 688| Promise\<void> | 无返回结果的Promise对象。当设置设备管理应用企业信息失败时,会抛出错误对象。 | 689 690**错误码**: 691 692以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 693 694| 错误码ID | 错误信息 | 695| ------- | ----------------------------------------------------- | 696| 9200001 | the application is not an administrator of the device. | 697 698**示例:** 699 700```ts 701import Want from '@ohos.app.ability.Want'; 702import { BusinessError } from '@ohos.base'; 703let wantTemp: Want = { 704 bundleName: 'com.example.myapplication', 705 abilityName: 'EntryAbility', 706}; 707let enterpriseInfo: adminManager.EnterpriseInfo = { 708 name: 'enterprise name', 709 description: 'enterprise description' 710} 711 712adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo).catch((err: BusinessError) => { 713 console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`); 714}); 715``` 716 717## adminManager.getEnterpriseInfo 718 719getEnterpriseInfo(admin: Want, callback: AsyncCallback<EnterpriseInfo>): void 720 721获取指定的设备管理应用的企业信息。使用callback异步回调。 722 723**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 724 725**系统API**: 此接口为系统接口。 726 727**模型约束**: 此接口仅可在Stage模型下使用。 728 729**参数:** 730 731| 参数名 | 类型 | 必填 | 说明 | 732| -------- | ---------------------------------------- | ---- | ------------------------ | 733| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用 | 734| callback | AsyncCallback<[EnterpriseInfo](#enterpriseinfo)> | 是 | 回调函数,当接口调用成功,err为null,data为设备管理应用的企业信息,否则err为错误对象。 | 735 736**错误码**: 737 738以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 739 740| 错误码ID | 错误信息 | 741| ------- | ----------------------------------------------------- | 742| 9200001 | the application is not an administrator of the device. | 743 744**示例:** 745 746```ts 747import Want from '@ohos.app.ability.Want'; 748let wantTemp: Want = { 749 bundleName: 'com.example.myapplication', 750 abilityName: 'EntryAbility', 751}; 752 753adminManager.getEnterpriseInfo(wantTemp, (err, result) => { 754 if (err) { 755 console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`); 756 return; 757 } 758 console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`); 759}); 760``` 761 762## adminManager.getEnterpriseInfo 763 764getEnterpriseInfo(admin: Want): Promise<EnterpriseInfo> 765 766获取指定的设备管理应用的企业信息,使用promise异步回调。 767 768**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 769 770**系统API**: 此接口为系统接口。 771 772**模型约束**: 此接口仅可在Stage模型下使用。 773 774**参数:** 775 776| 参数名 | 类型 | 必填 | 说明 | 777| ----- | ----------------------------------- | ---- | ------- | 778| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用 | 779 780**返回值:** 781 782| 类型 | 说明 | 783| ---------------------------------------- | ------------------------- | 784| Promise<[EnterpriseInfo](#enterpriseinfo)> | Promise对象,返回指定的设备管理应用的企业信息。 | 785 786**错误码**: 787 788以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 789 790| 错误码ID | 错误信息 | 791| ------- | ----------------------------------------------------- | 792| 9200001 | the application is not an administrator of the device. | 793 794**示例:** 795 796```ts 797import Want from '@ohos.app.ability.Want'; 798import { BusinessError } from '@ohos.base'; 799let wantTemp: Want = { 800 bundleName: 'com.example.myapplication', 801 abilityName: 'EntryAbility', 802}; 803 804adminManager.getEnterpriseInfo(wantTemp).then((result) => { 805 console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`); 806}).catch((err: BusinessError) => { 807 console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`); 808}); 809``` 810 811## adminManager.subscribeManagedEvent 812 813subscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>, callback: AsyncCallback\<void>): void 814 815指定的设备管理应用订阅系统管理事件。使用callback异步回调。 816 817**需要权限:** ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 818 819**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 820 821**系统API**: 此接口为系统接口。 822 823**模型约束**: 此接口仅可在Stage模型下使用。 824 825**参数:** 826 827| 参数名 | 类型 | 必填 | 说明 | 828| ----- | ----------------------------------- | ---- | ------- | 829| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 830| managedEvents | Array\<[ManagedEvent](#managedevent)> | 是 | 订阅事件数组。 | 831| callback | AsyncCallback\<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 832 833**错误码**: 834 835以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 836 837|错误码ID | 错误信息 | 838| ------- | ----------------------------------------------------- | 839| 9200001 | the application is not an administrator of the device. | 840| 9200008 | the specified system events enum is invalid. | 841 842**示例:** 843 844```ts 845import Want from '@ohos.app.ability.Want'; 846let wantTemp: Want = { 847 bundleName: 'bundleName', 848 abilityName: 'abilityName', 849}; 850let events: Array<adminManager.ManagedEvent> = [0, 1]; 851 852adminManager.subscribeManagedEvent(wantTemp, events, (err) => { 853 if (err) { 854 console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`); 855 return; 856 } 857 console.info('Succeeded in subscribe managed event'); 858}); 859``` 860 861## adminManager.subscribeManagedEvent 862 863subscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>): Promise\<void> 864 865指定的设备管理应用订阅系统管理事件。使用Promise异步回调。 866 867**需要权限:** ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 868 869**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 870 871**系统API**: 此接口为系统接口。 872 873**模型约束**: 此接口仅可在Stage模型下使用。 874 875**参数:** 876 877| 参数名 | 类型 | 必填 | 说明 | 878| ----- | ----------------------------------- | ---- | ------- | 879| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 880| managedEvents | Array\<[ManagedEvent](#managedevent)> | 是 | 订阅事件数组。 | 881 882**返回值:** 883 884| 类型 | 说明 | 885| ----- | ----------------------------------- | 886| Promise\<void> | 无返回结果的Promise对象。当指定的设备管理应用订阅系统事件失败时,会抛出错误对象。 | 887 888**错误码**: 889 890以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 891 892| 错误码ID | 错误信息 | 893| ------- | ----------------------------------------------------- | 894| 9200001 | the application is not an administrator of the device. | 895| 9200008 | the specified system events enum is invalid. | 896 897**示例:** 898 899```ts 900import Want from '@ohos.app.ability.Want'; 901import { BusinessError } from '@ohos.base'; 902let wantTemp: Want = { 903 bundleName: 'bundleName', 904 abilityName: 'abilityName', 905}; 906let events: Array<adminManager.ManagedEvent> = [0, 1]; 907 908adminManager.subscribeManagedEvent(wantTemp, events).then(() => { 909}).catch((err: BusinessError) => { 910 console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`); 911}) 912``` 913 914## adminManager.unsubscribeManagedEvent 915 916unsubscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>, callback: AsyncCallback\<void>): void 917 918指定的设备管理应用取消订阅系统管理事件。使用callback异步回调。 919 920**需要权限:** ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 921 922**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 923 924**系统API**: 此接口为系统接口。 925 926**模型约束**: 此接口仅可在Stage模型下使用。 927 928**参数:** 929 930| 参数名 | 类型 | 必填 | 说明 | 931| ----- | ----------------------------------- | ---- | ------- | 932| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 933| managedEvents | Array\<[ManagedEvent](#managedevent)> | 是 | 取消订阅事件数组。 | 934| callback | AsyncCallback\<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 935 936**错误码**: 937 938以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 939 940| 错误码ID | 错误信息 | 941| ------- | ----------------------------------------------------- | 942| 9200001 | the application is not an administrator of the device. | 943| 9200008 | the specified system events enum is invalid. | 944 945**示例:** 946 947```ts 948import Want from '@ohos.app.ability.Want'; 949let wantTemp: Want = { 950 bundleName: 'bundleName', 951 abilityName: 'abilityName', 952}; 953let events: Array<adminManager.ManagedEvent> = [0, 1]; 954 955adminManager.unsubscribeManagedEvent(wantTemp, events, (err) => { 956 if (err) { 957 console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`); 958 return; 959 } 960 console.info('Succeeded in unsubscribe managed event'); 961}); 962``` 963 964## adminManager.unsubscribeManagedEvent 965 966unsubscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>): Promise\<void> 967 968指定的设备管理应用取消订阅系统管理事件。使用promise异步回调。 969 970**需要权限:** ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 971 972**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 973 974**系统API**: 此接口为系统接口。 975 976**模型约束**: 此接口仅可在Stage模型下使用。 977 978**参数:** 979 980| 参数名 | 类型 | 必填 | 说明 | 981| ----- | ----------------------------------- | ---- | ------- | 982| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 983| managedEvents | Array\<[ManagedEvent](#managedevent)> | 是 | 取消订阅事件数组。 | 984 985**返回值:** 986 987| 类型 | 说明 | 988| ----- | ----------------------------------- | 989| Promise\<void> | 无返回结果的Promise对象。当指定设备管理应用取消订阅系统管理事件失败时,会抛出错误对象。 | 990 991**错误码**: 992 993以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)。 994 995| 错误码ID | 错误信息 | 996| ------- | ----------------------------------------------------- | 997| 9200001 | the application is not an administrator of the device. | 998| 9200008 | the specified system events enum is invalid. | 999 1000**示例:** 1001 1002```ts 1003import Want from '@ohos.app.ability.Want'; 1004import { BusinessError } from '@ohos.base'; 1005let wantTemp: Want = { 1006 bundleName: 'bundleName', 1007 abilityName: 'abilityName', 1008}; 1009let events: Array<adminManager.ManagedEvent> = [0, 1]; 1010 1011adminManager.unsubscribeManagedEvent(wantTemp, events).then(() => { 1012}).catch((err: BusinessError) => { 1013 console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`); 1014}) 1015``` 1016 1017## adminManager.authorizeAdmin<sup>10+</sup> 1018 1019authorizeAdmin(admin: Want, bundleName: string, callback: AsyncCallback<void>): void 1020 1021设备管理应用授予指定应用管理员权限。使用callback异步回调。 1022 1023**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 1024 1025**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1026 1027**系统API**: 此接口为系统接口。 1028 1029**模型约束**: 此接口仅可在Stage模型下使用。 1030 1031**参数:** 1032 1033| 参数名 | 类型 | 必填 | 说明 | 1034| ----- | ----------------------------------- | ---- | ------- | 1035| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 1036| bundleName | string | 是 | 被授予管理员权限应用的包名。 | 1037| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 1038 1039**错误码**: 1040 1041以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md) 1042 1043| 错误码ID | 错误信息 | 1044| ------- | ----------------------------------------------------- | 1045| 9200001 | the application is not an administrator of the device. | 1046| 9200002 | the administrator application does not have permission to manage the device. | 1047| 9200009 | authorize permission to the application failed. | 1048 1049**示例:** 1050 1051```ts 1052import Want from '@ohos.app.ability.Want'; 1053let wantTemp: Want = { 1054 bundleName: 'bundleName', 1055 abilityName: 'abilityName', 1056}; 1057let bundleName: string = "com.example.application"; 1058 1059adminManager.authorizeAdmin(wantTemp, bundleName, (err) => { 1060 if (err) { 1061 console.error(`Failed to authorize permission to the application. Code: ${err.code}, message: ${err.message}`); 1062 return; 1063 } 1064 console.info('Successfully authorized permission to the application'); 1065}); 1066``` 1067 1068## adminManager.authorizeAdmin<sup>10+</sup> 1069 1070authorizeAdmin(admin: Want, bundleName: string): Promise<void> 1071 1072设备管理应用授予指定应用管理员权限。使用Promise异步回调。 1073 1074**需要权限:** ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 1075 1076**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1077 1078**系统API**: 此接口为系统接口。 1079 1080**模型约束**: 此接口仅可在Stage模型下使用。 1081 1082**参数:** 1083 1084| 参数名 | 类型 | 必填 | 说明 | 1085| ----- | ----------------------------------- | ---- | ------- | 1086| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 1087| bundleName | string | 是 | 被授予管理员权限应用的包名。 | 1088 1089**返回值:** 1090 1091| 类型 | 说明 | 1092| ----- | ----------------------------------- | 1093| Promise<void> | 无返回结果的Promise对象。当设备管理应用授予指定应用管理员权限失败时,抛出错误对象。 | 1094 1095**错误码**: 1096 1097以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md) 1098 1099| 错误码ID | 错误信息 | 1100| ------- | ----------------------------------------------------- | 1101| 9200001 | the application is not an administrator of the device. | 1102| 9200002 | the administrator application does not have permission to manage the device. | 1103| 9200009 | authorize permission to the application failed. | 1104 1105**示例:** 1106 1107```ts 1108import Want from '@ohos.app.ability.Want'; 1109import { BusinessError } from '@ohos.base'; 1110let wantTemp: Want = { 1111 bundleName: 'bundleName', 1112 abilityName: 'abilityName', 1113}; 1114let bundleName: string = "com.example.application"; 1115 1116adminManager.authorizeAdmin(wantTemp, bundleName).then(() => { 1117}).catch((err: BusinessError) => { 1118 console.error(`Failed to authorize permission to the application. Code: ${err.code}, message: ${err.message}`); 1119}) 1120``` 1121 1122## EnterpriseInfo 1123 1124设备管理应用的企业信息。 1125 1126**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1127 1128**系统API**: 此接口为系统接口。 1129 1130**模型约束**: 此接口仅可在Stage模型下使用。 1131 1132| 名称 | 类型 | 必填 | 说明 | 1133| ----------- | --------| ---- | ------------------------------- | 1134| name | string | 是 | 表示设备管理应用所属企业的名称。 | 1135| description | string | 是 | 表示设备管理应用所属企业的描述。 | 1136 1137## AdminType 1138 1139设备管理应用的类型。 1140 1141**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1142 1143**系统API**: 此接口为系统接口。 1144 1145**模型约束**: 此接口仅可在Stage模型下使用。 1146 1147| 名称 | 值 | 说明 | 1148| ----------------- | ---- | ----- | 1149| ADMIN_TYPE_NORMAL | 0x00 | 普通设备管理应用。 | 1150| ADMIN_TYPE_SUPER | 0x01 | 超级设备管理应用。 | 1151 1152## ManagedEvent 1153 1154可订阅的系统管理事件。 1155 1156**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1157 1158**系统API**: 此接口为系统接口。 1159 1160**模型约束**: 此接口仅可在Stage模型下使用。 1161 1162| 名称 | 值 | 说明 | 1163| -------------------------- | ---- | ------------- | 1164| MANAGED_EVENT_BUNDLE_ADDED | 0 | 应用安装事件。 | 1165| MANAGED_EVENT_BUNDLE_REMOVED | 1 | 应用卸载事件。 | 1166| MANAGED_EVENT_APP_START<sup>10+</sup> | 2 | 应用启动事件。 | 1167| MANAGED_EVENT_APP_STOP<sup>10+</sup> | 3 | 应用停止事件。 | 1168 1169