1# @ohos.account.osAccount (系统帐号管理) 2 3本模块提供管理系统帐号的基础能力,包括系统帐号的添加、删除、查询、设置、订阅、启动等功能。 4 5> **说明:** 6> 7> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9 10## 导入模块 11 12```ts 13import account_osAccount from '@ohos.account.osAccount'; 14``` 15 16## account_osAccount.getAccountManager 17 18getAccountManager(): AccountManager 19 20获取系统帐号管理对象。 21 22**系统能力:** SystemCapability.Account.OsAccount 23 24**返回值:** 25 26| 类型 | 说明 | 27| --------------------------------- | ---------------- | 28| [AccountManager](#accountmanager) | 系统帐号管理对象。 | 29 30**示例:** 31 ```ts 32 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 33 ``` 34 35## OsAccountType 36 37表示系统帐号类型的枚举。 38 39**系统能力:** SystemCapability.Account.OsAccount。 40 41| 名称 | 值 | 说明 | 42| ------ | ------ | ----------- | 43| ADMIN | 0 | 管理员帐号。 | 44| NORMAL | 1 | 普通帐号。 | 45| GUEST | 2 | 访客帐号。 | 46 47## AccountManager 48 49系统帐号管理类。 50 51### activateOsAccount 52 53activateOsAccount(localId: number, callback: AsyncCallback<void>): void 54 55激活指定系统帐号。使用callback异步回调。 56 57**系统接口:** 此接口为系统接口。 58 59**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 60 61**系统能力:** SystemCapability.Account.OsAccount 62 63**参数:** 64 65| 参数名 | 类型 | 必填 | 说明 | 66| -------- | ------------------------- | ---- | -------------------------------------------------- | 67| localId | number | 是 | 系统帐号ID。 | 68| callback | AsyncCallback<void> | 是 | 回调函数。当帐号激活成功时,err为null,否则为错误对象。 | 69 70**错误码:** 71 72| 错误码ID | 错误信息 | 73| -------- | ------------------- | 74| 12300001 | System service exception. | 75| 12300002 | Invalid localId. | 76| 12300003 | Account not found. | 77| 12300008 | Restricted Account. | 78| 12300009 | Account has been activated. | 79 80**示例:** 激活ID为100的系统帐号 81 ```ts 82 import { BusinessError } from '@ohos.base'; 83 let localId: number = 100; 84 try { 85 accountManager.activateOsAccount(localId, (err: BusinessError)=>{ 86 if (err) { 87 console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`); 88 } else { 89 console.log('activateOsAccount successfully'); 90 } 91 }); 92 } catch (err) { 93 console.log('activateOsAccount failed, error:' + JSON.stringify(err)); 94 } 95 ``` 96 97### activateOsAccount 98 99activateOsAccount(localId: number): Promise<void> 100 101激活指定系统帐号。使用Promise异步回调。 102 103**系统接口:** 此接口为系统接口。 104 105**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 106 107**系统能力:** SystemCapability.Account.OsAccount 108 109**参数:** 110 111| 参数名 | 类型 | 必填 | 说明 | 112| ------- | ------ | ---- | -------------------- | 113| localId | number | 是 | 系统帐号ID。 | 114 115**返回值:** 116 117| 类型 | 说明 | 118| ------------------- | ------------------------------------ | 119| Promise<void> | Promise对象,无返回结果的Promise对象。 | 120 121**错误码:** 122 123| 错误码ID | 错误信息 | 124| -------- | ------------------- | 125| 12300001 | System service exception. | 126| 12300002 | Invalid localId. | 127| 12300003 | Account not found. | 128| 12300008 | Restricted Account. | 129| 12300009 | Account has been activated. | 130 131**示例:** 激活ID为100的系统帐号 132 ```ts 133 import { BusinessError } from '@ohos.base'; 134 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 135 let localId: number = 100; 136 try { 137 accountManager.activateOsAccount(localId).then(() => { 138 console.log('activateOsAccount successfully'); 139 }).catch((err: BusinessError) => { 140 console.log('activateOsAccount failed, err:' + JSON.stringify(err)); 141 }); 142 } catch (e) { 143 console.log('activateOsAccount exception: ' + JSON.stringify(e)); 144 } 145 ``` 146 147### checkMultiOsAccountEnabled<sup>9+</sup> 148 149checkMultiOsAccountEnabled(callback: AsyncCallback<boolean>): void 150 151判断是否支持多系统帐号。使用callback异步回调。 152 153**系统能力:** SystemCapability.Account.OsAccount 154 155**参数:** 156 157| 参数名 | 类型 | 必填 | 说明 | 158| -------- | ---------------------------- | ---- | ------------------------------------------------------ | 159| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示支持多系统帐号;返回false表示不支持。 | 160 161**错误码:** 162 163| 错误码ID | 错误信息 | 164| -------- | ------------------- | 165| 12300001 | System service exception. | 166 167**示例:** 168 169 ```ts 170 import { BusinessError } from '@ohos.base'; 171 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 172 try { 173 accountManager.checkMultiOsAccountEnabled((err: BusinessError, isEnabled: boolean) => { 174 if (err) { 175 console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`); 176 } else { 177 console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled); 178 } 179 }); 180 } catch (err) { 181 console.log('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err)); 182 } 183 ``` 184 185### checkMultiOsAccountEnabled<sup>9+</sup> 186 187checkMultiOsAccountEnabled(): Promise<boolean> 188 189判断是否支持多系统帐号。使用Promise异步回调。 190 191**系统能力:** SystemCapability.Account.OsAccount 192 193**返回值:** 194 195| 类型 | 说明 | 196| :--------------------- | :--------------------------------------------------------- | 197| Promise<boolean> | Promise对象。返回true表示支持多系统帐号;返回false表示不支持。 | 198 199**错误码:** 200 201| 错误码ID | 错误信息 | 202| -------- | ------------------- | 203| 12300001 | System service exception. | 204 205**示例:** 206 207 ```ts 208 import { BusinessError } from '@ohos.base'; 209 try { 210 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 211 accountManager.checkMultiOsAccountEnabled().then((isEnabled: boolean) => { 212 console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled); 213 }).catch((err: BusinessError) => { 214 console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`); 215 }); 216 } catch (err) { 217 console.log('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err)); 218 } 219 ``` 220 221### checkOsAccountActivated<sup>9+</sup> 222 223checkOsAccountActivated(localId: number, callback: AsyncCallback<boolean>): void 224 225判断指定系统帐号是否处于激活状态。使用callback异步回调。 226 227**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 228 229**系统能力:** SystemCapability.Account.OsAccount 230 231**参数:** 232 233| 参数名 | 类型 | 必填 | 说明 | 234| -------- | ---------------------------- | ---- | ------------------------------------------------------ | 235| localId | number | 是 | 系统帐号ID。 | 236| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示帐号已激活;返回false表示帐号未激活。 | 237 238**错误码:** 239 240| 错误码ID | 错误信息 | 241| -------- | ------------------- | 242| 12300001 | System service exception. | 243| 12300002 | Invalid localId. | 244| 12300003 | Account not found. | 245 246**示例:** 判断ID为100的系统帐号是否处于激活状态 247 248 ```ts 249 import { BusinessError } from '@ohos.base'; 250 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 251 let localId: number = 100; 252 try { 253 accountManager.checkOsAccountActivated(localId, (err: BusinessError, isActivated: boolean) => { 254 if (err) { 255 console.log('checkOsAccountActivated failed, error:' + JSON.stringify(err)); 256 } else { 257 console.log('checkOsAccountActivated successfully, isActivated:' + isActivated); 258 } 259 }); 260 } catch (err) { 261 console.log('checkOsAccountActivated exception: ' + JSON.stringify(err)); 262 } 263 ``` 264 265### checkOsAccountActivated<sup>9+</sup> 266 267checkOsAccountActivated(localId: number): Promise<boolean> 268 269判断指定系统帐号是否处于激活状态。使用Promise异步回调。 270 271**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 272 273**系统能力:** SystemCapability.Account.OsAccount 274 275**参数:** 276 277| 参数名 | 类型 | 必填 | 说明 | 278| ------- | ------ | ---- | --------------------------------- | 279| localId | number | 是 | 系统帐号ID。 | 280 281**返回值:** 282 283| 类型 | 说明 | 284| ---------------------- | ---------------------------------------------------------- | 285| Promise<boolean> | Promise对象。返回true表示帐号已激活;返回false表示帐号未激活。 | 286 287**错误码:** 288 289| 错误码ID | 错误信息 | 290| -------- | ------------------- | 291| 12300001 | System service exception. | 292| 12300002 | Invalid localId. | 293| 12300003 | Account not found. | 294 295**示例:** 判断ID为100的系统帐号是否处于激活状态 296 297 ```ts 298 import { BusinessError } from '@ohos.base'; 299 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 300 let localId: number = 100; 301 try { 302 accountManager.checkOsAccountActivated(localId).then((isActivated: boolean) => { 303 console.log('checkOsAccountActivated successfully, isActivated: ' + isActivated); 304 }).catch((err: BusinessError) => { 305 console.log('checkOsAccountActivated failed, error: ' + JSON.stringify(err)); 306 }); 307 } catch (err) { 308 console.log('checkOsAccountActivated exception: ' + JSON.stringify(err)); 309 } 310 ``` 311 312### checkOsAccountConstraintEnabled<sup>9+</sup> 313 314checkOsAccountConstraintEnabled(localId: number, constraint: string, callback: AsyncCallback<boolean>): void 315 316判断指定系统帐号是否具有指定约束。使用callback异步回调。 317 318**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 319 320**系统能力:** SystemCapability.Account.OsAccount 321 322**参数:** 323 324| 参数名 | 类型 | 必填 | 说明 | 325| ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- | 326| localId | number | 是 | 系统帐号ID。 | 327| constraint | string | 是 | 指定的[约束](#系统帐号约束列表)名称。 | 328| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 | 329 330**错误码:** 331 332| 错误码ID | 错误信息 | 333| -------- | ------------------- | 334| 12300001 | System service exception. | 335| 12300002 | Invalid localId or constraint. | 336| 12300003 | Account not found. | 337 338**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束 339 340 ```ts 341 import { BusinessError } from '@ohos.base'; 342 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 343 let localId: number = 100; 344 let constraint: string = 'constraint.wifi'; 345 try { 346 accountManager.checkOsAccountConstraintEnabled(localId, constraint, (err: BusinessError, isEnabled: boolean)=>{ 347 if (err) { 348 console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err)); 349 } else { 350 console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled); 351 } 352 }); 353 } catch (err) { 354 console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err)); 355 } 356 ``` 357 358### checkOsAccountConstraintEnabled<sup>9+</sup> 359 360checkOsAccountConstraintEnabled(localId: number, constraint: string): Promise<boolean> 361 362判断指定系统帐号是否具有指定约束。使用Promise异步回调。 363 364**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 365 366**系统能力:** SystemCapability.Account.OsAccount 367 368**参数:** 369 370| 参数名 | 类型 | 必填 | 说明 | 371| ---------- | ------ | ---- | ---------------------------------- | 372| localId | number | 是 | 系统帐号ID。 | 373| constraint | string | 是 | 指定的[约束](#系统帐号约束列表)名称。 | 374 375**返回值:** 376 377| 类型 | 说明 | 378| --------------------- | --------------------------------------------------------------------- | 379| Promise<boolean> | Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 | 380 381**错误码:** 382 383| 错误码ID | 错误信息 | 384| -------- | ------------------- | 385| 12300001 | System service exception. | 386| 12300002 | Invalid localId or constraint. | 387| 12300003 | Account not found. | 388 389**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束 390 391 ```ts 392 import { BusinessError } from '@ohos.base'; 393 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 394 let localId: number = 100; 395 let constraint: string = 'constraint.wifi'; 396 try { 397 accountManager.checkOsAccountConstraintEnabled(localId, constraint).then((isEnabled: boolean) => { 398 console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled); 399 }).catch((err: BusinessError) => { 400 console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err)); 401 }); 402 } catch (err) { 403 console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err)); 404 } 405 ``` 406 407### checkOsAccountTestable<sup>9+</sup> 408 409checkOsAccountTestable(callback: AsyncCallback<boolean>): void 410 411检查当前系统帐号是否为测试帐号。使用callback异步回调。 412 413**系统能力:** SystemCapability.Account.OsAccount 414 415**参数:** 416 417| 参数名 | 类型 | 必填 | 说明 | 418| -------- | ---------------------------- | ---- | --------------------------------------------------------------------- | 419| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 | 420 421**错误码:** 422 423| 错误码ID | 错误信息 | 424| -------- | ------------------- | 425| 12300001 | System service exception. | 426 427**示例:** 428 429 ```ts 430 import { BusinessError } from '@ohos.base'; 431 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 432 try { 433 accountManager.checkOsAccountTestable((err: BusinessError, isTestable: boolean) => { 434 if (err) { 435 console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err)); 436 } else { 437 console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable); 438 } 439 }); 440 } catch (err) { 441 console.log('checkOsAccountTestable error: ' + JSON.stringify(err)); 442 } 443 ``` 444 445### checkOsAccountTestable<sup>9+</sup> 446 447checkOsAccountTestable(): Promise<boolean> 448 449检查当前系统帐号是否为测试帐号。使用Promise异步回调。 450 451**系统能力:** SystemCapability.Account.OsAccount 452 453**返回值:** 454 455| 类型 | 说明 | 456| ---------------------- | ------------------------------------------------------------------------ | 457| Promise<boolean> | Promise对象。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 | 458 459**错误码:** 460 461| 错误码ID | 错误信息 | 462| -------- | ------------------- | 463| 12300001 | System service exception. | 464 465**示例:** 466 467 ```ts 468 import { BusinessError } from '@ohos.base'; 469 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 470 try { 471 accountManager.checkOsAccountTestable().then((isTestable: boolean) => { 472 console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable); 473 }).catch((err: BusinessError) => { 474 console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err)); 475 }); 476 } catch (err) { 477 console.log('checkOsAccountTestable exception: ' + JSON.stringify(err)); 478 } 479 ``` 480 481### checkOsAccountVerified<sup>9+</sup> 482 483checkOsAccountVerified(callback: AsyncCallback<boolean>): void 484 485检查当前系统帐号是否已认证解锁。使用callback异步回调。 486 487**系统能力:** SystemCapability.Account.OsAccount 488 489**参数:** 490 491| 参数名 | 类型 | 必填 | 说明 | 492| -------- | ---------------------------- | ---- | ------------------------------------------------------------- | 493| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 | 494 495**错误码:** 496 497| 错误码ID | 错误信息 | 498| -------- | ------------------- | 499| 12300001 | System service exception. | 500 501**示例:** 502 503 ```ts 504 import { BusinessError } from '@ohos.base'; 505 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 506 try { 507 accountManager.checkOsAccountVerified((err: BusinessError, isVerified: boolean) => { 508 if (err) { 509 console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); 510 } else { 511 console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); 512 } 513 }); 514 } catch (err) { 515 console.log('checkOsAccountVerified exception: ' + JSON.stringify(err)); 516 } 517 ``` 518 519### checkOsAccountVerified<sup>9+</sup> 520 521checkOsAccountVerified(): Promise<boolean> 522 523检查当前系统帐号是否已认证解锁。使用Promise异步回调。 524 525**系统能力:** SystemCapability.Account.OsAccount 526 527**返回值:** 528 529| 类型 | 说明 | 530| ---------------------- | ------------------------------------------------------------------------ | 531| Promise<boolean> | Promise对象。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 | 532 533**错误码:** 534 535| 错误码ID | 错误信息 | 536| -------- | ------------------- | 537| 12300001 | System service exception. | 538 539**示例:** 540 541 ```ts 542 import { BusinessError } from '@ohos.base'; 543 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 544 try { 545 accountManager.checkOsAccountVerified().then((isVerified: boolean) => { 546 console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); 547 }).catch((err: BusinessError) => { 548 console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); 549 }); 550 } catch (err) { 551 console.log('checkOsAccountVerified exception: ' + JSON.stringify(err)); 552 } 553 ``` 554 555### checkOsAccountVerified<sup>9+</sup> 556 557checkOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void 558 559检查指定系统帐号是否已验证。使用callback异步回调。 560 561**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 562 563**系统能力:** SystemCapability.Account.OsAccount 564 565**参数:** 566 567| 参数名 | 类型 | 必填 | 说明 | 568| -------- | ---------------------------- | ---- | ------------------------------------------------------------- | 569| localId | number | 是 | 系统帐号ID。 | 570| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 | 571 572**错误码:** 573 574| 错误码ID | 错误信息 | 575| -------- | ------------------- | 576| 12300001 | System service exception. | 577| 12300002 | Invalid localId. | 578| 12300003 | Account not found. | 579 580**示例:** 581 582 ```ts 583 import { BusinessError } from '@ohos.base'; 584 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 585 let localId: number = 100; 586 try { 587 accountManager.checkOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => { 588 if (err) { 589 console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); 590 } else { 591 console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); 592 } 593 }); 594 } catch (err) { 595 console.log('checkOsAccountVerified exception: ' + err); 596 } 597 ``` 598 599### checkOsAccountVerified<sup>9+</sup> 600 601checkOsAccountVerified(localId: number): Promise<boolean> 602 603检查指定系统帐号是否已验证。使用Promise异步回调。 604 605**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 606 607**系统能力:** SystemCapability.Account.OsAccount 608 609**参数:** 610 611| 参数名 | 类型 | 必填 | 说明 | 612| ------- | ------ | ---- | --------------------------------------------------------------- | 613| localId | number | 是 | 系统帐号ID。不填则检查当前系统帐号是否已验证。 | 614 615**返回值:** 616 617| 类型 | 说明 | 618| ---------------------- | ----------------------------------------------------------------- | 619| Promise<boolean> | Promise对象。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。 | 620 621**错误码:** 622 623| 错误码ID | 错误信息 | 624| -------- | ------------------- | 625| 12300001 | System service exception. | 626| 12300002 | Invalid localId. | 627| 12300003 | Account not found. | 628 629**示例:** 630 631 ```ts 632 import { BusinessError } from '@ohos.base'; 633 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 634 let localId: number = 100; 635 try { 636 accountManager.checkOsAccountVerified(localId).then((isVerified: boolean) => { 637 console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); 638 }).catch((err: BusinessError) => { 639 console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); 640 }); 641 } catch (err) { 642 console.log('checkOsAccountVerified exception: ' + JSON.stringify(err)); 643 } 644 ``` 645 646### checkOsAccountVerified<sup>9+</sup> 647 648checkOsAccountVerified(): Promise<boolean> 649 650检查当前系统帐号是否已验证。使用Promise异步回调。 651 652**系统能力:** SystemCapability.Account.OsAccount 653 654**返回值:** 655 656| 类型 | 说明 | 657| ---------------------- | ----------------------------------------------------------------- | 658| Promise<boolean> | Promise对象。返回true表示当前帐号已验证;返回false表示当前帐号未验证。 | 659 660**错误码:** 661 662| 错误码ID | 错误信息 | 663| -------- | ------------------- | 664| 12300001 | System service exception. | 665 666**示例:** 667 668 ```ts 669 import { BusinessError } from '@ohos.base'; 670 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 671 try { 672 accountManager.checkOsAccountVerified().then((isVerified: boolean) => { 673 console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); 674 }).catch((err: BusinessError) => { 675 console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); 676 }); 677 } catch (err) { 678 console.log('checkOsAccountVerified exception: ' + JSON.stringify(err)); 679 } 680 ``` 681 682### removeOsAccount 683 684removeOsAccount(localId: number, callback: AsyncCallback<void>): void 685 686删除指定系统帐号。使用callback异步回调。 687 688**系统接口:** 此接口为系统接口。 689 690**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 691 692**系统能力:** SystemCapability.Account.OsAccount 693 694**参数:** 695 696| 参数名 | 类型 | 必填 | 说明 | 697| -------- | ------------------------- | ---- | -------------------------------------------------- | 698| localId | number | 是 | 系统帐号ID。 | 699| callback | AsyncCallback<void> | 是 | 回调函数。如果删除帐号成功,err为null,否则为错误对象。 | 700 701**错误码:** 702 703| 错误码ID | 错误信息 | 704| -------- | ------------------- | 705| 12300001 | System service exception. | 706| 12300002 | Invalid localId. | 707| 12300003 | Account not found. | 708| 12300008 | Restricted Account. | 709 710**示例:** 711 712 ```ts 713 import { BusinessError } from '@ohos.base'; 714 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 715 let accountName: string = 'testAccountName'; 716 try { 717 accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL, 718 (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo) => { 719 accountManager.removeOsAccount(osAccountInfo.localId, (err: BusinessError)=>{ 720 if (err) { 721 console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); 722 } else { 723 console.log('removeOsAccount successfully'); 724 } 725 }); 726 }); 727 } catch (err) { 728 console.log('removeOsAccount exception: ' + JSON.stringify(err)); 729 } 730 ``` 731 732### removeOsAccount 733 734removeOsAccount(localId: number): Promise<void> 735 736删除指定系统帐号。使用Promise异步回调。 737 738**系统接口:** 此接口为系统接口。 739 740**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 741 742**系统能力:** SystemCapability.Account.OsAccount 743 744**参数:** 745 746| 参数名 | 类型 | 必填 | 说明 | 747| ------- | ------ | ---- | --------------------------------- | 748| localId | number | 是 | 系统帐号ID。 | 749 750**返回值:** 751 752| 类型 | 说明 | 753| ------------------- | ------------------------------------ | 754| Promise<void> | Promise对象,无返回结果的Promise对象。 | 755 756**错误码:** 757 758| 错误码ID | 错误信息 | 759| -------- | ------------------- | 760| 12300001 | System service exception. | 761| 12300002 | Invalid localId. | 762| 12300003 | Account not found. | 763| 12300008 | Restricted Account. | 764 765**示例:** 766 767 ```ts 768 import { BusinessError } from '@ohos.base'; 769 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 770 let accountName: string = 'testAccountName'; 771 try { 772 accountManager.createOsAccount(accountName, account_osAccount.OsAccountType.NORMAL, 773 (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{ 774 accountManager.removeOsAccount(osAccountInfo.localId).then(() => { 775 console.log('removeOsAccount successfully'); 776 }).catch((err: BusinessError) => { 777 console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); 778 }); 779 }); 780 } catch (err) { 781 console.log('removeOsAccount exception: ' + JSON.stringify(err)); 782 } 783 ``` 784 785### setOsAccountConstraints 786 787setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean,callback: AsyncCallback<void>): void 788 789为指定系统帐号设置/删除约束。使用callback异步回调。 790 791**系统接口:** 此接口为系统接口。 792 793**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 794 795**系统能力:** SystemCapability.Account.OsAccount 796 797**参数:** 798 799| 参数名 | 类型 | 必填 | 说明 | 800| ----------- | ------------------------- | ---- | ----------------------------------------------- | 801| localId | number | 是 | 系统帐号ID。 | 802| constraints | Array<string> | 是 | 待设置/删除的[约束](#系统帐号约束列表)列表。 | 803| enable | boolean | 是 | 设置(true)/删除(false) | 804| callback | AsyncCallback<void> | 是 | 回调函数。如果设置成功,err为null,否则为错误对象。 | 805 806**错误码:** 807 808| 错误码ID | 错误信息 | 809| -------- | ------------------- | 810| 12300001 | System service exception. | 811| 12300002 | Invalid localId or constraints. | 812| 12300003 | Account not found. | 813| 12300008 | Restricted Account. | 814 815**示例:** 给ID为100的系统帐号设置禁止使用Wi-Fi的约束 816 817 ```ts 818 import { BusinessError } from '@ohos.base'; 819 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 820 let localId: number = 100; 821 let constraint: string = 'constraint.wifi'; 822 try { 823 accountManager.setOsAccountConstraints(localId, [constraint], true, (err: BusinessError) => { 824 if (err) { 825 console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); 826 } else { 827 console.log('setOsAccountConstraints successfully'); 828 } 829 }); 830 } catch (err) { 831 console.log('setOsAccountConstraints exception: ' + JSON.stringify(err)); 832 } 833 ``` 834 835### setOsAccountConstraints 836 837setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean): Promise<void> 838 839为指定系统帐号设置/删除约束。使用Promise异步回调。 840 841**系统接口:** 此接口为系统接口。 842 843**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 844 845**系统能力:** SystemCapability.Account.OsAccount 846 847**参数:** 848 849| 参数名 | 类型 | 必填 | 说明 | 850| ----------- | ------------------- | ---- | -------------------------------------------- | 851| localId | number | 是 | 系统帐号ID。 | 852| constraints | Array<string> | 是 | 待设置/删除的[约束](#系统帐号约束列表)列表。 | 853| enable | boolean | 是 | 设置(true)/删除(false)。 | 854 855**返回值:** 856 857| 类型 | 说明 | 858| :------------------ | :----------------------------------- | 859| Promise<void> | Promise对象,无返回结果的Promise对象。 | 860 861**错误码:** 862 863| 错误码ID | 错误信息 | 864| -------- | ------------------- | 865| 12300001 | System service exception. | 866| 12300002 | Invalid localId or constraints. | 867| 12300003 | Account not found. | 868| 12300008 | Restricted Account. | 869 870**示例:** 删除ID为100的系统帐号的禁止使用Wi-Fi的约束 871 872 ```ts 873 import { BusinessError } from '@ohos.base'; 874 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 875 let localId: number = 100; 876 try { 877 accountManager.setOsAccountConstraints(localId, ['constraint.location.set'], false).then(() => { 878 console.log('setOsAccountConstraints succsuccessfully'); 879 }).catch((err: BusinessError) => { 880 console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); 881 }); 882 } catch (err) { 883 console.log('setOsAccountConstraints exception: ' + JSON.stringify(err)); 884 } 885 ``` 886 887### setOsAccountName 888 889setOsAccountName(localId: number, localName: string, callback: AsyncCallback<void>): void 890 891设置指定系统帐号的帐号名。使用callback异步回调。 892 893**系统接口:** 此接口为系统接口。 894 895**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 896 897**系统能力:** SystemCapability.Account.OsAccount 898 899**参数:** 900 901| 参数名 | 类型 | 必填 | 说明 | 902| :-------- | ------------------------- | ---- | ----------------------------------------------- | 903| localId | number | 是 | 系统帐号ID。 | 904| localName | string | 是 | 帐号名,最大长度为1024个字符。 | 905| callback | AsyncCallback<void> | 是 | 回调函数。如果设置成功,err为null,否则为错误对象。 | 906 907**错误码:** 908 909| 错误码ID | 错误信息 | 910| -------- | ------------------- | 911| 12300001 | System service exception. | 912| 12300002 | Invalid localId or localName. | 913| 12300003 | Account not found. | 914| 12300008 | Restricted Account. | 915 916**示例:** 将ID为100的系统帐号的帐号名设置成demoName 917 918 ```ts 919 import { BusinessError } from '@ohos.base'; 920 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 921 let localId: number = 100; 922 let name: string = 'demoName'; 923 try { 924 accountManager.setOsAccountName(localId, name, (err: BusinessError) => { 925 if (err) { 926 console.log('setOsAccountName failed, error: ' + JSON.stringify(err)); 927 } else { 928 console.log('setOsAccountName successfully'); 929 } 930 }); 931 } catch (err) { 932 console.log('setOsAccountName exception: ' + JSON.stringify(err)); 933 } 934 ``` 935 936### setOsAccountName 937 938setOsAccountName(localId: number, localName: string): Promise<void> 939 940设置指定系统帐号的帐号名。使用Promise异步调用。 941 942**系统接口:** 此接口为系统接口。 943 944**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 945 946**系统能力:** SystemCapability.Account.OsAccount 947 948**参数:** 949 950| 参数名 | 类型 | 必填 | 说明 | 951| --------- | ------ | ---- | --------------------------------- | 952| localId | number | 是 | 系统帐号ID。 | 953| localName | string | 是 | 帐号名,最大长度为1024。 | 954 955**返回值:** 956 957| 类型 | 说明 | 958| ------------------- | ------------------------------------ | 959| Promise<void> | Promise对象,无返回结果的Promise对象。 | 960 961**错误码:** 962 963| 错误码ID | 错误信息 | 964| -------- | ------------------- | 965| 12300001 | System service exception. | 966| 12300002 | Invalid localId or localName. | 967| 12300003 | Account not found. | 968| 12300008 | Restricted Account. | 969 970**示例:** 将ID为100的系统帐号的帐号名设置成demoName 971 972 ```ts 973 import { BusinessError } from '@ohos.base'; 974 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 975 let localId: number = 100; 976 let name: string = 'testName'; 977 try { 978 accountManager.setOsAccountName(localId, name).then(() => { 979 console.log('setOsAccountName successfully'); 980 }).catch((err: BusinessError) => { 981 console.log('setOsAccountName failed, error: ' + JSON.stringify(err)); 982 }); 983 } catch (err) { 984 console.log('setOsAccountName exception: ' + JSON.stringify(err)); 985 } 986 ``` 987 988### getOsAccountCount<sup>9+</sup> 989 990getOsAccountCount(callback: AsyncCallback<number>): void 991 992获取已创建的系统帐号数量。使用callback异步回调。 993 994**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 995 996**系统能力:** SystemCapability.Account.OsAccount 997 998**参数:** 999 1000| 参数名 | 类型 | 必填 | 说明 | 1001| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- | 1002| callback | AsyncCallback<number> | 是 | 回调函数。当获取成功时,err为null,data为已创建的系统帐号的数量;否则为错误对象。 | 1003 1004**错误码:** 1005 1006| 错误码ID | 错误信息 | 1007| -------- | ------------------- | 1008| 12300001 | System service exception. | 1009 1010**示例:** 1011 1012 ```ts 1013 import { BusinessError } from '@ohos.base'; 1014 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1015 try { 1016 accountManager.getOsAccountCount((err: BusinessError, count: number) => { 1017 if (err) { 1018 console.log('getOsAccountCount failed, error: ' + JSON.stringify(err)); 1019 } else { 1020 console.log('getOsAccountCount successfully, count: ' + count); 1021 } 1022 }); 1023 } catch (err) { 1024 console.log('getOsAccountCount exception: ' + JSON.stringify(err)); 1025 } 1026 ``` 1027 1028### getOsAccountCount<sup>9+</sup> 1029 1030getOsAccountCount(): Promise<number> 1031 1032获取已创建的系统帐号数量。使用Promise异步回调。 1033 1034**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1035 1036**系统能力:** SystemCapability.Account.OsAccount 1037 1038**返回值:** 1039 1040| 类型 | 说明 | 1041| --------------------- | -------------------------------------- | 1042| Promise<number> | Promise对象,返回已创建的系统帐号的数量。 | 1043 1044**错误码:** 1045 1046| 错误码ID | 错误信息 | 1047| -------- | ------------------- | 1048| 12300001 | System service exception. | 1049 1050**示例:** 1051 1052 ```ts 1053 import { BusinessError } from '@ohos.base'; 1054 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1055 try { 1056 accountManager.getOsAccountCount().then((count: number) => { 1057 console.log('getOsAccountCount successfully, count: ' + count); 1058 }).catch((err: BusinessError) => { 1059 console.log('getOsAccountCount failed, error: ' + JSON.stringify(err)); 1060 }); 1061 } catch(err) { 1062 console.log('getOsAccountCount exception: ' + JSON.stringify(err)); 1063 } 1064 ``` 1065 1066### getOsAccountLocalId<sup>9+</sup> 1067 1068getOsAccountLocalId(callback: AsyncCallback<number>): void 1069 1070获取当前进程所属的系统帐号ID,使用callback异步回调。 1071 1072**系统能力:** SystemCapability.Account.OsAccount 1073 1074**参数:** 1075 1076| 参数名 | 类型 | 必填 | 说明 | 1077| -------- | --------------------------- | ---- | ---------------------------------------------------------------------------- | 1078| callback | AsyncCallback<number> | 是 | 回调函数。当获取成功时,err为null,data为当前进程所属的系统帐号ID;否则为错误对象。 | 1079 1080**错误码:** 1081 1082| 错误码ID | 错误信息 | 1083| -------- | ------------------- | 1084| 12300001 | System service exception. | 1085 1086**示例:** 1087 1088 ```ts 1089 import { BusinessError } from '@ohos.base'; 1090 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1091 try { 1092 accountManager.getOsAccountLocalId((err: BusinessError, localId: number) => { 1093 if (err) { 1094 console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err)); 1095 } else { 1096 console.log('getOsAccountLocalId successfully, localId: ' + localId); 1097 } 1098 }); 1099 } catch (err) { 1100 console.log('getOsAccountLocalId exception: ' + JSON.stringify(err)); 1101 } 1102 ``` 1103 1104### getOsAccountLocalId<sup>9+</sup> 1105 1106getOsAccountLocalId(): Promise<number> 1107 1108获取当前进程所属的系统帐号ID,使用Promise异步回调。 1109 1110**系统能力:** SystemCapability.Account.OsAccount 1111 1112**返回值:** 1113 1114| 类型 | 说明 | 1115| --------------------- | ---------------------------------------- | 1116| Promise<number> | Promise对象,返回当前进程所属的系统帐号ID。 | 1117 1118**错误码:** 1119 1120| 错误码ID | 错误信息 | 1121| -------- | ------------------- | 1122| 12300001 | System service exception. | 1123 1124**示例:** 1125 1126 ```ts 1127 import { BusinessError } from '@ohos.base'; 1128 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1129 try { 1130 accountManager.getOsAccountLocalId().then((localId: number) => { 1131 console.log('getOsAccountLocalId successfully, localId: ' + localId); 1132 }).catch((err: BusinessError) => { 1133 console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err)); 1134 }); 1135 } catch (err) { 1136 console.log('getOsAccountLocalId exception: ' + JSON.stringify(err)); 1137 } 1138 ``` 1139 1140### getOsAccountLocalIdForUid<sup>9+</sup> 1141 1142getOsAccountLocalIdForUid(uid: number, callback: AsyncCallback<number>): void 1143 1144根据uid查询对应的系统帐号ID,使用callback异步回调。 1145 1146**系统能力:** SystemCapability.Account.OsAccount 1147 1148**参数:** 1149 1150| 参数名 | 类型 | 必填 | 说明 | 1151| -------- | --------------------------- | ---- | --------------------------------------------------------------------- | 1152| uid | number | 是 | 进程uid。 | 1153| callback | AsyncCallback<number> | 是 | 回调函数。如果查询成功,err为null,data为对应的系统帐号ID;否则为错误对象。 | 1154 1155**错误码:** 1156 1157| 错误码ID | 错误信息 | 1158| -------- | --------------- | 1159| 12300001 | System service exception. | 1160| 12300002 | Invalid uid. | 1161 1162**示例:** 查询值为12345678的uid所属的系统帐号的帐号ID 1163 1164 ```ts 1165 import { BusinessError } from '@ohos.base'; 1166 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1167 let uid: number = 12345678; 1168 try { 1169 accountManager.getOsAccountLocalIdForUid(uid, (err: BusinessError, localId: number) => { 1170 if (err) { 1171 console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err)); 1172 } 1173 console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId); 1174 }); 1175 } catch (err) { 1176 console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err)); 1177 } 1178 ``` 1179 1180### getOsAccountLocalIdForUid<sup>9+</sup> 1181 1182getOsAccountLocalIdForUid(uid: number): Promise<number> 1183 1184根据uid查询对应的系统帐号ID,使用Promise异步回调。 1185 1186**系统能力:** SystemCapability.Account.OsAccount 1187 1188**参数:** 1189 1190| 参数名 | 类型 | 必填 | 说明 | 1191| ------ | ------ | ---- | --------- | 1192| uid | number | 是 | 进程uid。 | 1193 1194**返回值:** 1195 1196| 类型 | 说明 | 1197| --------------------- | --------------------------------------- | 1198| Promise<number> | Promise对象,返回指定uid对应的系统帐号ID。 | 1199 1200**错误码:** 1201 1202| 错误码ID | 错误信息 | 1203| -------- | ------------- | 1204| 12300001 | System service exception. | 1205| 12300002 | Invalid uid. | 1206 1207**示例:** 查询值为12345678的uid所属的系统帐号ID 1208 1209 ```ts 1210 import { BusinessError } from '@ohos.base'; 1211 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1212 let uid: number = 12345678; 1213 try { 1214 accountManager.getOsAccountLocalIdForUid(uid).then((localId: number) => { 1215 console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId); 1216 }).catch((err: BusinessError) => { 1217 console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err)); 1218 }); 1219 } catch (err) { 1220 console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err)); 1221 } 1222 ``` 1223 1224### getOsAccountLocalIdForUidSync<sup>10+</sup> 1225 1226getOsAccountLocalIdForUidSync(uid: number): number 1227 1228根据uid查询对应的系统帐号ID。使用同步方式返回结果。 1229 1230**系统能力:** SystemCapability.Account.OsAccount 1231 1232**参数:** 1233 1234| 参数名 | 类型 | 必填 | 说明 | 1235| ------ | ------ | ---- | --------- | 1236| uid | number | 是 | 进程uid。 | 1237 1238**返回值:** 1239 1240| 类型 | 说明 | 1241| --------------------- | --------------------------------------- | 1242| number | 返回指定uid对应的系统帐号ID。 | 1243 1244**错误码:** 1245 1246| 错误码ID | 错误信息 | 1247| -------- | ------------- | 1248| 12300002 | Invalid uid. | 1249 1250**示例:** 查询值为12345678的uid所属的系统帐号ID 1251 1252 ```ts 1253 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1254 let uid: number = 12345678; 1255 try { 1256 let localId : number = accountManager.getOsAccountLocalIdForUidSync(uid); 1257 console.log('getOsAccountLocalIdForUidSync successfully, localId: ' + localId); 1258 } catch (err) { 1259 console.log('getOsAccountLocalIdForUidSync exception: ' + JSON.stringify(err)); 1260 } 1261 ``` 1262 1263### getOsAccountLocalIdForDomain<sup>9+</sup> 1264 1265getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void 1266 1267根据域帐号信息,获取与其关联的系统帐号ID。使用callback异步回调。 1268 1269**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1270 1271**系统能力:** SystemCapability.Account.OsAccount 1272 1273**参数:** 1274 1275| 参数名 | 类型 | 必填 | 说明 | 1276| ---------- | --------------------------------------- | ---- | -------------------------------------------------------------------------- | 1277| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 域帐号信息。 | 1278| callback | AsyncCallback<number> | 是 | 回调函数。如果查询成功,err为null,data为域帐号关联的系统帐号ID;否则为错误对象。 | 1279 1280**错误码:** 1281 1282| 错误码ID | 错误信息 | 1283| -------- | ------------- | 1284| 12300001 | System service exception. | 1285| 12300002 | Invalid domainInfo. | 1286 1287**示例:** 1288 1289 ```ts 1290 import { BusinessError } from '@ohos.base'; 1291 let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'}; 1292 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1293 try { 1294 accountManager.getOsAccountLocalIdForDomain(domainInfo, (err: BusinessError, localId: number) => { 1295 if (err) { 1296 console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err)); 1297 } else { 1298 console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId); 1299 } 1300 }); 1301 } catch (err) { 1302 console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err)); 1303 } 1304 ``` 1305 1306### getOsAccountLocalIdForDomain<sup>9+</sup> 1307 1308getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo): Promise<number> 1309 1310根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用Promise异步回调。 1311 1312**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1313 1314**系统能力:** SystemCapability.Account.OsAccount 1315 1316**参数:** 1317 1318| 参数名 | 类型 | 必填 | 说明 | 1319| ---------- | --------------------------------------- | ---- | ------------ | 1320| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 域帐号信息。 | 1321 1322**返回值:** 1323 1324| 类型 | 说明 | 1325| :-------------------- | :------------------------------------- | 1326| Promise<number> | Promise对象,返回域帐号关联的系统帐号ID。 | 1327 1328**错误码:** 1329 1330| 错误码ID | 错误信息 | 1331| -------- | ------------- | 1332| 12300001 | System service exception. | 1333| 12300002 | Invalid domainInfo. | 1334 1335**示例:** 1336 1337 ```ts 1338 import { BusinessError } from '@ohos.base'; 1339 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1340 let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'}; 1341 try { 1342 accountManager.getOsAccountLocalIdForDomain(domainInfo).then((localId: number) => { 1343 console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId); 1344 }).catch((err: BusinessError) => { 1345 console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err)); 1346 }); 1347 } catch (err) { 1348 console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err)); 1349 } 1350 ``` 1351 1352### queryMaxOsAccountNumber 1353 1354queryMaxOsAccountNumber(callback: AsyncCallback<number>): void 1355 1356查询允许创建的系统帐号的最大数量。使用callback异步回调。 1357 1358**系统接口:** 此接口为系统接口。 1359 1360**系统能力:** SystemCapability.Account.OsAccount 1361 1362**参数:** 1363 1364| 参数名 | 类型 | 必填 | 说明 | 1365| -------- | --------------------------- | ---- | -------------------------------------------------------------------------------- | 1366| callback | AsyncCallback<number> | 是 | 回调函数,如果查询成功,err为null,data为允许创建的系统帐号的最大数量;否则为错误对象。 | 1367 1368**错误码:** 1369 1370| 错误码ID | 错误信息 | 1371| -------- | ------------- | 1372| 12300001 | System service exception. | 1373 1374**示例:** 1375 1376 ```ts 1377 import { BusinessError } from '@ohos.base'; 1378 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1379 try { 1380 accountManager.queryMaxOsAccountNumber((err: BusinessError, maxCnt: number) => { 1381 if (err) { 1382 console.log('queryMaxOsAccountNumber failed, error:' + JSON.stringify(err)); 1383 } else { 1384 console.log('queryMaxOsAccountNumber successfully, maxCnt:' + maxCnt); 1385 } 1386 }); 1387 } catch (err) { 1388 console.log('queryMaxOsAccountNumber exception: ' + JSON.stringify(err)); 1389 } 1390 ``` 1391 1392### queryMaxOsAccountNumber 1393 1394queryMaxOsAccountNumber(): Promise<number> 1395 1396查询允许创建的系统帐号的最大数量。使用Promise异步回调。 1397 1398**系统接口:** 此接口为系统接口。 1399 1400**系统能力:** SystemCapability.Account.OsAccount 1401 1402**返回值:** 1403 1404| 类型 | 说明 | 1405| --------------------- | ------------------------------------------- | 1406| Promise<number> | Promise对象,返回允许创建的系统帐号的最大数量。 | 1407 1408**错误码:** 1409 1410| 错误码ID | 错误信息 | 1411| -------- | ------------- | 1412| 12300001 | System service exception. | 1413 1414**示例:** 1415 1416 ```ts 1417 import { BusinessError } from '@ohos.base'; 1418 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1419 try { 1420 accountManager.queryMaxOsAccountNumber().then((maxCnt: number) => { 1421 console.log('queryMaxOsAccountNumber successfully, maxCnt: ' + maxCnt); 1422 }).catch((err: BusinessError) => { 1423 console.log('queryMaxOsAccountNumber failed, error: ' + JSON.stringify(err)); 1424 }); 1425 } catch (err) { 1426 console.log('queryMaxOsAccountNumber exception: ' + JSON.stringify(err)); 1427 } 1428 ``` 1429 1430### getOsAccountConstraints<sup>9+</sup> 1431 1432getOsAccountConstraints(localId: number, callback: AsyncCallback<Array<string>>): void 1433 1434获取指定系统帐号的全部约束。使用callback异步回调。 1435 1436**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1437 1438**系统能力:** SystemCapability.Account.OsAccount 1439 1440**参数:** 1441 1442| 参数名 | 类型 | 必填 | 说明 | 1443| -------- | ---------------------------------------- | ---- | -------------------------------------------------------------------------------------------- | 1444| localId | number | 是 | 系统帐号ID。 | 1445| callback | AsyncCallback<Array<string>> | 是 | 回调函数,如果获取成功,err为null,data为该系统帐号的全部[约束](#系统帐号约束列表);否则为错误对象。 | 1446 1447**错误码:** 1448 1449| 错误码ID | 错误信息 | 1450| -------- | ------------------- | 1451| 12300001 | System service exception. | 1452| 12300002 | Invalid localId. | 1453| 12300003 | Account not found. | 1454 1455**示例:** 获取ID为100的系统帐号的全部约束 1456 1457 ```ts 1458 import { BusinessError } from '@ohos.base'; 1459 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1460 let localId: number = 100; 1461 try { 1462 accountManager.getOsAccountConstraints(localId, (err: BusinessError, constraints: string[]) => { 1463 if (err) { 1464 console.log('getOsAccountConstraints failed, err: ' + JSON.stringify(err)); 1465 } else { 1466 console.log('getOsAccountConstraints successfully, constraints: ' + JSON.stringify(constraints)); 1467 } 1468 }); 1469 } catch (err) { 1470 console.log('getOsAccountConstraints exception: ' + JSON.stringify(err)); 1471 } 1472 ``` 1473 1474### getOsAccountConstraints<sup>9+</sup> 1475 1476getOsAccountConstraints(localId: number): Promise<Array<string>> 1477 1478获取指定系统帐号的全部约束。使用Promise异步回调。 1479 1480**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1481 1482**系统能力:** SystemCapability.Account.OsAccount 1483 1484**参数:** 1485 1486| 参数名 | 类型 | 必填 | 说明 | 1487| ------- | ------ | ---- | ------------ | 1488| localId | number | 是 | 系统帐号ID。 | 1489 1490**返回值:** 1491 1492| 类型 | 说明 | 1493| ---------------------------------- | ---------------------------------------------------------- | 1494| Promise<Array<string>> | Promise对象,返回指定系统帐号的全部[约束](#系统帐号约束列表)。 | 1495 1496**错误码:** 1497 1498| 错误码ID | 错误信息 | 1499| -------- | ------------------- | 1500| 12300001 | System service exception. | 1501| 12300002 | Invalid localId. | 1502| 12300003 | Account not found. | 1503 1504**示例:** 获取ID为100的系统帐号的全部约束 1505 1506 ```ts 1507 import { BusinessError } from '@ohos.base'; 1508 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1509 let localId: number = 100; 1510 try { 1511 accountManager.getOsAccountConstraints(localId).then((constraints: string[]) => { 1512 console.log('getOsAccountConstraints, constraints: ' + constraints); 1513 }).catch((err: BusinessError) => { 1514 console.log('getOsAccountConstraints err: ' + JSON.stringify(err)); 1515 }); 1516 } catch (e) { 1517 console.log('getOsAccountConstraints exception: ' + JSON.stringify(e)); 1518 } 1519 ``` 1520 1521### queryAllCreatedOsAccounts 1522 1523queryAllCreatedOsAccounts(callback: AsyncCallback<Array<OsAccountInfo>>): void 1524 1525查询已创建的所有系统帐号的信息列表。使用callback异步回调。 1526 1527**系统接口:** 此接口为系统接口。 1528 1529**系统能力:** SystemCapability.Account.OsAccount 1530 1531**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1532 1533**参数:** 1534 1535| 参数名 | 类型 | 必填 | 说明 | 1536| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- | 1537| callback | AsyncCallback<Array<[OsAccountInfo](#osaccountinfo)>> | 是 | 回调函数。如果查询成功,err为null,data为已创建的所有系统帐号的信息列表;否则为错误对象。 | 1538 1539**错误码:** 1540 1541| 错误码ID | 错误信息 | 1542| -------- | ------------- | 1543| 12300001 | System service exception. | 1544 1545**示例:** 1546 1547 ```ts 1548 import { BusinessError } from '@ohos.base'; 1549 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1550 try { 1551 accountManager.queryAllCreatedOsAccounts((err: BusinessError, accountArr: account_osAccount.OsAccountInfo[])=>{ 1552 console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err)); 1553 console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr)); 1554 }); 1555 } catch (e) { 1556 console.log('queryAllCreatedOsAccounts exception: ' + JSON.stringify(e)); 1557 } 1558 ``` 1559 1560### queryAllCreatedOsAccounts 1561 1562queryAllCreatedOsAccounts(): Promise<Array<OsAccountInfo>> 1563 1564查询已创建的所有系统帐号的信息列表。使用Promise异步回调。 1565 1566**系统接口:** 此接口为系统接口。 1567 1568**系统能力:** SystemCapability.Account.OsAccount 1569 1570**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1571 1572**返回值:** 1573 1574| 类型 | 说明 | 1575| ----------------------------------------------------------- | --------------------------------------------- | 1576| Promise<Array<[OsAccountInfo](#osaccountinfo)>> | Promise对象,返回已创建的所有系统帐号的信息列表。 | 1577 1578**错误码:** 1579 1580| 错误码ID | 错误信息 | 1581| -------- | ------------- | 1582| 12300001 | System service exception. | 1583 1584**示例:** 1585 1586 ```ts 1587 import { BusinessError } from '@ohos.base'; 1588 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1589 try { 1590 accountManager.queryAllCreatedOsAccounts().then((accountArr: account_osAccount.OsAccountInfo[]) => { 1591 console.log('queryAllCreatedOsAccounts, accountArr: ' + JSON.stringify(accountArr)); 1592 }).catch((err: BusinessError) => { 1593 console.log('queryAllCreatedOsAccounts err: ' + JSON.stringify(err)); 1594 }); 1595 } catch (e) { 1596 console.log('queryAllCreatedOsAccounts exception: ' + JSON.stringify(e)); 1597 } 1598 ``` 1599 1600### getActivatedOsAccountLocalIds<sup>9+</sup> 1601 1602getActivatedOsAccountLocalIds(callback: AsyncCallback<Array<number>>): void 1603 1604查询当前处于激活状态的系统帐号的ID列表。使用callback异步回调。 1605 1606**系统能力:** SystemCapability.Account.OsAccount 1607 1608**参数:** 1609 1610| 参数名 | 类型 | 必填 | 说明 | 1611| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ | 1612| callback | AsyncCallback<Array<number>> | 是 | 回调函数。如果查询成功,err为null,data为当前处于激活状态的系统帐号的ID列表;否则为错误对象。 | 1613 1614**错误码:** 1615 1616| 错误码ID | 错误信息 | 1617| -------- | ------------- | 1618| 12300001 | System service exception. | 1619 1620**示例:** 1621 1622 ```ts 1623 import { BusinessError } from '@ohos.base'; 1624 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1625 try { 1626 accountManager.getActivatedOsAccountLocalIds((err: BusinessError, idArray: number[])=>{ 1627 console.log('getActivatedOsAccountLocalIds err:' + JSON.stringify(err)); 1628 console.log('getActivatedOsAccountLocalIds idArray length:' + idArray.length); 1629 for(let i=0;i<idArray.length;i++) { 1630 console.info('activated os account id: ' + idArray[i]); 1631 } 1632 }); 1633 } catch (e) { 1634 console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e)); 1635 } 1636 ``` 1637 1638### getActivatedOsAccountLocalIds<sup>9+</sup> 1639 1640getActivatedOsAccountLocalIds(): Promise<Array<number>> 1641 1642查询当前处于激活状态的系统帐号的ID列表。使用Promise异步回调。 1643 1644**系统能力:** SystemCapability.Account.OsAccount 1645 1646**返回值:** 1647 1648| 类型 | 说明 | 1649| :--------------------------------- | :------------------------------------------------ | 1650| Promise<Array<number>> | Promise对象,返回当前处于激活状态的系统帐号的ID列表。 | 1651 1652**错误码:** 1653 1654| 错误码ID | 错误信息 | 1655| -------- | ------------- | 1656| 12300001 | System service exception. | 1657 1658**示例:** 1659 1660 ```ts 1661 import { BusinessError } from '@ohos.base'; 1662 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1663 try { 1664 accountManager.getActivatedOsAccountLocalIds().then((idArray: number[]) => { 1665 console.log('getActivatedOsAccountLocalIds, idArray: ' + idArray); 1666 }).catch((err: BusinessError) => { 1667 console.log('getActivatedOsAccountLocalIds err: ' + JSON.stringify(err)); 1668 }); 1669 } catch (e) { 1670 console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e)); 1671 } 1672 ``` 1673 1674### createOsAccount 1675 1676createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback<OsAccountInfo>): void 1677 1678创建一个系统帐号。使用callback异步回调。 1679 1680**系统接口:** 此接口为系统接口。 1681 1682**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1683 1684**系统能力:** SystemCapability.Account.OsAccount 1685 1686**参数:** 1687 1688| 参数名 | 类型 | 必填 | 说明 | 1689| :-------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------- | 1690| localName | string | 是 | 创建的系统帐号的名称。 | 1691| type | [OsAccountType](#osaccounttype) | 是 | 创建的系统帐号的类型。 | 1692| callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | 是 | 回调函数。如果创建成功,err为null,data为新创建的系统帐号的信息;否则为错误对象。 | 1693 1694**错误码:** 1695 1696| 错误码ID | 错误信息 | 1697| -------- | ------------------------- | 1698| 12300001 | System service exception. | 1699| 12300002 | Invalid localName or type. | 1700| 12300005 | Multi-user not supported. | 1701| 12300006 | Unsupported account type. | 1702| 12300007 | The number of accounts reaches the upper limit. | 1703 1704**示例:** 1705 1706 ```ts 1707 import { BusinessError } from '@ohos.base'; 1708 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1709 try { 1710 accountManager.createOsAccount('testName', account_osAccount.OsAccountType.NORMAL, 1711 (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{ 1712 console.log('createOsAccount err:' + JSON.stringify(err)); 1713 console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo)); 1714 }); 1715 } catch (e) { 1716 console.log('createOsAccount exception: ' + JSON.stringify(e)); 1717 } 1718 ``` 1719 1720### createOsAccount 1721 1722createOsAccount(localName: string, type: OsAccountType): Promise<OsAccountInfo> 1723 1724创建一个系统帐号。使用Promise异步回调。 1725 1726**系统接口:** 此接口为系统接口。 1727 1728**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1729 1730**系统能力:** SystemCapability.Account.OsAccount 1731 1732**参数:** 1733 1734| 参数名 | 类型 | 必填 | 说明 | 1735| --------- | ------------------------------- | ---- | ---------------------- | 1736| localName | string | 是 | 创建的系统帐号的名称。 | 1737| type | [OsAccountType](#osaccounttype) | 是 | 创建的系统帐号的类型。 | 1738 1739**返回值:** 1740 1741| 类型 | 说明 | 1742| ---------------------------------------------- | ------------------------------------- | 1743| Promise<[OsAccountInfo](#osaccountinfo)> | Promise对象,返回新创建的系统帐号的信息。 | 1744 1745**错误码:** 1746 1747| 错误码ID | 错误信息 | 1748| -------- | ------------------------- | 1749| 12300001 | System service exception. | 1750| 12300002 | Invalid localName or type. | 1751| 12300005 | Multi-user not supported. | 1752| 12300006 | Unsupported account type. | 1753| 12300007 | The number of accounts reaches the upper limit. | 1754 1755**示例:** 1756 1757 ```ts 1758 import { BusinessError } from '@ohos.base'; 1759 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1760 try { 1761 accountManager.createOsAccount('testAccountName', account_osAccount.OsAccountType.NORMAL).then( 1762 (accountInfo: account_osAccount.OsAccountInfo) => { 1763 console.log('createOsAccount, accountInfo: ' + JSON.stringify(accountInfo)); 1764 }).catch((err: BusinessError) => { 1765 console.log('createOsAccount err: ' + JSON.stringify(err)); 1766 }); 1767 } catch (e) { 1768 console.log('createOsAccount exception: ' + JSON.stringify(e)); 1769 } 1770 ``` 1771 1772### createOsAccountForDomain<sup>8+</sup> 1773 1774createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, callback: AsyncCallback<OsAccountInfo>): void 1775 1776根据域帐号信息,创建一个系统帐号并将其与域帐号关联。使用callback异步回调。 1777 1778**系统接口:** 此接口为系统接口。 1779 1780**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1781 1782**系统能力:** SystemCapability.Account.OsAccount 1783 1784**参数:** 1785 1786| 参数名 | 类型 | 必填 | 说明 | 1787| ---------- | ---------------------------------------------------- | ---- | -------------------------------------------------------------------------- | 1788| type | [OsAccountType](#osaccounttype) | 是 | 创建的系统帐号的类型。 | 1789| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 域帐号信息。 | 1790| callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | 是 | 回调函数。如果创建成功,err为null,data为新创建的系统帐号的信息;否则为错误对象。 | 1791 1792**错误码:** 1793 1794| 错误码ID | 错误信息 | 1795| -------- | ------------------- | 1796| 12300001 | System service exception. | 1797| 12300002 | Invalid type or domainInfo. | 1798| 12300005 | Multi-user not supported. | 1799| 12300006 | Unsupported account type. | 1800| 12300007 | The number of accounts reaches the upper limit. | 1801 1802**示例:** 1803 1804 ```ts 1805 import { BusinessError } from '@ohos.base'; 1806 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1807 let domainInfo: account_osAccount.DomainAccountInfo = 1808 {domain: 'testDomain', accountName: 'testAccountName'}; 1809 try { 1810 accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo, 1811 (err: BusinessError, osAccountInfo: account_osAccount.OsAccountInfo)=>{ 1812 console.log('createOsAccountForDomain err:' + JSON.stringify(err)); 1813 console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo)); 1814 }); 1815 } catch (e) { 1816 console.log('createOsAccountForDomain exception: ' + JSON.stringify(e)); 1817 } 1818 ``` 1819 1820### createOsAccountForDomain<sup>8+</sup> 1821 1822createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo): Promise<OsAccountInfo> 1823 1824根据传入的域帐号信息,创建与其关联的系统帐号。使用Promise异步回调。 1825 1826**系统接口:** 此接口为系统接口。 1827 1828**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 1829 1830**系统能力:** SystemCapability.Account.OsAccount 1831 1832**参数:** 1833 1834| 参数名 | 类型 | 必填 | 说明 | 1835| ---------- | ---------------------------------------- | ---- | -------------------- | 1836| type | [OsAccountType](#osaccounttype) | 是 | 创建的系统帐号的类型。 | 1837| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 域帐号信息。 | 1838 1839**返回值:** 1840 1841| 类型 | 说明 | 1842| ---------------------------------------------- | -------------------------------------- | 1843| Promise<[OsAccountInfo](#osaccountinfo)> | Promise对象,返回新创建的系统帐号的信息。 | 1844 1845**错误码:** 1846 1847| 错误码ID | 错误信息 | 1848| -------- | ------------------- | 1849| 12300001 | System service exception. | 1850| 12300002 | Invalid type or domainInfo. | 1851| 12300005 | Multi-user not supported. | 1852| 12300006 | Unsupported account type. | 1853| 12300007 | The number of accounts reaches the upper limit. | 1854 1855**示例:** 1856 1857 ```ts 1858 import { BusinessError } from '@ohos.base'; 1859 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1860 let domainInfo: account_osAccount.DomainAccountInfo = 1861 {domain: 'testDomain', accountName: 'testAccountName'}; 1862 try { 1863 accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo).then( 1864 (accountInfo: account_osAccount.OsAccountInfo) => { 1865 console.log('createOsAccountForDomain, account info: ' + JSON.stringify(accountInfo)); 1866 }).catch((err: BusinessError) => { 1867 console.log('createOsAccountForDomain err: ' + JSON.stringify(err)); 1868 }); 1869 } catch (e) { 1870 console.log('createOsAccountForDomain exception: ' + JSON.stringify(e)); 1871 } 1872 ``` 1873 1874### getCurrentOsAccount<sup>9+</sup> 1875 1876getCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void 1877 1878查询当前进程所属的系统帐号的信息。使用callback异步回调。 1879 1880**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS<sup>10+</sup> 1881 1882**系统能力:** SystemCapability.Account.OsAccount 1883 1884**参数:** 1885 1886| 参数名 | 类型 | 必填 | 说明 | 1887| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | 1888| callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | 是 | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号信息;否则为错误对象。 | 1889 1890**错误码:** 1891 1892| 错误码ID | 错误信息 | 1893| -------- | ------------------- | 1894| 12300001 | System service exception. | 1895 1896**示例:** 1897 1898 ```ts 1899 import { BusinessError } from '@ohos.base'; 1900 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1901 try { 1902 accountManager.getCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{ 1903 console.log('getCurrentOsAccount err:' + JSON.stringify(err)); 1904 console.log('getCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo)); 1905 }); 1906 } catch (e) { 1907 console.log('getCurrentOsAccount exception: ' + JSON.stringify(e)); 1908 } 1909 ``` 1910 1911### getCurrentOsAccount<sup>9+</sup> 1912 1913getCurrentOsAccount(): Promise<OsAccountInfo> 1914 1915查询当前进程所属的系统帐号的信息。使用Promise异步回调。 1916 1917**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS<sup>10+</sup> 1918 1919**系统能力:** SystemCapability.Account.OsAccount 1920 1921**返回值:** 1922 1923| 类型 | 说明 | 1924| ---------------------------------------------- | ----------------------------------------- | 1925| Promise<[OsAccountInfo](#osaccountinfo)> | Promise对象,返回当前进程所属的系统帐号信息。 | 1926 1927**错误码:** 1928 1929| 错误码ID | 错误信息 | 1930| -------- | ------------------- | 1931| 12300001 | System service exception. | 1932 1933**示例:** 1934 1935 ```ts 1936 import { BusinessError } from '@ohos.base'; 1937 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1938 try { 1939 accountManager.getCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => { 1940 console.log('getCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo)); 1941 }).catch((err: BusinessError) => { 1942 console.log('getCurrentOsAccount err: ' + JSON.stringify(err)); 1943 }); 1944 } catch (e) { 1945 console.log('getCurrentOsAccount exception: ' + JSON.stringify(e)); 1946 } 1947 ``` 1948 1949### queryOsAccountById 1950 1951queryOsAccountById(localId: number, callback: AsyncCallback<OsAccountInfo>): void 1952 1953查询指定系统帐号的信息。使用callback异步回调。 1954 1955**系统接口:** 此接口为系统接口。 1956 1957**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 1958 1959**系统能力:** SystemCapability.Account.OsAccount 1960 1961**参数:** 1962 1963| 参数名 | 类型 | 必填 | 说明 | 1964| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------------------ | 1965| localId | number | 是 | 要查询的系统帐号的ID。 | 1966| callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | 是 | 回调函数。如果查询成功,err为null,data为查到的系统帐号的信息;否则为错误对象。 | 1967 1968**错误码:** 1969 1970| 错误码ID | 错误信息 | 1971| -------- | ------------------- | 1972| 12300001 | System service exception. | 1973| 12300002 | Invalid localId. | 1974| 12300003 | Account not found. | 1975 1976**示例:** 查询ID为100的系统帐号信息 1977 1978 ```ts 1979 import { BusinessError } from '@ohos.base'; 1980 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1981 let localId: number = 100; 1982 try { 1983 accountManager.queryOsAccountById(localId, (err: BusinessError, accountInfo: account_osAccount.OsAccountInfo)=>{ 1984 console.log('queryOsAccountById err:' + JSON.stringify(err)); 1985 console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo)); 1986 }); 1987 } catch (e) { 1988 console.log('queryOsAccountById exception: ' + JSON.stringify(e)); 1989 } 1990 ``` 1991 1992### queryOsAccountById 1993 1994queryOsAccountById(localId: number): Promise<OsAccountInfo> 1995 1996查询指定系统帐号的信息。使用Promise异步回调。 1997 1998**系统接口:** 此接口为系统接口。 1999 2000**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 2001 2002**系统能力:** SystemCapability.Account.OsAccount 2003 2004**参数:** 2005 2006| 参数名 | 类型 | 必填 | 说明 | 2007| ------- | ------ | ---- | -------------------- | 2008| localId | number | 是 | 要查询的系统帐号的ID | 2009 2010**返回值:** 2011 2012| 类型 | 说明 | 2013| ---------------------------------------------- | ------------------------------------ | 2014| Promise<[OsAccountInfo](#osaccountinfo)> | Promise对象,返回查到的系统帐号的信息。 | 2015 2016**错误码:** 2017 2018| 错误码ID | 错误信息 | 2019| -------- | ------------------- | 2020| 12300001 | System service exception. | 2021| 12300002 | Invalid localId. | 2022| 12300003 | Account not found. | 2023 2024**示例:** 查询ID为100的系统帐号信息 2025 2026 ```ts 2027 import { BusinessError } from '@ohos.base'; 2028 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2029 let localId: number = 100; 2030 try { 2031 accountManager.queryOsAccountById(localId).then((accountInfo: account_osAccount.OsAccountInfo) => { 2032 console.log('queryOsAccountById, accountInfo: ' + JSON.stringify(accountInfo)); 2033 }).catch((err: BusinessError) => { 2034 console.log('queryOsAccountById err: ' + JSON.stringify(err)); 2035 }); 2036 } catch (e) { 2037 console.log('queryOsAccountById exception: ' + JSON.stringify(e)); 2038 } 2039 ``` 2040 2041### getOsAccountType<sup>9+</sup> 2042 2043getOsAccountType(callback: AsyncCallback<OsAccountType>): void 2044 2045查询当前进程所属的系统帐号的帐号类型。使用callback异步回调。 2046 2047**系统能力:** SystemCapability.Account.OsAccount 2048 2049**参数:** 2050 2051| 参数名 | 类型 | 必填 | 说明 | 2052| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- | 2053| callback | AsyncCallback<[OsAccountType](#osaccounttype)> | 是 | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号的帐号类型;否则为错误对象。 | 2054 2055**错误码:** 2056 2057| 错误码ID | 错误信息 | 2058| -------- | ------------------- | 2059| 12300001 | System service exception. | 2060 2061**示例:** 2062 2063 ```ts 2064 import { BusinessError } from '@ohos.base'; 2065 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2066 try { 2067 accountManager.getOsAccountType((err: BusinessError, accountType: account_osAccount.OsAccountType) => { 2068 console.log('getOsAccountType err: ' + JSON.stringify(err)); 2069 console.log('getOsAccountType accountType: ' + accountType); 2070 }); 2071 } catch (e) { 2072 console.log('getOsAccountType exception: ' + JSON.stringify(e)); 2073 } 2074 ``` 2075 2076### getOsAccountType<sup>9+</sup> 2077 2078getOsAccountType(): Promise<OsAccountType> 2079 2080查询当前进程所属的系统帐号的帐号类型。使用Promise异步回调。 2081 2082**系统能力:** SystemCapability.Account.OsAccount 2083 2084**返回值:** 2085 2086| 类型 | 说明 | 2087| ---------------------------------------------- | ----------------------------------------------- | 2088| Promise<[OsAccountType](#osaccounttype)> | Promise对象,返回当前进程所属的系统帐号的帐号类型。 | 2089 2090**错误码:** 2091 2092| 错误码ID | 错误信息 | 2093| -------- | ------------------- | 2094| 12300001 | System service exception. | 2095 2096**示例:** 2097 2098 ```ts 2099 import { BusinessError } from '@ohos.base'; 2100 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2101 try { 2102 accountManager.getOsAccountType().then((accountType: account_osAccount.OsAccountType) => { 2103 console.log('getOsAccountType, accountType: ' + accountType); 2104 }).catch((err: BusinessError) => { 2105 console.log('getOsAccountType err: ' + JSON.stringify(err)); 2106 }); 2107 } catch (e) { 2108 console.log('getOsAccountType exception: ' + JSON.stringify(e)); 2109 } 2110 ``` 2111 2112### queryDistributedVirtualDeviceId<sup>9+</sup> 2113 2114queryDistributedVirtualDeviceId(callback: AsyncCallback<string>): void 2115 2116获取分布式虚拟设备ID。使用callback异步回调。 2117 2118**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS 2119 2120**系统能力:** SystemCapability.Account.OsAccount 2121 2122**参数:** 2123 2124| 参数名 | 类型 | 必填 | 说明 | 2125| -------- | --------------------------- | ---- | --------------------------------------------------------------------- | 2126| callback | AsyncCallback<string> | 是 | 回调函数。如果获取成功,err为null,data为分布式虚拟设备ID;否则为错误对象。 | 2127 2128**错误码:** 2129 2130| 错误码ID | 错误信息 | 2131| -------- | ------------------- | 2132| 12300001 | System service exception. | 2133 2134**示例:** 2135 2136 ```ts 2137 import { BusinessError } from '@ohos.base'; 2138 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2139 try { 2140 accountManager.queryDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => { 2141 console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err)); 2142 console.log('queryDistributedVirtualDeviceId virtualID: ' + virtualID); 2143 }); 2144 } catch (e) { 2145 console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e)); 2146 } 2147 ``` 2148 2149### queryDistributedVirtualDeviceId<sup>9+</sup> 2150 2151queryDistributedVirtualDeviceId(): Promise<string> 2152 2153获取分布式虚拟设备ID。使用Promise异步回调。 2154 2155**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS 2156 2157**系统能力:** SystemCapability.Account.OsAccount 2158 2159**返回值:** 2160 2161| 类型 | 说明 | 2162| --------------------- | --------------------------------- | 2163| Promise<string> | Promise对象,返回分布式虚拟设备ID。 | 2164 2165**错误码:** 2166 2167| 错误码ID | 错误信息 | 2168| -------- | ------------------- | 2169| 12300001 | System service exception. | 2170 2171**示例:** 2172 2173 ```ts 2174 import { BusinessError } from '@ohos.base'; 2175 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2176 try { 2177 accountManager.queryDistributedVirtualDeviceId().then((virtualID: string) => { 2178 console.log('queryDistributedVirtualDeviceId, virtualID: ' + virtualID); 2179 }).catch((err: BusinessError) => { 2180 console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err)); 2181 }); 2182 } catch (e) { 2183 console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e)); 2184 } 2185 ``` 2186 2187### getOsAccountProfilePhoto 2188 2189getOsAccountProfilePhoto(localId: number, callback: AsyncCallback<string>): void 2190 2191获取指定系统帐号的头像信息。使用callback异步回调。 2192 2193**系统接口:** 此接口为系统接口。 2194 2195**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 2196 2197**系统能力:** SystemCapability.Account.OsAccount 2198 2199**参数:** 2200 2201| 参数名 | 类型 | 必填 | 说明 | 2202| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- | 2203| localId | number | 是 | 系统帐号ID。 | 2204| callback | AsyncCallback<string> | 是 | 回调函数。如果获取成功,err为null,data为指定系统帐号的头像信息;否则为错误对象。 | 2205 2206**错误码:** 2207 2208| 错误码ID | 错误信息 | 2209| -------- | ------------------- | 2210| 12300001 | System service exception. | 2211| 12300002 | Invalid localId. | 2212| 12300003 | Account not found. | 2213 2214**示例:** 获取ID为100的系统帐号的头像 2215 2216 ```ts 2217 import { BusinessError } from '@ohos.base'; 2218 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2219 let localId: number = 100; 2220 try { 2221 accountManager.getOsAccountProfilePhoto(localId, (err: BusinessError, photo: string)=>{ 2222 console.log('getOsAccountProfilePhoto err:' + JSON.stringify(err)); 2223 console.log('get photo:' + photo + ' by localId: ' + localId); 2224 }); 2225 } catch (e) { 2226 console.log('getOsAccountProfilePhoto exception: ' + JSON.stringify(e)); 2227 } 2228 ``` 2229 2230### getOsAccountProfilePhoto 2231 2232getOsAccountProfilePhoto(localId: number): Promise<string> 2233 2234获取指定系统帐号的头像信息。使用Promise异步回调。 2235 2236**系统接口:** 此接口为系统接口。 2237 2238**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 2239 2240**系统能力:** SystemCapability.Account.OsAccount 2241 2242**参数:** 2243 2244| 参数名 | 类型 | 必填 | 说明 | 2245| ------- | ------ | ---- | ------------ | 2246| localId | number | 是 | 系统帐号ID。 | 2247 2248**返回值:** 2249 2250| 类型 | 说明 | 2251| --------------------- | -------------------------------------- | 2252| Promise<string> | Promise对象,返回指定系统帐号的头像信息。 | 2253 2254**错误码:** 2255 2256| 错误码ID | 错误信息 | 2257| -------- | ------------------- | 2258| 12300001 | System service exception. | 2259| 12300002 | Invalid localId. | 2260| 12300003 | Account not found. | 2261 2262**示例:** 获取ID为100的系统帐号的头像 2263 2264 ```ts 2265 import { BusinessError } from '@ohos.base'; 2266 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2267 let localId: number = 100; 2268 try { 2269 accountManager.getOsAccountProfilePhoto(localId).then((photo: string) => { 2270 console.log('getOsAccountProfilePhoto: ' + photo); 2271 }).catch((err: BusinessError) => { 2272 console.log('getOsAccountProfilePhoto err: ' + JSON.stringify(err)); 2273 }); 2274 } catch (e) { 2275 console.log('getOsAccountProfilePhoto exception: ' + JSON.stringify(e)); 2276 } 2277 ``` 2278 2279### setOsAccountProfilePhoto 2280 2281setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback<void>): void 2282 2283为指定系统帐号设置头像信息。使用callback异步回调。 2284 2285**系统接口:** 此接口为系统接口。 2286 2287**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 2288 2289**系统能力:** SystemCapability.Account.OsAccount 2290 2291**参数:** 2292 2293| 参数名 | 类型 | 必填 | 说明 | 2294| -------- | ------------------------- | ---- | ------------ | 2295| localId | number | 是 | 系统帐号ID。 | 2296| photo | string | 是 | 头像信息。 | 2297| callback | AsyncCallback<void> | 是 | 回调函数。如果设置成功,err为null,否则为错误对象。 | 2298 2299**错误码:** 2300 2301| 错误码ID | 错误信息 | 2302| -------- | ------------------- | 2303| 12300001 | System service exception. | 2304| 12300002 | Invalid localId or photo. | 2305| 12300003 | Account not found. | 2306| 12300008 | Restricted Account. | 2307 2308**示例:** 给ID为100的系统帐号设置头像 2309 2310 ```ts 2311 import { BusinessError } from '@ohos.base'; 2312 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2313 let localId: number = 100; 2314 let photo: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ 2315 'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+ 2316 'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+ 2317 '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==' 2318 try { 2319 accountManager.setOsAccountProfilePhoto(localId, photo, (err: BusinessError)=>{ 2320 console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err)); 2321 }); 2322 } catch (e) { 2323 console.log('setOsAccountProfilePhoto exception: ' + JSON.stringify(e)); 2324 } 2325 ``` 2326 2327### setOsAccountProfilePhoto 2328 2329setOsAccountProfilePhoto(localId: number, photo: string): Promise<void> 2330 2331为指定系统帐号设置头像信息。使用Promise异步回调。 2332 2333**系统接口:** 此接口为系统接口。 2334 2335**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 2336 2337**系统能力:** SystemCapability.Account.OsAccount 2338 2339**参数:** 2340 2341| 参数名 | 类型 | 必填 | 说明 | 2342| ------- | ------ | ---- | ------------ | 2343| localId | number | 是 | 系统帐号ID。 | 2344| photo | string | 是 | 头像信息。 | 2345 2346**返回值:** 2347 2348| 类型 | 说明 | 2349| ------------------- | ------------------------------------ | 2350| Promise<void> | Promise对象,无返回结果的Promise对象。 | 2351 2352**错误码:** 2353 2354| 错误码ID | 错误信息 | 2355| -------- | ------------------- | 2356| 12300001 | System service exception. | 2357| 12300002 | Invalid localId or photo. | 2358| 12300003 | Account not found. | 2359| 12300008 | Restricted Account. | 2360 2361**示例:** 给ID为100的系统帐号设置头像 2362 2363 ```ts 2364 import { BusinessError } from '@ohos.base'; 2365 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2366 let localId: number = 100; 2367 let photo: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ 2368 'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+ 2369 'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+ 2370 '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==' 2371 try { 2372 accountManager.setOsAccountProfilePhoto(localId, photo).then(() => { 2373 console.log('setOsAccountProfilePhoto success'); 2374 }).catch((err: BusinessError) => { 2375 console.log('setOsAccountProfilePhoto err: ' + JSON.stringify(err)); 2376 }); 2377 } catch (e) { 2378 console.log('setOsAccountProfilePhoto exception: ' + JSON.stringify(e)); 2379 } 2380 ``` 2381 2382### getOsAccountLocalIdForSerialNumber<sup>9+</sup> 2383 2384getOsAccountLocalIdForSerialNumber(serialNumber: number, callback: AsyncCallback<number>): void 2385 2386通过SN码查询与其关联的系统帐号的帐号ID。使用callback异步回调。 2387 2388**系统能力:** SystemCapability.Account.OsAccount 2389 2390**参数:** 2391 2392| 参数名 | 类型 | 必填 | 说明 | 2393| ------------ | --------------------------- | ---- | ---------------------------------------------------------------------------- | 2394| serialNumber | number | 是 | 帐号SN码。 | 2395| callback | AsyncCallback<number> | 是 | 回调函数。如果成功,err为null,data为与SN码关联的系统帐号的帐号ID;否则为错误对象。 | 2396 2397**错误码:** 2398 2399| 错误码ID | 错误信息 | 2400| -------- | ------------------- | 2401| 12300001 | System service exception. | 2402| 12300002 | Invalid serialNumber. | 2403| 12300003 | The account indicated by serialNumber dose not exist. | 2404 2405**示例:** 查询与SN码12345关联的系统帐号的ID 2406 2407 ```ts 2408 import { BusinessError } from '@ohos.base'; 2409 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2410 let serialNumber: number = 12345; 2411 try { 2412 accountManager.getOsAccountLocalIdForSerialNumber(serialNumber, (err: BusinessError, localId: number)=>{ 2413 console.log('ger localId err:' + JSON.stringify(err)); 2414 console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber); 2415 }); 2416 } catch (e) { 2417 console.log('ger localId exception: ' + JSON.stringify(e)); 2418 } 2419 ``` 2420 2421### getOsAccountLocalIdForSerialNumber<sup>9+</sup> 2422 2423getOsAccountLocalIdForSerialNumber(serialNumber: number): Promise<number> 2424 2425通过SN码查询与其关联的系统帐号的帐号ID。使用Promise异步回调。 2426 2427**系统能力:** SystemCapability.Account.OsAccount 2428 2429**参数:** 2430 2431| 参数名 | 类型 | 必填 | 说明 | 2432| ------------ | ------ | ---- | ---------- | 2433| serialNumber | number | 是 | 帐号SN码。 | 2434 2435**返回值:** 2436 2437| 类型 | 说明 | 2438| --------------------- | -------------------------------------------- | 2439| Promise<number> | Promise对象,返回与SN码关联的系统帐号的帐号ID。 | 2440 2441**错误码:** 2442 2443| 错误码ID | 错误信息 | 2444| -------- | ------------------- | 2445| 12300001 | System service exception. | 2446| 12300002 | Invalid serialNumber. | 2447| 12300003 | The account indicated by serialNumber dose not exist. | 2448 2449**示例:** 查询与SN码12345关联的系统帐号的ID 2450 2451 ```ts 2452 import { BusinessError } from '@ohos.base'; 2453 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2454 let serialNumber: number = 12345; 2455 try { 2456 accountManager.getOsAccountLocalIdForSerialNumber(serialNumber).then((localId: number) => { 2457 console.log('getOsAccountLocalIdForSerialNumber localId: ' + localId); 2458 }).catch((err: BusinessError) => { 2459 console.log('getOsAccountLocalIdForSerialNumber err: ' + JSON.stringify(err)); 2460 }); 2461 } catch (e) { 2462 console.log('getOsAccountLocalIdForSerialNumber exception: ' + JSON.stringify(e)); 2463 } 2464 ``` 2465 2466### getSerialNumberForOsAccountLocalId<sup>9+</sup> 2467 2468getSerialNumberForOsAccountLocalId(localId: number, callback: AsyncCallback<number>): void 2469 2470通过系统帐号ID获取与该系统帐号关联的SN码。使用callback异步回调。 2471 2472**系统能力:** SystemCapability.Account.OsAccount 2473 2474**参数:** 2475 2476| 参数名 | 类型 | 必填 | 说明 | 2477| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- | 2478| localId | number | 是 | 系统帐号ID。 | 2479| callback | AsyncCallback<number> | 是 | 回调函数。如果获取成功,err为null,data为与该系统帐号关联的SN码;否则为错误对象。 | 2480 2481**错误码:** 2482 2483| 错误码ID | 错误信息 | 2484| -------- | ------------------- | 2485| 12300001 | System service exception. | 2486| 12300002 | Invalid localId. | 2487| 12300003 | Account not found. | 2488 2489**示例:** 获取ID为100的系统帐号关联的SN码 2490 2491 ```ts 2492 import { BusinessError } from '@ohos.base'; 2493 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2494 let localId: number = 100; 2495 try { 2496 accountManager.getSerialNumberForOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{ 2497 console.log('ger serialNumber err:' + JSON.stringify(err)); 2498 console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId); 2499 }); 2500 } catch (e) { 2501 console.log('ger serialNumber exception: ' + JSON.stringify(e)); 2502 } 2503 ``` 2504 2505### getSerialNumberForOsAccountLocalId<sup>9+</sup> 2506 2507getSerialNumberForOsAccountLocalId(localId: number): Promise<number> 2508 2509通过系统帐号ID获取与该系统帐号关联的SN码。使用Promise异步回调。 2510 2511**系统能力:** SystemCapability.Account.OsAccount 2512 2513**参数:** 2514 2515| 参数名 | 类型 | 必填 | 说明 | 2516| ------- | ------ | ---- | ----------- | 2517| localId | number | 是 | 系统帐号ID。 | 2518 2519**返回值:** 2520 2521| 类型 | 说明 | 2522| :-------------------- | :------------------------------------- | 2523| Promise<number> | Promise对象,返回与该系统帐号关联的SN码。 | 2524 2525**错误码:** 2526 2527| 错误码ID | 错误信息 | 2528| -------- | ------------------- | 2529| 12300001 | System service exception. | 2530| 12300002 | Invalid localId. | 2531| 12300003 | Account not found. | 2532 2533**示例:** 获取ID为100的系统帐号关联的SN码 2534 2535 ```ts 2536 import { BusinessError } from '@ohos.base'; 2537 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2538 let localId: number = 100; 2539 try { 2540 accountManager.getSerialNumberForOsAccountLocalId(localId).then((serialNumber: number) => { 2541 console.log('getSerialNumberForOsAccountLocalId serialNumber: ' + serialNumber); 2542 }).catch((err: BusinessError) => { 2543 console.log('getSerialNumberForOsAccountLocalId err: ' + JSON.stringify(err)); 2544 }); 2545 } catch (e) { 2546 console.log('getSerialNumberForOsAccountLocalId exception: ' + JSON.stringify(e)); 2547 } 2548 ``` 2549 2550### on 2551 2552on(type: 'activate' | 'activating', name: string, callback: Callback<number>): void 2553 2554订阅系统帐号的激活完成与激活中的事件。使用callback异步回调。 2555 2556**系统接口:** 此接口为系统接口。 2557 2558**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 2559 2560**系统能力:** SystemCapability.Account.OsAccount 2561 2562**参数:** 2563 2564| 参数名 | 类型 | 必填 | 说明 | 2565| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 2566| type | 'activate' \| 'activating' | 是 | 订阅类型,activate表示订阅的是帐号已激活完成的事件,activating表示订阅的是帐号正在激活的事件。 | 2567| name | string | 是 | 订阅名称,可自定义,要求非空且长度不超过1024字节。 | 2568| callback | Callback<number> | 是 | 订阅系统帐号激活完成与激活中的事件回调,表示激活完成后或正在激活中的系统帐号ID。 | 2569 2570**错误码:** 2571 2572| 错误码ID | 错误信息 | 2573| -------- | ------------- | 2574| 12300001 | System service exception. | 2575| 12300002 | Invalid type or name. | 2576 2577**示例:** 2578 2579 ```ts 2580 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2581 function onCallback(receiveLocalId: number){ 2582 console.log('receive localId:' + receiveLocalId); 2583 } 2584 try { 2585 accountManager.on('activating', 'osAccountOnOffNameA', onCallback); 2586 } catch (e) { 2587 console.log('receive localId exception: ' + JSON.stringify(e)); 2588 } 2589 ``` 2590 2591### off 2592 2593off(type: 'activate' | 'activating', name: string, callback?: Callback<number>): void 2594 2595取消订阅系统帐号的激活完成与激活中的事件。使用callback异步回调。 2596 2597**系统接口:** 此接口为系统接口。 2598 2599**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 2600 2601**系统能力:** SystemCapability.Account.OsAccount 2602 2603**参数:** 2604 2605| 参数名 | 类型 | 必填 | 说明 | 2606| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 2607| type | 'activate' \| 'activating' | 是 | 取消订阅类型,activate表示取消订阅帐号已激活完成的事件,activating取消订阅帐号正在激活的事件。 | 2608| name | string | 是 | 订阅名称,可自定义,要求非空且长度不超过1024字节,需要与订阅接口传入的值保持一致。 | 2609| callback | Callback<number> | 否 | 取消订阅系统帐号激活完成与激活中的事件回调,默认为空,表示取消该类型事件的所有回调。 | 2610 2611**错误码:** 2612 2613| 错误码ID | 错误信息 | 2614| -------- | ------------- | 2615| 12300001 | System service exception. | 2616| 12300002 | Invalid type or name. | 2617 2618**示例:** 2619 2620 ```ts 2621 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2622 function offCallback(){ 2623 console.log('off enter') 2624 } 2625 try { 2626 accountManager.off('activating', 'osAccountOnOffNameA', offCallback); 2627 } catch (e) { 2628 console.log('off exception: ' + JSON.stringify(e)); 2629 } 2630 ``` 2631 2632### getBundleIdForUid<sup>9+</sup> 2633 2634getBundleIdForUid(uid: number, callback: AsyncCallback<number>): void 2635 2636通过uid查询对应的bundleId,使用callback异步回调。 2637 2638**系统接口:** 此接口为系统接口。 2639 2640**系统能力:** SystemCapability.Account.OsAccount 2641 2642**参数:** 2643 2644| 参数名 | 类型 | 必填 | 说明 | 2645| -------- | --------------------------- | ---- | ------------------------------------------------------------------------ | 2646| uid | number | 是 | 进程uid。 | 2647| callback | AsyncCallback<number> | 是 | 回调函数。如果查询成功,err为null,data为与uid对应的bundleId;否则为错误对象。 | 2648 2649**错误码:** 2650 2651| 错误码ID | 错误信息 | 2652| -------- | ------------- | 2653| 12300001 | System service exception. | 2654| 12300002 | Invalid uid. | 2655 2656**示例:** 2657 2658 ```ts 2659 import { BusinessError } from '@ohos.base'; 2660 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2661 let testUid: number = 1000000; 2662 try { 2663 accountManager.getBundleIdForUid(testUid, (err: BusinessError, bundleId: number) => { 2664 console.info('getBundleIdForUid errInfo:' + JSON.stringify(err)); 2665 console.info('getBundleIdForUid bundleId:' + JSON.stringify(bundleId)); 2666 }); 2667 } catch (e) { 2668 console.info('getBundleIdForUid exception: ' + JSON.stringify(e)); 2669 } 2670 ``` 2671 2672### getBundleIdForUid<sup>9+</sup> 2673 2674getBundleIdForUid(uid: number): Promise<number> 2675 2676通过uid查询对应的bundleId,使用Promise异步回调。 2677 2678**系统接口:** 此接口为系统接口。 2679 2680**系统能力:** SystemCapability.Account.OsAccount 2681 2682**参数:** 2683 2684| 参数名 | 类型 | 必填 | 说明 | 2685| ------- | ------ | ---- | ------------ | 2686| uid | number | 是 | 进程uid。 | 2687 2688**返回值:** 2689 2690| 类型 | 说明 | 2691| --------------------- | ------------------------------------ | 2692| Promise<number> | Promise对象,返回与uid对应的bundleId。 | 2693 2694**错误码:** 2695 2696| 错误码ID | 错误信息 | 2697| -------- | ------------- | 2698| 12300001 | System service exception. | 2699| 12300002 | Invalid uid. | 2700 2701**示例:** 2702 2703 ```ts 2704 import { BusinessError } from '@ohos.base'; 2705 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2706 let testUid: number = 1000000; 2707 try { 2708 accountManager.getBundleIdForUid(testUid).then((result: number) => { 2709 console.info('getBundleIdForUid bundleId:' + JSON.stringify(result)); 2710 }).catch((err: BusinessError) => { 2711 console.info('getBundleIdForUid errInfo:' + JSON.stringify(err)); 2712 }); 2713 } catch (e) { 2714 console.info('getBundleIdForUid exception: ' + JSON.stringify(e)); 2715 } 2716 ``` 2717 2718### getBundleIdForUidSync<sup>10+</sup> 2719 2720getBundleIdForUidSync(uid: number): number 2721 2722通过uid查询对应的bundleId。使用同步方式返回结果。 2723 2724**系统接口:** 此接口为系统接口。 2725 2726**系统能力:** SystemCapability.Account.OsAccount 2727 2728**参数:** 2729 2730| 参数名 | 类型 | 必填 | 说明 | 2731| ------- | ------ | ---- | ------------ | 2732| uid | number | 是 | 进程uid。 | 2733 2734**返回值:** 2735 2736| 类型 | 说明 | 2737| ------ | ------------------------ | 2738| number | 表示与进程uid对应的bundleId。 | 2739 2740**错误码:** 2741 2742| 错误码ID | 错误信息 | 2743| -------- | ------------- | 2744| 12300002 | Invalid uid. | 2745 2746**示例:** 2747 2748 ```ts 2749 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2750 let testUid: number = 1000000; 2751 try { 2752 let bundleId : number = accountManager.getBundleIdForUidSync(testUid); 2753 console.info('getBundleIdForUidSync bundleId:' + bundleId); 2754 } catch (e) { 2755 console.info('getBundleIdForUidSync exception: ' + JSON.stringify(e)); 2756 } 2757 ``` 2758 2759### isMainOsAccount<sup>9+</sup> 2760 2761isMainOsAccount(callback: AsyncCallback<boolean>): void; 2762 2763查询当前进程是否处于主用户,使用callback异步回调。 2764 2765**系统接口:** 此接口为系统接口。 2766 2767**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 2768 2769**系统能力:** SystemCapability.Account.OsAccount 2770 2771**参数:** 2772 2773| 参数名 | 类型 | 必填 | 说明 | 2774| -------- | ---------------------------- | ---- | ----------------------------------------------------------------- | 2775| callback | AsyncCallback<boolean> | 是 | 回调函数,返回true表示当前帐号为主帐号,返回false表示当前帐号非主帐号。 | 2776 2777**错误码:** 2778 2779| 错误码ID | 错误信息 | 2780| -------- | ------------- | 2781| 12300001 | System service exception. | 2782 2783**示例:** 2784 2785 ```ts 2786 import { BusinessError } from '@ohos.base'; 2787 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2788 try { 2789 accountManager.isMainOsAccount((err: BusinessError,result: boolean)=>{ 2790 console.info('isMainOsAccount errInfo:' + JSON.stringify(err)); 2791 console.info('isMainOsAccount result:' + JSON.stringify(result)); 2792 }); 2793 } catch (e) { 2794 console.info('isMainOsAccount exception: ' + JSON.stringify(e)); 2795 } 2796 ``` 2797### isMainOsAccount<sup>9+</sup> 2798 2799isMainOsAccount(): Promise<boolean>; 2800 2801查询当前进程是否处于主用户,使用Promise异步回调。 2802 2803**系统接口:** 此接口为系统接口。 2804 2805**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 2806 2807**系统能力:** SystemCapability.Account.OsAccount 2808 2809**返回值:** 2810 2811| 类型 | 说明 | 2812| ---------------------- | --------------------------------------------------------------------- | 2813| Promise<boolean> | Promise对象,返回true表示当前帐号为主帐号,返回false表示当前帐号非主帐号。 | 2814 2815**错误码:** 2816 2817| 错误码ID | 错误信息 | 2818| -------- | ------------- | 2819| 12300001 | System service exception. | 2820 2821**示例:** 2822 2823 ```ts 2824 import { BusinessError } from '@ohos.base'; 2825 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2826 try { 2827 accountManager.isMainOsAccount().then((result: boolean) => { 2828 console.info('isMainOsAccount result:' + JSON.stringify(result)); 2829 }).catch((err: BusinessError) => { 2830 console.info('isMainOsAccount errInfo:' + JSON.stringify(err)); 2831 }); 2832 } catch (e) { 2833 console.info('isMainOsAccount exception: ' + JSON.stringify(e)); 2834 } 2835 ``` 2836### getOsAccountConstraintSourceTypes<sup>9+</sup> 2837 2838getOsAccountConstraintSourceTypes(localId: number, constraint: string, callback: AsyncCallback<Array<ConstraintSourceTypeInfo>>): void; 2839 2840查询指定系统帐号的指定约束来源信息,使用callback异步回调。 2841 2842**系统接口:** 此接口为系统接口。 2843 2844**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 2845 2846**系统能力:** SystemCapability.Account.OsAccount 2847 2848**参数:** 2849 2850| 参数名 | 类型 | 必填 | 说明 | 2851| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 2852| localId | number | 是 | 要查询的系统帐号ID | 2853| constraint | string | 是 | 要查询的[约束](#系统帐号约束列表)名称 | 2854| callback | AsyncCallback<Array<[ConstraintSourceTypeInfo](#constraintsourcetypeinfo9)>> | 是 | 回调函数。如果成功,err为null,data为指定系统帐号的指定[约束](#系统帐号约束列表)来源信息;否则为错误对象。 | 2855 2856**错误码:** 2857 2858| 错误码ID | 错误信息 | 2859| -------- | ------------- | 2860| 12300001 | System service exception. | 2861| 12300002 | Invalid name or constraint. | 2862| 12300003 | Account not found. | 2863 2864**示例:** 2865 2866 ```ts 2867 import { BusinessError } from '@ohos.base'; 2868 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2869 try { 2870 accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi', 2871 (err: BusinessError,sourceTypeInfos: account_osAccount.ConstraintSourceTypeInfo[])=>{ 2872 console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err)); 2873 console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(sourceTypeInfos)); 2874 }); 2875 } catch (e) { 2876 console.info('getOsAccountConstraintSourceTypes exception: ' + JSON.stringify(e)); 2877 } 2878 ``` 2879 2880### getOsAccountConstraintSourceTypes<sup>9+</sup> 2881 2882getOsAccountConstraintSourceTypes(localId: number, constraint: string): Promise<Array<ConstraintSourceTypeInfo>>; 2883 2884查询指定系统帐号的指定约束来源信息,使用Promise异步回调。 2885 2886**系统接口:** 此接口为系统接口。 2887 2888**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 2889 2890**系统能力:** SystemCapability.Account.OsAccount 2891 2892**参数:** 2893 2894| 参数名 | 类型 | 必填 | 说明 | 2895| ------- | ------ | ---- | ------------ | 2896| localId | number | 是 | 要查询的系统帐号ID | 2897| constraint | string | 是 | 要查询的[约束](#系统帐号约束列表)名称 | 2898 2899**返回值:** 2900 2901| 类型 | 说明 | 2902| --------------------- | ------------------------------------------------------------ | 2903| Promise<Array<[ConstraintSourceTypeInfo](#constraintsourcetypeinfo9)>> | Promise对象,返回指定系统帐号的指定[约束](#系统帐号约束列表)来源信息。 | 2904 2905**错误码:** 2906 2907| 错误码ID | 错误信息 | 2908| -------- | ------------- | 2909| 12300001 | System service exception. | 2910| 12300002 | Invalid name or constraint. | 2911| 12300003 | Account not found. | 2912 2913**示例:** 2914 2915 ```ts 2916 import { BusinessError } from '@ohos.base'; 2917 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2918 try { 2919 accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi').then( 2920 (result: account_osAccount.ConstraintSourceTypeInfo[]) => { 2921 console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(result)); 2922 }).catch((err: BusinessError) => { 2923 console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err)); 2924 }); 2925 } catch (e) { 2926 console.info('getOsAccountConstraintSourceTypes exception: ' + JSON.stringify(e)); 2927 } 2928 ``` 2929 2930### isMultiOsAccountEnable<sup>(deprecated)</sup> 2931 2932isMultiOsAccountEnable(callback: AsyncCallback<boolean>): void 2933 2934判断是否支持多系统帐号。使用callback异步回调。 2935 2936> **说明:** 2937> 2938> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkMultiOsAccountEnabled](#checkmultiosaccountenabled9)。 2939 2940**系统能力:** SystemCapability.Account.OsAccount 2941 2942**参数:** 2943 2944| 参数名 | 类型 | 必填 | 说明 | 2945| -------- | ---------------------------- | ---- | ------------------------------------------------------ | 2946| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示支持多系统帐号;返回false表示不支持。 | 2947 2948**示例:** 2949 2950 ```ts 2951 import { BusinessError } from '@ohos.base'; 2952 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2953 accountManager.isMultiOsAccountEnable((err: BusinessError, isEnabled: boolean) => { 2954 if (err) { 2955 console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err)); 2956 } else { 2957 console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled); 2958 } 2959 }); 2960 ``` 2961 2962### isMultiOsAccountEnable<sup>(deprecated)</sup> 2963 2964isMultiOsAccountEnable(): Promise<boolean> 2965 2966判断是否支持多系统帐号。使用Promise异步回调。 2967 2968> **说明:** 2969> 2970> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkMultiOsAccountEnabled](#checkmultiosaccountenabled9-1)。 2971 2972**系统能力:** SystemCapability.Account.OsAccount 2973 2974**返回值:** 2975 2976| 类型 | 说明 | 2977| :--------------------- | :--------------------------------------------------------- | 2978| Promise<boolean> | Promise对象。返回true表示支持多系统帐号;返回false表示不支持。 | 2979 2980**示例:** 2981 2982 ```ts 2983 import { BusinessError } from '@ohos.base'; 2984 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2985 accountManager.isMultiOsAccountEnable().then((isEnabled: boolean) => { 2986 console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled); 2987 }).catch((err: BusinessError) => { 2988 console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err)); 2989 }); 2990 ``` 2991 2992 2993### isOsAccountActived<sup>(deprecated)</sup> 2994 2995isOsAccountActived(localId: number, callback: AsyncCallback<boolean>): void 2996 2997判断指定系统帐号是否处于激活状态。使用callback异步回调。 2998 2999> **说明:** 3000> 3001> 从 API version 7开始支持从API version 9开始废弃, 建议使用[checkOsAccountActivated](#checkosaccountactivated9)。 3002 3003**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 3004 3005**系统能力:** SystemCapability.Account.OsAccount 3006 3007**参数:** 3008 3009| 参数名 | 类型 | 必填 | 说明 | 3010| -------- | ---------------------------- | ---- | ------------------------------------------------------ | 3011| localId | number | 是 | 系统帐号ID。 | 3012| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示帐号已激活;返回false表示帐号未激活。 | 3013 3014**示例:** 判断ID为100的系统帐号是否处于激活状态 3015 3016 ```ts 3017 import { BusinessError } from '@ohos.base'; 3018 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3019 let localId: number = 100; 3020 accountManager.isOsAccountActived(localId, (err: BusinessError, isActived: boolean) => { 3021 if (err) { 3022 console.log('isOsAccountActived failed, err:' + JSON.stringify(err)); 3023 } else { 3024 console.log('isOsAccountActived successfully, isActived:' + isActived); 3025 } 3026 }); 3027 ``` 3028 3029### isOsAccountActived<sup>(deprecated)</sup> 3030 3031isOsAccountActived(localId: number): Promise<boolean> 3032 3033判断指定系统帐号是否处于激活状态。使用Promise异步回调。 3034 3035> **说明:** 3036> 3037> 从 API version 7开始支持从API version 9开始废弃, 建议使用[checkOsAccountActivated](#checkosaccountactivated9-1)。 3038 3039**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 3040 3041**系统能力:** SystemCapability.Account.OsAccount 3042 3043**参数:** 3044 3045| 参数名 | 类型 | 必填 | 说明 | 3046| ------- | ------ | ---- | --------------------------------- | 3047| localId | number | 是 | 系统帐号ID。 | 3048 3049**返回值:** 3050 3051| 类型 | 说明 | 3052| --------------------- | ----------------------------------------------------------- | 3053| Promise<boolean> | Promise对象。返回true表示帐号已激活;返回false表示帐号未激活。 | 3054 3055**示例:** 判断ID为100的系统帐号是否处于激活状态 3056 3057 ```ts 3058 import { BusinessError } from '@ohos.base'; 3059 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3060 let localId: number = 100; 3061 accountManager.isOsAccountActived(localId).then((isActived: boolean) => { 3062 console.log('isOsAccountActived successfully, isActived: ' + isActived); 3063 }).catch((err: BusinessError) => { 3064 console.log('isOsAccountActived failed, error: ' + JSON.stringify(err)); 3065 }); 3066 ``` 3067 3068### isOsAccountConstraintEnable<sup>(deprecated)</sup> 3069 3070isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback<boolean>): void 3071 3072判断指定系统帐号是否具有指定约束。使用callback异步回调。 3073 3074> **说明:** 3075> 3076> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountConstraintEnabled](#checkosaccountconstraintenabled9)。 3077 3078**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 3079 3080**系统能力:** SystemCapability.Account.OsAccount 3081 3082**参数:** 3083 3084| 参数名 | 类型 | 必填 | 说明 | 3085| ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- | 3086| localId | number | 是 | 系统帐号ID。 | 3087| constraint | string | 是 | 指定的[约束](#系统帐号约束列表)名称。 | 3088| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 | 3089 3090**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束 3091 3092 ```ts 3093 import { BusinessError } from '@ohos.base'; 3094 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3095 let localId: number = 100; 3096 let constraint: string = 'constraint.wifi'; 3097 accountManager.isOsAccountConstraintEnable(localId, constraint, (err: BusinessError, isEnabled: boolean) => { 3098 if (err) { 3099 console.log('isOsAccountConstraintEnable failed, error: ' + JSON.stringify(err)); 3100 } else { 3101 console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled); 3102 } 3103 }); 3104 ``` 3105 3106### isOsAccountConstraintEnable<sup>(deprecated)</sup> 3107 3108isOsAccountConstraintEnable(localId: number, constraint: string): Promise<boolean> 3109 3110判断指定系统帐号是否具有指定约束。使用Promise异步回调。 3111 3112> **说明:** 3113> 3114> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountConstraintEnabled](#checkosaccountconstraintenabled9-1)。 3115 3116**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 3117 3118**系统能力:** SystemCapability.Account.OsAccount 3119 3120**参数:** 3121 3122| 参数名 | 类型 | 必填 | 说明 | 3123| ---------- | ------ | ---- | ---------------------------------- | 3124| localId | number | 是 | 系统帐号ID。 | 3125| constraint | string | 是 | 指定的[约束](#系统帐号约束列表)名称。 | 3126 3127**返回值:** 3128 3129| 类型 | 说明 | 3130| ---------------------- | --------------------------------------------------------------------- | 3131| Promise<boolean> | Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。 | 3132 3133**示例:** 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束 3134 3135 ```ts 3136 import { BusinessError } from '@ohos.base'; 3137 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3138 let localId: number = 100; 3139 let constraint: string = 'constraint.wifi'; 3140 accountManager.isOsAccountConstraintEnable(localId, constraint).then((isEnabled: boolean) => { 3141 console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled); 3142 }).catch((err: BusinessError) => { 3143 console.log('isOsAccountConstraintEnable err: ' + JSON.stringify(err)); 3144 }); 3145 ``` 3146 3147### isTestOsAccount<sup>(deprecated)</sup> 3148 3149isTestOsAccount(callback: AsyncCallback<boolean>): void 3150 3151检查当前系统帐号是否为测试帐号。使用callback异步回调。 3152 3153> **说明:** 3154> 3155> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountTestable](#checkosaccounttestable9)。 3156 3157**系统能力:** SystemCapability.Account.OsAccount 3158 3159**参数:** 3160 3161| 参数名 | 类型 | 必填 | 说明 | 3162| -------- | ---------------------------- | ---- | --------------------------------------------------------------------- | 3163| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 | 3164 3165**示例:** 3166 3167 ```ts 3168 import { BusinessError } from '@ohos.base'; 3169 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3170 accountManager.isTestOsAccount((err: BusinessError, isTestable: boolean) => { 3171 if (err) { 3172 console.log('isTestOsAccount failed, error: ' + JSON.stringify(err)); 3173 } else { 3174 console.log('isTestOsAccount successfully, isTestable: ' + isTestable); 3175 } 3176 }); 3177 ``` 3178 3179### isTestOsAccount<sup>(deprecated)</sup> 3180 3181isTestOsAccount(): Promise<boolean> 3182 3183检查当前系统帐号是否为测试帐号。使用Promise异步回调。 3184 3185> **说明:** 3186> 3187> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountTestable](#checkosaccounttestable9-1)。 3188 3189**系统能力:** SystemCapability.Account.OsAccount 3190 3191**返回值:** 3192 3193| 类型 | 说明 | 3194| ---------------------- | ------------------------------------------------------------------------ | 3195| Promise<boolean> | Promise对象。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。 | 3196 3197**示例:** 3198 3199 ```ts 3200 import { BusinessError } from '@ohos.base'; 3201 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3202 accountManager.isTestOsAccount().then((isTestable: boolean) => { 3203 console.log('isTestOsAccount successfully, isTestable: ' + isTestable); 3204 }).catch((err: BusinessError) => { 3205 console.log('isTestOsAccount failed, error: ' + JSON.stringify(err)); 3206 }); 3207 ``` 3208 3209### isOsAccountVerified<sup>(deprecated)</sup> 3210 3211isOsAccountVerified(callback: AsyncCallback<boolean>): void 3212 3213检查当前系统帐号是否已验证。使用callback异步回调。 3214 3215> **说明:** 3216> 3217> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountVerified](#checkosaccountverified9)。 3218 3219**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 3220 3221**系统能力:** SystemCapability.Account.OsAccount 3222 3223**参数:** 3224 3225| 参数名 | 类型 | 必填 | 说明 | 3226| -------- | ---------------------------- | ---- | ------------------------------------------------------------- | 3227| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示指定帐号已验证;返回false表示指定帐号未验证。 | 3228 3229**示例:** 3230 3231 ```ts 3232 import { BusinessError } from '@ohos.base'; 3233 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3234 accountManager.isOsAccountVerified((err: BusinessError, isVerified: boolean) => { 3235 if (err) { 3236 console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err)); 3237 } else { 3238 console.log('isOsAccountVerified successfully, isVerified: ' + isVerified); 3239 } 3240 }); 3241 ``` 3242 3243### isOsAccountVerified<sup>(deprecated)</sup> 3244 3245isOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void 3246 3247检查指定系统帐号是否已验证。使用callback异步回调。 3248 3249> **说明:** 3250> 3251> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountVerified](#checkosaccountverified9-1)。 3252 3253**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 3254 3255**系统能力:** SystemCapability.Account.OsAccount 3256 3257**参数:** 3258 3259| 参数名 | 类型 | 必填 | 说明 | 3260| -------- | ---------------------------- | ---- | ------------------------------------------------------------- | 3261| localId | number | 是 | 系统帐号ID。 | 3262| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示指定帐号已验证;返回false表示指定帐号未验证。 | 3263 3264**示例:** 3265 3266 ```ts 3267 import { BusinessError } from '@ohos.base'; 3268 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3269 let localId: number = 100; 3270 accountManager.isOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => { 3271 if (err) { 3272 console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err)); 3273 } else { 3274 console.log('isOsAccountVerified successfully, isVerified: ' + isVerified); 3275 } 3276 }); 3277 ``` 3278 3279### isOsAccountVerified<sup>(deprecated)</sup> 3280 3281isOsAccountVerified(localId?: number): Promise<boolean> 3282 3283检查指定系统帐号是否已验证。使用Promise异步回调。 3284 3285> **说明:** 3286> 3287> 从 API version 7开始支持,从API version 9开始废弃。建议使用[checkOsAccountVerified](#checkosaccountverified9-2)。 3288 3289**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 3290 3291**系统能力:** SystemCapability.Account.OsAccount 3292 3293**参数:** 3294 3295| 参数名 | 类型 | 必填 | 说明 | 3296| ------- | ------ | ---- | ---------------------------------------------------------------- | 3297| localId | number | 否 | 系统帐号ID。不填则检查当前系统帐号是否已验证。 | 3298 3299**返回值:** 3300 3301| 类型 | 说明 | 3302| ---------------------- | ----------------------------------------------------------------- | 3303| Promise<boolean> | Promise对象。返回true表示指定帐号已验证;返回false表示指定帐号未验证。 | 3304 3305**示例:** 3306 3307 ```ts 3308 import { BusinessError } from '@ohos.base'; 3309 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3310 accountManager.isOsAccountVerified().then((isVerified: boolean) => { 3311 console.log('isOsAccountVerified successfully, isVerified: ' + isVerified); 3312 }).catch((err: BusinessError) => { 3313 console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err)); 3314 }); 3315 ``` 3316 3317### getCreatedOsAccountsCount<sup>(deprecated)</sup> 3318 3319getCreatedOsAccountsCount(callback: AsyncCallback<number>): void 3320 3321获取已创建的系统帐号数量。使用callback异步回调。 3322 3323> **说明:** 3324> 3325> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountCount](#getosaccountcount9)。 3326 3327**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 3328 3329**系统能力:** SystemCapability.Account.OsAccount 3330 3331**参数:** 3332 3333| 参数名 | 类型 | 必填 | 说明 | 3334| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- | 3335| callback | AsyncCallback<number> | 是 | 回调函数。当获取成功时,err为null,data为已创建的系统帐号的数量;否则为错误对象。 | 3336 3337**示例:** 3338 3339 ```ts 3340 import { BusinessError } from '@ohos.base'; 3341 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3342 accountManager.getCreatedOsAccountsCount((err: BusinessError, count: number)=>{ 3343 if (err) { 3344 console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err)); 3345 } else { 3346 console.log('getCreatedOsAccountsCount successfully, count: ' + count); 3347 } 3348 }); 3349 ``` 3350 3351### getCreatedOsAccountsCount<sup>(deprecated)</sup> 3352 3353getCreatedOsAccountsCount(): Promise<number> 3354 3355获取已创建的系统帐号数量,使用Promise异步回调。 3356 3357> **说明:** 3358> 3359> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountCount](#getosaccountcount9-1)。 3360 3361**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 3362 3363**系统能力:** SystemCapability.Account.OsAccount 3364 3365**返回值:** 3366 3367| 类型 | 说明 | 3368| --------------------- | -------------------------------------- | 3369| Promise<number> | Promise对象,返回已创建的系统帐号的数量。 | 3370 3371**示例:** 3372 3373 ```ts 3374 import { BusinessError } from '@ohos.base'; 3375 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3376 accountManager.getCreatedOsAccountsCount().then((count: number) => { 3377 console.log('getCreatedOsAccountsCount successfully, count: ' + count); 3378 }).catch((err: BusinessError) => { 3379 console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err)); 3380 }); 3381 ``` 3382 3383### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup> 3384 3385getOsAccountLocalIdFromProcess(callback: AsyncCallback<number>): void 3386 3387获取当前进程所属的系统帐号ID,使用callback异步回调。 3388 3389> **说明:** 3390> 3391> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalId](#getosaccountlocalid9)。 3392 3393**系统能力:** SystemCapability.Account.OsAccount 3394 3395**参数:** 3396 3397| 参数名 | 类型 | 必填 | 说明 | 3398| -------- | --------------------------- | ---- | ---------------------------------------------------------------------------- | 3399| callback | AsyncCallback<number> | 是 | 回调函数。当获取成功时,err为null,data为当前进程所属的系统帐号ID;否则为错误对象。 | 3400 3401**示例:** 3402 3403 ```ts 3404 import { BusinessError } from '@ohos.base'; 3405 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3406 accountManager.getOsAccountLocalIdFromProcess((err: BusinessError, localId: number) => { 3407 if (err) { 3408 console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err)); 3409 } else { 3410 console.log('getOsAccountLocalIdFromProcess failed, error: ' + localId); 3411 } 3412 }); 3413 ``` 3414 3415### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup> 3416 3417getOsAccountLocalIdFromProcess(): Promise<number> 3418 3419获取当前进程所属的系统帐号ID,使用Promise异步回调。 3420 3421> **说明:** 3422> 3423> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalId](#getosaccountlocalid9-1)。 3424 3425**系统能力:** SystemCapability.Account.OsAccount 3426 3427**返回值:** 3428 3429| 类型 | 说明 | 3430| :-------------------- | :--------------------------------------- | 3431| Promise<number> | Promise对象,返回当前进程所属的系统帐号ID。 | 3432 3433**示例:** 3434 3435 ```ts 3436 import { BusinessError } from '@ohos.base'; 3437 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3438 accountManager.getOsAccountLocalIdFromProcess().then((localId: number) => { 3439 console.log('getOsAccountLocalIdFromProcess successfully, localId: ' + localId); 3440 }).catch((err: BusinessError) => { 3441 console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err)); 3442 }); 3443 ``` 3444 3445### getOsAccountLocalIdFromUid<sup>(deprecated)</sup> 3446 3447getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback<number>): void 3448 3449根据uid查询对应的系统帐号ID。使用callback异步回调。 3450 3451> **说明:** 3452> 3453> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForUid](#getosaccountlocalidforuid9)。 3454 3455**系统能力:** SystemCapability.Account.OsAccount 3456 3457**参数:** 3458 3459| 参数名 | 类型 | 必填 | 说明 | 3460| -------- | --------------------------- | ---- | --------------------------------------------------------------------- | 3461| uid | number | 是 | 进程uid。 | 3462| callback | AsyncCallback<number> | 是 | 回调函数。如果查询成功,err为null,data为对应的系统帐号ID;否则为错误对象。 | 3463 3464**示例:** 查询值为12345678的uid所属的系统帐号ID 3465 3466 ```ts 3467 import { BusinessError } from '@ohos.base'; 3468 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3469 let uid: number = 12345678; 3470 accountManager.getOsAccountLocalIdFromUid(uid, (err: BusinessError, localId: number) => { 3471 if (err) { 3472 console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err)); 3473 } else { 3474 console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId); 3475 } 3476 }); 3477 ``` 3478 3479### getOsAccountLocalIdFromUid<sup>(deprecated)</sup> 3480 3481getOsAccountLocalIdFromUid(uid: number): Promise<number> 3482 3483根据uid查询对应的系统帐号ID,使用Promise异步回调。 3484 3485> **说明:** 3486> 3487> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForUid](#getosaccountlocalidforuid9-1)。 3488 3489**系统能力:** SystemCapability.Account.OsAccount 3490 3491**参数:** 3492 3493| 参数名 | 类型 | 必填 | 说明 | 3494| ------ | ------ | ---- | --------- | 3495| uid | number | 是 | 进程uid。 | 3496 3497**返回值:** 3498 3499| 类型 | 说明 | 3500| :-------------------- | :----------------------------------- | 3501| Promise<number> | Promise对象,返回uid对应的系统帐号ID。 | 3502 3503**示例:** 查询值为12345678的uid所属的系统帐号ID 3504 3505 ```ts 3506 import { BusinessError } from '@ohos.base'; 3507 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3508 let uid: number = 12345678; 3509 accountManager.getOsAccountLocalIdFromUid(uid).then((localId: number) => { 3510 console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId); 3511 }).catch((err: BusinessError) => { 3512 console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err)); 3513 }); 3514 ``` 3515 3516### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup> 3517 3518getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void 3519 3520根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用callback异步回调。 3521 3522> **说明:** 3523> 3524> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForDomain](#getosaccountlocalidfordomain9)。 3525 3526**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 3527 3528**系统能力:** SystemCapability.Account.OsAccount 3529 3530**参数:** 3531 3532| 参数名 | 类型 | 必填 | 说明 | 3533| ---------- | --------------------------------------- | ---- | --------------------------------------------------------------------------- | 3534| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 域帐号信息。 | 3535| callback | AsyncCallback<number> | 是 | 回调函数,如果获取成功,err为null,data为域帐号关联的系统帐号ID;否则为错误对象。 | 3536 3537**示例:** 3538 3539 ```ts 3540 import { BusinessError } from '@ohos.base'; 3541 let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'}; 3542 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3543 accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err: BusinessError, localId: number) => { 3544 if (err) { 3545 console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err)); 3546 } else { 3547 console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId); 3548 } 3549 }); 3550 ``` 3551 3552### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup> 3553 3554getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise<number> 3555 3556根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用Promise异步回调。 3557 3558> **说明:** 3559> 3560> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForDomain](#getosaccountlocalidfordomain9-1)。 3561 3562**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 3563 3564**系统能力:** SystemCapability.Account.OsAccount 3565 3566**参数:** 3567 3568| 参数名 | 类型 | 必填 | 说明 | 3569| ---------- | --------------------------------------- | ---- | ------------ | 3570| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 域帐号信息。 | 3571 3572**返回值:** 3573 3574| 类型 | 说明 | 3575| :-------------------- | :------------------------------------- | 3576| Promise<number> | Promise对象,返回域帐号关联的系统帐号ID。 | 3577 3578**示例:** 3579 3580 ```ts 3581 import { BusinessError } from '@ohos.base'; 3582 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3583 let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'}; 3584 accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((localId: number) => { 3585 console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId); 3586 }).catch((err: BusinessError) => { 3587 console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err)); 3588 }); 3589 ``` 3590 3591### getOsAccountAllConstraints<sup>(deprecated)</sup> 3592 3593getOsAccountAllConstraints(localId: number, callback: AsyncCallback<Array<string>>): void 3594 3595获取指定系统帐号的全部约束。使用callback异步回调。 3596 3597> **说明:** 3598> 3599> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountConstraints](#getosaccountconstraints9)。 3600 3601**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 3602 3603**系统能力:** SystemCapability.Account.OsAccount 3604 3605**参数:** 3606 3607| 参数名 | 类型 | 必填 | 说明 | 3608| -------- | ---------------------------------------- | ---- | ---------------------------------------------------------------------------------------------- | 3609| localId | number | 是 | 系统帐号ID。 | 3610| callback | AsyncCallback<Array<string>> | 是 | 回调函数。如果获取成功,err为null,data为指定系统帐号的全部[约束](#系统帐号约束列表);否则为错误对象。 | 3611 3612**示例:** 获取ID为100的系统帐号的全部约束 3613 3614 ```ts 3615 import { BusinessError } from '@ohos.base'; 3616 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3617 let localId: number = 100; 3618 accountManager.getOsAccountAllConstraints(localId, (err: BusinessError, constraints: string[])=>{ 3619 console.log('getOsAccountAllConstraints err:' + JSON.stringify(err)); 3620 console.log('getOsAccountAllConstraints:' + JSON.stringify(constraints)); 3621 }); 3622 ``` 3623 3624### getOsAccountAllConstraints<sup>(deprecated)</sup> 3625 3626getOsAccountAllConstraints(localId: number): Promise<Array<string>> 3627 3628> **说明:** 3629> 3630> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountConstraints](#getosaccountconstraints9-1)。 3631 3632获取指定系统帐号的全部约束。使用Promise异步回调。 3633 3634**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 3635 3636**系统能力:** SystemCapability.Account.OsAccount 3637 3638**参数:** 3639 3640| 参数名 | 类型 | 必填 | 说明 | 3641| ------- | ------ | ---- | ------------ | 3642| localId | number | 是 | 系统帐号ID。 | 3643 3644**返回值:** 3645 3646| 类型 | 说明 | 3647| :--------------------------------- | :----------------------------------------------------------- | 3648| Promise<Array<string>> | Promise对象,返回指定系统帐号的全部[约束](#系统帐号约束列表)。 | 3649 3650**示例:** 获取ID为100的系统帐号的全部约束 3651 3652 ```ts 3653 import { BusinessError } from '@ohos.base'; 3654 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3655 let localId: number = 100; 3656 accountManager.getOsAccountAllConstraints(localId).then((constraints: string[]) => { 3657 console.log('getOsAccountAllConstraints, constraints: ' + constraints); 3658 }).catch((err: BusinessError) => { 3659 console.log('getOsAccountAllConstraints err: ' + JSON.stringify(err)); 3660 }); 3661 ``` 3662 3663### queryActivatedOsAccountIds<sup>(deprecated)</sup> 3664 3665queryActivatedOsAccountIds(callback: AsyncCallback<Array<number>>): void 3666 3667查询当前处于激活状态的系统帐号的ID列表。使用callback异步回调。 3668 3669> **说明:** 3670> 3671> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getActivatedOsAccountLocalIds](#getactivatedosaccountlocalids9)。 3672 3673**系统能力:** SystemCapability.Account.OsAccount 3674 3675**参数:** 3676 3677| 参数名 | 类型 | 必填 | 说明 | 3678| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ | 3679| callback | AsyncCallback<Array<number>> | 是 | 回调函数。如果查询成功,err为null,data为当前处于激活状态的系统帐号的ID列表;否则为错误对象。 | 3680 3681**示例:** 3682 3683 ```ts 3684 import { BusinessError } from '@ohos.base'; 3685 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3686 accountManager.queryActivatedOsAccountIds((err: BusinessError, idArray: number[])=>{ 3687 console.log('queryActivatedOsAccountIds err:' + JSON.stringify(err)); 3688 console.log('queryActivatedOsAccountIds idArray length:' + idArray.length); 3689 for(let i=0;i<idArray.length;i++) { 3690 console.info('activated os account id: ' + idArray[i]); 3691 } 3692 }); 3693 ``` 3694 3695### queryActivatedOsAccountIds<sup>(deprecated)</sup> 3696 3697queryActivatedOsAccountIds(): Promise<Array<number>> 3698 3699> **说明:** 3700> 3701> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getActivatedOsAccountLocalIds](#getactivatedosaccountlocalids9-1)。 3702 3703查询当前处于激活状态的系统帐号的ID列表。使用Promise异步回调。 3704 3705**系统能力:** SystemCapability.Account.OsAccount 3706 3707**返回值:** 3708 3709| 类型 | 说明 | 3710| ---------------------------------- | ------------------------------------------------- | 3711| Promise<Array<number>> | Promise对象,返回当前处于激活状态的系统帐号的ID列表。 | 3712 3713**示例:** 3714 3715 ```ts 3716 import { BusinessError } from '@ohos.base'; 3717 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3718 accountManager.queryActivatedOsAccountIds().then((idArray: number[]) => { 3719 console.log('queryActivatedOsAccountIds, idArray: ' + idArray); 3720 }).catch((err: BusinessError) => { 3721 console.log('queryActivatedOsAccountIds err: ' + JSON.stringify(err)); 3722 }); 3723 ``` 3724 3725### queryCurrentOsAccount<sup>(deprecated)</sup> 3726 3727queryCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void 3728 3729查询当前进程所属的系统帐号的信息。使用callback异步回调。 3730 3731> **说明:** 3732> 3733> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getCurrentOsAccount](#getcurrentosaccount9)。 3734 3735**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 3736 3737**系统能力:** SystemCapability.Account.OsAccount 3738 3739**参数:** 3740 3741| 参数名 | 类型 | 必填 | 说明 | 3742| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | 3743| callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | 是 | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号信息;否则为错误对象。 | 3744 3745**示例:** 3746 3747 ```ts 3748 import { BusinessError } from '@ohos.base'; 3749 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3750 accountManager.queryCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{ 3751 console.log('queryCurrentOsAccount err:' + JSON.stringify(err)); 3752 console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo)); 3753 }); 3754 ``` 3755 3756### queryCurrentOsAccount<sup>(deprecated)</sup> 3757 3758queryCurrentOsAccount(): Promise<OsAccountInfo> 3759 3760查询当前进程所属的系统帐号的信息。使用Promise异步回调。 3761 3762> **说明:** 3763> 3764> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getCurrentOsAccount](#getcurrentosaccount9-1)。 3765 3766**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 3767 3768**系统能力:** SystemCapability.Account.OsAccount 3769 3770**返回值:** 3771 3772| 类型 | 说明 | 3773| ---------------------------------------------- | ------------------------------------------ | 3774| Promise<[OsAccountInfo](#osaccountinfo)> | Promise对象,返回当前进程所属的系统帐号信息。 | 3775 3776**示例:** 3777 3778 ```ts 3779 import { BusinessError } from '@ohos.base'; 3780 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3781 accountManager.queryCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => { 3782 console.log('queryCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo)); 3783 }).catch((err: BusinessError) => { 3784 console.log('queryCurrentOsAccount err: ' + JSON.stringify(err)); 3785 }); 3786 ``` 3787 3788### getOsAccountTypeFromProcess<sup>(deprecated)</sup> 3789 3790getOsAccountTypeFromProcess(callback: AsyncCallback<OsAccountType>): void 3791 3792查询当前进程所属的系统帐号的帐号类型。使用callback异步回调。 3793 3794> **说明:** 3795> 3796> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountType](#getosaccounttype9)。 3797 3798**系统能力:** SystemCapability.Account.OsAccount 3799 3800**参数:** 3801 3802| 参数名 | 类型 | 必填 | 说明 | 3803| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- | 3804| callback | AsyncCallback<[OsAccountType](#osaccounttype)> | 是 | 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号的帐号类型;否则为错误对象。 | 3805 3806**示例:** 3807 3808 ```ts 3809 import { BusinessError } from '@ohos.base'; 3810 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3811 accountManager.getOsAccountTypeFromProcess((err: BusinessError, accountType: account_osAccount.OsAccountType) => { 3812 console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err)); 3813 console.log('getOsAccountTypeFromProcess accountType: ' + accountType); 3814 }); 3815 ``` 3816 3817### getOsAccountTypeFromProcess<sup>(deprecated)</sup> 3818 3819getOsAccountTypeFromProcess(): Promise<OsAccountType> 3820 3821查询当前进程所属的系统帐号的帐号类型。使用Promise异步回调。 3822 3823> **说明:** 3824> 3825> 从 API version 7开始支持,从API version 9开始废弃。建议使用[getOsAccountType](#getosaccounttype9-1)。 3826 3827**系统能力:** SystemCapability.Account.OsAccount 3828 3829**返回值:** 3830 3831| 类型 | 说明 | 3832| ---------------------------------------------- | ----------------------------------------------- | 3833| Promise<[OsAccountType](#osaccounttype)> | Promise对象,返回当前进程所属的系统帐号的帐号类型。 | 3834 3835**示例:** 3836 3837 ```ts 3838 import { BusinessError } from '@ohos.base'; 3839 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3840 accountManager.getOsAccountTypeFromProcess().then((accountType: account_osAccount.OsAccountType) => { 3841 console.log('getOsAccountTypeFromProcess, accountType: ' + accountType); 3842 }).catch((err: BusinessError) => { 3843 console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err)); 3844 }); 3845 ``` 3846 3847### getDistributedVirtualDeviceId<sup>(deprecated)</sup> 3848 3849getDistributedVirtualDeviceId(callback: AsyncCallback<string>): void 3850 3851获取分布式虚拟设备ID。使用callback异步回调。 3852 3853> **说明:** 3854> 3855> 从 API version 7开始支持,从API version 9开始废弃。建议使用[queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9)。 3856 3857**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 或 ohos.permission.MANAGE_LOCAL_ACCOUNTS 3858 3859**系统能力:** SystemCapability.Account.OsAccount 3860 3861**参数:** 3862 3863| 参数名 | 类型 | 必填 | 说明 | 3864| -------- | --------------------------- | ---- | --------------------------------------------------------------------- | 3865| callback | AsyncCallback<string> | 是 | 回调函数。如果获取成功,err为null,data为分布式虚拟设备ID;否则为错误对象。 | 3866 3867**示例:** 3868 3869 ```ts 3870 import { BusinessError } from '@ohos.base'; 3871 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3872 accountManager.getDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => { 3873 console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err)); 3874 console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID); 3875 }); 3876 ``` 3877 3878### getDistributedVirtualDeviceId<sup>(deprecated)</sup> 3879 3880getDistributedVirtualDeviceId(): Promise<string> 3881 3882获取分布式虚拟设备ID。使用Promise异步回调。 3883 3884> **说明:** 3885> 3886> 从 API version 7开始支持,从API version 9开始废弃。建议使用[queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9-1)。 3887 3888**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 或 ohos.permission.MANAGE_LOCAL_ACCOUNTS 3889 3890**系统能力:** SystemCapability.Account.OsAccount 3891 3892**返回值:** 3893 3894| 类型 | 说明 | 3895| --------------------- | --------------------------------- | 3896| Promise<string> | Promise对象,返回分布式虚拟设备ID。 | 3897 3898**示例:** 3899 3900 ```ts 3901 import { BusinessError } from '@ohos.base'; 3902 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3903 accountManager.getDistributedVirtualDeviceId().then((virtualID: string) => { 3904 console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID); 3905 }).catch((err: BusinessError) => { 3906 console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err)); 3907 }); 3908 ``` 3909 3910### getOsAccountLocalIdBySerialNumber<sup>(deprecated)</sup> 3911 3912getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback<number>): void 3913 3914通过SN码查询与其关联的系统帐号的帐号ID。使用callback异步回调。 3915 3916> **说明:** 3917> 3918> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForSerialNumber](#getosaccountlocalidforserialnumber9)。 3919 3920**系统能力:** SystemCapability.Account.OsAccount 3921 3922**参数:** 3923 3924| 参数名 | 类型 | 必填 | 说明 | 3925| ------------ | --------------------------- | ---- | -------------------------------------------------------------------------------- | 3926| serialNumber | number | 是 | 帐号SN码。 | 3927| callback | AsyncCallback<number> | 是 | 回调函数。如果查询成功,err为null,data为与SN码关联的系统帐号的帐号ID;否则为错误对象。 | 3928 3929**示例:** 查询与SN码12345关联的系统帐号的ID 3930 3931 ```ts 3932 import { BusinessError } from '@ohos.base'; 3933 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3934 let serialNumber: number = 12345; 3935 accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err: BusinessError, localId: number)=>{ 3936 console.log('ger localId err:' + JSON.stringify(err)); 3937 console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber); 3938 }); 3939 ``` 3940 3941### getOsAccountLocalIdBySerialNumber<sup>(deprecated)</sup> 3942 3943getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise<number> 3944 3945通过SN码查询与其关联的系统帐号的帐号ID。使用Promise异步回调。 3946 3947> **说明:** 3948> 3949> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getOsAccountLocalIdForSerialNumber](#getosaccountlocalidforserialnumber9-1)。 3950 3951**系统能力:** SystemCapability.Account.OsAccount 3952 3953**参数:** 3954 3955| 参数名 | 类型 | 必填 | 说明 | 3956| ------------ | ------ | ---- | ---------- | 3957| serialNumber | number | 是 | 帐号SN码。 | 3958 3959**返回值:** 3960 3961| 类型 | 说明 | 3962| --------------------- | -------------------------------------------- | 3963| Promise<number> | Promise对象,返回与SN码关联的系统帐号的帐号ID。 | 3964 3965**示例:** 查询与SN码12345关联的系统帐号的ID 3966 3967 ```ts 3968 import { BusinessError } from '@ohos.base'; 3969 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 3970 let serialNumber: number = 12345; 3971 accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId: number) => { 3972 console.log('getOsAccountLocalIdBySerialNumber localId: ' + localId); 3973 }).catch((err: BusinessError) => { 3974 console.log('getOsAccountLocalIdBySerialNumber err: ' + JSON.stringify(err)); 3975 }); 3976 ``` 3977 3978### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup> 3979 3980getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback<number>): void 3981 3982通过系统帐号ID获取与该系统帐号关联的SN码。使用callback异步回调。 3983 3984> **说明:** 3985> 3986> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getSerialNumberForOsAccountLocalId](#getserialnumberforosaccountlocalid9)。 3987 3988**系统能力:** SystemCapability.Account.OsAccount 3989 3990**参数:** 3991 3992| 参数名 | 类型 | 必填 | 说明 | 3993| -------- | --------------------------- | ---- | --------------------------------------------------------------------------- | 3994| localId | number | 是 | 系统帐号ID。 | 3995| callback | AsyncCallback<number> | 是 | 回调函数。如果获取成功,err为null,data为与该系统帐号关联的SN码;否则为错误对象。 | 3996 3997**示例:** 获取ID为100的系统帐号关联的SN码 3998 3999 ```ts 4000 import { BusinessError } from '@ohos.base'; 4001 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 4002 let localId: number = 100; 4003 accountManager.getSerialNumberByOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{ 4004 console.log('ger serialNumber err:' + JSON.stringify(err)); 4005 console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId); 4006 }); 4007 ``` 4008 4009### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup> 4010 4011getSerialNumberByOsAccountLocalId(localId: number): Promise<number> 4012 4013通过系统帐号ID获取与该系统帐号关联的SN码。使用Promise异步回调。 4014 4015> **说明:** 4016> 4017> 从 API version 8开始支持,从API version 9开始废弃。建议使用[getSerialNumberForOsAccountLocalId](#getserialnumberforosaccountlocalid9-1)。 4018 4019**系统能力:** SystemCapability.Account.OsAccount 4020 4021**参数:** 4022 4023| 参数名 | 类型 | 必填 | 说明 | 4024| ------- | ------ | ---- | ----------- | 4025| localId | number | 是 | 系统帐号ID。 | 4026 4027**返回值:** 4028 4029| 类型 | 说明 | 4030| --------------------- | -------------------------------------- | 4031| Promise<number> | Promise对象,返回与该系统帐号关联的SN码。 | 4032 4033**示例:** 获取ID为100的系统帐号关联的SN码 4034 4035 ```ts 4036 import { BusinessError } from '@ohos.base'; 4037 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 4038 let localId: number = 100; 4039 accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber: number) => { 4040 console.log('getSerialNumberByOsAccountLocalId serialNumber: ' + serialNumber); 4041 }).catch((err: BusinessError) => { 4042 console.log('getSerialNumberByOsAccountLocalId err: ' + JSON.stringify(err)); 4043 }); 4044 ``` 4045 4046## UserAuth<sup>8+</sup> 4047 4048用户认证类。 4049 4050**系统接口:** 此接口为系统接口。 4051 4052### constructor<sup>8+</sup> 4053 4054constructor() 4055 4056创建用户认证的实例。 4057 4058**系统接口:** 此接口为系统接口。 4059 4060**系统能力**:SystemCapability.Account.OsAccount 4061 4062**示例:** 4063 ```ts 4064 let userAuth = new account_osAccount.UserAuth(); 4065 ``` 4066 4067### getVersion<sup>8+</sup> 4068 4069getVersion(): number; 4070 4071返回版本信息。 4072 4073**系统接口:** 此接口为系统接口。 4074 4075**系统能力:** SystemCapability.Account.OsAccount 4076 4077**返回值:** 4078 4079| 类型 | 说明 | 4080| :----- | :----------- | 4081| number | 返回版本信息。| 4082 4083**示例:** 4084 ```ts 4085 let userAuth = new account_osAccount.UserAuth(); 4086 let version: number = userAuth.getVersion(); 4087 console.log('getVersion version = ' + version); 4088 ``` 4089 4090### getAvailableStatus<sup>8+</sup> 4091 4092getAvailableStatus(authType: AuthType, authTrustLevel: AuthTrustLevel): number; 4093 4094获取指定认证类型和认证可信等级的认证能力的可用状态。 4095 4096**系统接口:** 此接口为系统接口。 4097 4098**系统能力:** SystemCapability.Account.OsAccount 4099 4100**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 4101 4102**参数:** 4103 4104| 参数名 | 类型 | 必填 | 说明 | 4105| --------------- | -----------------------------------| ---- | ------------------------- | 4106| authType | [AuthType](#authtype8) | 是 | 认证类型。 | 4107| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是 | 认证的可信等级。 | 4108 4109**返回值:** 4110 4111| 类型 | 说明 | 4112| ------ | ----------------------------- | 4113| number | 返回认证能力的可用状态。 | 4114 4115**错误码:** 4116 4117| 错误码ID | 错误信息 | 4118| -------- | --------------------------- | 4119| 12300001 | System service exception. | 4120| 12300002 | Invalid authType or authTrustLevel. | 4121 4122**示例:** 4123 ```ts 4124 let userAuth = new account_osAccount.UserAuth(); 4125 let authType: account_osAccount.AuthType = account_osAccount.AuthType.PIN; 4126 let authTrustLevel: account_osAccount.AuthTrustLevel = account_osAccount.AuthTrustLevel.ATL1; 4127 try { 4128 let status: number = userAuth.getAvailableStatus(authType, authTrustLevel); 4129 console.log('getAvailableStatus status = ' + status); 4130 } catch (e) { 4131 console.log('getAvailableStatus exception = ' + JSON.stringify(e)); 4132 } 4133 ``` 4134 4135### getProperty<sup>8+</sup> 4136 4137getProperty(request: GetPropertyRequest, callback: AsyncCallback<ExecutorProperty>): void; 4138 4139基于指定的请求信息获取属性。使用callback异步回调。 4140 4141**系统接口:** 此接口为系统接口。 4142 4143**系统能力:** SystemCapability.Account.OsAccount 4144 4145**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 4146 4147**参数:** 4148 4149| 参数名 | 类型 | 必填 | 说明 | 4150| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------ | 4151| request | [GetPropertyRequest](#getpropertyrequest8) | 是 | 请求信息,包括认证类型和属性类型列表。 | 4152| callback | AsyncCallback<[ExecutorProperty](#executorproperty8)> | 是 | 回调函数。如果获取成功,err为null,data为执行器属性信息;否则为错误对象。| 4153 4154**错误码:** 4155 4156| 错误码ID | 错误信息 | 4157| -------- | --------------------------- | 4158| 12300001 | System service exception. | 4159| 12300002 | Invalid request. | 4160 4161**示例:** 4162 ```ts 4163 import { BusinessError } from '@ohos.base'; 4164 let userAuth = new account_osAccount.UserAuth(); 4165 let keys: Array<account_osAccount.GetPropertyType> = [ 4166 account_osAccount.GetPropertyType.AUTH_SUB_TYPE, 4167 account_osAccount.GetPropertyType.REMAIN_TIMES, 4168 account_osAccount.GetPropertyType.FREEZING_TIME 4169 ]; 4170 let request: account_osAccount.GetPropertyRequest = { 4171 authType: account_osAccount.AuthType.PIN, 4172 keys: keys 4173 }; 4174 try { 4175 userAuth.getProperty(request, (err: BusinessError, result: account_osAccount.ExecutorProperty) => { 4176 console.log('getProperty err = ' + JSON.stringify(err)); 4177 console.log('getProperty result = ' + JSON.stringify(result)); 4178 }); 4179 } catch (e) { 4180 console.log('getProperty exception = ' + JSON.stringify(e)); 4181 } 4182 ``` 4183 4184### getProperty<sup>8+</sup> 4185 4186getProperty(request: GetPropertyRequest): Promise<ExecutorProperty>; 4187 4188基于指定的请求信息获取属性。使用Promise异步回调。 4189 4190**系统接口:** 此接口为系统接口。 4191 4192**系统能力:** SystemCapability.Account.OsAccount 4193 4194**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 4195 4196**参数:** 4197 4198| 参数名 | 类型 | 必填 | 说明 | 4199| -------- | ------------------------------------------------------ | ---- | ---------------------------------- | 4200| request | [GetPropertyRequest](#getpropertyrequest8) | 是 | 请求信息,包括认证类型和属性类型列表。 | 4201 4202**返回值:** 4203 4204| 类型 | 说明 | 4205| :---------------------------------------------------------------- | :-------------------------------------------------- | 4206| Promise<[ExecutorProperty](#executorproperty8)> | Promise对象,返回执行者属性信息。 | 4207 4208**错误码:** 4209 4210| 错误码ID | 错误信息 | 4211| -------- | --------------------------- | 4212| 12300001 | System service exception. | 4213| 12300002 | Invalid request. | 4214 4215**示例:** 4216 ```ts 4217 import { BusinessError } from '@ohos.base'; 4218 let userAuth = new account_osAccount.UserAuth(); 4219 let keys: Array<account_osAccount.GetPropertyType> = [ 4220 account_osAccount.GetPropertyType.AUTH_SUB_TYPE, 4221 account_osAccount.GetPropertyType.REMAIN_TIMES, 4222 account_osAccount.GetPropertyType.FREEZING_TIME 4223 ]; 4224 let request: account_osAccount.GetPropertyRequest = { 4225 authType: account_osAccount.AuthType.PIN, 4226 keys: keys 4227 }; 4228 try { 4229 userAuth.getProperty(request).then((result: account_osAccount.ExecutorProperty) => { 4230 console.log('getProperty result = ' + JSON.stringify(result)); 4231 }).catch((err: BusinessError) => { 4232 console.log('getProperty error = ' + JSON.stringify(err)); 4233 }); 4234 } catch (e) { 4235 console.log('getProperty exception = ' + JSON.stringify(e)); 4236 } 4237 ``` 4238 4239### setProperty<sup>8+</sup> 4240 4241setProperty(request: SetPropertyRequest, callback: AsyncCallback<void>): void; 4242 4243设置可用于初始化算法的属性。使用callback异步回调。 4244 4245**系统接口:** 此接口为系统接口。 4246 4247**系统能力:** SystemCapability.Account.OsAccount 4248 4249**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 4250 4251**参数:** 4252 4253| 参数名 | 类型 | 必填 | 说明 | 4254| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------- | 4255| request | [SetPropertyRequest](#setpropertyrequest8)| 是 | 请求信息,包括认证类型和要设置的密钥值。 | 4256| callback | AsyncCallback<void> | 是 | 回调函数。如果设置成功,err为null,否则为错误对象。 | 4257 4258**错误码:** 4259 4260| 错误码ID | 错误信息 | 4261| -------- | --------------------------- | 4262| 12300001 | System service exception. | 4263| 12300002 | Invalid request. | 4264 4265**示例:** 4266 ```ts 4267 import { BusinessError } from '@ohos.base'; 4268 let userAuth = new account_osAccount.UserAuth(); 4269 let request: account_osAccount.SetPropertyRequest = { 4270 authType: account_osAccount.AuthType.PIN, 4271 key: account_osAccount.SetPropertyType.INIT_ALGORITHM, 4272 setInfo: new Uint8Array([0]) 4273 }; 4274 try { 4275 userAuth.setProperty(request, (err: BusinessError) => { 4276 if (err) { 4277 console.log('setProperty failed, error = ' + JSON.stringify(err)); 4278 } else { 4279 console.log('setProperty successfully'); 4280 } 4281 }); 4282 } catch (e) { 4283 console.log('setProperty exception = ' + JSON.stringify(e)); 4284 } 4285 ``` 4286 4287### setProperty<sup>8+</sup> 4288 4289setProperty(request: SetPropertyRequest): Promise<void>; 4290 4291设置可用于初始化算法的属性。使用Promise异步回调。 4292 4293**系统接口:** 此接口为系统接口。 4294 4295**系统能力:** SystemCapability.Account.OsAccount 4296 4297**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 4298 4299**参数:** 4300 4301| 参数名 | 类型 | 必填 | 说明 | 4302| -------- | ------------------------------------------ | ---- | ---------------------------------------- | 4303| request | [SetPropertyRequest](#setpropertyrequest8) | 是 | 请求信息,包括身份验证类型和要设置的密钥值。 | 4304 4305**返回值:** 4306 4307| 类型 | 说明 | 4308| :-------------------- | :------------------------------------------------------------ | 4309| Promise<void> | Promise对象,无返回结果的Promise对象。 | 4310 4311**错误码:** 4312 4313| 错误码ID | 错误信息 | 4314| -------- | --------------------------- | 4315| 12300001 | System service exception. | 4316| 12300002 | Invalid request. | 4317 4318**示例:** 4319 ```ts 4320 import { BusinessError } from '@ohos.base'; 4321 let userAuth = new account_osAccount.UserAuth(); 4322 let request: account_osAccount.SetPropertyRequest = { 4323 authType: account_osAccount.AuthType.PIN, 4324 key: account_osAccount.SetPropertyType.INIT_ALGORITHM, 4325 setInfo: new Uint8Array([0]) 4326 }; 4327 try { 4328 userAuth.setProperty(request).then(() => { 4329 console.log('setProperty successfully'); 4330 }).catch((err: BusinessError) => { 4331 console.log('setProperty failed, error = ' + JSON.stringify(err)); 4332 }); 4333 } catch (e) { 4334 console.log('setProperty exception = ' + JSON.stringify(e)); 4335 } 4336 ``` 4337 4338### auth<sup>8+</sup> 4339 4340auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array; 4341 4342认证当前用户。使用callback异步回调。 4343 4344**系统接口:** 此接口为系统接口。 4345 4346**系统能力:** SystemCapability.Account.OsAccount 4347 4348**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 4349 4350**参数:** 4351 4352| 参数名 | 类型 | 必填 | 说明 | 4353| --------------- | ---------------------------------------- | --- | ------------------------------------ | 4354| challenge | Uint8Array | 是 | 指示挑战值,挑战值为一个随机数,用于提升安全性。| 4355| authType | [AuthType](#authtype8) | 是 | 指示认证类型。 | 4356| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是 | 指示认证结果的信任级别。 | 4357| callback | [IUserAuthCallback](#iuserauthcallback8) | 是 | 回调对象,返回认证结果。 | 4358 4359**返回值:** 4360 4361| 类型 | 说明 | 4362| ---------- | ------------------ | 4363| Uint8Array | 返回取消的上下文ID。 | 4364 4365**错误码:** 4366 4367| 错误码ID | 错误信息 | 4368| -------- | --------------------- | 4369| 12300001 | System service exception. | 4370| 12300002 | Invalid challenge, authType or authTrustLevel. | 4371| 12300101 | Credential is incorrect. | 4372| 12300102 | Credential not enrolled. | 4373| 12300105 | Unsupported authTrustLevel. | 4374| 12300106 | Unsupported authType. | 4375| 12300109 | Authentication is canceled. | 4376| 12300110 | Authentication is locked. | 4377| 12300111 | Authentication timeout. | 4378| 12300112 | Authentication service is busy. | 4379 4380**示例:** 4381 ```ts 4382 let userAuth = new account_osAccount.UserAuth(); 4383 let challenge: Uint8Array = new Uint8Array([0]); 4384 let authType: account_osAccount.AuthType = account_osAccount.AuthType.PIN; 4385 let authTrustLevel: account_osAccount.AuthTrustLevel = account_osAccount.AuthTrustLevel.ATL1; 4386 try { 4387 userAuth.auth(challenge, authType, authTrustLevel, { 4388 onResult: (result: number, extraInfo: account_osAccount.AuthResult) => { 4389 console.log('auth result = ' + result); 4390 console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); 4391 } 4392 }); 4393 } catch (e) { 4394 console.log('auth exception = ' + JSON.stringify(e)); 4395 } 4396 ``` 4397 4398### authUser<sup>8+</sup> 4399 4400authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array; 4401 4402认证指定用户。使用callback异步回调。 4403 4404**系统接口:** 此接口为系统接口。 4405 4406**系统能力:** SystemCapability.Account.OsAccount 4407 4408**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 4409 4410**参数:** 4411 4412| 参数名 | 类型 | 必填 | 说明 | 4413| --------------- | ---------------------------------------------------- | --- | ------------------------------------ | 4414| userId | number | 是 | 指示用户身份。 | 4415| challenge | Uint8Array | 是 | 指示挑战值,挑战值为一个随机数,用于提升安全性。 | 4416| authType | [AuthType](#authtype8) | 是 | 指示认证类型。 | 4417| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是 | 指示认证结果的信任级别。 | 4418| callback | [IUserAuthCallback](#iuserauthcallback8) | 是 | 回调对象,返回认证结果。 | 4419 4420**返回值:** 4421 4422| 类型 | 说明 | 4423| ---------- | ------------------ | 4424| Uint8Array | 返回取消的上下文ID。 | 4425 4426**错误码:** 4427 4428| 错误码ID | 错误信息 | 4429| -------- | --------------------- | 4430| 12300001 | System service exception. | 4431| 12300002 | Invalid userId, challenge, authType or authTrustLevel. | 4432| 12300101 | Credential is incorrect. | 4433| 12300102 | Credential not enrolled. | 4434| 12300105 | Unsupported authTrustLevel. | 4435| 12300106 | Unsupported authType. | 4436| 12300109 | Authentication is canceled. | 4437| 12300110 | Authentication is locked. | 4438| 12300111 | Authentication timeout. | 4439| 12300112 | Authentication service is busy. | 4440 4441**示例:** 4442 ```ts 4443 let userAuth = new account_osAccount.UserAuth(); 4444 let userID: number = 100; 4445 let challenge: Uint8Array = new Uint8Array([0]); 4446 let authType: account_osAccount.AuthType = account_osAccount.AuthType.PIN; 4447 let authTrustLevel: account_osAccount.AuthTrustLevel = account_osAccount.AuthTrustLevel.ATL1; 4448 try { 4449 userAuth.authUser(userID, challenge, authType, authTrustLevel, { 4450 onResult: (result,extraInfo) => { 4451 console.log('authUser result = ' + result); 4452 console.log('authUser extraInfo = ' + JSON.stringify(extraInfo)); 4453 } 4454 }); 4455 } catch (e) { 4456 console.log('authUser exception = ' + JSON.stringify(e)); 4457 } 4458 ``` 4459 4460### cancelAuth<sup>8+</sup> 4461 4462cancelAuth(contextID: Uint8Array): void; 4463 4464取消指定的认证操作。 4465 4466**系统接口:** 此接口为系统接口。 4467 4468**系统能力:** SystemCapability.Account.OsAccount 4469 4470**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 4471 4472**参数:** 4473 4474| 参数名 | 类型 | 必填 | 说明 | 4475| ----------| ---------- | ---- | ------------------------------------------ | 4476| contextId | Uint8Array | 是 | 指示身份验证上下文ID,此ID动态生成没有具体值。 | 4477 4478**错误码:** 4479 4480| 错误码ID | 错误信息 | 4481| -------- | ------------------ | 4482| 12300001 | System service exception. | 4483| 12300002 | Invalid contextId. | 4484 4485**示例:** 4486 ```ts 4487 let userAuth = new account_osAccount.UserAuth(); 4488 let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth(); 4489 let challenge = new Uint8Array([0]); 4490 let contextId: Uint8Array = userAuth.auth(challenge, account_osAccount.AuthType.PIN, account_osAccount.AuthTrustLevel.ATL1, { 4491 onResult: (result: number, extraInfo: account_osAccount.AuthResult) => { 4492 console.log('auth result = ' + result); 4493 console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); 4494 } 4495 }); 4496 try { 4497 userAuth.cancelAuth(contextId); 4498 } catch (e) { 4499 console.log('cancelAuth exception = ' + JSON.stringify(e)); 4500 } 4501 ``` 4502 4503## PINAuth<sup>8+</sup> 4504 4505PIN码认证基类。 4506 4507**系统接口:** 此接口为系统接口。 4508 4509### constructor<sup>8+</sup> 4510 4511constructor() 4512 4513创建PIN码认证的实例。 4514 4515**系统接口:** 此接口为系统接口。 4516 4517**系统能力**:SystemCapability.Account.OsAccount 4518 4519**示例:** 4520 ```ts 4521 let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth(); 4522 ``` 4523 4524### registerInputer<sup>8+</sup> 4525 4526registerInputer(inputer: IInputer): void; 4527 4528注册PIN码输入器。 4529 4530**系统接口:** 此接口为系统接口。 4531 4532**系统能力:** SystemCapability.Account.OsAccount 4533 4534**需要权限:** ohos.permission.ACCESS_PIN_AUTH 4535 4536**参数:** 4537 4538| 参数名 | 类型 | 必填 | 说明 | 4539| ----------| ----------------------- | --- | -------------------------- | 4540| inputer | [IInputer](#iinputer8) | 是 | PIN码输入器,用于获取PIN码。 | 4541 4542**错误码:** 4543 4544| 错误码ID | 错误信息 | 4545| -------- | --------------------------- | 4546| 12300001 | System service exception. | 4547| 12300002 | Invalid inputer. | 4548| 12300103 | Inputer already registered. | 4549 4550**示例:** 4551 ```ts 4552 let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth(); 4553 let password = new Uint8Array([0, 0, 0, 0, 0]); 4554 try { 4555 pinAuth.registerInputer({ 4556 onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => { 4557 callback.onSetData(authSubType, password); 4558 } 4559 }); 4560 console.log('registerInputer result success.'); 4561 } catch (e) { 4562 console.log('registerInputer exception = ' + JSON.stringify(e)); 4563 } 4564 ``` 4565 4566### unregisterInputer<sup>8+</sup> 4567 4568unregisterInputer(): void; 4569 4570解注册PIN码输入器。 4571 4572**系统接口:** 此接口为系统接口。 4573 4574**系统能力:** SystemCapability.Account.OsAccount 4575 4576**需要权限:** ohos.permission.ACCESS_PIN_AUTH 4577 4578**示例:** 4579 ```ts 4580 let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth(); 4581 pinAuth.unregisterInputer(); 4582 ``` 4583 4584## InputerManager <sup>9+</sup> 4585 4586凭据输入管理器。 4587 4588### registerInputer<sup>9+</sup> 4589 4590static registerInputer(authType: AuthType, inputer: IInputer): void 4591 4592注册凭据输入器。 4593 4594**系统接口:** 此接口为系统接口。 4595 4596**系统能力:** SystemCapability.Account.OsAccount 4597 4598**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 或 ohos.permission.MANAGE_USER_IDM 4599 4600**参数:** 4601 4602| 参数名 | 类型 | 必填 | 说明 | 4603| ----------| ----------------------- | --- | -------------------------- | 4604| authType | [AuthType](#authtype8) | 是 | 认证类型。 | 4605| inputer | [IInputer](#iinputer8) | 是 | 凭据输入器,用于获取凭据。 | 4606 4607**错误码:** 4608 4609| 错误码ID | 错误信息 | 4610| -------- | --------------------------- | 4611| 12300001 | System service exception. | 4612| 12300002 | Invalid authType or inputer. | 4613| 12300103 | The credential inputer has been registered. | 4614| 12300106 | Unsupported authType. | 4615 4616**示例:** 4617 ```ts 4618 let authType: account_osAccount.AuthType = account_osAccount.AuthType.DOMAIN; 4619 let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0]); 4620 try { 4621 account_osAccount.InputerManager.registerInputer(authType, { 4622 onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => { 4623 callback.onSetData(authSubType, password); 4624 } 4625 }); 4626 console.log('registerInputer success.'); 4627 } catch (e) { 4628 console.log('registerInputer exception = ' + JSON.stringify(e)); 4629 } 4630 ``` 4631 4632### unregisterInputer<sup>9+</sup> 4633 4634static unregisterInputer(authType: AuthType): void 4635 4636解注册凭据输入器。 4637 4638**系统接口:** 此接口为系统接口。 4639 4640**系统能力:** SystemCapability.Account.OsAccount 4641 4642**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 或 ohos.permission.MANAGE_USER_IDM 4643 4644**参数:** 4645 4646| 参数名 | 类型 | 必填 | 说明 | 4647| ----------| ----------------------- | --- | -------------------------- | 4648| authType | [AuthType](#authtype8) | 是 | 认证类型。 | 4649 4650**错误码:** 4651 4652| 错误码ID | 错误信息 | 4653| -------- | --------------------------- | 4654| 12300002 | Invalid authType. | 4655 4656**示例:** 4657 ```ts 4658 let authType: account_osAccount.AuthType = account_osAccount.AuthType.DOMAIN; 4659 try { 4660 account_osAccount.InputerManager.unregisterInputer(authType); 4661 console.log('unregisterInputer success.'); 4662 } catch(err) { 4663 console.log('unregisterInputer err:' + JSON.stringify(err)); 4664 } 4665 ``` 4666 4667## DomainPlugin<sup>9+</sup> 4668 4669域插件,提供域帐号认证功能。 4670 4671**系统接口:** 此接口为系统接口。 4672 4673### auth<sup>9+</sup> 4674 4675auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void 4676 4677认证指定的域帐号。 4678 4679**系统接口:** 此接口为系统接口。 4680 4681**系统能力:** SystemCapability.Account.OsAccount 4682 4683**参数:** 4684 4685| 参数名 | 类型 | 必填 | 说明 | 4686| ---------- | --------------------------------------- | ---- | --------------- | 4687| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 4688| credential | Uint8Array | 是 | 指示域帐号的凭据。| 4689| callback | [IUserAuthCallback](#iuserauthcallback8) | 是 | 指示认证结果回调。| 4690 4691**示例:** 4692 ```ts 4693 import { AsyncCallback } from '@ohos.base'; 4694 let plugin: account_osAccount.DomainPlugin = { 4695 auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array, 4696 callback: account_osAccount.IUserAuthCallback) => { 4697 // mock authentication 4698 // notify authentication result 4699 let result: account_osAccount.AuthResult = { 4700 token: new Uint8Array([0]), 4701 remainTimes: 5, 4702 freezingTime: 0 4703 }; 4704 callback.onResult(0, result); 4705 }, 4706 authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4707 callback: account_osAccount.IUserAuthCallback) => {}, 4708 authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4709 callback: account_osAccount.IUserAuthCallback) => {}, 4710 getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions, 4711 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {}, 4712 getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4713 callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {}, 4714 bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number, 4715 callback: AsyncCallback<void>) => {}, 4716 unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 4717 isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4718 callback: AsyncCallback<boolean>) => {}, 4719 getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 4720 } 4721 account_osAccount.DomainAccountManager.registerPlugin(plugin); 4722 let userAuth = new account_osAccount.UserAuth(); 4723 let challenge: Uint8Array = new Uint8Array([0]); 4724 let authType: account_osAccount.AuthType = account_osAccount.AuthType.DOMAIN; 4725 let authTrustLevel: account_osAccount.AuthTrustLevel = account_osAccount.AuthTrustLevel.ATL1; 4726 try { 4727 userAuth.auth(challenge, authType, authTrustLevel, { 4728 onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => { 4729 console.log('auth resultCode = ' + resultCode); 4730 console.log('auth authResult = ' + JSON.stringify(authResult)); 4731 } 4732 }); 4733 } catch (err) { 4734 console.log('auth exception = ' + JSON.stringify(err)); 4735 } 4736 ``` 4737 4738### authWithPopup<sup>10+</sup> 4739 4740authWithPopup(domainAccountInfo: DomainAccountInfo, callback: IUserAuthCallback): void 4741 4742弹窗认证指定的域帐号。 4743 4744**系统接口:** 此接口为系统接口。 4745 4746**系统能力:** SystemCapability.Account.OsAccount 4747 4748**参数:** 4749 4750| 参数名 | 类型 | 必填 | 说明 | 4751| ---------- | --------------------------------------- | ---- | --------------- | 4752| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 4753| callback | [IUserAuthCallback](#iuserauthcallback8) | 是 | 指示认证结果回调。| 4754 4755**示例:** 4756 ```ts 4757 import { AsyncCallback } from '@ohos.base'; 4758 let plugin: account_osAccount.DomainPlugin = { 4759 auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array, 4760 callback: account_osAccount.IUserAuthCallback) => {}, 4761 authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4762 callback: account_osAccount.IUserAuthCallback) => { 4763 // mock authentication 4764 // notify authentication result 4765 let result: account_osAccount.AuthResult = { 4766 token: new Uint8Array([0]), 4767 remainTimes: 5, 4768 freezingTime: 0 4769 }; 4770 callback.onResult(0, result); 4771 }, 4772 authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4773 callback: account_osAccount.IUserAuthCallback) => {}, 4774 getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions, 4775 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {}, 4776 getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4777 callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {}, 4778 bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number, 4779 callback: AsyncCallback<void>) => {}, 4780 unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 4781 isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4782 callback: AsyncCallback<boolean>) => {}, 4783 getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 4784 } 4785 account_osAccount.DomainAccountManager.registerPlugin(plugin) 4786 ``` 4787 4788### authWithToken<sup>10+</sup> 4789 4790authWithToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: IUserAuthCallback): void 4791 4792使用授权令牌认证指定的域帐号。 4793 4794**系统接口:** 此接口为系统接口。 4795 4796**系统能力:** SystemCapability.Account.OsAccount 4797 4798**参数:** 4799 4800| 参数名 | 类型 | 必填 | 说明 | 4801| ---------- | --------------------------------------- | ---- | --------------- | 4802| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 4803| token | Uint8Array | 是 | 指示PIN码或生物识别认证成功时生成的授权令牌。| 4804| callback | [IUserAuthCallback](#iuserauthcallback8) | 是 | 指示认证结果回调。| 4805 4806**示例:** 4807 ```ts 4808 import { AsyncCallback } from '@ohos.base'; 4809 let plugin: account_osAccount.DomainPlugin = { 4810 auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array, 4811 callback: account_osAccount.IUserAuthCallback) => {}, 4812 authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4813 callback: account_osAccount.IUserAuthCallback) => {}, 4814 authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4815 callback: account_osAccount.IUserAuthCallback) => { 4816 // mock authentication 4817 // notify authentication result 4818 let result: account_osAccount.AuthResult = { 4819 token: new Uint8Array([0]), 4820 remainTimes: 5, 4821 freezingTime: 0 4822 }; 4823 callback.onResult(0, result); 4824 }, 4825 getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions, 4826 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {}, 4827 getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4828 callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {}, 4829 bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number, 4830 callback: AsyncCallback<void>) => {}, 4831 unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 4832 isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4833 callback: AsyncCallback<boolean>) => {}, 4834 getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 4835 } 4836 account_osAccount.DomainAccountManager.registerPlugin(plugin) 4837 ``` 4838 4839### getAccountInfo<sup>10+</sup> 4840 4841getAccountInfo(options: GetDomainAccountInfoPluginOptions, callback: AsyncCallback<DomainAccountInfo>): void 4842 4843查询指定域帐号的信息。 4844 4845**系统接口:** 此接口为系统接口。 4846 4847**系统能力:** SystemCapability.Account.OsAccount 4848 4849**参数:** 4850 4851| 参数名 | 类型 | 必填 | 说明 | 4852| ---------- | --------------------------------------- | ---- | --------------- | 4853| options | [GetDomainAccountInfoPluginOptions](#getdomainaccountinfopluginoptions10) | 是 | 指示域帐号信息。| 4854| callback | AsyncCallback<[DomainAccountInfo](#domainaccountinfo8)> | 是 | 指示查询结果回调。| 4855 4856**示例:** 4857 ```ts 4858 import { AsyncCallback, BusinessError } from '@ohos.base'; 4859 let plugin: account_osAccount.DomainPlugin = { 4860 auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array, 4861 callback: account_osAccount.IUserAuthCallback) => {}, 4862 authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4863 callback: account_osAccount.IUserAuthCallback) => {}, 4864 authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4865 callback: account_osAccount.IUserAuthCallback) => {}, 4866 getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions, 4867 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => { 4868 // mock getting account information 4869 // notify result 4870 let code: BusinessError = { 4871 code: 0, 4872 name: "", 4873 message: "" 4874 }; 4875 let accountInfo: account_osAccount.DomainAccountInfo = { 4876 domain: options.domain, 4877 accountName: options.accountName, 4878 accountId: 'xxxx' 4879 }; 4880 callback(code, accountInfo); 4881 }, 4882 getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4883 callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {}, 4884 bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number, 4885 callback: AsyncCallback<void>) => {}, 4886 unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 4887 isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4888 callback: AsyncCallback<boolean>) => {}, 4889 getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 4890 } 4891 account_osAccount.DomainAccountManager.registerPlugin(plugin) 4892 ``` 4893 4894### getAuthStatusInfo<sup>10+</sup> 4895 4896getAuthStatusInfo(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback<AuthStatusInfo>): void 4897 4898查询指定域帐号的认证状态信息。 4899 4900**系统接口:** 此接口为系统接口。 4901 4902**系统能力:** SystemCapability.Account.OsAccount 4903 4904**参数:** 4905 4906| 参数名 | 类型 | 必填 | 说明 | 4907| ---------- | --------------------------------------- | ---- | --------------- | 4908| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 4909| callback | AsyncCallback<[AuthStatusInfo](#authstatusinfo10)> | 是 | 指示查询结果回调。| 4910 4911**示例:** 4912 ```ts 4913 import { AsyncCallback, BusinessError } from '@ohos.base'; 4914 let plugin: account_osAccount.DomainPlugin = { 4915 auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array, 4916 callback: account_osAccount.IUserAuthCallback) => {}, 4917 authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4918 callback: account_osAccount.IUserAuthCallback) => {}, 4919 authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4920 callback: account_osAccount.IUserAuthCallback) => {}, 4921 getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions, 4922 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {}, 4923 getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4924 callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => { 4925 let code: BusinessError = { 4926 code: 0, 4927 name: "", 4928 message: "" 4929 }; 4930 let statusInfo: account_osAccount.AuthStatusInfo = { 4931 remainTimes: 5, 4932 freezingTime: 0 4933 }; 4934 callback(code, statusInfo); 4935 }, 4936 bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number, 4937 callback: AsyncCallback<void>) => {}, 4938 unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 4939 isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4940 callback: AsyncCallback<boolean>) => {}, 4941 getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 4942 } 4943 account_osAccount.DomainAccountManager.registerPlugin(plugin) 4944 ``` 4945 4946### bindAccount<sup>10+</sup> 4947 4948bindAccount(domainAccountInfo: DomainAccountInfo, localId: number, callback: AsyncCallback<void>): void 4949 4950绑定指定的域帐号。 4951 4952**系统接口:** 此接口为系统接口。 4953 4954**系统能力:** SystemCapability.Account.OsAccount 4955 4956**参数:** 4957 4958| 参数名 | 类型 | 必填 | 说明 | 4959| ---------- | --------------------------------------- | ---- | --------------- | 4960| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 4961| callback | AsyncCallback<void> | 是 | 指示绑定结果回调。| 4962 4963**示例:** 4964 ```ts 4965 import { AsyncCallback, BusinessError } from '@ohos.base'; 4966 let plugin: account_osAccount.DomainPlugin = { 4967 auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array, 4968 callback: account_osAccount.IUserAuthCallback) => {}, 4969 authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4970 callback: account_osAccount.IUserAuthCallback) => {}, 4971 authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4972 callback: account_osAccount.IUserAuthCallback) => {}, 4973 getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions, 4974 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {}, 4975 getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo, 4976 callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {}, 4977 bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number, 4978 callback: AsyncCallback<void>) => { 4979 // mock unbinding operation 4980 // notify binding result 4981 let code: BusinessError = { 4982 code: 0, 4983 name: "", 4984 message: "" 4985 }; 4986 callback(code); 4987 }, 4988 unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 4989 isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 4990 callback: AsyncCallback<boolean>) => {}, 4991 getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 4992 } 4993 account_osAccount.DomainAccountManager.registerPlugin(plugin) 4994 ``` 4995 4996### unbindAccount<sup>10+</sup> 4997 4998unbindAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback<void>): void 4999 5000解绑指定的域帐号。 5001 5002**系统接口:** 此接口为系统接口。 5003 5004**系统能力:** SystemCapability.Account.OsAccount 5005 5006**参数:** 5007 5008| 参数名 | 类型 | 必填 | 说明 | 5009| ---------- | --------------------------------------- | ---- | --------------- | 5010| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 5011| callback | AsyncCallback<void> | 是 | 指示绑定结果回调。| 5012 5013**示例:** 5014 ```ts 5015 import { AsyncCallback, BusinessError } from '@ohos.base'; 5016 let plugin: account_osAccount.DomainPlugin = { 5017 auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array, 5018 callback: account_osAccount.IUserAuthCallback) => {}, 5019 authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo, 5020 callback: account_osAccount.IUserAuthCallback) => {}, 5021 authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 5022 callback: account_osAccount.IUserAuthCallback) => {}, 5023 getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions, 5024 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {}, 5025 getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo, 5026 callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {}, 5027 bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number, 5028 callback: AsyncCallback<void>) => {}, 5029 unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => { 5030 // mock unbinding operation 5031 // notify unbinding result 5032 let code: BusinessError = { 5033 code: 0, 5034 name: "", 5035 message: "" 5036 }; 5037 callback(code); 5038 }, 5039 isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 5040 callback: AsyncCallback<boolean>) => {}, 5041 getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 5042 } 5043 account_osAccount.DomainAccountManager.registerPlugin(plugin) 5044 ``` 5045 5046### isAccountTokenValid<sup>10+</sup> 5047 5048isAccountTokenValid(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: AsyncCallback<boolean>): void 5049 5050检查指定的域帐号令牌是否有效。 5051 5052**系统接口:** 此接口为系统接口。 5053 5054**系统能力:** SystemCapability.Account.OsAccount 5055 5056**参数:** 5057 5058| 参数名 | 类型 | 必填 | 说明 | 5059| ---------- | --------------------------------------- | ---- | --------------- | 5060| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 5061| token | Uint8Array | 是 | 指示域帐号令牌。 | 5062| callback | AsyncCallback<boolean> | 是 | 指示检查结果回调。| 5063 5064**示例:** 5065 ```ts 5066 import { AsyncCallback, BusinessError } from '@ohos.base'; 5067 let plugin: account_osAccount.DomainPlugin = { 5068 auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array, 5069 callback: account_osAccount.IUserAuthCallback) => {}, 5070 authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo, 5071 callback: account_osAccount.IUserAuthCallback) => {}, 5072 authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 5073 callback: account_osAccount.IUserAuthCallback) => {}, 5074 getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions, 5075 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {}, 5076 getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo, 5077 callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {}, 5078 bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number, 5079 callback: AsyncCallback<void>) => {}, 5080 unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 5081 isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 5082 callback: AsyncCallback<boolean>) => { 5083 // mock checking operation 5084 // notify checking result 5085 let code: BusinessError = { 5086 code: 0, 5087 name: "", 5088 message: "" 5089 }; 5090 callback(code, true); 5091 }, 5092 getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 5093 } 5094 account_osAccount.DomainAccountManager.registerPlugin(plugin) 5095 ``` 5096 5097### getAccessToken<sup>10+</sup> 5098 5099getAccessToken(options: GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>): void 5100 5101根据指定的选项获取域访问令牌。 5102 5103**系统接口:** 此接口为系统接口。 5104 5105**系统能力:** SystemCapability.Account.OsAccount 5106 5107**参数:** 5108 5109| 参数名 | 类型 | 必填 | 说明 | 5110| ---------- | --------------------------------------- | ---- | --------------- | 5111| options | [GetDomainAccessTokenOptions](#getdomainaccesstokenoptions10) | 是 | 指示获取域访问令牌的选项。| 5112| callback | AsyncCallback<Uint8Array> | 是 | 指示结果回调。| 5113 5114**示例:** 5115 ```ts 5116 import { AsyncCallback, BusinessError } from '@ohos.base'; 5117 let plugin: account_osAccount.DomainPlugin = { 5118 auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array, 5119 callback: account_osAccount.IUserAuthCallback) => {}, 5120 authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo, 5121 callback: account_osAccount.IUserAuthCallback) => {}, 5122 authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 5123 callback: account_osAccount.IUserAuthCallback) => {}, 5124 getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions, 5125 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {}, 5126 getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo, 5127 callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {}, 5128 bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number, 5129 callback: AsyncCallback<void>) => {}, 5130 unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 5131 isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 5132 callback: AsyncCallback<boolean>) => {}, 5133 getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => { 5134 // mock getting operation 5135 // notify result 5136 let code: BusinessError = { 5137 code: 0, 5138 name: "", 5139 message: "" 5140 }; 5141 let token: Uint8Array = new Uint8Array([0]); 5142 callback(code, token); 5143 } 5144 } 5145 account_osAccount.DomainAccountManager.registerPlugin(plugin) 5146 ``` 5147 5148## DomainAccountManager <sup>9+</sup> 5149域帐号管理器类。 5150 5151### registerPlugin<sup>9+</sup> 5152 5153static registerPlugin(plugin: DomainPlugin): void 5154 5155注册域插件。 5156 5157**系统接口:** 此接口为系统接口。 5158 5159**系统能力:** SystemCapability.Account.OsAccount 5160 5161**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 5162 5163**参数:** 5164 5165| 参数名 | 类型 | 必填 | 说明 | 5166| ----------| ----------------------- | --- | -------------------------- | 5167| plugin | [DomainPlugin](#domainplugin9) | 是 | 指示域插件。 | 5168 5169**错误码:** 5170 5171| 错误码ID | 错误信息 | 5172| -------- | --------------------------- | 5173| 12300201 | The domain plugin has been registered. | 5174 5175**示例:** 5176 ```ts 5177 import { AsyncCallback } from '@ohos.base'; 5178 let plugin: account_osAccount.DomainPlugin = { 5179 auth: (domainAccountInfo: account_osAccount.DomainAccountInfo, credential: Uint8Array, 5180 callback: account_osAccount.IUserAuthCallback) => {}, 5181 authWithPopup: (domainAccountInfo: account_osAccount.DomainAccountInfo, 5182 callback: account_osAccount.IUserAuthCallback) => {}, 5183 authWithToken: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 5184 callback: account_osAccount.IUserAuthCallback) => {}, 5185 getAccountInfo: (options: account_osAccount.GetDomainAccountInfoPluginOptions, 5186 callback: AsyncCallback<account_osAccount.DomainAccountInfo>) => {}, 5187 getAuthStatusInfo: (domainAccountInfo: account_osAccount.DomainAccountInfo, 5188 callback: AsyncCallback<account_osAccount.AuthStatusInfo>) => {}, 5189 bindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, localId: number, 5190 callback: AsyncCallback<void>) => {}, 5191 unbindAccount: (domainAccountInfo: account_osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 5192 isAccountTokenValid: (domainAccountInfo: account_osAccount.DomainAccountInfo, token: Uint8Array, 5193 callback: AsyncCallback<boolean>) => {}, 5194 getAccessToken: (options: account_osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 5195 } 5196 try { 5197 account_osAccount.DomainAccountManager.registerPlugin(plugin); 5198 console.log('registerPlugin success.'); 5199 } catch(err) { 5200 console.log('registerPlugin err:' + JSON.stringify(err)); 5201 } 5202 ``` 5203 5204### unregisterPlugin<sup>9+</sup> 5205 5206static unregisterPlugin(): void 5207 5208注销域插件。 5209 5210**系统接口:** 此接口为系统接口。 5211 5212**系统能力:** SystemCapability.Account.OsAccount 5213 5214**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 5215 5216**示例:** 5217 ```ts 5218 try { 5219 account_osAccount.DomainAccountManager.unregisterPlugin(); 5220 console.log('unregisterPlugin success.'); 5221 } catch(err) { 5222 console.log('unregisterPlugin err:' + JSON.stringify(err)); 5223 } 5224 ``` 5225 5226### auth<sup>10+</sup> 5227 5228auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void 5229 5230认证指定的域帐号。 5231 5232**系统接口:** 此接口为系统接口。 5233 5234**系统能力:** SystemCapability.Account.OsAccount 5235 5236**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 5237 5238**参数:** 5239 5240| 参数名 | 类型 | 必填 | 说明 | 5241| ---------- | --------------------------------------- | ---- | --------------- | 5242| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 5243| credential | Uint8Array | 是 | 指示域帐号的凭据。| 5244| callback | [IUserAuthCallback](#iuserauthcallback8) | 是 | 指示认证结果回调。| 5245 5246**错误码:** 5247 5248| 错误码ID | 错误信息 | 5249| -------- | --------------------------- | 5250| 12300001 | System service exception. | 5251| 12300002 | Invalid domainAccountInfo or credential. | 5252| 12300003 | Domain account does not exist. | 5253| 12300013 | Network exception. | 5254| 12300101 | Authentication failed. | 5255| 12300109 | Authentication is canceled. | 5256| 12300110 | Authentication is locked. | 5257| 12300111 | Authentication timeout. | 5258| 12300112 | Authentication service is busy. | 5259| 12300113 | Authentication service does not exist. | 5260| 12300114 | Authentication service exception. | 5261 5262**示例:** 5263 ```ts 5264 let domainAccountInfo: account_osAccount.DomainAccountInfo = { 5265 domain: 'CHINA', 5266 accountName: 'zhangsan' 5267 } 5268 let credential = new Uint8Array([0]) 5269 try { 5270 account_osAccount.DomainAccountManager.auth(domainAccountInfo, credential, { 5271 onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => { 5272 console.log('auth resultCode = ' + resultCode); 5273 console.log('auth authResult = ' + JSON.stringify(authResult)); 5274 } 5275 }); 5276 } catch (err) { 5277 console.log('auth exception = ' + JSON.stringify(err)); 5278 } 5279 ``` 5280 5281### authWithPopup<sup>10+</sup> 5282 5283authWithPopup(callback: IUserAuthCallback): void 5284 5285弹框认证指定的域帐号。 5286 5287**系统接口:** 此接口为系统接口。 5288 5289**系统能力:** SystemCapability.Account.OsAccount 5290 5291**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 5292 5293**参数:** 5294 5295| 参数名 | 类型 | 必填 | 说明 | 5296| ---------- | --------------------------------------- | ---- | --------------- | 5297| callback | [IUserAuthCallback](#iuserauthcallback8) | 是 | 指示认证结果回调。| 5298 5299**错误码:** 5300 5301| 错误码ID | 错误信息 | 5302| -------- | --------------------------- | 5303| 12300001 | System service exception. | 5304| 12300003 | No domain account is bound. | 5305| 12300013 | Network exception. | 5306| 12300101 | Authentication failed. | 5307| 12300109 | Authentication is canceled. | 5308| 12300110 | Authentication is locked. | 5309| 12300111 | Authentication timeout. | 5310| 12300112 | Authentication service is busy. | 5311| 12300113 | Authentication service does not exist. | 5312| 12300114 | Authentication service exception. | 5313 5314**示例:** 5315 ```ts 5316 try { 5317 account_osAccount.DomainAccountManager.authWithPopup({ 5318 onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => { 5319 console.log('auth resultCode = ' + resultCode); 5320 console.log('auth authResult = ' + JSON.stringify(authResult)); 5321 } 5322 }) 5323 } catch (err) { 5324 console.log('auth exception = ' + JSON.stringify(err)); 5325 } 5326 ``` 5327 5328### authWithPopup<sup>10+</sup> 5329 5330authWithPopup(localId: number, callback: IUserAuthCallback): void 5331 5332弹框认证指定的域帐号。 5333 5334**系统接口:** 此接口为系统接口。 5335 5336**系统能力:** SystemCapability.Account.OsAccount 5337 5338**需要权限:** ohos.permission.ACCESS_USER_AUTH_INTERNAL 5339 5340**参数:** 5341 5342| 参数名 | 类型 | 必填 | 说明 | 5343| ---------- | --------------------------------------- | ---- | --------------- | 5344| localId | number | 是 | 指示绑定域帐号的系统帐号的本地标识。| 5345| callback | [IUserAuthCallback](#iuserauthcallback8) | 是 | 指示认证结果回调。| 5346 5347**错误码:** 5348 5349| 错误码ID | 错误信息 | 5350| -------- | --------------------------- | 5351| 12300001 | System service exception. | 5352| 12300002 | Invalid localId. | 5353| 12300003 | No domain account is bound. | 5354| 12300013 | Network exception. | 5355| 12300101 | Authentication failed. | 5356| 12300109 | Authentication is canceled. | 5357| 12300110 | Authentication is locked. | 5358| 12300111 | Authentication timeout. | 5359| 12300112 | Authentication service is busy. | 5360| 12300113 | Authentication service does not exist. | 5361| 12300114 | Authentication service exception. | 5362 5363**示例:** 5364 ```ts 5365 try { 5366 account_osAccount.DomainAccountManager.authWithPopup(100, { 5367 onResult: (resultCode: number, authResult: account_osAccount.AuthResult) => { 5368 console.log('authWithPopup resultCode = ' + resultCode); 5369 console.log('authWithPopup authResult = ' + JSON.stringify(authResult)); 5370 } 5371 }) 5372 } catch (err) { 5373 console.log('authWithPopup exception = ' + JSON.stringify(err)); 5374 } 5375 ``` 5376 5377### hasAccount<sup>10+</sup> 5378 5379hasAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback<boolean>): void 5380 5381检查是否存在指定的域帐号。 5382 5383**系统接口:** 此接口为系统接口。 5384 5385**系统能力:** SystemCapability.Account.OsAccount 5386 5387**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 5388 5389**参数:** 5390 5391| 参数名 | 类型 | 必填 | 说明 | 5392| ---------- | --------------------------------------- | ---- | --------------- | 5393| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 5394| callback | AsyncCallback<boolean> | 是 | 指示检查结果回调。| 5395 5396**错误码:** 5397 5398| 错误码ID | 错误信息 | 5399| -------- | --------------------------- | 5400| 12300001 | System service exception. | 5401| 12300002 | Invalid domainAccountInfo. | 5402| 12300013 | Network exception. | 5403| 12300111 | Operation timeout. | 5404 5405**示例:** 5406 ```ts 5407 import { BusinessError } from '@ohos.base'; 5408 let domainAccountInfo: account_osAccount.DomainAccountInfo = { 5409 domain: 'CHINA', 5410 accountName: 'zhangsan' 5411 } 5412 try { 5413 account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo, (err: BusinessError, result: boolean) => { 5414 if (err) { 5415 console.log('call hasAccount failed, error: ' + JSON.stringify(err)); 5416 } else { 5417 console.log('hasAccount result: ' + result); 5418 } 5419 }); 5420 } catch (err) { 5421 console.log('hasAccount exception = ' + JSON.stringify(err)); 5422 } 5423 ``` 5424 5425### hasAccount<sup>10+</sup> 5426 5427hasAccount(domainAccountInfo: DomainAccountInfo): Promise<boolean> 5428 5429检查是否存在指定的域帐号。 5430 5431**系统接口:** 此接口为系统接口。 5432 5433**系统能力:** SystemCapability.Account.OsAccount 5434 5435**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 5436 5437**参数:** 5438 5439| 参数名 | 类型 | 必填 | 说明 | 5440| ---------- | --------------------------------------- | ---- | --------------- | 5441| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 5442 5443**返回值:** 5444 5445| 类型 | 说明 | 5446| :------------------------ | ----------------------- | 5447| Promise<boolean> | Promise对象,返回指定的域帐号是否存在。 | 5448 5449**错误码:** 5450 5451| 错误码ID | 错误信息 | 5452| -------- | --------------------------- | 5453| 12300001 | System service exception. | 5454| 12300002 | Invalid domainAccountInfo. | 5455| 12300013 | Network exception. | 5456| 12300111 | Operation timeout. | 5457 5458**示例:** 5459 ```ts 5460 import { BusinessError } from '@ohos.base'; 5461 let domainAccountInfo: account_osAccount.DomainAccountInfo = { 5462 domain: 'CHINA', 5463 accountName: 'zhangsan' 5464 } 5465 try { 5466 account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo).then((result: boolean) => { 5467 console.log('hasAccount result: ' + result); 5468 }).catch((err: BusinessError) => { 5469 console.log('call hasAccount failed, error: ' + JSON.stringify(err)); 5470 }); 5471 } catch (err) { 5472 console.log('hasAccount exception = ' + JSON.stringify(err)); 5473 } 5474 ``` 5475 5476### updateAccountToken<sup>10+</sup> 5477 5478updateAccountToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: AsyncCallback<void>): void; 5479 5480更新指定域帐号的令牌,空令牌表示目标域帐号的令牌失效。使用callback异步回调。 5481 5482**系统接口:** 此接口为系统接口。 5483 5484**系统能力:** SystemCapability.Account.OsAccount 5485 5486**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 5487 5488**参数:** 5489 5490| 参数名 | 类型 | 必填 | 说明 | 5491| ---------- | --------------------------------------- | ---- | --------------- | 5492| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 5493| token | Uint8Array | 是 | 指示域帐号的令牌。| 5494| callback | AsyncCallback<void> | 是 | 回调函数。如果更新成功,err为null,否则为错误对象。| 5495 5496**错误码:** 5497 5498| 错误码ID | 错误信息 | 5499| -------- | --------------------------- | 5500| 12300001 | System service exception. | 5501| 12300002 | Invalid token. | 5502| 12300003 | Account not found. | 5503 5504**示例:** 5505 ```ts 5506 import { BusinessError } from '@ohos.base'; 5507 let domainAccountInfo: account_osAccount.DomainAccountInfo = { 5508 domain: 'CHINA', 5509 accountName: 'zhangsan', 5510 accountId: '123456' 5511 } 5512 let token = new Uint8Array([0]) 5513 try { 5514 account_osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token, (err: BusinessError) => { 5515 if (err != null) { 5516 console.log('updateAccountToken failed, error: ' + JSON.stringify(err)); 5517 } else { 5518 console.log('updateAccountToken successfully'); 5519 } 5520 }) 5521 } catch (err) { 5522 console.log('updateAccountToken exception = ' + JSON.stringify(err)); 5523 } 5524 ``` 5525 5526### updateAccountToken<sup>10+</sup> 5527 5528updateAccountToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array): Promise<void> 5529 5530更新指定域帐号的令牌,空令牌表示目标域帐号的令牌失效。使用Promise异步回调。 5531 5532**系统接口:** 此接口为系统接口。 5533 5534**系统能力:** SystemCapability.Account.OsAccount 5535 5536**需要权限:** ohos.permission.MANAGE_LOCAL_ACCOUNTS 5537 5538**参数:** 5539 5540| 参数名 | 类型 | 必填 | 说明 | 5541| ---------- | --------------------------------------- | ---- | --------------- | 5542| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 指示域帐号信息。| 5543| token | Uint8Array | 是 | 指示域帐号的令牌。| 5544 5545**返回值:** 5546 5547| 类型 | 说明 | 5548| :------------------------ | ----------------------- | 5549| Promise<void> | Promise对象,无返回结果的Promise对象。 | 5550 5551**错误码:** 5552 5553| 错误码ID | 错误信息 | 5554| -------- | --------------------------- | 5555| 12300001 | System service exception. | 5556| 12300002 | Invalid token. | 5557| 12300003 | Account not found. | 5558 5559**示例:** 5560 ```ts 5561 import { BusinessError } from '@ohos.base'; 5562 let domainAccountInfo: account_osAccount.DomainAccountInfo = { 5563 domain: 'CHINA', 5564 accountName: 'zhangsan', 5565 accountId: '123456' 5566 } 5567 let token = new Uint8Array([0]) 5568 try { 5569 account_osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token).then(() => { 5570 console.log('updateAccountToken successfully'); 5571 }).catch((err: BusinessError) => { 5572 console.log('updateAccountToken failed, error: ' + JSON.stringify(err)); 5573 }); 5574 } catch (err) { 5575 console.log('updateAccountToken exception = ' + JSON.stringify(err)); 5576 } 5577 ``` 5578 5579### getAccountInfo<sup>10+</sup> 5580 5581getAccountInfo(options: GetDomainAccountInfoOptions, callback: AsyncCallback<DomainAccountInfo>): void 5582 5583查询指定的域帐号信息,callback方式。 5584 5585**系统接口:** 此接口为系统接口。 5586 5587**系统能力:** SystemCapability.Account.OsAccount 5588 5589**需要权限:** ohos.permission.GET_DOMAIN_ACCOUNTS 5590 5591**参数:** 5592 5593| 参数名 | 类型 | 必填 | 说明 | 5594| ---------- | --------------------------------------- | ---- | --------------- | 5595| options | [GetDomainAccountInfoOptions](#getdomainaccountinfooptions10) | 是 | 指示域帐号信息。| 5596| callback | AsyncCallback<DomainAccountInfo> | 是 | 指示查询结果回调。| 5597 5598**错误码:** 5599 5600| 错误码ID | 错误信息 | 5601| -------- | --------------------------- | 5602| 12300001 | System service exception. | 5603| 12300003 | Account not found. | 5604| 12300013 | Network exception. | 5605| 12300111 | Operation timeout. | 5606 5607**示例:** 5608 ```ts 5609 import { BusinessError } from '@ohos.base'; 5610 let domainAccountInfo: account_osAccount.GetDomainAccountInfoOptions = { 5611 domain: 'CHINA', 5612 accountName: 'zhangsan' 5613 } 5614 try { 5615 account_osAccount.DomainAccountManager.getAccountInfo(domainAccountInfo, 5616 (err: BusinessError, result: account_osAccount.DomainAccountInfo) => { 5617 if (err) { 5618 console.log('call getAccountInfo failed, error: ' + JSON.stringify(err)); 5619 } else { 5620 console.log('getAccountInfo result: ' + result); 5621 } 5622 }); 5623 } catch (err) { 5624 console.log('getAccountInfo exception = ' + JSON.stringify(err)); 5625 } 5626 ``` 5627 5628### getAccountInfo<sup>10+</sup> 5629 5630getAccountInfo(options: GetDomainAccountInfoOptions): Promise<DomainAccountInfo> 5631 5632查询指定的域帐号信息,promise方式。 5633 5634**系统接口:** 此接口为系统接口。 5635 5636**系统能力:** SystemCapability.Account.OsAccount 5637 5638**需要权限:** ohos.permission.GET_DOMAIN_ACCOUNTS 5639 5640**参数:** 5641 5642| 参数名 | 类型 | 必填 | 说明 | 5643| ---------- | --------------------------------------- | ---- | --------------- | 5644| options | [GetDomainAccountInfoOptions](#getdomainaccountinfooptions10) | 是 | 指示域帐号信息。| 5645 5646**返回值:** 5647 5648| 类型 | 说明 | 5649| :------------------------ | ----------------------- | 5650| Promise<DomainAccountInfo> | Promise对象,返回指定的域帐号信息。 | 5651 5652**错误码:** 5653 5654| 错误码ID | 错误信息 | 5655| -------- | --------------------------- | 5656| 12300001 | System service exception. | 5657| 12300003 | Account not found. | 5658| 12300013 | Network exception. | 5659| 12300111 | Operation timeout. | 5660 5661**示例:** 5662 ```ts 5663 import { BusinessError } from '@ohos.base'; 5664 let domainAccountInfo: account_osAccount.GetDomainAccountInfoOptions = { 5665 domain: 'CHINA', 5666 accountName: 'zhangsan' 5667 } 5668 try { 5669 account_osAccount.DomainAccountManager.getAccountInfo(domainAccountInfo) 5670 .then((result: account_osAccount.DomainAccountInfo) => { 5671 console.log('getAccountInfo result: ' + result); 5672 }).catch((err: BusinessError) => { 5673 console.log('call getAccountInfo failed, error: ' + JSON.stringify(err)); 5674 }); 5675 } catch (err) { 5676 console.log('getAccountInfo exception = ' + JSON.stringify(err)); 5677 } 5678 ``` 5679 5680## UserIdentityManager<sup>8+</sup> 5681 5682获取用户身份管理类。 5683 5684**系统接口:** 此接口为系统接口。 5685 5686### constructor<sup>8+</sup> 5687 5688constructor() 5689 5690用户身份管理类的默认构造函数。 5691 5692**系统接口:** 此接口为系统接口。 5693 5694**系统能力**:SystemCapability.Account.OsAccount 5695 5696**示例:** 5697 ```ts 5698 let userIDM = new account_osAccount.UserIdentityManager(); 5699 ``` 5700 5701### openSession<sup>8+</sup> 5702 5703openSession(callback: AsyncCallback<Uint8Array>): void; 5704 5705打开会话,获取挑战值。使用callback异步回调。 5706 5707**系统接口:** 此接口为系统接口。 5708 5709**系统能力:** SystemCapability.Account.OsAccount 5710 5711**需要权限:** ohos.permission.MANAGE_USER_IDM 5712 5713**参数:** 5714 5715| 参数名 | 类型 | 必填 | 说明 | 5716| -------- | -------------------------------- | ---- | -------------------------------------------------------------- | 5717| callback | AsyncCallback<Uint8Array> | 是 | 回调函数。如果打开会话成功,err为null,data为挑战值;否则为错误对象。| 5718 5719**错误码:** 5720 5721| 错误码ID | 错误信息 | 5722| -------- | --------------------------- | 5723| 12300001 | System service exception. | 5724 5725**示例:** 5726 ```ts 5727 import { BusinessError } from '@ohos.base'; 5728 let userIDM = new account_osAccount.UserIdentityManager(); 5729 try { 5730 userIDM.openSession((err: BusinessError, challenge: Uint8Array) => { 5731 console.log('openSession error = ' + JSON.stringify(err)); 5732 console.log('openSession challenge = ' + JSON.stringify(challenge)); 5733 }); 5734 } catch (e) { 5735 console.log('openSession exception = ' + JSON.stringify(e)); 5736 } 5737 ``` 5738 5739### openSession<sup>8+</sup> 5740 5741openSession(): Promise<Uint8Array>; 5742 5743打开会话,获取挑战值。使用Promise异步回调。 5744 5745**系统接口:** 此接口为系统接口。 5746 5747**系统能力:** SystemCapability.Account.OsAccount 5748 5749**需要权限:** ohos.permission.MANAGE_USER_IDM 5750 5751**返回值:** 5752 5753| 类型 | 说明 | 5754| :------------------------ | ----------------------- | 5755| Promise<Uint8Array> | Promise对象,返回挑战值。 | 5756 5757**错误码:** 5758 5759| 错误码ID | 错误信息 | 5760| -------- | --------------------------- | 5761| 12300001 | System service exception. | 5762 5763**示例:** 5764 ```ts 5765 import { BusinessError } from '@ohos.base'; 5766 let userIDM = new account_osAccount.UserIdentityManager(); 5767 try { 5768 userIDM.openSession().then((challenge: Uint8Array) => { 5769 console.info('openSession challenge = ' + JSON.stringify(challenge)); 5770 }).catch((err: BusinessError) => { 5771 console.info('openSession error = ' + JSON.stringify(err)); 5772 }); 5773 } catch (e) { 5774 console.log('openSession exception = ' + JSON.stringify(e)); 5775 } 5776 ``` 5777 5778### addCredential<sup>8+</sup> 5779 5780addCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void; 5781 5782添加凭据,添加用户凭据信息,传入凭据添加方法和凭据信息(凭据类型,子类,如果添加用户的非密码凭据,则传入密码身份验证令牌),并获取结果/获取信息。 5783 5784**系统接口:** 此接口为系统接口。 5785 5786**系统能力:** SystemCapability.Account.OsAccount 5787 5788**需要权限:** ohos.permission.MANAGE_USER_IDM 5789 5790**参数:** 5791 5792| 参数名 | 类型 | 必填 | 说明 | 5793| --------------- | ------------------------------------ | --- | ---------------------------- | 5794| credentialInfo | [CredentialInfo](#credentialinfo8) | 是 | 指示凭据信息。 | 5795| callback | [IIdmCallback](#iidmcallback8) | 是 | 回调对象,返回添加凭据的结果。 | 5796 5797**错误码:** 5798 5799| 错误码ID | 错误信息 | 5800| -------- | ------------------- | 5801| 12300001 | System service exception. | 5802| 12300002 | Invalid credentialInfo, i.e. authType or authSubType. | 5803| 12300101 | Token is invalid. | 5804| 12300106 | Unsupported authType. | 5805| 12300109 | Operation is canceled. | 5806| 12300111 | Operation timeout. | 5807| 12300115 | The number of credentials reaches the upper limit. | 5808 5809**示例:** 5810 ```ts 5811 import { BusinessError } from '@ohos.base'; 5812 let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]); 5813 let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth(); 5814 pinAuth.registerInputer({ 5815 onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => { 5816 callback.onSetData(authSubType, password); 5817 } 5818 }); 5819 let credentialInfo: account_osAccount.CredentialInfo = { 5820 credType: account_osAccount.AuthType.PIN, 5821 credSubType: account_osAccount.AuthSubType.PIN_SIX, 5822 token: new Uint8Array([]), 5823 }; 5824 let userIDM = new account_osAccount.UserIdentityManager(); 5825 userIDM.openSession((err: BusinessError, challenge: Uint8Array) => { 5826 try { 5827 userIDM.addCredential(credentialInfo, { 5828 onResult: (result: number, extraInfo: account_osAccount.RequestResult) => { 5829 console.log('addCredential result = ' + result); 5830 console.log('addCredential extraInfo = ' + extraInfo); 5831 } 5832 }); 5833 } catch (e) { 5834 console.log('addCredential exception = ' + JSON.stringify(e)); 5835 } 5836 }); 5837 ``` 5838 5839### updateCredential<sup>8+</sup> 5840 5841updateCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void; 5842 5843更新凭据。使用callback异步回调。 5844 5845**系统接口:** 此接口为系统接口。 5846 5847**系统能力:** SystemCapability.Account.OsAccount 5848 5849**需要权限:** ohos.permission.MANAGE_USER_IDM 5850 5851**参数:** 5852 5853| 参数名 | 类型 | 必填 | 说明 | 5854| --------------- | ------------------------------------- | --- | ------------------------- | 5855| credentialInfo | [CredentialInfo](#credentialinfo8) | 是 | 指示凭据信息。 | 5856| callback | [IIdmCallback](#iidmcallback8) | 是 | 回调对象,返回更新凭据的结果。 | 5857 5858**错误码:** 5859 5860| 错误码ID | 错误信息 | 5861| -------- | ------------------- | 5862| 12300001 | System service exception. | 5863| 12300002 | Invalid credentialInfo, i.e. authType or authSubType or token. | 5864| 12300101 | Token is invalid. | 5865| 12300102 | Credential not enrolled.| 5866| 12300106 | Unsupported authType. | 5867| 12300109 | Operation is canceled. | 5868| 12300111 | Operation timeout. | 5869 5870**示例:** 5871 ```ts 5872 import { BusinessError } from '@ohos.base'; 5873 let userIDM = new account_osAccount.UserIdentityManager(); 5874 let userAuth: account_osAccount.UserAuth = new account_osAccount.UserAuth(); 5875 let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth(); 5876 let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]); 5877 let credentialInfo: account_osAccount.CredentialInfo = { 5878 credType: account_osAccount.AuthType.PIN, 5879 credSubType: account_osAccount.AuthSubType.PIN_SIX, 5880 token: new Uint8Array([]), 5881 }; 5882 pinAuth.registerInputer({ 5883 onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => { 5884 callback.onSetData(authSubType, password); 5885 } 5886 }); 5887 userIDM.openSession((err: BusinessError, challenge: Uint8Array) => { 5888 userAuth.auth(challenge, credentialInfo.credType, account_osAccount.AuthTrustLevel.ATL1, { 5889 onResult: (result: number, extraInfo: account_osAccount.AuthResult) => { 5890 if (result != account_osAccount.ResultCode.SUCCESS) { 5891 return; 5892 } 5893 if (extraInfo.token != null) { 5894 credentialInfo.token = extraInfo.token; 5895 } 5896 try { 5897 userIDM.updateCredential(credentialInfo, { 5898 onResult: (result: number, extraInfo: account_osAccount.RequestResult) => { 5899 console.log('updateCredential result = ' + result); 5900 console.log('updateCredential extraInfo = ' + extraInfo); 5901 } 5902 }); 5903 } catch (e) { 5904 console.log('updateCredential exception = ' + JSON.stringify(e)); 5905 } 5906 } 5907 }); 5908 }); 5909 ``` 5910 5911### closeSession<sup>8+</sup> 5912 5913closeSession(): void; 5914 5915关闭会话,结束IDM操作。 5916 5917**系统接口:** 此接口为系统接口。 5918 5919**系统能力:** SystemCapability.Account.OsAccount 5920 5921**需要权限:** ohos.permission.MANAGE_USER_IDM 5922 5923**示例:** 5924 ```ts 5925 let userIDM = new account_osAccount.UserIdentityManager(); 5926 userIDM.closeSession(); 5927 ``` 5928 5929### cancel<sup>8+</sup> 5930 5931cancel(challenge: Uint8Array): void; 5932 5933根据挑战值取消条目。 5934 5935**系统接口:** 此接口为系统接口。 5936 5937**系统能力:** SystemCapability.Account.OsAccount 5938 5939**需要权限:** ohos.permission.MANAGE_USER_IDM 5940 5941**参数:** 5942 5943| 参数名 | 类型 | 必填 | 说明 | 5944| -------- | ----------- | ---- | ----- | 5945| challenge | Uint8Array | 是 | 挑战值。 | 5946 5947**错误码:** 5948 5949| 错误码ID | 错误信息 | 5950| -------- | ------------------- | 5951| 12300001 | System service exception. | 5952| 12300002 | Invalid challenge. | 5953 5954**示例:** 5955 ```ts 5956 let userIDM = new account_osAccount.UserIdentityManager(); 5957 let challenge: Uint8Array = new Uint8Array([0]); 5958 try { 5959 userIDM.cancel(challenge); 5960 } catch(err) { 5961 console.log('cancel err:' + JSON.stringify(err)); 5962 } 5963 ``` 5964 5965### delUser<sup>8+</sup> 5966 5967delUser(token: Uint8Array, callback: IIdmCallback): void; 5968 5969删除具有身份验证令牌的用户,使用callback方式异步返回结果。 5970 5971**系统接口:** 此接口为系统接口。 5972 5973**系统能力:** SystemCapability.Account.OsAccount 5974 5975**需要权限:** ohos.permission.MANAGE_USER_IDM 5976 5977**参数:** 5978 5979| 参数名 | 类型 | 必填 | 说明 | 5980| -------- | ------------------------------ | --- | ------------------------- | 5981| token | Uint8Array | 是 | 身份验证令牌。 | 5982| callback | [IIdmCallback](#iidmcallback8) | 是 | 回调对象,返回删除用户的结果。| 5983 5984**错误码:** 5985 5986| 错误码ID | 错误信息 | 5987| -------- | ------------------- | 5988| 12300001 | System service exception. | 5989| 12300101 | Token is invalid. | 5990 5991**示例:** 5992 ```ts 5993 let userIDM = new account_osAccount.UserIdentityManager(); 5994 let token: Uint8Array = new Uint8Array([0]); 5995 try { 5996 userIDM.delUser(token, { 5997 onResult: (result: number, extraInfo: account_osAccount.RequestResult) => { 5998 console.log('delUser result = ' + result); 5999 console.log('delUser extraInfo = ' + JSON.stringify(extraInfo)); 6000 } 6001 }); 6002 } catch (e) { 6003 console.log('delUser exception = ' + JSON.stringify(e)); 6004 } 6005 ``` 6006 6007### delCred<sup>8+</sup> 6008 6009delCred(credentialId: Uint8Array, token: Uint8Array, callback: IIdmCallback): void; 6010 6011删除用户凭据信息。 6012 6013**系统接口:** 此接口为系统接口。 6014 6015**系统能力:** SystemCapability.Account.OsAccount 6016 6017**需要权限:** ohos.permission.MANAGE_USER_IDM 6018 6019**参数:** 6020 6021| 参数名 | 类型 | 必填 | 说明 | 6022| --------------- | ----------------------------------- | --- | ---------------------------| 6023| credentialId | Uint8Array | 是 | 凭证索引。 | 6024| token | Uint8Array | 是 | 身份验证令牌。 | 6025| callback | [IIdmCallback](#iidmcallback8) | 是 | 回调对象,返回删除凭据的结果。 | 6026 6027**错误码:** 6028 6029| 错误码ID | 错误信息 | 6030| -------- | ------------------- | 6031| 12300001 | System service exception. | 6032| 12300002 | Invalid credentialId. | 6033| 12300101 | Token is invalid. | 6034| 12300102 | Credential not enrolled. | 6035 6036**示例:** 6037 ```ts 6038 let userIDM = new account_osAccount.UserIdentityManager(); 6039 let credentialId: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0]); 6040 let token: Uint8Array = new Uint8Array([0]); 6041 try { 6042 userIDM.delCred(credentialId, token, { 6043 onResult: (result: number, extraInfo: account_osAccount.RequestResult) => { 6044 console.log('delCred result = ' + result); 6045 console.log('delCred extraInfo = ' + JSON.stringify(extraInfo)); 6046 } 6047 }); 6048 } catch (e) { 6049 console.log('delCred exception = ' + JSON.stringify(e)); 6050 } 6051 ``` 6052 6053### getAuthInfo<sup>8+</sup> 6054 6055getAuthInfo(callback: AsyncCallback<Array<EnrolledCredInfo>>): void; 6056 6057获取认证信息。使用callback异步回调。 6058 6059**系统接口:** 此接口为系统接口。 6060 6061**系统能力:** SystemCapability.Account.OsAccount 6062 6063**需要权限:** ohos.permission.USE_USER_IDM 6064 6065**参数:** 6066 6067| 参数名 | 类型 | 必填 | 说明 | 6068| -------- | ------------------------------------------------------------------------ | ---- | --------------------------------------------- | 6069| callback | AsyncCallback<Array<[EnrolledCredInfo](#enrolledcredinfo8)>> | 是 | 回调函数。如果成功,err为null,data为当前用户的所有已注册凭据信息;否则为错误对象。| 6070 6071**错误码:** 6072 6073| 错误码ID | 错误信息 | 6074| -------- | --------------------- | 6075| 12300001 | System service exception. | 6076| 12300102 | Credential not enrolled. | 6077 6078**示例:** 6079 ```ts 6080 import { BusinessError } from '@ohos.base'; 6081 let userIDM = new account_osAccount.UserIdentityManager(); 6082 try { 6083 userIDM.getAuthInfo((err: BusinessError, result: account_osAccount.EnrolledCredInfo[]) => { 6084 console.log('getAuthInfo err = ' + JSON.stringify(err)); 6085 console.log('getAuthInfo result = ' + JSON.stringify(result)); 6086 }); 6087 } catch (e) { 6088 console.log('getAuthInfo exception = ' + JSON.stringify(e)); 6089 } 6090 ``` 6091 6092### getAuthInfo<sup>8+</sup> 6093 6094getAuthInfo(authType: AuthType, callback: AsyncCallback<Array<EnrolledCredInfo>>): void; 6095 6096获取指定类型的认证信息。使用callback异步回调。 6097 6098**系统接口:** 此接口为系统接口。 6099 6100**系统能力:** SystemCapability.Account.OsAccount 6101 6102**需要权限:** ohos.permission.USE_USER_IDM 6103 6104**参数:** 6105 6106| 参数名 | 类型 | 必填 | 说明 | 6107| -------- | -------------------------------------------------- | ---- | -------------------------------------------------- | 6108| authType | [AuthType](#authtype8) | 是 | 认证类型。 | 6109| callback | AsyncCallback<Array<[EnrolledCredInfo](#enrolledcredinfo8)>> | 是 | 回调函数,如果获取成功,err为null,data为当前用户指定类型的所有已注册凭据信息;否则为错误对象。 | 6110 6111**错误码:** 6112 6113| 错误码ID | 错误信息 | 6114| -------- | ------------------- | 6115| 12300001 | System service exception. | 6116| 12300002 | Invalid authType. | 6117| 12300102 | Credential not enrolled. | 6118 6119**示例:** 6120 ```ts 6121 import { BusinessError } from '@ohos.base'; 6122 let userIDM = new account_osAccount.UserIdentityManager(); 6123 try { 6124 userIDM.getAuthInfo(account_osAccount.AuthType.PIN, 6125 (err: BusinessError, result: account_osAccount.EnrolledCredInfo[]) => { 6126 console.log('getAuthInfo err = ' + JSON.stringify(err)); 6127 console.log('getAuthInfo result = ' + JSON.stringify(result)); 6128 }); 6129 } catch (e) { 6130 console.log('getAuthInfo exception = ' + JSON.stringify(e)); 6131 } 6132 ``` 6133 6134### getAuthInfo<sup>8+</sup> 6135 6136getAuthInfo(authType?: AuthType): Promise<Array<EnrolledCredInfo>>; 6137 6138获取认证信息。使用Promise异步回调。 6139 6140**系统接口:** 此接口为系统接口。 6141 6142**系统能力:** SystemCapability.Account.OsAccount 6143 6144**需要权限:** ohos.permission.USE_USER_IDM 6145 6146**参数:** 6147 6148| 参数名 | 类型 | 必填 | 说明 | 6149| -------- | ----------------------------------- | ---- | -------- | 6150| authType | [AuthType](#authtype8) | 否 | 认证类型,默认为空,表示查询所有认证类型的信息。| 6151 6152**返回值:** 6153 6154| 类型 | 说明 | 6155| :------------------------------------------- | :----------------------------------------------------------------------- | 6156| Promise<Array<[EnrolledCredInfo](#enrolledcredinfo8)>> | Promise对象,返回当前用户指定类型的所有已注册凭据信息。| 6157 6158**错误码:** 6159 6160| 错误码ID | 错误信息 | 6161| -------- | ------------------- | 6162| 12300001 | System service exception. | 6163| 12300002 | Invalid authType. | 6164| 12300102 | Credential not enrolled. | 6165 6166**示例:** 6167 ```ts 6168 import { BusinessError } from '@ohos.base'; 6169 let userIDM = new account_osAccount.UserIdentityManager(); 6170 try { 6171 userIDM.getAuthInfo(account_osAccount.AuthType.PIN).then((result: account_osAccount.EnrolledCredInfo[]) => { 6172 console.log('getAuthInfo result = ' + JSON.stringify(result)) 6173 }).catch((err: BusinessError) => { 6174 console.log('getAuthInfo error = ' + JSON.stringify(err)); 6175 }); 6176 } catch (e) { 6177 console.log('getAuthInfo exception = ' + JSON.stringify(e)); 6178 } 6179 ``` 6180 6181## IInputData<sup>8+</sup> 6182 6183密码数据回调。 6184 6185**系统接口:** 此接口为系统接口。 6186 6187### onSetData<sup>8+</sup> 6188 6189onSetData: (authSubType: AuthSubType, data: Uint8Array) => void; 6190 6191**系统接口:** 此接口为系统接口。 6192 6193通知设置数据。 6194 6195**系统能力:** SystemCapability.Account.OsAccount 6196 6197**参数:** 6198 6199| 参数名 | 类型 | 必填 | 说明 | 6200| ---------- | ---------------------------------------- | ---- | ----------------------------------------------- | 6201| authSubType | [AuthSubType](#authsubtype8) | 是 | 用于认证的凭据子类型。 | 6202| data | Uint8Array | 是 | 要设置的数据是凭据,用来在认证、添加、修改凭据操作。 | 6203 6204**错误码:** 6205 6206| 错误码ID | 错误信息 | 6207| -------- | ------------------- | 6208| 12300002 | Invalid pinSubType. | 6209 6210**示例:** 6211 ```ts 6212 let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]); 6213 let passwordNumber: Uint8Array = new Uint8Array([1, 2, 3, 4]); 6214 let inputer: account_osAccount.IInputer = { 6215 onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => { 6216 if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) { 6217 callback.onSetData(authSubType, passwordNumber); 6218 } else { 6219 callback.onSetData(authSubType, password); 6220 } 6221 } 6222 }; 6223 ``` 6224 6225## IInputer<sup>8+</sup> 6226 6227凭据输入器回调。 6228 6229**系统接口:** 此接口为系统接口。 6230 6231### onGetData<sup>8+</sup> 6232 6233onGetData: (authSubType: AuthSubType, callback: IInputData) => void; 6234 6235通知获取数据。 6236 6237**系统接口:** 此接口为系统接口。 6238 6239**系统能力:** SystemCapability.Account.OsAccount 6240 6241**参数:** 6242 6243| 参数名 | 类型 | 必填 | 说明 | 6244| ---------- | --------------------------------------- | ---- | --------------- | 6245| callback | [IInputData](#iinputdata8) | 是 | 指示密码数据回调。| 6246 6247**示例:** 6248 ```ts 6249 let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]); 6250 let passwordNumber: Uint8Array = new Uint8Array([1, 2, 3, 4]); 6251 let inputer: account_osAccount.IInputer = { 6252 onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => { 6253 if (authSubType == account_osAccount.AuthSubType.PIN_NUMBER) { 6254 callback.onSetData(authSubType, passwordNumber); 6255 } else { 6256 callback.onSetData(authSubType, password); 6257 } 6258 } 6259 }; 6260 let pinAuth: account_osAccount.PINAuth = new account_osAccount.PINAuth(); 6261 let result = pinAuth.registerInputer(inputer); 6262 console.log('registerInputer result: ' + result); 6263 ``` 6264 6265## IUserAuthCallback<sup>8+</sup> 6266 6267表示用户认证回调类。 6268 6269**系统接口:** 此接口为系统接口。 6270 6271### onResult<sup>8+</sup> 6272 6273onResult: (result: number, extraInfo: AuthResult) => void; 6274 6275身份认证结果回调函数,返回结果码和认证结果信息。 6276 6277**系统接口:** 此接口为系统接口。 6278 6279**系统能力:** SystemCapability.Account.OsAccount 6280 6281**参数:** 6282 6283| 参数名 | 类型 | 必填 | 说明 | 6284| --------- | --------------------------------------- | ---- | ------------------- | 6285| result | number | 是 | 表示身份认证结果代码。| 6286| extraInfo | [AuthResult](#authresult8) | 是 | 表示不同情况下的具体信息,如果认证通过,则在extrainfo中返回认证令牌,如果身份验证失败,则在extrainfo中返回剩余的身份验证时间,如果身份验证执行器被锁定,冻结时间将在extrainfo中返回。| 6287 6288**示例:** 6289 ```ts 6290 let authCallback: account_osAccount.IUserAuthCallback = { 6291 onResult: (result: number, extraInfo: account_osAccount.AuthResult) => { 6292 console.log('auth result = ' + result); 6293 console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); 6294 } 6295 }; 6296 ``` 6297 6298### onAcquireInfo?<sup>8+</sup> 6299 6300onAcquireInfo?: (module: number, acquire: number, extraInfo: any) => void; 6301 6302身份认证信息获取回调函数。 6303 6304**系统接口:** 此接口为系统接口。 6305 6306**系统能力:** SystemCapability.Account.OsAccount 6307 6308**参数:** 6309 6310| 参数名 | 类型 | 必填 | 说明 | 6311| --------- | ------- | ---- | ----------------------------- | 6312| module | number | 是 | 指示用于身份验证的执行器类型。 | 6313| acquire | number | 是 | 指示不同身份验证执行器的tip代码。| 6314| extraInfo | any | 是 | 保留参数。 | 6315 6316**示例:** 6317 ```ts 6318 let authCallback: account_osAccount.IUserAuthCallback = { 6319 onResult: (result: number, extraInfo: account_osAccount.AuthResult) => { 6320 console.log('auth result = ' + result) 6321 console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); 6322 }, 6323 onAcquireInfo: (module: number, acquire: number, extraInfo: account_osAccount.RequestResult) => { 6324 console.log('auth module = ' + module); 6325 console.log('auth acquire = ' + acquire); 6326 console.info('auth extraInfo = ' + JSON.stringify(extraInfo)); 6327 } 6328 }; 6329 ``` 6330 6331## IIdmCallback<sup>8+</sup> 6332 6333表示身份管理回调类。 6334 6335**系统接口:** 此接口为系统接口。 6336 6337### onResult<sup>8+</sup> 6338 6339onResult: (result: number, extraInfo: RequestResult) => void; 6340 6341身份管理操作结果回调函数,返回结果码和请求结果信息。 6342 6343**系统接口:** 此接口为系统接口。 6344 6345**系统能力:** SystemCapability.Account.OsAccount 6346 6347**参数:** 6348 6349| 参数名 | 类型 | 必填 | 说明 | 6350| --------- | --------------------------------------- | ---- | ----------------------- | 6351| result | number | 是 | 表示身份认证结果代码。 | 6352| extraInfo | [RequestResult](#requestresult8) | 是 | 针对不同情况传递具体信息。| 6353 6354**示例:** 6355 ```ts 6356 let idmCallback: account_osAccount.IIdmCallback = { 6357 onResult: (result: number, extraInfo: account_osAccount.RequestResult) => { 6358 console.log('callback result = ' + result) 6359 console.info('callback extraInfo = ' + JSON.stringify(extraInfo)); 6360 } 6361 }; 6362 ``` 6363 6364### onAcquireInfo?<sup>8+</sup> 6365 6366onAcquireInfo?: (module: number, acquire: number, extraInfo: any) => void; 6367 6368身份管理信息获取回调函数。 6369 6370**系统接口:** 此接口为系统接口。 6371 6372**系统能力:** SystemCapability.Account.OsAccount 6373 6374**参数:** 6375 6376| 参数名 | 类型 | 必填 | 说明 | 6377| --------- | ------- | ---- | ----------------------------- | 6378| module | number | 是 | 指示用于身份验证的执行器类型。 | 6379| acquire | number | 是 | 指示不同身份验证执行器的tip代码。| 6380| extraInfo | any | 是 | 保留参数。 | 6381 6382**示例:** 6383 ```ts 6384 let idmCallback: account_osAccount.IIdmCallback = { 6385 onResult: (result: number, extraInfo: Object) => { 6386 console.log('callback result = ' + result) 6387 console.log('callback onResult = ' + JSON.stringify(extraInfo)); 6388 }, 6389 onAcquireInfo: (module: number, acquire: number, extraInfo: Object) => { 6390 console.log('callback module = ' + module); 6391 console.log('callback acquire = ' + acquire); 6392 console.log('callback onacquireinfo = ' + JSON.stringify(extraInfo)); 6393 } 6394 }; 6395 ``` 6396 6397## GetPropertyRequest<sup>8+</sup> 6398 6399提供获取属性请求的信息。 6400 6401**系统接口:** 此接口为系统接口。 6402 6403**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6404 6405| 名称 | 类型 | 必填 | 说明 | 6406| -------- | ------------------------------------------------------------- | ----- | ----------------------- | 6407| authType | [AuthType](#authtype8) | 是 | 身份验证凭据类型。 | 6408| keys | Array<[GetPropertyType](#getpropertytype8)> | 是 | 指示要获取的属性类型数组。 | 6409 6410## SetPropertyRequest<sup>8+</sup> 6411 6412提供设置属性请求的信息。 6413 6414**系统接口:** 此接口为系统接口。 6415 6416**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6417 6418| 名称 | 类型 | 必填 | 说明 | 6419| -------- | ------------------------------------------------ | ----- | -------------------- | 6420| authType | [AuthType](#authtype8) | 是 | 身份验证凭据类型。 | 6421| key | [SetPropertyType](#setpropertytype8) | 是 | 指示要设置的属性类型。 | 6422| setInfo | Uint8Array | 是 | 指示要设置的信息。 | 6423 6424## ExecutorProperty<sup>8+</sup> 6425 6426提供执行器的属性。 6427 6428**系统接口:** 此接口为系统接口。 6429 6430**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6431 6432| 名称 | 类型 | 可读 | 可写 | 说明 | 6433| ------------ | ---------------------------- | ----- | -----|----------------- | 6434| result | number | 是 | 是 | 指示结果。 | 6435| authSubType | [AuthSubType](#authsubtype8) | 是 | 是 | 指示认证凭据子类型。| 6436| remainTimes | number | 是 | 是 | 指示剩余次数。 | 6437| freezingTime | number | 是 | 是 | 指示冻结时间。 | 6438| enrollmentProgress<sup>10+</sup> | string | 是 | 是 | 指示录入进度,默认为空。 | 6439| sensorInfo<sup>10+</sup> | string | 是 | 是 | 指示传感器信息,默认为空。 | 6440 6441## AuthResult<sup>8+</sup> 6442 6443表示认证结果的信息。 6444 6445**系统接口:** 此接口为系统接口。 6446 6447**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6448 6449| 名称 | 类型 | 必填 | 说明 | 6450| ------------ | ----------- | ----- | ----------------- | 6451| token | Uint8Array | 否 | 指示认证令牌,默认为空。 | 6452| remainTimes | number | 否 | 指示剩余次数,默认为空。 | 6453| freezingTime | number | 否 | 指示冻结时间,默认为空。 | 6454 6455## CredentialInfo<sup>8+</sup> 6456 6457表示凭证信息。 6458 6459**系统接口:** 此接口为系统接口。 6460 6461**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6462 6463| 名称 | 类型 | 必填 | 说明 | 6464| ------------ | ---------------------------------------- | ----- | ----------------- | 6465| credType | [AuthType](#authtype8) | 是 | 指示凭据类型。 | 6466| credSubType | [AuthSubType](#authsubtype8) | 是 | 指示凭据子类型。 | 6467| token | Uint8Array | 是 | 指示认证令牌。 | 6468 6469## RequestResult<sup>8+</sup> 6470 6471表示请求结果的信息。 6472 6473**系统接口:** 此接口为系统接口。 6474 6475**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6476 6477| 名称 | 类型 | 必填 | 说明 | 6478| ------------ | ----------- | ----- | ----------------- | 6479| credentialId | Uint8Array | 否 | 指示凭据索引,默认为空。 | 6480 6481## EnrolledCredInfo<sup>8+</sup> 6482 6483表示已注册凭据的信息。 6484 6485**系统接口:** 此接口为系统接口。 6486 6487**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6488 6489| 名称 | 类型 | 必填 | 说明 | 6490| ------------ | ---------------------------------------- | ----- | ------------------- | 6491| credentialId | Uint8Array | 是 | 指示凭据索引。 | 6492| authType | [AuthType](#authtype8) | 是 | 指示认证凭据类型。 | 6493| authSubType | [AuthSubType](#authsubtype8) | 是 | 指示认证凭据子类型。 | 6494| templateId | Uint8Array | 是 | 指示凭据模板ID。 | 6495 6496## GetPropertyType<sup>8+</sup> 6497 6498表示要获取的属性类型的枚举。 6499 6500**系统接口:** 此接口为系统接口。 6501 6502**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6503 6504| 名称 | 值 | 说明 | 6505| ------------- | ------ | --------- | 6506| AUTH_SUB_TYPE | 1 | 认证子类型。 | 6507| REMAIN_TIMES | 2 | 剩余时间。 | 6508| FREEZING_TIME | 3 | 冻结时间。 | 6509| ENROLLMENT_PROGRESS<sup>10+</sup> | 4 | 录入进度。 | 6510| SENSOR_INFO<sup>10+</sup> | 5 | 传感器信息。 | 6511 6512## SetPropertyType<sup>8+</sup> 6513 6514表示要设置的属性类型的枚举。 6515 6516**系统接口:** 此接口为系统接口。 6517 6518**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6519 6520| 名称 | 值 | 说明 | 6521| -------------- | ----- | ----------- | 6522| INIT_ALGORITHM | 1 | 初始化算法。 | 6523 6524## AuthType<sup>8+</sup> 6525 6526表示身份验证的凭据类型的枚举。 6527 6528**系统接口:** 此接口为系统接口。 6529 6530**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6531 6532| 名称 | 值 | 说明 | 6533| ----- | ----- | ---------------- | 6534| PIN | 1 | 表示PIN认证类型。 | 6535| FACE | 2 | 表示脸部认证类型。| 6536| FINGERPRINT<sup>10+</sup> | 4 | 表示指纹认证类型。 | 6537| DOMAIN<sup>9+</sup> | 1024 | 表示域认证类型。| 6538 6539## AuthSubType<sup>8+</sup> 6540 6541表示用于认证的凭据子类型的枚举。 6542 6543**系统接口:** 此接口为系统接口。 6544 6545**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6546 6547| 名称 | 值 | 说明 | 6548| ---------- | ----- | ------------------ | 6549| PIN_SIX | 10000 | 表示6位凭证。 | 6550| PIN_NUMBER | 10001 | 表示自定义数字凭证。 | 6551| PIN_MIXED | 10002 | 表示自定义混合凭据。 | 6552| FACE_2D | 20000 | 表示2D 人脸凭证。 | 6553| FACE_3D | 20001 | 表示3D 人脸凭证。 | 6554| FINGERPRINT_CAPACITIVE<sup>10+</sup> | 30000 | 表示电容式指纹。 | 6555| FINGERPRINT_OPTICAL<sup>10+</sup> | 30001 | 表示光学指纹。 | 6556| FINGERPRINT_ULTRASONIC<sup>10+</sup> | 30002 | 表示超声波指纹。 | 6557| DOMAIN_MIXED<sup>9+</sup> | 10240001 | 表示域认证混合凭证。 | 6558 6559## AuthTrustLevel<sup>8+</sup> 6560 6561表示认证结果的受信任级别的枚举。 6562 6563**系统接口:** 此接口为系统接口。 6564 6565**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6566 6567| 名称 | 值 | 说明 | 6568| ---- | ------ | ----------- | 6569| ATL1 | 10000 | 信任级别 1。 | 6570| ATL2 | 20000 | 信任级别 2。 | 6571| ATL3 | 30000 | 信任级别 3。 | 6572| ATL4 | 40000 | 信任级别 4。 | 6573 6574## Module<sup>8+</sup> 6575 6576表示获取信息的模块的枚举。 6577 6578**系统接口:** 此接口为系统接口。 6579 6580**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6581 6582| 名称 | 值 | 说明 | 6583| --------- | ------ | ------------------------ | 6584| FACE_AUTH | 1 | 表示从人脸认证获取的信息。 | 6585 6586## ResultCode<sup>8+</sup> 6587 6588表示身份验证结果码。 6589 6590**系统接口:** 此接口为系统接口。 6591 6592**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6593 6594| 名称 | 值 | 说明 | 6595| ----------------------- | ----- | ---------------------------------------- | 6596| SUCCESS | 0 | 表示身份验证成功或支持此功能。 | 6597| FAIL | 1 | 表示验证器无法识别用户。 | 6598| GENERAL_ERROR | 2 | 表示其他错误。 | 6599| CANCELED | 3 | 表示身份验证已取消。 | 6600| TIMEOUT | 4 | 表示身份验证已超时。 | 6601| TYPE_NOT_SUPPORT | 5 | 表示不支持此身份验证类型。 | 6602| TRUST_LEVEL_NOT_SUPPORT | 6 | 表示不支持身份验证信任级别。 | 6603| BUSY | 7 | 表示身份验证任务正忙。等待几秒钟,然后重试。 | 6604| INVALID_PARAMETERS | 8 | 表示参数不正确。 | 6605| LOCKED | 9 | 指示身份验证器已锁定。 | 6606| NOT_ENROLLED | 10 | 表示用户尚未注册验证器。 | 6607 6608## FaceTipsCode<sup>8+</sup> 6609 6610表示人脸验证过程中提示的枚举。 6611 6612**系统接口:** 此接口为系统接口。 6613 6614**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6615 6616| 名称 | 值 | 说明 | 6617| ----------------------------- | ----- | ---------------------------------------- | 6618| FACE_AUTH_TIP_TOO_BRIGHT | 1 | 表示由于高照明,获得的面部图像太亮。 | 6619| FACE_AUTH_TIP_TOO_DARK | 2 | 表示由于照明度低,获得的面部图像太暗。 | 6620| FACE_AUTH_TIP_TOO_CLOSE | 3 | 表示面部离设备太近。 | 6621| FACE_AUTH_TIP_TOO_FAR | 4 | 表示面部离设备太远。 | 6622| FACE_AUTH_TIP_TOO_HIGH | 5 | 表示设备太高,仅捕捉面部上部。 | 6623| FACE_AUTH_TIP_TOO_LOW | 6 | 表示设备太低,仅捕捉面部下部。 | 6624| FACE_AUTH_TIP_TOO_RIGHT | 7 | 指示设备向右偏移,并且仅捕捉面部的右侧部分。 | 6625| FACE_AUTH_TIP_TOO_LEFT | 8 | 指示设备向左偏移,并且仅捕捉面部的左侧部分。 | 6626| FACE_AUTH_TIP_TOO_MUCH_MOTION | 9 | 表示面部信息收集过程中面部移动过快。 | 6627| FACE_AUTH_TIP_POOR_GAZE | 10 | 表示面未朝向设备。 | 6628| FACE_AUTH_TIP_NOT_DETECTED | 11 | 表示未检测到人脸。 | 6629 6630## FingerprintTips<sup>8+</sup> 6631 6632表示指纹身份验证过程中提示的枚举。 6633 6634**系统接口:** 此接口为系统接口。 6635 6636**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount 6637 6638| 名称 | 值 | 说明 | 6639| ----------------------------- | ----- | ----------------------------------------------- | 6640| FINGERPRINT_TIP_GOOD | 0 | 表示采集的图像良好。 | 6641| FINGERPRINT_TIP_IMAGER_DIRTY | 1 | 表示由于传感器上可疑或检测到污垢,指纹图像噪声过大。 | 6642| FINGERPRINT_TIP_INSUFFICIENT | 2 | 表示由于检测到的情况,指纹图像噪声太大,无法处理。 | 6643| FINGERPRINT_TIP_PARTIAL | 3 | 表示仅检测到部分指纹图像。 | 6644| FINGERPRINT_TIP_TOO_FAST | 4 | 表示指纹图像由于快速运动而不完整。 | 6645| FINGERPRINT_TIP_TOO_SLOW | 5 | 表示由于缺少运动,指纹图像无法读取。 | 6646| FINGERPRINT_TIP_FINGER_DOWN<sup>10+</sup> | 6 | 表示手指落下。 | 6647| FINGERPRINT_TIP_FINGER_UP<sup>10+</sup> | 7 | 表示手指抬起。 | 6648 6649## OsAccountInfo 6650 6651表示系统帐号信息。 6652 6653**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。 6654 6655| 名称 | 类型 | 必填 | 说明 | 6656| ------------------------------ | ------------------------------------------------------------ | ---- | --------------------------------- | 6657| localId | number | 是 | 系统帐号ID。 | 6658| localName | string | 是 | 系统帐号名称。 | 6659| type | [OsAccountType](#osaccounttype) | 是 | 系统帐号类型。 | 6660| constraints | Array<string> | 否 | 系统帐号[约束](#系统帐号约束列表),默认为空。| 6661| isVerified<sup>8+</sup> | boolean | 是 | 帐号是否验证。 | 6662| photo<sup>8+</sup> | string | 否 | 系统帐号头像,默认为空。 | 6663| createTime<sup>8+</sup> | number | 是 | 系统帐号创建时间。 | 6664| lastLoginTime<sup>8+</sup> | number | 否 | 系统帐号最后一次登录时间,默认为空。 | 6665| serialNumber<sup>8+</sup> | number | 是 | 系统帐号SN码。 | 6666| isActived<sup>8+</sup> | boolean | 是 | 系统帐号激活状态。 | 6667| isCreateCompleted<sup>8+</sup> | boolean | 是 | 系统帐号创建是否完整。 | 6668| distributedInfo | [distributedAccount.DistributedInfo](js-apis-distributed-account.md#distributedinfo) | 否 | 分布式帐号信息,默认为空。 | 6669| domainInfo<sup>8+</sup> | [DomainAccountInfo](#domainaccountinfo8) | 否 | 域帐号信息,默认为空。 | 6670 6671## DomainAccountInfo<sup>8+</sup> 6672 6673表示域帐号信息。 6674 6675**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。 6676 6677| 名称 | 类型 | 必填 | 说明 | 6678| ----------- | ------ | ---- | ---------- | 6679| domain | string | 是 | 域名。 | 6680| accountName | string | 是 | 域帐号名。 | 6681| accountId<sup>10+</sup> | string | 否 | 域帐号标识。<br>**系统接口:** 此接口为系统接口,默认为空。 | 6682 6683## 系统帐号约束列表 6684 6685| 约束 | 说明 | 6686| ------------------------------------- | ------------------------------ | 6687| constraint.wifi | 禁止使用Wi-Fi | 6688| constraint.wifi.set | 禁止配置Wi-Fi | 6689| constraint.locale.set | 禁止配置设备语言 | 6690| constraint.app.accounts | 禁止添加和删除应用帐号 | 6691| constraint.apps.install | 禁止安装应用 | 6692| constraint.apps.uninstall | 禁止卸载应用 | 6693| constraint.location.shared | 禁止打开位置共享 | 6694| constraint.unknown.sources.install | 禁止安装未知来源的应用 | 6695| constraint.global.unknown.app.install | 禁止所有用户安装未知来源的应用 | 6696| constraint.bluetooth.set | 禁止配置蓝牙 | 6697| constraint.bluetooth | 禁止使用蓝牙 | 6698| constraint.bluetooth.share | 禁止共享使用蓝牙 | 6699| constraint.usb.file.transfer | 禁止通过USB传输文件 | 6700| constraint.credentials.set | 禁止配置用户凭据 | 6701| constraint.os.account.remove | 禁止删除用户 | 6702| constraint.managed.profile.remove | 禁止删除此用户的托管配置文件 | 6703| constraint.debug.features.use | J禁止启用或访问调试功能 | 6704| constraint.vpn.set | 禁止配置VPN | 6705| constraint.date.time.set | 禁止配置日期时间和时区 | 6706| constraint.tethering.config | 禁止配置Tethering | 6707| constraint.network.reset | 禁止重置网络设置 | 6708| constraint.factory.reset | 禁止出厂设置 | 6709| constraint.os.account.create | 禁止创建新用户 | 6710| constraint.add.managed.profile | 禁止添加托管配置文件 | 6711| constraint.apps.verify.disable | 强制应用程序验证 | 6712| constraint.cell.broadcasts.set | 禁止配置小区广播 | 6713| constraint.mobile.networks.set | 禁止配置移动网络 | 6714| constraint.control.apps | 禁止在设置或启动模块中修改应用程序 | 6715| constraint.physical.media | 禁止装载物理外部介质 | 6716| constraint.microphone | 禁止使用麦克风 | 6717| constraint.microphone.unmute | 禁止取消麦克风静音 | 6718| constraint.volume.adjust | 禁止调整音量 | 6719| constraint.calls.outgoing | 禁止拨打外呼电话 | 6720| constraint.sms.use | 禁止发送或接收短信 | 6721| constraint.fun | 禁止享受乐趣 | 6722| constraint.windows.create | 禁止创建应用程序窗口以外的窗口 | 6723| constraint.system.error.dialogs | 禁止显示崩溃或无响应应用程序的系统错误对话框 | 6724| constraint.cross.profile.copy.paste | 禁止通过将数据粘贴到其他用户或配置文件来导出剪贴板内容 | 6725| constraint.beam.outgoing | 禁止使用NFC从应用程序传送数据 | 6726| constraint.wallpaper | 禁止管理壁纸 | 6727| constraint.safe.boot | 禁止进入安全引导模式 | 6728| constraint.parent.profile.app.linking | 允许父配置文件中的应用程序处理来自托管配置文件的Web链接 | 6729| constraint.audio.record | 禁止录制音频 | 6730| constraint.camera.use | 禁止使用摄像机 | 6731| constraint.os.account.background.run | 禁止在后台运行 | 6732| constraint.data.roam | 禁止漫游通话时使用蜂窝数据 | 6733| constraint.os.account.set.icon | 禁止修改用户头像 | 6734| constraint.wallpaper.set | 禁止设置壁纸 | 6735| constraint.oem.unlock | 禁止启用oem解锁 | 6736| constraint.device.unmute | 禁止取消设备静音 | 6737| constraint.password.unified | 禁止托管配置文件与主用户进行统一锁屏质询 | 6738| constraint.autofill | 禁止使用自动填充服务 | 6739| constraint.content.capture | 禁止捕获用户屏幕 | 6740| constraint.content.suggestions | 禁止接收内容建议 | 6741| constraint.os.account.start | 禁止切换用户 | 6742| constraint.location.set | 禁止配置位置服务 | 6743| constraint.airplane.mode.set | 禁止飞行模式 | 6744| constraint.brightness.set | 禁止配置亮度 | 6745| constraint.share.into.profile | 禁止将主要用户的文件/图片/数据共享到托管配置文件中 | 6746| constraint.ambient.display | 禁止显示环境 | 6747| constraint.screen.timeout.set | 禁止配置屏幕关闭的超时 | 6748| constraint.print | 禁止打印 | 6749| constraint.private.dns.set | 禁止配置专用DNS | 6750 6751## ConstraintSourceTypeInfo<sup>9+</sup> 6752 6753表示约束来源类型信息。 6754 6755**系统接口:** 此接口为系统接口。 6756 6757**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。 6758 6759| 名称 | 类型 | 必填 | 说明 | 6760| ----------- | ------ | ---- | ---------- | 6761| localId | number | 是 | 系统帐号ID | 6762| type | [ConstraintSourceType](#constraintsourcetype9) | 是 | 约束来源类型 | 6763 6764## ConstraintSourceType<sup>9+</sup> 6765 6766表示约束来源类型的枚举。 6767 6768**系统接口:** 此接口为系统接口。 6769 6770**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。 6771 6772| 名称 | 值 | 说明 | 6773| ------ | ------ | ------------ | 6774| CONSTRAINT_NOT_EXIST | 0 | 约束不存在 | 6775| CONSTRAINT_TYPE_BASE | 1 | 约束源自系统设置 | 6776| CONSTRAINT_TYPE_DEVICE_OWNER | 2 | 约束源自设备所有者设置 | 6777| CONSTRAINT_TYPE_PROFILE_OWNER | 3 | 约束源自资料所有者设置 | 6778 6779## AuthStatusInfo<sup>10+</sup> 6780 6781表示认证状态信息。 6782 6783**系统接口:** 此接口为系统接口。 6784 6785**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。 6786 6787| 名称 | 类型 | 必填 | 说明 | 6788| ----------- | ------ | ---- | ---------- | 6789| remainTimes | number | 是 | 剩余次数 | 6790| freezingTime | number | 是 | 冻结时间 | 6791 6792## GetDomainAccessTokenOptions<sup>10+</sup> 6793 6794表示获取域访问令牌的选项。 6795 6796**系统接口:** 此接口为系统接口。 6797 6798**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。 6799 6800| 名称 | 类型 | 必填 | 说明 | 6801| ----------- | ------ | ---- | ---------- | 6802| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | 是 | 域帐号的信息 | 6803| domainAccountToken | Uint8Array | 是 | 域帐号的令牌 | 6804| businessParams | { [key: string]: object } | 是 | 业务参数,由业务方根据请求协议自定义 | 6805| callerUid | number | 是 | 调用方唯一标识符 | 6806 6807## GetDomainAccountInfoOptions<sup>10+</sup> 6808 6809表示查询域帐号信息的选项。 6810 6811**系统接口:** 此接口为系统接口。 6812 6813**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。 6814 6815| 名称 | 类型 | 必填 | 说明 | 6816| ----------- | ------ | ---- | ---------- | 6817| accountName | string | 是 | 域帐号名。 | 6818| domain | string | 否 | 域名。 | 6819 6820## GetDomainAccountInfoPluginOptions<sup>10+</sup> 6821 6822表示插件查询域帐号信息的选项。GetDomainAccountInfoPluginOptions类继承[GetDomainAccountInfoOptions](#getdomainaccountinfooptions10) 6823 6824**系统接口:** 此接口为系统接口。 6825 6826**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.OsAccount。 6827 6828| 名称 | 类型 | 必填 | 说明 | 6829| ----------- | ------ | ---- | ---------- | 6830| callerUid | number | 是 | 调用方唯一标识符 | 6831