1# @ohos.account.osAccount (System Account) (System API) 2 3The **osAccount** module provides basic capabilities for managing system (OS) accounts, including adding, deleting, querying, setting, subscribing to, and enabling a system account. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [ohos.account.osAccount (System Account Management)](js-apis-osAccount.md). 9 10## Modules to Import 11 12```ts 13import { osAccount } from '@kit.BasicServicesKit'; 14``` 15 16## AccountManager 17 18Provides APIs for managing system accounts. 19 20### activateOsAccount 21 22activateOsAccount(localId: number, callback: AsyncCallback<void>): void 23 24Activates a system account. This API uses an asynchronous callback to return the result. 25 26**System API**: This is a system API. 27 28**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 29 30**System capability**: SystemCapability.Account.OsAccount 31 32**Parameters** 33 34| Name | Type | Mandatory| Description | 35| -------- | ------------------------- | ---- | -------------------------------------------------- | 36| localId | number | Yes | ID of the target system account. | 37| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 38 39**Error codes** 40 41| ID| Error Message | 42| -------- | ------------------- | 43| 201 | Permission denied.| 44| 202 | Not system application.| 45| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 46| 12300001 | The system service works abnormally. | 47| 12300002 | Invalid localId. | 48| 12300003 | Account not found. | 49| 12300008 | Restricted Account. | 50| 12300016 | The number of logged in accounts reaches the upper limit. | 51 52**Example**: Activate system account 100. 53 ```ts 54 import { BusinessError } from '@kit.BasicServicesKit'; 55 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 56 let localId: number = 100; 57 try { 58 accountManager.activateOsAccount(localId, (err: BusinessError)=>{ 59 if (err) { 60 console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`); 61 } else { 62 console.log('activateOsAccount successfully'); 63 } 64 }); 65 } catch (err) { 66 console.log('activateOsAccount failed, error:' + JSON.stringify(err)); 67 } 68 ``` 69 70### activateOsAccount 71 72activateOsAccount(localId: number): Promise<void> 73 74Activates a system account. This API uses a promise to return the result. 75 76**System API**: This is a system API. 77 78**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 79 80**System capability**: SystemCapability.Account.OsAccount 81 82**Parameters** 83 84| Name | Type | Mandatory| Description | 85| ------- | ------ | ---- | -------------------- | 86| localId | number | Yes | ID of the target system account.| 87 88**Return value** 89 90| Type | Description | 91| ------------------- | ------------------------------------ | 92| Promise<void> | Promise that returns no value.| 93 94**Error codes** 95 96| ID| Error Message | 97| -------- | ------------------- | 98| 201 | Permission denied.| 99| 202 | Not system application.| 100| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 101| 12300001 | The system service works abnormally. | 102| 12300002 | Invalid localId. | 103| 12300003 | Account not found. | 104| 12300008 | Restricted Account. | 105| 12300016 | The number of logged in accounts reaches the upper limit. | 106 107**Example**: Activate system account 100. 108 ```ts 109 import { BusinessError } from '@kit.BasicServicesKit'; 110 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 111 let localId: number = 100; 112 try { 113 accountManager.activateOsAccount(localId).then(() => { 114 console.log('activateOsAccount successfully'); 115 }).catch((err: BusinessError) => { 116 console.log('activateOsAccount failed, err:' + JSON.stringify(err)); 117 }); 118 } catch (e) { 119 console.log('activateOsAccount exception: ' + JSON.stringify(e)); 120 } 121 ``` 122 123### deactivateOsAccount<sup>12+</sup> 124 125deactivateOsAccount(localId: number): Promise<void> 126 127Deactivates (logs out of) a system account. This API uses a promise to return the result. 128 129**System API**: This is a system API. 130 131**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 132 133**System capability**: SystemCapability.Account.OsAccount 134 135**Parameters** 136 137| Name | Type | Mandatory| Description | 138| ------- | ------ | ---- | -------------------- | 139| localId | number | Yes | ID of the target system account.| 140 141**Return value** 142 143| Type | Description | 144| ------------------- | ------------------------------------ | 145| Promise<void> | Promise that returns no value.| 146 147**Error codes** 148 149| ID| Error Message | 150| -------- | ------------------- | 151| 201 | Permission denied.| 152| 202 | Not system application.| 153| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 154| 12300001 | The system service works abnormally. | 155| 12300003 | Account not found. | 156| 12300008 | Restricted Account. | 157 158**Example**: Deactivate system account 100. 159 ```ts 160 import { BusinessError } from '@kit.BasicServicesKit'; 161 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 162 let localId: number = 100; 163 try { 164 accountManager.deactivateOsAccount(localId).then(() => { 165 console.log('deactivateOsAccount successfully'); 166 }).catch((err: BusinessError) => { 167 console.log('deactivateOsAccount failed, err:' + JSON.stringify(err)); 168 }); 169 } catch (e) { 170 console.log('deactivateOsAccount exception: ' + JSON.stringify(e)); 171 } 172 ``` 173 174### isOsAccountActivated<sup>11+</sup> 175 176isOsAccountActivated(localId: number): Promise<boolean> 177 178Checks whether a system account is activated. This API uses a promise to return the result. 179 180**System API**: This is a system API. 181 182**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 183 184**System capability**: SystemCapability.Account.OsAccount 185 186**Parameters** 187 188| Name | Type | Mandatory| Description | 189| ------- | ------ | ---- | --------------------------------- | 190| localId | number | Yes | ID of the target system account.| 191 192**Return value** 193 194| Type | Description | 195| ---------------------- | ---------------------------------------------------------- | 196| Promise<boolean> | Promise used to return the result. The value **true** means the account is activated; the value **false** means the opposite.| 197 198**Error codes** 199 200| ID| Error Message | 201| -------- | ------------------- | 202| 201 | Permission denied.| 203| 202 | Not system application.| 204| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 205| 12300001 | The system service works abnormally. | 206| 12300003 | Account not found. | 207 208**Example**: Check whether system account 100 is activated. 209 210 ```ts 211 import { BusinessError } from '@kit.BasicServicesKit'; 212 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 213 let localId: number = 100; 214 try { 215 accountManager.isOsAccountActivated(localId).then((isActivated: boolean) => { 216 console.log('isOsAccountActivated successfully, isActivated: ' + isActivated); 217 }).catch((err: BusinessError) => { 218 console.log('isOsAccountActivated failed, error: ' + JSON.stringify(err)); 219 }); 220 } catch (err) { 221 console.log('isOsAccountActivated exception: ' + JSON.stringify(err)); 222 } 223 ``` 224 225### isOsAccountConstraintEnabled<sup>11+</sup> 226 227isOsAccountConstraintEnabled(localId: number, constraint: string): Promise<boolean> 228 229Checks whether a constraint is enabled for a system account. This API uses a promise to return the result. 230 231**System API**: This is a system API. 232 233**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 234 235**System capability**: SystemCapability.Account.OsAccount 236 237**Parameters** 238 239| Name | Type | Mandatory| Description | 240| ---------- | ------ | ---- | ---------------------------------- | 241| localId | number | Yes | ID of the target system account. | 242| constraint | string | Yes | [Constraint](js-apis-osAccount.md#constraints) to check.| 243 244**Return value** 245 246| Type | Description | 247| --------------------- | --------------------------------------------------------------------- | 248| Promise<boolean> | Promise used to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.| 249 250**Error codes** 251 252| ID| Error Message | 253| -------- | ------------------- | 254| 201 | Permission denied.| 255| 202 | Not system application.| 256| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 257| 12300001 | The system service works abnormally. | 258| 12300003 | Account not found. | 259 260**Example**: Check whether system account 100 is forbidden to use Wi-Fi. 261 262 ```ts 263 import { BusinessError } from '@kit.BasicServicesKit'; 264 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 265 let localId: number = 100; 266 let constraint: string = 'constraint.wifi'; 267 try { 268 accountManager.isOsAccountConstraintEnabled(localId, constraint).then((isEnabled: boolean) => { 269 console.log('isOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled); 270 }).catch((err: BusinessError) => { 271 console.log('isOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err)); 272 }); 273 } catch (err) { 274 console.log('isOsAccountConstraintEnabled exception: ' + JSON.stringify(err)); 275 } 276 ``` 277 278### isOsAccountUnlocked<sup>11+</sup> 279 280isOsAccountUnlocked(localId: number): Promise<boolean> 281 282Checks whether a system account has been verified. This API uses a promise to return the result. 283 284**System API**: This is a system API. 285 286**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 287 288**System capability**: SystemCapability.Account.OsAccount 289 290**Parameters** 291 292| Name | Type | Mandatory| Description | 293| ------- | ------ | ---- | --------------------------------------------------------------- | 294| localId | number | Yes | ID of the target system account. If this parameter is not specified, this API checks whether the current system account has been verified.| 295 296**Return value** 297 298| Type | Description | 299| ---------------------- | ----------------------------------------------------------------- | 300| Promise<boolean> | Promise used to return the result. The value **true** means the system account has been verified; the value **false** means the opposite.| 301 302**Error codes** 303 304| ID| Error Message | 305| -------- | ------------------- | 306| 201 | Permission denied.| 307| 202 | Not system application.| 308| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 309| 12300001 | The system service works abnormally. | 310| 12300003 | Account not found. | 311 312**Example** 313 314 ```ts 315 import { BusinessError } from '@kit.BasicServicesKit'; 316 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 317 let localId: number = 100; 318 try { 319 accountManager.isOsAccountUnlocked(localId).then((isVerified: boolean) => { 320 console.log('isOsAccountUnlocked successfully, isVerified: ' + isVerified); 321 }).catch((err: BusinessError) => { 322 console.log('isOsAccountUnlocked failed, error: ' + JSON.stringify(err)); 323 }); 324 } catch (err) { 325 console.log('isOsAccountUnlocked exception: ' + JSON.stringify(err)); 326 } 327 ``` 328 329### removeOsAccount 330 331removeOsAccount(localId: number, callback: AsyncCallback<void>): void 332 333Removes a system account. This API uses an asynchronous callback to return the result. 334 335**System API**: This is a system API. 336 337**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 338 339**System capability**: SystemCapability.Account.OsAccount 340 341**Parameters** 342 343| Name | Type | Mandatory| Description | 344| -------- | ------------------------- | ---- | -------------------------------------------------- | 345| localId | number | Yes | ID of the target system account. | 346| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 347 348**Error codes** 349 350| ID| Error Message | 351| -------- | ------------------- | 352| 201 | Permission denied.| 353| 202 | Not system application.| 354| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 355| 12300001 | The system service works abnormally. | 356| 12300002 | Invalid localId. | 357| 12300003 | Account not found. | 358| 12300008 | Restricted Account. | 359| 12300010 | Service busy. Possible causes: The target account is being operated. | 360 361**Example** 362 363 ```ts 364 import { BusinessError } from '@kit.BasicServicesKit'; 365 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 366 let accountName: string = 'testAccountName'; 367 try { 368 accountManager.createOsAccount(accountName, osAccount.OsAccountType.NORMAL, 369 (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo) => { 370 accountManager.removeOsAccount(osAccountInfo.localId, (err: BusinessError)=>{ 371 if (err) { 372 console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); 373 } else { 374 console.log('removeOsAccount successfully'); 375 } 376 }); 377 }); 378 } catch (err) { 379 console.log('removeOsAccount exception: ' + JSON.stringify(err)); 380 } 381 ``` 382 383### removeOsAccount 384 385removeOsAccount(localId: number): Promise<void> 386 387Removes a system account. This API uses a promise to return the result. 388 389**System API**: This is a system API. 390 391**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 392 393**System capability**: SystemCapability.Account.OsAccount 394 395**Parameters** 396 397| Name | Type | Mandatory| Description | 398| ------- | ------ | ---- | --------------------------------- | 399| localId | number | Yes | ID of the target system account.| 400 401**Return value** 402 403| Type | Description | 404| ------------------- | ------------------------------------ | 405| Promise<void> | Promise that returns no value.| 406 407**Error codes** 408 409| ID| Error Message | 410| -------- | ------------------- | 411| 201 | Permission denied.| 412| 202 | Not system application.| 413| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 414| 12300001 | The system service works abnormally. | 415| 12300002 | Invalid localId. | 416| 12300003 | Account not found. | 417| 12300008 | Restricted Account. | 418| 12300010 | Service busy. Possible causes: The target account is being operated. | 419 420**Example** 421 422 ```ts 423 import { BusinessError } from '@kit.BasicServicesKit'; 424 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 425 let accountName: string = 'testAccountName'; 426 try { 427 accountManager.createOsAccount(accountName, osAccount.OsAccountType.NORMAL, 428 (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ 429 accountManager.removeOsAccount(osAccountInfo.localId).then(() => { 430 console.log('removeOsAccount successfully'); 431 }).catch((err: BusinessError) => { 432 console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); 433 }); 434 }); 435 } catch (err) { 436 console.log('removeOsAccount exception: ' + JSON.stringify(err)); 437 } 438 ``` 439 440### setOsAccountConstraints 441 442setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean,callback: AsyncCallback<void>): void 443 444Sets or removes constraints for a system account. This API uses an asynchronous callback to return the result. 445 446**System API**: This is a system API. 447 448**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 449 450**System capability**: SystemCapability.Account.OsAccount 451 452**Parameters** 453 454| Name | Type | Mandatory| Description | 455| ----------- | ------------------------- | ---- | ----------------------------------------------- | 456| localId | number | Yes | ID of the target system account. | 457| constraints | Array<string> | Yes | [Constraints](js-apis-osAccount.md#constraints) to set or remove. | 458| enable | boolean | Yes | Whether to set or remove constraints. The value **true** means to set constraints, and **false** means to remove constraints. | 459| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 460 461**Error codes** 462 463| ID| Error Message | 464| -------- | ------------------- | 465| 201 | Permission denied.| 466| 202 | Not system application.| 467| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 468| 12300001 | The system service works abnormally. | 469| 12300002 | Invalid localId or constraints. | 470| 12300003 | Account not found. | 471| 12300008 | Restricted Account. | 472 473**Example**: Disable Wi-Fi for system account 100. 474 475 ```ts 476 import { BusinessError } from '@kit.BasicServicesKit'; 477 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 478 let localId: number = 100; 479 let constraint: string = 'constraint.wifi'; 480 try { 481 accountManager.setOsAccountConstraints(localId, [constraint], true, (err: BusinessError) => { 482 if (err) { 483 console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); 484 } else { 485 console.log('setOsAccountConstraints successfully'); 486 } 487 }); 488 } catch (err) { 489 console.log('setOsAccountConstraints exception: ' + JSON.stringify(err)); 490 } 491 ``` 492 493### setOsAccountConstraints 494 495setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean): Promise<void> 496 497Sets or removes constraints for a system account. This API uses a promise to return the result. 498 499**System API**: This is a system API. 500 501**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 502 503**System capability**: SystemCapability.Account.OsAccount 504 505**Parameters** 506 507| Name | Type | Mandatory| Description | 508| ----------- | ------------------- | ---- | -------------------------------------------- | 509| localId | number | Yes | ID of the target system account. | 510| constraints | Array<string> | Yes | [Constraints](js-apis-osAccount.md#constraints) to set or remove. | 511| enable | boolean | Yes | Set or remove constraints. The value **true** means to set constraints, and **false** means to remove constraints. | 512 513**Return value** 514 515| Type | Description | 516| :------------------ | :----------------------------------- | 517| Promise<void> | Promise that returns no value.| 518 519**Error codes** 520 521| ID| Error Message | 522| -------- | ------------------- | 523| 201 | Permission denied.| 524| 202 | Not system application.| 525| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 526| 12300001 | The system service works abnormally. | 527| 12300002 | Invalid localId or constraints. | 528| 12300003 | Account not found. | 529| 12300008 | Restricted Account. | 530 531**Example**: Remove the constraint on the use of Wi-Fi for system account 100. 532 533 ```ts 534 import { BusinessError } from '@kit.BasicServicesKit'; 535 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 536 let localId: number = 100; 537 try { 538 accountManager.setOsAccountConstraints(localId, ['constraint.location.set'], false).then(() => { 539 console.log('setOsAccountConstraints succsuccessfully'); 540 }).catch((err: BusinessError) => { 541 console.log('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); 542 }); 543 } catch (err) { 544 console.log('setOsAccountConstraints exception: ' + JSON.stringify(err)); 545 } 546 ``` 547 548### setOsAccountName 549 550setOsAccountName(localId: number, localName: string, callback: AsyncCallback<void>): void 551 552Sets the name of a system account. This API uses an asynchronous callback to return the result. 553 554**System API**: This is a system API. 555 556**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 557 558**System capability**: SystemCapability.Account.OsAccount 559 560**Parameters** 561 562| Name | Type | Mandatory| Description | 563| :-------- | ------------------------- | ---- | ----------------------------------------------- | 564| localId | number | Yes | ID of the target system account. | 565| localName | string | Yes | Account name to set. The value cannot exceed 1024 characters. | 566| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 567 568**Error codes** 569 570| ID| Error Message | 571| -------- | ------------------- | 572| 201 | Permission denied.| 573| 202 | Not system application.| 574| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 575| 12300001 | The system service works abnormally. | 576| 12300002 | Invalid localId or localName. | 577| 12300003 | Account not found. | 578| 12300008 | Restricted Account. | 579 580**Example**: Set the name of system account 100 to **demoName**. 581 582 ```ts 583 import { BusinessError } from '@kit.BasicServicesKit'; 584 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 585 let localId: number = 100; 586 let name: string = 'demoName'; 587 try { 588 accountManager.setOsAccountName(localId, name, (err: BusinessError) => { 589 if (err) { 590 console.log('setOsAccountName failed, error: ' + JSON.stringify(err)); 591 } else { 592 console.log('setOsAccountName successfully'); 593 } 594 }); 595 } catch (err) { 596 console.log('setOsAccountName exception: ' + JSON.stringify(err)); 597 } 598 ``` 599 600### setOsAccountName 601 602setOsAccountName(localId: number, localName: string): Promise<void> 603 604Sets the name of a system account. This API uses a promise to return the result. 605 606**System API**: This is a system API. 607 608**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 609 610**System capability**: SystemCapability.Account.OsAccount 611 612**Parameters** 613 614| Name | Type | Mandatory| Description | 615| --------- | ------ | ---- | --------------------------------- | 616| localId | number | Yes | ID of the target system account.| 617| localName | string | Yes | Account name to set. The value cannot exceed 1024 characters. | 618 619**Return value** 620 621| Type | Description | 622| ------------------- | ------------------------------------ | 623| Promise<void> | Promise that returns no value.| 624 625**Error codes** 626 627| ID| Error Message | 628| -------- | ------------------- | 629| 201 | Permission denied.| 630| 202 | Not system application.| 631| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 632| 12300001 | The system service works abnormally. | 633| 12300002 | Invalid localId or localName. | 634| 12300003 | Account not found. | 635| 12300008 | Restricted Account. | 636 637**Example**: Set the name of system account 100 to **demoName**. 638 639 ```ts 640 import { BusinessError } from '@kit.BasicServicesKit'; 641 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 642 let localId: number = 100; 643 let name: string = 'testName'; 644 try { 645 accountManager.setOsAccountName(localId, name).then(() => { 646 console.log('setOsAccountName successfully'); 647 }).catch((err: BusinessError) => { 648 console.log('setOsAccountName failed, error: ' + JSON.stringify(err)); 649 }); 650 } catch (err) { 651 console.log('setOsAccountName exception: ' + JSON.stringify(err)); 652 } 653 ``` 654 655### queryMaxOsAccountNumber 656 657queryMaxOsAccountNumber(callback: AsyncCallback<number>): void 658 659Queries the maximum number of system accounts that can be created. This API uses an asynchronous callback to return the result. 660 661**System API**: This is a system API. 662 663**System capability**: SystemCapability.Account.OsAccount 664 665**Parameters** 666 667| Name | Type | Mandatory| Description | 668| -------- | --------------------------- | ---- | -------------------------------------------------------------------------------- | 669| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the maximum number of system accounts that can be created. Otherwise, **err** is an error object.| 670 671**Error codes** 672 673| ID| Error Message | 674| -------- | ------------- | 675| 202 | Not system application.| 676| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 677| 12300001 | The system service works abnormally. | 678 679**Example** 680 681 ```ts 682 import { BusinessError } from '@kit.BasicServicesKit'; 683 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 684 try { 685 accountManager.queryMaxOsAccountNumber((err: BusinessError, maxCnt: number) => { 686 if (err) { 687 console.log('queryMaxOsAccountNumber failed, error:' + JSON.stringify(err)); 688 } else { 689 console.log('queryMaxOsAccountNumber successfully, maxCnt:' + maxCnt); 690 } 691 }); 692 } catch (err) { 693 console.log('queryMaxOsAccountNumber exception: ' + JSON.stringify(err)); 694 } 695 ``` 696 697### queryMaxOsAccountNumber 698 699queryMaxOsAccountNumber(): Promise<number> 700 701Queries the maximum number of system accounts that can be created. This API uses a promise to return the result. 702 703**System API**: This is a system API. 704 705**System capability**: SystemCapability.Account.OsAccount 706 707**Return value** 708 709| Type | Description | 710| --------------------- | ------------------------------------------- | 711| Promise<number> | Promise used to return the maximum number of system accounts that can be created.| 712 713**Error codes** 714 715| ID| Error Message | 716| -------- | ------------- | 717| 202 | Not system application.| 718| 12300001 | The system service works abnormally. | 719 720**Example** 721 722 ```ts 723 import { BusinessError } from '@kit.BasicServicesKit'; 724 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 725 try { 726 accountManager.queryMaxOsAccountNumber().then((maxCnt: number) => { 727 console.log('queryMaxOsAccountNumber successfully, maxCnt: ' + maxCnt); 728 }).catch((err: BusinessError) => { 729 console.log('queryMaxOsAccountNumber failed, error: ' + JSON.stringify(err)); 730 }); 731 } catch (err) { 732 console.log('queryMaxOsAccountNumber exception: ' + JSON.stringify(err)); 733 } 734 ``` 735 736### queryMaxLoggedInOsAccountNumber<sup>12+</sup> 737 738queryMaxLoggedInOsAccountNumber(): Promise<number> 739 740Queries the maximum number of system accounts allowed to log in to the system. This API uses a promise to return the result. 741 742**System API**: This is a system API. 743 744**System capability**: SystemCapability.Account.OsAccount 745 746**Return value** 747 748| Type | Description | 749| --------------------- | ------------------------------------------- | 750| Promise<number> | Promise used to return the result.| 751 752**Error codes** 753 754| ID| Error Message | 755| -------- | ------------- | 756| 202 | Not system application.| 757| 12300001 | The system service works abnormally. | 758 759**Example** 760 761 ```ts 762 import { BusinessError } from '@kit.BasicServicesKit'; 763 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 764 try { 765 accountManager.queryMaxLoggedInOsAccountNumber().then((maxNum: number) => { 766 console.log('queryMaxLoggedInOsAccountNumber successfully, maxNum: ' + maxNum); 767 }).catch((err: BusinessError) => { 768 console.log('queryMaxLoggedInOsAccountNumber failed, error: ' + JSON.stringify(err)); 769 }); 770 } catch (err) { 771 console.log('queryMaxLoggedInOsAccountNumber exception: ' + JSON.stringify(err)); 772 } 773 ``` 774 775### getEnabledOsAccountConstraints<sup>11+</sup> 776 777getEnabledOsAccountConstraints(localId: number): Promise<Array<string>> 778 779Obtains all the enabled constraints of a system account. This API uses a promise to return the result. 780 781**System API**: This is a system API. 782 783**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 784 785**System capability**: SystemCapability.Account.OsAccount 786 787**Parameters** 788 789| Name | Type | Mandatory| Description | 790| ------- | ------ | ---- | ------------ | 791| localId | number | Yes | ID of the target system account.| 792 793**Return value** 794 795| Type | Description | 796| ---------------------------------- | ---------------------------------------------------------- | 797| Promise<Array<string>> | Promise used to return all the enabled [constraints](js-apis-osAccount.md#constraints) of the system account.| 798 799**Error codes** 800 801| ID| Error Message | 802| -------- | ------------------- | 803| 201 | Permission denied.| 804| 202 | Not system application.| 805| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 806| 12300001 | The system service works abnormally. | 807| 12300003 | Account not found. | 808 809**Example**: Obtain all constraints of system account 100. 810 811 ```ts 812 import { BusinessError } from '@kit.BasicServicesKit'; 813 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 814 let localId: number = 100; 815 try { 816 accountManager.getEnabledOsAccountConstraints(localId).then((constraints: string[]) => { 817 console.log('getEnabledOsAccountConstraints, constraints: ' + constraints); 818 }).catch((err: BusinessError) => { 819 console.log('getEnabledOsAccountConstraints err: ' + JSON.stringify(err)); 820 }); 821 } catch (e) { 822 console.log('getEnabledOsAccountConstraints exception: ' + JSON.stringify(e)); 823 } 824 ``` 825 826### queryAllCreatedOsAccounts 827 828queryAllCreatedOsAccounts(callback: AsyncCallback<Array<OsAccountInfo>>): void 829 830Queries information about all the system accounts created. This API uses an asynchronous callback to return the result. 831 832**System API**: This is a system API. 833 834**System capability**: SystemCapability.Account.OsAccount 835 836**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 837 838**Parameters** 839 840| Name | Type | Mandatory| Description | 841| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- | 842| callback | AsyncCallback<Array<[OsAccountInfo](js-apis-osAccount.md#osaccountinfo)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is a list of all created system accounts. Otherwise, **data** is an error object.| 843 844**Error codes** 845 846| ID| Error Message | 847| -------- | ------------- | 848| 201 | Permission denied.| 849| 202 | Not system application.| 850| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 851| 12300001 | The system service works abnormally. | 852 853**Example** 854 855 ```ts 856 import { BusinessError } from '@kit.BasicServicesKit'; 857 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 858 try { 859 accountManager.queryAllCreatedOsAccounts((err: BusinessError, accountArr: osAccount.OsAccountInfo[])=>{ 860 console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err)); 861 console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr)); 862 }); 863 } catch (e) { 864 console.log('queryAllCreatedOsAccounts exception: ' + JSON.stringify(e)); 865 } 866 ``` 867 868### queryAllCreatedOsAccounts 869 870queryAllCreatedOsAccounts(): Promise<Array<OsAccountInfo>> 871 872Queries information about all the system accounts created. This API uses a promise to return the result. 873 874**System API**: This is a system API. 875 876**System capability**: SystemCapability.Account.OsAccount 877 878**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 879 880**Return value** 881 882| Type | Description | 883| ----------------------------------------------------------- | --------------------------------------------- | 884| Promise<Array<[OsAccountInfo](js-apis-osAccount.md#osaccountinfo)>> | Promise used to return the information about all the system accounts created.| 885 886**Error codes** 887 888| ID| Error Message | 889| -------- | ------------- | 890| 201 | Permission denied.| 891| 202 | Not system application.| 892| 12300001 | The system service works abnormally. | 893 894**Example** 895 896 ```ts 897 import { BusinessError } from '@kit.BasicServicesKit'; 898 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 899 try { 900 accountManager.queryAllCreatedOsAccounts().then((accountArr: osAccount.OsAccountInfo[]) => { 901 console.log('queryAllCreatedOsAccounts, accountArr: ' + JSON.stringify(accountArr)); 902 }).catch((err: BusinessError) => { 903 console.log('queryAllCreatedOsAccounts err: ' + JSON.stringify(err)); 904 }); 905 } catch (e) { 906 console.log('queryAllCreatedOsAccounts exception: ' + JSON.stringify(e)); 907 } 908 ``` 909 910### createOsAccount 911 912createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback<OsAccountInfo>): void 913 914Creates a system account. This API uses an asynchronous callback to return the result. 915 916**System API**: This is a system API. 917 918**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 919 920**System capability**: SystemCapability.Account.OsAccount 921 922**Parameters** 923 924| Name | Type | Mandatory| Description | 925| :-------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------- | 926| localName | string | Yes | Name of the system account to create. | 927| type | [OsAccountType](js-apis-osAccount.md#osaccounttype) | Yes | Type of the system account to create. | 928| callback | AsyncCallback<[OsAccountInfo](js-apis-osAccount.md#osaccountinfo)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the created system account. Otherwise, **err** is an error object.| 929 930**Error codes** 931 932| ID | Error Message | 933| -------- | ------------------------- | 934| 201 | Permission denied.| 935| 202 | Not system application.| 936| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 937| 12300001 | The system service works abnormally. | 938| 12300002 | Invalid localName or type. | 939| 12300004 | Local name already exists. | 940| 12300005 | Multi-user not supported. | 941| 12300006 | Unsupported account type. | 942| 12300007 | The number of accounts has reached the upper limit. | 943 944**Example** 945 946 ```ts 947 import { BusinessError } from '@kit.BasicServicesKit'; 948 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 949 try { 950 accountManager.createOsAccount('testName', osAccount.OsAccountType.NORMAL, 951 (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ 952 console.log('createOsAccount err:' + JSON.stringify(err)); 953 console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo)); 954 }); 955 } catch (e) { 956 console.log('createOsAccount exception: ' + JSON.stringify(e)); 957 } 958 ``` 959 960### createOsAccount 961 962createOsAccount(localName: string, type: OsAccountType, options?: CreateOsAccountOptions): Promise<OsAccountInfo> 963 964Creates a system account. This API uses a promise to return the result. 965 966**System API**: This is a system API. 967 968**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 969 970**System capability**: SystemCapability.Account.OsAccount 971 972**Parameters** 973 974| Name | Type | Mandatory| Description | 975| --------- | ------------------------------- | ---- | ---------------------- | 976| localName | string | Yes | Name of the system account to create.| 977| type | [OsAccountType](js-apis-osAccount.md#osaccounttype) | Yes | Type of the system account to create.| 978| options | [CreateOsAccountOptions](js-apis-osAccount-sys.md#createosaccountoptions12) | No | Options for creating a system account. By default, this parameter is left blank.<br>This parameter is supported since API version 12.| 979 980**Return value** 981 982| Type | Description | 983| ---------------------------------------------- | ------------------------------------- | 984| Promise<[OsAccountInfo](js-apis-osAccount.md#osaccountinfo)> | Promise used to return the information about the created system account.| 985 986**Error codes** 987 988| ID | Error Message | 989| -------- | ------------------------- | 990| 201 | Permission denied.| 991| 202 | Not system application.| 992| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 993| 12300001 | The system service works abnormally. | 994| 12300002 | Invalid localName, type or options. | 995| 12300004 | Local name already exists. | 996| 12300005 | Multi-user not supported. | 997| 12300006 | Unsupported account type. | 998| 12300007 | The number of accounts has reached the upper limit. | 999| 12300015 | The short name already exists. | 1000 1001**Example** 1002 1003 ```ts 1004 import { BusinessError } from '@kit.BasicServicesKit'; 1005 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1006 let options: osAccount.CreateOsAccountOptions = { 1007 shortName: 'myShortName' 1008 } 1009 try { 1010 accountManager.createOsAccount('testAccountName', osAccount.OsAccountType.NORMAL, options).then( 1011 (accountInfo: osAccount.OsAccountInfo) => { 1012 console.log('createOsAccount, accountInfo: ' + JSON.stringify(accountInfo)); 1013 }).catch((err: BusinessError) => { 1014 console.log('createOsAccount err: ' + JSON.stringify(err)); 1015 }); 1016 } catch (e) { 1017 console.log('createOsAccount exception: ' + JSON.stringify(e)); 1018 } 1019 ``` 1020 1021### createOsAccountForDomain<sup>8+</sup> 1022 1023createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, callback: AsyncCallback<OsAccountInfo>): void 1024 1025Creates a system account and associates it with the specified domain account. This API uses an asynchronous callback to return the result. 1026 1027**System API**: This is a system API. 1028 1029**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1030 1031**System capability**: SystemCapability.Account.OsAccount 1032 1033**Parameters** 1034 1035| Name | Type | Mandatory| Description | 1036| ---------- | ---------------------------------------------------- | ---- | -------------------------------------------------------------------------- | 1037| type | [OsAccountType](js-apis-osAccount.md#osaccounttype) | Yes | Type of the system account to create. | 1038| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information. | 1039| callback | AsyncCallback<[OsAccountInfo](js-apis-osAccount.md#osaccountinfo)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the created system account. Otherwise, **err** is an error object.| 1040 1041**Error codes** 1042 1043| ID| Error Message | 1044| -------- | ------------------- | 1045| 201 | Permission denied.| 1046| 202 | Not system application.| 1047| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1048| 801 | Capability not supported.| 1049| 12300001 | The system service works abnormally. | 1050| 12300002 | Invalid type or domainInfo. | 1051| 12300004 | Account already exists. | 1052| 12300005 | Multi-user not supported. | 1053| 12300006 | Unsupported account type. | 1054| 12300007 | The number of accounts has reached the upper limit. | 1055 1056**Example** 1057 1058 ```ts 1059 import { BusinessError } from '@kit.BasicServicesKit'; 1060 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1061 let domainInfo: osAccount.DomainAccountInfo = 1062 {domain: 'testDomain', accountName: 'testAccountName'}; 1063 try { 1064 accountManager.createOsAccountForDomain(osAccount.OsAccountType.NORMAL, domainInfo, 1065 (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ 1066 console.log('createOsAccountForDomain err:' + JSON.stringify(err)); 1067 console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo)); 1068 }); 1069 } catch (e) { 1070 console.log('createOsAccountForDomain exception: ' + JSON.stringify(e)); 1071 } 1072 ``` 1073 1074### createOsAccountForDomain<sup>8+</sup> 1075 1076createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, options?: CreateOsAccountForDomainOptions): Promise<OsAccountInfo> 1077 1078Creates a system account and associates it with the specified domain account. This API uses a promise to return the result. 1079 1080**System API**: This is a system API. 1081 1082**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1083 1084**System capability**: SystemCapability.Account.OsAccount 1085 1086**Parameters** 1087 1088| Name | Type | Mandatory| Description | 1089| ---------- | ---------------------------------------- | ---- | -------------------- | 1090| type | [OsAccountType](js-apis-osAccount.md#osaccounttype) | Yes | Type of the system account to create.| 1091| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information. | 1092| options | [CreateOsAccountForDomainOptions](#createosaccountfordomainoptions12) | No | Optional parameters for creating the account. By default, this parameter is left blank.<br>This parameter is supported since API version 12.| 1093 1094**Return value** 1095 1096| Type | Description | 1097| ---------------------------------------------- | -------------------------------------- | 1098| Promise<[OsAccountInfo](js-apis-osAccount.md#osaccountinfo)> | Promise used to return the information about the created system account.| 1099 1100**Error codes** 1101 1102| ID| Error Message | 1103| -------- | ------------------- | 1104| 201 | Permission denied.| 1105| 202 | Not system application.| 1106| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1107| 801 | Capability not supported.| 1108| 12300001 | The system service works abnormally. | 1109| 12300002 | Invalid type, domainInfo or options. | 1110| 12300004 | Account already exists. | 1111| 12300005 | Multi-user not supported. | 1112| 12300006 | Unsupported account type. | 1113| 12300007 | The number of accounts has reached the upper limit. | 1114| 12300015 | The short name already exists. | 1115 1116**Example** 1117 1118 ```ts 1119 import { BusinessError } from '@kit.BasicServicesKit'; 1120 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1121 let domainInfo: osAccount.DomainAccountInfo = 1122 {domain: 'testDomain', accountName: 'testAccountName'}; 1123 let options: osAccount.CreateOsAccountForDomainOptions = { 1124 shortName: 'myShortName' 1125 } 1126 try { 1127 accountManager.createOsAccountForDomain(osAccount.OsAccountType.NORMAL, domainInfo, options).then( 1128 (accountInfo: osAccount.OsAccountInfo) => { 1129 console.log('createOsAccountForDomain, account info: ' + JSON.stringify(accountInfo)); 1130 }).catch((err: BusinessError) => { 1131 console.log('createOsAccountForDomain err: ' + JSON.stringify(err)); 1132 }); 1133 } catch (e) { 1134 console.log('createOsAccountForDomain exception: ' + JSON.stringify(e)); 1135 } 1136 ``` 1137 1138### queryOsAccount<sup>11+</sup> 1139 1140queryOsAccount(): Promise<OsAccountInfo> 1141 1142Obtains information about the system account to which the current process belongs. This API uses a promise to return the result. 1143 1144**System API**: This is a system API. 1145 1146**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.GET_LOCAL_ACCOUNTS 1147 1148**System capability**: SystemCapability.Account.OsAccount 1149 1150**Return value** 1151 1152| Type | Description | 1153| ---------------------------------------------- | ----------------------------------------- | 1154| Promise<[OsAccountInfo](js-apis-osAccount.md#osaccountinfo)> | Promise used to return the system account information obtained.| 1155 1156**Error codes** 1157 1158| ID| Error Message | 1159| -------- | ------------------- | 1160| 201 | Permission denied.| 1161| 202 | Not system application.| 1162| 12300001 | The system service works abnormally. | 1163 1164**Example** 1165 1166 ```ts 1167 import { BusinessError } from '@kit.BasicServicesKit'; 1168 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1169 try { 1170 accountManager.queryOsAccount().then((accountInfo: osAccount.OsAccountInfo) => { 1171 console.log('queryOsAccount, accountInfo: ' + JSON.stringify(accountInfo)); 1172 }).catch((err: BusinessError) => { 1173 console.log('queryOsAccount err: ' + JSON.stringify(err)); 1174 }); 1175 } catch (e) { 1176 console.log('queryOsAccount exception: ' + JSON.stringify(e)); 1177 } 1178 ``` 1179 1180### queryOsAccountById 1181 1182queryOsAccountById(localId: number, callback: AsyncCallback<OsAccountInfo>): void 1183 1184Queries information about the system account of the given ID. This API uses an asynchronous callback to return the result. 1185 1186**System API**: This is a system API. 1187 1188**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 1189 1190**System capability**: SystemCapability.Account.OsAccount 1191 1192**Parameters** 1193 1194| Name | Type | Mandatory| Description | 1195| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------------------ | 1196| localId | number | Yes | ID of the target system account. | 1197| callback | AsyncCallback<[OsAccountInfo](js-apis-osAccount.md#osaccountinfo)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the system account information obtained. Otherwise, **data** is an error object.| 1198 1199**Error codes** 1200 1201| ID| Error Message | 1202| -------- | ------------------- | 1203| 201 | Permission denied.| 1204| 202 | Not system application.| 1205| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1206| 12300001 | The system service works abnormally. | 1207| 12300002 | Invalid localId. | 1208| 12300003 | Account not found. | 1209 1210**Example**: Query information about system account 100. 1211 1212 ```ts 1213 import { BusinessError } from '@kit.BasicServicesKit'; 1214 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1215 let localId: number = 100; 1216 try { 1217 accountManager.queryOsAccountById(localId, (err: BusinessError, accountInfo: osAccount.OsAccountInfo)=>{ 1218 console.log('queryOsAccountById err:' + JSON.stringify(err)); 1219 console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo)); 1220 }); 1221 } catch (e) { 1222 console.log('queryOsAccountById exception: ' + JSON.stringify(e)); 1223 } 1224 ``` 1225 1226### queryOsAccountById 1227 1228queryOsAccountById(localId: number): Promise<OsAccountInfo> 1229 1230Queries information about the system account of the given ID. This API uses a promise to return the result. 1231 1232**System API**: This is a system API. 1233 1234**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 1235 1236**System capability**: SystemCapability.Account.OsAccount 1237 1238**Parameters** 1239 1240| Name | Type | Mandatory| Description | 1241| ------- | ------ | ---- | -------------------- | 1242| localId | number | Yes | ID of the target system account.| 1243 1244**Return value** 1245 1246| Type | Description | 1247| ---------------------------------------------- | ------------------------------------ | 1248| Promise<[OsAccountInfo](js-apis-osAccount.md#osaccountinfo)> | Promise used to return the system account information obtained.| 1249 1250**Error codes** 1251 1252| ID| Error Message | 1253| -------- | ------------------- | 1254| 201 | Permission denied.| 1255| 202 | Not system application.| 1256| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1257| 12300001 | The system service works abnormally. | 1258| 12300002 | Invalid localId. | 1259| 12300003 | Account not found. | 1260 1261**Example**: Query information about system account 100. 1262 1263 ```ts 1264 import { BusinessError } from '@kit.BasicServicesKit'; 1265 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1266 let localId: number = 100; 1267 try { 1268 accountManager.queryOsAccountById(localId).then((accountInfo: osAccount.OsAccountInfo) => { 1269 console.log('queryOsAccountById, accountInfo: ' + JSON.stringify(accountInfo)); 1270 }).catch((err: BusinessError) => { 1271 console.log('queryOsAccountById err: ' + JSON.stringify(err)); 1272 }); 1273 } catch (e) { 1274 console.log('queryOsAccountById exception: ' + JSON.stringify(e)); 1275 } 1276 ``` 1277 1278### getOsAccountProfilePhoto 1279 1280getOsAccountProfilePhoto(localId: number, callback: AsyncCallback<string>): void 1281 1282Obtains the profile photo of a system account. This API uses an asynchronous callback to return the result. 1283 1284**System API**: This is a system API. 1285 1286**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1287 1288**System capability**: SystemCapability.Account.OsAccount 1289 1290**Parameters** 1291 1292| Name | Type | Mandatory| Description | 1293| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- | 1294| localId | number | Yes | ID of the target system account. | 1295| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the profile photo information obtained. Otherwise, **err** is an error object.| 1296 1297**Error codes** 1298 1299| ID| Error Message | 1300| -------- | ------------------- | 1301| 201 | Permission denied.| 1302| 202 | Not system application.| 1303| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1304| 12300001 | The system service works abnormally. | 1305| 12300002 | Invalid localId. | 1306| 12300003 | Account not found. | 1307 1308**Example**: Obtain the profile photo of system account 100. 1309 1310 ```ts 1311 import { BusinessError } from '@kit.BasicServicesKit'; 1312 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1313 let localId: number = 100; 1314 try { 1315 accountManager.getOsAccountProfilePhoto(localId, (err: BusinessError, photo: string)=>{ 1316 console.log('getOsAccountProfilePhoto err:' + JSON.stringify(err)); 1317 console.log('get photo:' + photo + ' by localId: ' + localId); 1318 }); 1319 } catch (e) { 1320 console.log('getOsAccountProfilePhoto exception: ' + JSON.stringify(e)); 1321 } 1322 ``` 1323 1324### getOsAccountProfilePhoto 1325 1326getOsAccountProfilePhoto(localId: number): Promise<string> 1327 1328Obtains the profile photo of a system account. This API uses a promise to return the result. 1329 1330**System API**: This is a system API. 1331 1332**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1333 1334**System capability**: SystemCapability.Account.OsAccount 1335 1336**Parameters** 1337 1338| Name | Type | Mandatory| Description | 1339| ------- | ------ | ---- | ------------ | 1340| localId | number | Yes | ID of the target system account.| 1341 1342**Return value** 1343 1344| Type | Description | 1345| --------------------- | -------------------------------------- | 1346| Promise<string> | Promise used to return the profile photo information obtained.| 1347 1348**Error codes** 1349 1350| ID| Error Message | 1351| -------- | ------------------- | 1352| 201 | Permission denied.| 1353| 202 | Not system application.| 1354| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1355| 12300001 | The system service works abnormally. | 1356| 12300002 | Invalid localId. | 1357| 12300003 | Account not found. | 1358 1359**Example**: Obtain the profile photo of system account 100. 1360 1361 ```ts 1362 import { BusinessError } from '@kit.BasicServicesKit'; 1363 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1364 let localId: number = 100; 1365 try { 1366 accountManager.getOsAccountProfilePhoto(localId).then((photo: string) => { 1367 console.log('getOsAccountProfilePhoto: ' + photo); 1368 }).catch((err: BusinessError) => { 1369 console.log('getOsAccountProfilePhoto err: ' + JSON.stringify(err)); 1370 }); 1371 } catch (e) { 1372 console.log('getOsAccountProfilePhoto exception: ' + JSON.stringify(e)); 1373 } 1374 ``` 1375 1376### setOsAccountProfilePhoto 1377 1378setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback<void>): void 1379 1380Sets a profile photo for a system account. This API uses an asynchronous callback to return the result. 1381 1382**System API**: This is a system API. 1383 1384**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1385 1386**System capability**: SystemCapability.Account.OsAccount 1387 1388**Parameters** 1389 1390| Name | Type | Mandatory| Description | 1391| -------- | ------------------------- | ---- | ------------ | 1392| localId | number | Yes | ID of the target system account.| 1393| photo | string | Yes | Profile photo information. | 1394| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 1395 1396**Error codes** 1397 1398| ID| Error Message | 1399| -------- | ------------------- | 1400| 201 | Permission denied.| 1401| 202 | Not system application.| 1402| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1403| 12300001 | The system service works abnormally. | 1404| 12300002 | Invalid localId or photo. | 1405| 12300003 | Account not found. | 1406| 12300008 | Restricted Account. | 1407 1408**Example**: Set a profile photo for system account 100. 1409 1410 ```ts 1411 import { BusinessError } from '@kit.BasicServicesKit'; 1412 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1413 let localId: number = 100; 1414 let photo: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ 1415 'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+ 1416 'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+ 1417 '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==' 1418 try { 1419 accountManager.setOsAccountProfilePhoto(localId, photo, (err: BusinessError)=>{ 1420 console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err)); 1421 }); 1422 } catch (e) { 1423 console.log('setOsAccountProfilePhoto exception: ' + JSON.stringify(e)); 1424 } 1425 ``` 1426 1427### setOsAccountProfilePhoto 1428 1429setOsAccountProfilePhoto(localId: number, photo: string): Promise<void> 1430 1431Sets a profile photo for a system account. This API uses a promise to return the result. 1432 1433**System API**: This is a system API. 1434 1435**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1436 1437**System capability**: SystemCapability.Account.OsAccount 1438 1439**Parameters** 1440 1441| Name | Type | Mandatory| Description | 1442| ------- | ------ | ---- | ------------ | 1443| localId | number | Yes | ID of the target system account.| 1444| photo | string | Yes | Profile photo information. | 1445 1446**Return value** 1447 1448| Type | Description | 1449| ------------------- | ------------------------------------ | 1450| Promise<void> | Promise that returns no value.| 1451 1452**Error codes** 1453 1454| ID| Error Message | 1455| -------- | ------------------- | 1456| 201 | Permission denied.| 1457| 202 | Not system application.| 1458| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1459| 12300001 | The system service works abnormally. | 1460| 12300002 | Invalid localId or photo. | 1461| 12300003 | Account not found. | 1462| 12300008 | Restricted Account. | 1463 1464**Example**: Set a profile photo for system account 100. 1465 1466 ```ts 1467 import { BusinessError } from '@kit.BasicServicesKit'; 1468 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1469 let localId: number = 100; 1470 let photo: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ 1471 'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+ 1472 'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+ 1473 '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==' 1474 try { 1475 accountManager.setOsAccountProfilePhoto(localId, photo).then(() => { 1476 console.log('setOsAccountProfilePhoto success'); 1477 }).catch((err: BusinessError) => { 1478 console.log('setOsAccountProfilePhoto err: ' + JSON.stringify(err)); 1479 }); 1480 } catch (e) { 1481 console.log('setOsAccountProfilePhoto exception: ' + JSON.stringify(e)); 1482 } 1483 ``` 1484 1485### on 1486 1487on(type: 'activate' | 'activating', name: string, callback: Callback<number>): void 1488 1489Subscribes to the system account activation states, including the states of the account being activated and the account with activation completed. This API uses an asynchronous callback to return the result. 1490 1491**System API**: This is a system API. 1492 1493**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 1494 1495**System capability**: SystemCapability.Account.OsAccount 1496 1497**Parameters** 1498 1499| Name | Type | Mandatory| Description | 1500| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 1501| type | 'activate' \| 'activating' | Yes | Type of the event to subscribe to. The value **activate** indicates that a system account is activated, and **activating** indicates that a system account is being activated.| 1502| name | string | Yes | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes. | 1503| callback | Callback<number> | Yes | Callback used to return the ID of the system account being activated or activated. | 1504 1505**Error codes** 1506 1507| ID| Error Message | 1508| -------- | ------------- | 1509| 201 | Permission denied.| 1510| 202 | Not system application.| 1511| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1512| 12300001 | The system service works abnormally. | 1513| 12300002 | Invalid type or name. | 1514 1515**Example** 1516 1517 ```ts 1518 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1519 function onCallback(receiveLocalId: number){ 1520 console.log('receive localId:' + receiveLocalId); 1521 } 1522 try { 1523 accountManager.on('activating', 'osAccountOnOffNameA', onCallback); 1524 } catch (e) { 1525 console.log('receive localId exception: ' + JSON.stringify(e)); 1526 } 1527 ``` 1528 1529### off 1530 1531off(type: 'activate' | 'activating', name: string, callback?: Callback<number>): void 1532 1533Unsubscribes from the system account activation states, including the states of the account being activated and the account with activation completed. This API uses an asynchronous callback to return the result. 1534 1535**System API**: This is a system API. 1536 1537**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION 1538 1539**System capability**: SystemCapability.Account.OsAccount 1540 1541**Parameters** 1542 1543| Name | Type | Mandatory| Description | 1544| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 1545| type | 'activate' \| 'activating' | Yes | Type of the event to unsubscribe from. The value **activate** indicates that a system account is activated, and **activating** indicates that a system account is being activated.| 1546| name | string | Yes | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes, and must be the same as the value passed by **on()**.| 1547| callback | Callback<number> | No | Callback to unregister. By default, this parameter is left empty, which unregisters all callbacks for the system account activation states. | 1548 1549**Error codes** 1550 1551| ID| Error Message | 1552| -------- | ------------- | 1553| 201 | Permission denied.| 1554| 202 | Not system application.| 1555| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1556| 12300001 | The system service works abnormally. | 1557| 12300002 | Invalid type or name. | 1558 1559**Example** 1560 1561 ```ts 1562 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1563 function offCallback(){ 1564 console.log('off enter') 1565 } 1566 try { 1567 accountManager.off('activating', 'osAccountOnOffNameA', offCallback); 1568 } catch (e) { 1569 console.log('off exception: ' + JSON.stringify(e)); 1570 } 1571 ``` 1572 1573### on<sup>12+</sup> 1574 1575on(type: 'switching', callback: Callback<OsAccountSwitchEventData>): void 1576 1577Subscribes to the switchover between a foreground system account and a background system account in progress. This API uses an asynchronous callback to return the result. 1578 1579**System API**: This is a system API. 1580 1581**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1582 1583**System capability**: SystemCapability.Account.OsAccount 1584 1585**Parameters** 1586 1587| Name | Type | Mandatory| Description | 1588| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 1589| type | 'switching' | Yes | Event type. The value **switching** indicates that the switchover between a foreground system account and a background account is being performed.| 1590| callback | Callback<[OsAccountSwitchEventData](#osaccountswitcheventdata12)> | Yes | Callback used to return the system account IDs before and after the switchover. | 1591 1592**Error codes** 1593 1594| ID| Error Message | 1595| -------- | ------------- | 1596| 201 | Permission denied.| 1597| 202 | Not system application.| 1598| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1599| 12300001 | The system service works abnormally. | 1600| 12300002 | Invalid type. | 1601 1602**Example** 1603 1604 ```ts 1605 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1606 function onSwitchingCallback(eventData: osAccount.OsAccountSwitchEventData){ 1607 console.log('receive eventData:' + JSON.stringify(eventData)); 1608 } 1609 try { 1610 accountManager.on('switching', onSwitchingCallback); 1611 } catch (e) { 1612 console.log('receive eventData exception: ' + JSON.stringify(e)); 1613 } 1614 ``` 1615 1616### off<sup>12+</sup> 1617 1618off(type: 'switching', callback?: Callback<OsAccountSwitchEventData>): void 1619 1620Unsubscribes from the switchover between a foreground system account and a background system account in progress. This API uses an asynchronous callback to return the result. 1621 1622**System API**: This is a system API. 1623 1624**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1625 1626**System capability**: SystemCapability.Account.OsAccount 1627 1628**Parameters** 1629 1630| Name | Type | Mandatory| Description | 1631| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 1632| type | 'switching' | Yes | Event type. The value **switching** indicates that the switchover between a foreground system account and a background account is being performed.| 1633| callback | Callback<[OsAccountSwitchEventData](#osaccountswitcheventdata12)> | No | Callback to unregister. By default, this parameter is left empty, which unregisters all callbacks for the **switching** event. | 1634 1635**Error codes** 1636 1637| ID| Error Message | 1638| -------- | ------------- | 1639| 201 | Permission denied.| 1640| 202 | Not system application.| 1641| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1642| 12300001 | The system service works abnormally. | 1643| 12300002 | Invalid type. | 1644 1645**Example** 1646 1647 ```ts 1648 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1649 try { 1650 accountManager.off('switching'); 1651 } catch (e) { 1652 console.log('off exception: ' + JSON.stringify(e)); 1653 } 1654 ``` 1655 1656### on<sup>12+</sup> 1657 1658on(type: 'switched', callback: Callback<OsAccountSwitchEventData>): void 1659 1660Subscribes to the end of a switchover between a foreground system account and a background system account. This API uses an asynchronous callback to return the result. 1661 1662**System API**: This is a system API. 1663 1664**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1665 1666**System capability**: SystemCapability.Account.OsAccount 1667 1668**Parameters** 1669 1670| Name | Type | Mandatory| Description | 1671| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 1672| type | 'switched' | Yes | Event type. The value **switched** indicates that the switchover between a foreground system account and a background system account is complete.| 1673| callback | Callback<[OsAccountSwitchEventData](#osaccountswitcheventdata12)> | Yes | Callback used to return the system account IDs before and after the switchover. | 1674 1675**Error codes** 1676 1677| ID| Error Message | 1678| -------- | ------------- | 1679| 201 | Permission denied.| 1680| 202 | Not system application.| 1681| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1682| 12300001 | The system service works abnormally. | 1683| 12300002 | Invalid type. | 1684 1685**Example** 1686 1687 ```ts 1688 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1689 function onSwitchedCallback(eventData: osAccount.OsAccountSwitchEventData){ 1690 console.log('receive eventData:' + JSON.stringify(eventData)); 1691 } 1692 try { 1693 accountManager.on('switched', onSwitchedCallback); 1694 } catch (e) { 1695 console.log('receive eventData exception: ' + JSON.stringify(e)); 1696 } 1697 ``` 1698 1699### off<sup>12+</sup> 1700 1701off(type: 'switched', callback?: Callback<OsAccountSwitchEventData>): void 1702 1703Unsubscribes from the end of a switchover between a foreground system account and a background system account. This API uses an asynchronous callback to return the result. 1704 1705**System API**: This is a system API. 1706 1707**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1708 1709**System capability**: SystemCapability.Account.OsAccount 1710 1711**Parameters** 1712 1713| Name | Type | Mandatory| Description | 1714| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 1715| type | 'switched' | Yes | Event type. The value **switched** indicates that the switchover between a foreground system account and a background system account is complete.| 1716| callback | Callback<[OsAccountSwitchEventData](#osaccountswitcheventdata12)> | No | Callback to unregister. By default, this parameter is left empty, which unregisters all callbacks for the **switched** event. | 1717 1718**Error codes** 1719 1720| ID| Error Message | 1721| -------- | ------------- | 1722| 201 | Permission denied.| 1723| 202 | Not system application.| 1724| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1725| 12300001 | The system service works abnormally. | 1726| 12300002 | Invalid type. | 1727 1728**Example** 1729 1730 ```ts 1731 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1732 try { 1733 accountManager.off('switched'); 1734 } catch (e) { 1735 console.log('off exception: ' + JSON.stringify(e)); 1736 } 1737 ``` 1738 1739### getBundleIdForUid<sup>9+</sup> 1740 1741getBundleIdForUid(uid: number, callback: AsyncCallback<number>): void 1742 1743Obtains the bundle ID based on the UID. This API uses an asynchronous callback to return the result. 1744 1745**System API**: This is a system API. 1746 1747**System capability**: SystemCapability.Account.OsAccount 1748 1749**Parameters** 1750 1751| Name | Type | Mandatory| Description | 1752| -------- | --------------------------- | ---- | ------------------------------------------------------------------------ | 1753| uid | number | Yes | Process UID. | 1754| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the bundle ID obtained. Otherwise, **data** is an error object.| 1755 1756**Error codes** 1757 1758| ID| Error Message | 1759| -------- | ------------- | 1760| 202 | Not system application.| 1761| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1762| 12300001 | The system service works abnormally. | 1763| 12300002 | Invalid uid. | 1764 1765**Example** 1766 1767 ```ts 1768 import { BusinessError } from '@kit.BasicServicesKit'; 1769 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1770 let testUid: number = 1000000; 1771 try { 1772 accountManager.getBundleIdForUid(testUid, (err: BusinessError, bundleId: number) => { 1773 console.info('getBundleIdForUid errInfo:' + JSON.stringify(err)); 1774 console.info('getBundleIdForUid bundleId:' + JSON.stringify(bundleId)); 1775 }); 1776 } catch (e) { 1777 console.info('getBundleIdForUid exception: ' + JSON.stringify(e)); 1778 } 1779 ``` 1780 1781### getBundleIdForUid<sup>9+</sup> 1782 1783getBundleIdForUid(uid: number): Promise<number> 1784 1785Obtains the bundle ID based on the UID. This API uses a promise to return the result. 1786 1787**System API**: This is a system API. 1788 1789**System capability**: SystemCapability.Account.OsAccount 1790 1791**Parameters** 1792 1793| Name | Type | Mandatory| Description | 1794| ------- | ------ | ---- | ------------ | 1795| uid | number | Yes | Process UID.| 1796 1797**Return value** 1798 1799| Type | Description | 1800| --------------------- | ------------------------------------ | 1801| Promise<number> | Promise used to return the bundle ID obtained.| 1802 1803**Error codes** 1804 1805| ID| Error Message | 1806| -------- | ------------- | 1807| 202 | Not system application.| 1808| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1809| 12300001 | The system service works abnormally. | 1810| 12300002 | Invalid uid. | 1811 1812**Example** 1813 1814 ```ts 1815 import { BusinessError } from '@kit.BasicServicesKit'; 1816 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1817 let testUid: number = 1000000; 1818 try { 1819 accountManager.getBundleIdForUid(testUid).then((result: number) => { 1820 console.info('getBundleIdForUid bundleId:' + JSON.stringify(result)); 1821 }).catch((err: BusinessError) => { 1822 console.info('getBundleIdForUid errInfo:' + JSON.stringify(err)); 1823 }); 1824 } catch (e) { 1825 console.info('getBundleIdForUid exception: ' + JSON.stringify(e)); 1826 } 1827 ``` 1828 1829### getBundleIdForUidSync<sup>10+</sup> 1830 1831getBundleIdForUidSync(uid: number): number 1832 1833Obtains the bundle ID based on the specified UID. The API returns the result synchronously. 1834 1835**System API**: This is a system API. 1836 1837**System capability**: SystemCapability.Account.OsAccount 1838 1839**Parameters** 1840 1841| Name | Type | Mandatory| Description | 1842| ------- | ------ | ---- | ------------ | 1843| uid | number | Yes | Process UID.| 1844 1845**Return value** 1846 1847| Type | Description | 1848| ------ | ------------------------ | 1849| number | Bundle ID obtained.| 1850 1851**Error codes** 1852 1853| ID| Error Message | 1854| -------- | ------------- | 1855| 202 | Not system application.| 1856| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1857| 12300002 | Invalid uid. | 1858 1859**Example** 1860 1861 ```ts 1862 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1863 let testUid: number = 1000000; 1864 try { 1865 let bundleId : number = accountManager.getBundleIdForUidSync(testUid); 1866 console.info('getBundleIdForUidSync bundleId:' + bundleId); 1867 } catch (e) { 1868 console.info('getBundleIdForUidSync exception: ' + JSON.stringify(e)); 1869 } 1870 ``` 1871 1872### isMainOsAccount<sup>9+</sup> 1873 1874isMainOsAccount(callback: AsyncCallback<boolean>): void 1875 1876Checks whether the current process belongs to the main system account. This API uses an asynchronous callback to return the result. 1877 1878**System API**: This is a system API. 1879 1880**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1881 1882**System capability**: SystemCapability.Account.OsAccount 1883 1884**Parameters** 1885 1886| Name | Type | Mandatory| Description | 1887| -------- | ---------------------------- | ---- | ----------------------------------------------------------------- | 1888| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If **true** is returned, the current process belongs to the main system account. If **false** is returned, the current process does not belong to the main system account.| 1889 1890**Error codes** 1891 1892| ID| Error Message | 1893| -------- | ------------- | 1894| 201 | Permission denied.| 1895| 202 | Not system application.| 1896| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1897| 12300001 | The system service works abnormally. | 1898 1899**Example** 1900 1901 ```ts 1902 import { BusinessError } from '@kit.BasicServicesKit'; 1903 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1904 try { 1905 accountManager.isMainOsAccount((err: BusinessError,result: boolean)=>{ 1906 console.info('isMainOsAccount errInfo:' + JSON.stringify(err)); 1907 console.info('isMainOsAccount result:' + JSON.stringify(result)); 1908 }); 1909 } catch (e) { 1910 console.info('isMainOsAccount exception: ' + JSON.stringify(e)); 1911 } 1912 ``` 1913 1914### isMainOsAccount<sup>9+</sup> 1915 1916isMainOsAccount(): Promise<boolean>; 1917 1918Checks whether the current process belongs to the main system account. This API uses a promise to return the result. 1919 1920**System API**: This is a system API. 1921 1922**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1923 1924**System capability**: SystemCapability.Account.OsAccount 1925 1926**Return value** 1927 1928| Type | Description | 1929| ---------------------- | --------------------------------------------------------------------- | 1930| Promise<boolean> | Promise used to return the result. If **true** is returned, the current process belongs to the main system account. If **false** is returned, the current process does not belong to the main system account.| 1931 1932**Error codes** 1933 1934| ID| Error Message | 1935| -------- | ------------- | 1936| 201 | Permission denied.| 1937| 202 | Not system application.| 1938| 12300001 | The system service works abnormally. | 1939 1940**Example** 1941 1942 ```ts 1943 import { BusinessError } from '@kit.BasicServicesKit'; 1944 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1945 try { 1946 accountManager.isMainOsAccount().then((result: boolean) => { 1947 console.info('isMainOsAccount result:' + JSON.stringify(result)); 1948 }).catch((err: BusinessError) => { 1949 console.info('isMainOsAccount errInfo:' + JSON.stringify(err)); 1950 }); 1951 } catch (e) { 1952 console.info('isMainOsAccount exception: ' + JSON.stringify(e)); 1953 } 1954 ``` 1955 1956### getOsAccountConstraintSourceTypes<sup>9+</sup> 1957 1958getOsAccountConstraintSourceTypes(localId: number, constraint: string, callback: AsyncCallback<Array<ConstraintSourceTypeInfo>>): void 1959 1960Obtains the constraint source information of a system account. This API uses an asynchronous callback to return the result. 1961 1962**System API**: This is a system API. 1963 1964**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1965 1966**System capability**: SystemCapability.Account.OsAccount 1967 1968**Parameters** 1969 1970| Name | Type | Mandatory| Description | 1971| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 1972| localId | number | Yes | ID of the target system account.| 1973| constraint | string | Yes | [Constraint](js-apis-osAccount.md#constraints) whose source information is to be obtained.| 1974| callback | AsyncCallback<Array<[ConstraintSourceTypeInfo](#constraintsourcetypeinfo9)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the [constraint](js-apis-osAccount.md#constraints) source information obtained. Otherwise, **err** is an error object. | 1975 1976**Error codes** 1977 1978| ID| Error Message | 1979| -------- | ------------- | 1980| 201 | Permission denied.| 1981| 202 | Not system application.| 1982| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1983| 12300001 | The system service works abnormally. | 1984| 12300002 | Invalid name or constraint. | 1985| 12300003 | Account not found. | 1986 1987**Example** 1988 1989 ```ts 1990 import { BusinessError } from '@kit.BasicServicesKit'; 1991 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 1992 try { 1993 accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi', 1994 (err: BusinessError,sourceTypeInfos: osAccount.ConstraintSourceTypeInfo[])=>{ 1995 console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err)); 1996 console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(sourceTypeInfos)); 1997 }); 1998 } catch (e) { 1999 console.info('getOsAccountConstraintSourceTypes exception: ' + JSON.stringify(e)); 2000 } 2001 ``` 2002 2003### getOsAccountConstraintSourceTypes<sup>9+</sup> 2004 2005getOsAccountConstraintSourceTypes(localId: number, constraint: string): Promise<Array<ConstraintSourceTypeInfo>>; 2006 2007Obtains the constraint source information of a system account. This API uses a promise to return the result. 2008 2009**System API**: This is a system API. 2010 2011**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 2012 2013**System capability**: SystemCapability.Account.OsAccount 2014 2015**Parameters** 2016 2017| Name | Type | Mandatory| Description | 2018| ------- | ------ | ---- | ------------ | 2019| localId | number | Yes | ID of the target system account.| 2020| constraint | string | Yes | [Constraint](js-apis-osAccount.md#constraints) whose source information is to be obtained.| 2021 2022**Return value** 2023 2024| Type | Description | 2025| --------------------- | ------------------------------------------------------------ | 2026| Promise<Array<[ConstraintSourceTypeInfo](#constraintsourcetypeinfo9)>> | Promise used to return the source information of the specified [constraint](js-apis-osAccount.md#constraints).| 2027 2028**Error codes** 2029 2030| ID| Error Message | 2031| -------- | ------------- | 2032| 201 | Permission denied.| 2033| 202 | Not system application.| 2034| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2035| 12300001 | The system service works abnormally. | 2036| 12300002 | Invalid name or constraint. | 2037| 12300003 | Account not found. | 2038 2039**Example** 2040 2041 ```ts 2042 import { BusinessError } from '@kit.BasicServicesKit'; 2043 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 2044 try { 2045 accountManager.getOsAccountConstraintSourceTypes(100, 'constraint.wifi').then( 2046 (result: osAccount.ConstraintSourceTypeInfo[]) => { 2047 console.info('getOsAccountConstraintSourceTypes sourceTypeInfos:' + JSON.stringify(result)); 2048 }).catch((err: BusinessError) => { 2049 console.info('getOsAccountConstraintSourceTypes errInfo:' + JSON.stringify(err)); 2050 }); 2051 } catch (e) { 2052 console.info('getOsAccountConstraintSourceTypes exception: ' + JSON.stringify(e)); 2053 } 2054 ``` 2055 2056### getOsAccountType<sup>12+</sup> 2057 2058getOsAccountType(localId: number): Promise<OsAccountType>; 2059 2060Obtains the type of a system account. This API uses a promise to return the result. 2061 2062**System API**: This is a system API. 2063 2064**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 2065 2066**System capability**: SystemCapability.Account.OsAccount 2067 2068**Parameters** 2069 2070| Name | Type | Mandatory| Description | 2071| ------- | ------ | ---- | ------------ | 2072| localId | number | Yes | ID of the target system account.| 2073 2074**Return value** 2075 2076| Type | Description | 2077| --------------------- | ------------------------------------------------------------ | 2078| Promise<[OsAccountType](js-apis-osAccount.md#osaccounttype)> | Promise used to return the type of the system account obtained.| 2079 2080**Error codes** 2081 2082| ID| Error Message | 2083| -------- | ------------- | 2084| 201 | Permission denied.| 2085| 202 | Not system application.| 2086| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2087| 12300001 | The system service works abnormally. | 2088| 12300003 | Account not found. | 2089 2090**Example** 2091 2092 ```ts 2093 import { BusinessError } from '@kit.BasicServicesKit'; 2094 let accountManager: osAccount.AccountManager = osAccount.getAccountManager(); 2095 try { 2096 let localId: number = 100; 2097 accountManager.getOsAccountType(localId).then((type: osAccount.OsAccountType) => { 2098 console.info('getOsAccountType Type:' + type); 2099 }).catch((err: BusinessError) => { 2100 console.info('getOsAccountType errInfo:' + JSON.stringify(err)); 2101 }); 2102 } catch (e) { 2103 console.info('getOsAccountType exception: ' + JSON.stringify(e)); 2104 } 2105 ``` 2106 2107## UserAuth<sup>8+</sup> 2108 2109Provides APIs for user authentication. 2110 2111**System API**: This is a system API. 2112 2113### constructor<sup>8+</sup> 2114 2115constructor() 2116 2117A constructor used to create an instance for user authentication. 2118 2119**System API**: This is a system API. 2120 2121**System capability**: SystemCapability.Account.OsAccount 2122 2123**Error codes** 2124 2125| ID| Error Message | 2126| -------- | ------------- | 2127| 202 | Not system application.| 2128 2129**Example** 2130 ```ts 2131 let userAuth = new osAccount.UserAuth(); 2132 ``` 2133 2134### getVersion<sup>8+</sup> 2135 2136getVersion(): number; 2137 2138Obtains version information. 2139 2140**System API**: This is a system API. 2141 2142**System capability**: SystemCapability.Account.OsAccount 2143 2144**Return value** 2145 2146| Type | Description | 2147| :----- | :----------- | 2148| number | Version information obtained.| 2149 2150**Error codes** 2151 2152| ID| Error Message | 2153| -------- | ------------- | 2154| 202 | Not system application.| 2155 2156**Example** 2157 ```ts 2158 let userAuth = new osAccount.UserAuth(); 2159 let version: number = userAuth.getVersion(); 2160 console.log('getVersion version = ' + version); 2161 ``` 2162 2163### getAvailableStatus<sup>8+</sup> 2164 2165getAvailableStatus(authType: AuthType, authTrustLevel: AuthTrustLevel): number; 2166 2167Obtains the available status of the authentication capability corresponding to the specified authentication type and trust level. 2168 2169**System API**: This is a system API. 2170 2171**System capability**: SystemCapability.Account.OsAccount 2172 2173**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2174 2175**Parameters** 2176 2177| Name | Type | Mandatory| Description | 2178| --------------- | -----------------------------------| ---- | ------------------------- | 2179| authType | [AuthType](#authtype8) | Yes | Authentication credential type. | 2180| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | Yes | Trust level of the authentication.| 2181 2182**Return value** 2183 2184| Type | Description | 2185| ------ | ----------------------------- | 2186| number | Available status of the authentication capability.| 2187 2188**Error codes** 2189 2190| ID| Error Message | 2191| -------- | --------------------------- | 2192| 201 | Permission denied.| 2193| 202 | Not system application.| 2194| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2195| 12300001 | The system service works abnormally. | 2196| 12300002 | Invalid authType or authTrustLevel. | 2197 2198**Example** 2199 ```ts 2200 let userAuth = new osAccount.UserAuth(); 2201 let authType: osAccount.AuthType = osAccount.AuthType.PIN; 2202 let authTrustLevel: osAccount.AuthTrustLevel = osAccount.AuthTrustLevel.ATL1; 2203 try { 2204 let status: number = userAuth.getAvailableStatus(authType, authTrustLevel); 2205 console.log('getAvailableStatus status = ' + status); 2206 } catch (e) { 2207 console.log('getAvailableStatus exception = ' + JSON.stringify(e)); 2208 } 2209 ``` 2210 2211### getProperty<sup>8+</sup> 2212 2213getProperty(request: GetPropertyRequest, callback: AsyncCallback<ExecutorProperty>): void 2214 2215Obtains the executor property based on the request. This API uses an asynchronous callback to return the result. 2216 2217**System API**: This is a system API. 2218 2219**System capability**: SystemCapability.Account.OsAccount 2220 2221**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2222 2223**Parameters** 2224 2225| Name | Type | Mandatory| Description | 2226| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------ | 2227| request | [GetPropertyRequest](#getpropertyrequest8) | Yes | Request information, including the authentication credential type and property list.| 2228| callback | AsyncCallback<[ExecutorProperty](#executorproperty8)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the executor property information obtained. Otherwise, **err** is an error object.| 2229 2230**Error codes** 2231 2232| ID| Error Message | 2233| -------- | --------------------------- | 2234| 201 | Permission denied.| 2235| 202 | Not system application.| 2236| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2237| 12300001 | The system service works abnormally. | 2238| 12300002 | Invalid request. | 2239| 12300003 | Account not found. | 2240 2241**Example** 2242 ```ts 2243 import { BusinessError } from '@kit.BasicServicesKit'; 2244 let userAuth = new osAccount.UserAuth(); 2245 let keys: Array<osAccount.GetPropertyType> = [ 2246 osAccount.GetPropertyType.AUTH_SUB_TYPE, 2247 osAccount.GetPropertyType.REMAIN_TIMES, 2248 osAccount.GetPropertyType.FREEZING_TIME 2249 ]; 2250 let request: osAccount.GetPropertyRequest = { 2251 authType: osAccount.AuthType.PIN, 2252 keys: keys 2253 }; 2254 try { 2255 userAuth.getProperty(request, (err: BusinessError, result: osAccount.ExecutorProperty) => { 2256 console.log('getProperty err = ' + JSON.stringify(err)); 2257 console.log('getProperty result = ' + JSON.stringify(result)); 2258 }); 2259 } catch (e) { 2260 console.log('getProperty exception = ' + JSON.stringify(e)); 2261 } 2262 ``` 2263 2264### getProperty<sup>8+</sup> 2265 2266getProperty(request: GetPropertyRequest): Promise<ExecutorProperty>; 2267 2268Obtains the executor property based on the request. This API uses a promise to return the result. 2269 2270**System API**: This is a system API. 2271 2272**System capability**: SystemCapability.Account.OsAccount 2273 2274**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2275 2276**Parameters** 2277 2278| Name | Type | Mandatory| Description | 2279| -------- | ------------------------------------------------------ | ---- | ---------------------------------- | 2280| request | [GetPropertyRequest](#getpropertyrequest8) | Yes | Request information, including the authentication credential type and property list.| 2281 2282**Return value** 2283 2284| Type | Description | 2285| :---------------------------------------------------------------- | :-------------------------------------------------- | 2286| Promise<[ExecutorProperty](#executorproperty8)> | Promise used to return the executor property information obtained.| 2287 2288**Error codes** 2289 2290| ID| Error Message | 2291| -------- | --------------------------- | 2292| 201 | Permission denied.| 2293| 202 | Not system application.| 2294| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2295| 12300001 | The system service works abnormally. | 2296| 12300002 | Invalid request. | 2297| 12300003 | Account not found. | 2298 2299**Example** 2300 ```ts 2301 import { BusinessError } from '@kit.BasicServicesKit'; 2302 let userAuth = new osAccount.UserAuth(); 2303 let keys: Array<osAccount.GetPropertyType> = [ 2304 osAccount.GetPropertyType.AUTH_SUB_TYPE, 2305 osAccount.GetPropertyType.REMAIN_TIMES, 2306 osAccount.GetPropertyType.FREEZING_TIME 2307 ]; 2308 let request: osAccount.GetPropertyRequest = { 2309 authType: osAccount.AuthType.PIN, 2310 keys: keys 2311 }; 2312 try { 2313 userAuth.getProperty(request).then((result: osAccount.ExecutorProperty) => { 2314 console.log('getProperty result = ' + JSON.stringify(result)); 2315 }).catch((err: BusinessError) => { 2316 console.log('getProperty error = ' + JSON.stringify(err)); 2317 }); 2318 } catch (e) { 2319 console.log('getProperty exception = ' + JSON.stringify(e)); 2320 } 2321 ``` 2322 2323### getPropertyByCredentialId<sup>14+</sup> 2324 2325getPropertyByCredentialId(credentialId: Uint8Array, keys: Array<GetPropertyType>): Promise<ExecutorProperty>; 2326 2327Obtains the specified property information of the associated executor based on the credential ID. This API uses a promise to return the result. 2328 2329**System API**: This is a system API. 2330 2331**System capability**: SystemCapability.Account.OsAccount 2332 2333**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2334 2335**Parameters** 2336 2337| Name | Type | Mandatory| Description | 2338| -------- | ------------------------------------------------------ | ---- | ---------------------------------- | 2339| credentialId | Uint8Array | Yes | Credential ID.| 2340| keys | Array<[GetPropertyType](#getpropertytype8)> | Yes | Property type array to be queried.| 2341 2342**Return value** 2343 2344| Type | Description | 2345| :---------------------------------------------------------------- | :-------------------------------------------------- | 2346| Promise<[ExecutorProperty](#executorproperty8)> | Promise used to return the executor attributes.| 2347 2348**Error codes** 2349 2350| ID| Error Message | 2351| -------- | --------------------------- | 2352| 201 | Permission denied.| 2353| 202 | Not system application.| 2354| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2355| 12300001 | The system service works abnormally. | 2356| 12300002 | Invalid keys. | 2357| 12300102 | The credential does not exist. | 2358 2359**Example** 2360 ```ts 2361 import { BusinessError } from '@kit.BasicServicesKit'; 2362 let userIDM = new osAccount.UserIdentityManager(); 2363 let credInfo: osAccount.EnrolledCredInfo[] = []; 2364 try { 2365 credInfo = await userIDM.getAuthInfo(osAccount.AuthType.PRIVATE_PIN); 2366 } catch (e) { 2367 console.log('getAuthInfo exception = ' + JSON.stringify(e)); 2368 return; 2369 } 2370 if (credInfo.length == 0) { 2371 console.log('no credential infos'); 2372 return; 2373 } 2374 let testCredentialId: Uint8Array = credInfo[0].credentialId; 2375 let keys: Array<osAccount.GetPropertyType> = [ 2376 osAccount.GetPropertyType.AUTH_SUB_TYPE, 2377 osAccount.GetPropertyType.REMAIN_TIMES, 2378 osAccount.GetPropertyType.FREEZING_TIME 2379 ]; 2380 try { 2381 let userAuth = new osAccount.UserAuth(); 2382 userAuth.getPropertyByCredentialId(testCredentialId, keys).then((result: osAccount.ExecutorProperty) => { 2383 console.log('getPropertyByCredentialId result = ' + JSON.stringify(result)); 2384 }).catch((err: BusinessError) => { 2385 console.log('getPropertyByCredentialId error = ' + JSON.stringify(err)); 2386 }); 2387 } catch (e) { 2388 console.log('getPropertyByCredentialId exception = ' + JSON.stringify(e)); 2389 } 2390 ``` 2391 2392### setProperty<sup>8+</sup> 2393 2394setProperty(request: SetPropertyRequest, callback: AsyncCallback<void>): void 2395 2396Sets the property for the initialization algorithm. This API uses an asynchronous callback to return the result. 2397 2398**System API**: This is a system API. 2399 2400**System capability**: SystemCapability.Account.OsAccount 2401 2402**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2403 2404**Parameters** 2405 2406| Name | Type | Mandatory| Description | 2407| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------- | 2408| request | [SetPropertyRequest](#setpropertyrequest8)| Yes | Request information, including the authentication credential type and the key value to set. | 2409| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 2410 2411**Error codes** 2412 2413| ID| Error Message | 2414| -------- | --------------------------- | 2415| 201 | Permission denied.| 2416| 202 | Not system application.| 2417| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2418| 12300001 | The system service works abnormally. | 2419| 12300002 | Invalid request. | 2420 2421**Example** 2422 ```ts 2423 import { BusinessError } from '@kit.BasicServicesKit'; 2424 let userAuth = new osAccount.UserAuth(); 2425 let request: osAccount.SetPropertyRequest = { 2426 authType: osAccount.AuthType.PIN, 2427 key: osAccount.SetPropertyType.INIT_ALGORITHM, 2428 setInfo: new Uint8Array([0]) 2429 }; 2430 try { 2431 userAuth.setProperty(request, (err: BusinessError) => { 2432 if (err) { 2433 console.log('setProperty failed, error = ' + JSON.stringify(err)); 2434 } else { 2435 console.log('setProperty successfully'); 2436 } 2437 }); 2438 } catch (e) { 2439 console.log('setProperty exception = ' + JSON.stringify(e)); 2440 } 2441 ``` 2442 2443### setProperty<sup>8+</sup> 2444 2445setProperty(request: SetPropertyRequest): Promise<void>; 2446 2447Sets the property for the initialization algorithm. This API uses a promise to return the result. 2448 2449**System API**: This is a system API. 2450 2451**System capability**: SystemCapability.Account.OsAccount 2452 2453**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2454 2455**Parameters** 2456 2457| Name | Type | Mandatory| Description | 2458| -------- | ------------------------------------------ | ---- | ---------------------------------------- | 2459| request | [SetPropertyRequest](#setpropertyrequest8) | Yes | Request information, including the authentication credential type and the key value to set.| 2460 2461**Return value** 2462 2463| Type | Description | 2464| :-------------------- | :------------------------------------------------------------ | 2465| Promise<void> | Promise that returns no value.| 2466 2467**Error codes** 2468 2469| ID| Error Message | 2470| -------- | --------------------------- | 2471| 201 | Permission denied.| 2472| 202 | Not system application.| 2473| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2474| 12300001 | The system service works abnormally. | 2475| 12300002 | Invalid request. | 2476 2477**Example** 2478 ```ts 2479 import { BusinessError } from '@kit.BasicServicesKit'; 2480 let userAuth = new osAccount.UserAuth(); 2481 let request: osAccount.SetPropertyRequest = { 2482 authType: osAccount.AuthType.PIN, 2483 key: osAccount.SetPropertyType.INIT_ALGORITHM, 2484 setInfo: new Uint8Array([0]) 2485 }; 2486 try { 2487 userAuth.setProperty(request).then(() => { 2488 console.log('setProperty successfully'); 2489 }).catch((err: BusinessError) => { 2490 console.log('setProperty failed, error = ' + JSON.stringify(err)); 2491 }); 2492 } catch (e) { 2493 console.log('setProperty exception = ' + JSON.stringify(e)); 2494 } 2495 ``` 2496 2497### prepareRemoteAuth<sup>12+</sup> 2498 2499prepareRemoteAuth(remoteNetworkId: string): Promise<void>; 2500 2501Prepares for remote authentication. This API uses a promise to return the result. 2502 2503**System API**: This is a system API. 2504 2505**System capability**: SystemCapability.Account.OsAccount 2506 2507**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2508 2509**Parameters** 2510 2511| Name | Type | Mandatory| Description | 2512| -------- | ------ | ---- | --------------- | 2513| remoteNetworkId | string | Yes | Remote network ID. | 2514 2515**Return value** 2516 2517| Type | Description | 2518| :-------------------- | :------------------------------------------------------------ | 2519| Promise<void> | Promise that returns no value.| 2520 2521**Error codes** 2522 2523| ID| Error Message | 2524| -------- | --------------------------- | 2525| 201 | Permission denied.| 2526| 202 | Not system application.| 2527| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2528| 12300001 | System service exception. | 2529| 12300002 | Invalid remoteNetworkId. | 2530 2531**Example** 2532 ```ts 2533 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 2534 import { BusinessError } from '@kit.BasicServicesKit'; 2535 2536 let userAuth = new osAccount.UserAuth(); 2537 let distributedDeviceMgr = distributedDeviceManager.createDeviceManager("com.example.bundleName"); 2538 distributedDeviceMgr.getAvailableDeviceList().then((data: Array<distributedDeviceManager.DeviceBasicInfo>) => { 2539 try { 2540 if (data.length > 0 && data[0].networkId != null) { 2541 userAuth.prepareRemoteAuth(data[0].networkId).then(() => { 2542 console.log('prepareRemoteAuth successfully'); 2543 }).catch((err: BusinessError) => { 2544 console.log('prepareRemoteAuth failed, error = ' + JSON.stringify(err)); 2545 }); 2546 } 2547 } catch (e) { 2548 console.log('prepareRemoteAuth exception = ' + JSON.stringify(e)); 2549 } 2550 } 2551 ) 2552 ``` 2553 2554### auth<sup>8+</sup> 2555 2556auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array; 2557 2558Performs authentication of the current user. This API uses an asynchronous callback to return the result. 2559 2560**System API**: This is a system API. 2561 2562**System capability**: SystemCapability.Account.OsAccount 2563 2564**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2565 2566**Parameters** 2567 2568| Name | Type | Mandatory| Description | 2569| --------------- | ---------------------------------------- | --- | ------------------------------------ | 2570| challenge | Uint8Array | Yes | Challenge value, which is a random number used to improve security.| 2571| authType | [AuthType](#authtype8) | Yes | Authentication credential type. | 2572| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | Yes | Trust level of the authentication result. | 2573| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback used to return the authentication result. | 2574 2575**Return value** 2576 2577| Type | Description | 2578| ---------- | ------------------ | 2579| Uint8Array | ID of the context for canceling the authentication.| 2580 2581**Error codes** 2582 2583| ID| Error Message | 2584| -------- | --------------------- | 2585| 201 | Permission denied.| 2586| 202 | Not system application.| 2587| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2588| 12300001 | The system service works abnormally. | 2589| 12300002 | Invalid challenge, authType or authTrustLevel. | 2590| 12300013 | Network exception. | 2591| 12300101 | The credential is incorrect. | 2592| 12300102 | The credential does not exist. | 2593| 12300105 | The trust level is not supported. | 2594| 12300106 | The authentication type is not supported. | 2595| 12300109 | The authentication, enrollment, or update operation is canceled. | 2596| 12300110 | The authentication is locked. | 2597| 12300111 | The authentication time out. | 2598| 12300112 | The authentication service is busy. | 2599| 12300113 | The authentication service does not exist. | 2600| 12300114 | The authentication service works abnormally. | 2601| 12300117 | PIN is expired. | 2602| 12300211 | Server unreachable. | 2603 2604**Example** 2605 ```ts 2606 let userAuth = new osAccount.UserAuth(); 2607 let challenge: Uint8Array = new Uint8Array([0]); 2608 let authType: osAccount.AuthType = osAccount.AuthType.PIN; 2609 let authTrustLevel: osAccount.AuthTrustLevel = osAccount.AuthTrustLevel.ATL1; 2610 try { 2611 userAuth.auth(challenge, authType, authTrustLevel, { 2612 onResult: (result: number, extraInfo: osAccount.AuthResult) => { 2613 console.log('auth result = ' + result); 2614 console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); 2615 } 2616 }); 2617 } catch (e) { 2618 console.log('auth exception = ' + JSON.stringify(e)); 2619 } 2620 ``` 2621 2622### auth<sup>12+</sup> 2623 2624auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, options: AuthOptions, callback: IUserAuthCallback): Uint8Array 2625 2626Starts user authentication based on the specified challenge value, authentication type (PIN, facial, or fingerprint authentication), authentication trust level, and optional parameters (such as the account ID and authentication intent). This API uses an asynchronous callback to return the result. 2627 2628**System API**: This is a system API. 2629 2630**System capability**: SystemCapability.Account.OsAccount 2631 2632**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2633 2634**Parameters** 2635 2636| Name | Type | Mandatory| Description | 2637| --------------- | ---------------------------------------- | --- | ------------------------------------ | 2638| challenge | Uint8Array | Yes | Challenge value, which is a random number used to prevent replay attacks and improve security.| 2639| authType | [AuthType](#authtype8) | Yes | Authentication credential type. | 2640| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | Yes | Trust level of the authentication result. | 2641| options | [AuthOptions](#authoptions12) | Yes| Optional parameters for the authentication.| 2642| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback used to return the authentication result. | 2643 2644**Return value** 2645 2646| Type | Description | 2647| ---------- | ------------------ | 2648| Uint8Array | ID of the context for canceling the authentication.| 2649 2650**Error codes** 2651 2652| ID| Error Message | 2653| -------- | --------------------- | 2654| 201 | Permission denied.| 2655| 202 | Not system application.| 2656| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2657| 12300001 | The system service works abnormally. | 2658| 12300002 | Invalid challenge, authType, authTrustLevel or options. | 2659| 12300003 | Account not found. | 2660| 12300013 | Network exception. | 2661| 12300101 | The credential is incorrect. | 2662| 12300102 | The credential does not exist. | 2663| 12300105 | The trust level is not supported. | 2664| 12300106 | The authentication type is not supported. | 2665| 12300109 | The authentication, enrollment, or update operation is canceled. | 2666| 12300110 | The authentication is locked. | 2667| 12300111 | The authentication time out. | 2668| 12300112 | The authentication service is busy. | 2669| 12300113 | The authentication service does not exist. | 2670| 12300114 | The authentication service works abnormally. | 2671| 12300117 | PIN is expired. | 2672| 12300211 | Server unreachable. | 2673 2674**Example** 2675 ```ts 2676 let userAuth = new osAccount.UserAuth(); 2677 let challenge: Uint8Array = new Uint8Array([0]); 2678 let authType: osAccount.AuthType = osAccount.AuthType.PIN; 2679 let authTrustLevel: osAccount.AuthTrustLevel = osAccount.AuthTrustLevel.ATL1; 2680 let options: osAccount.AuthOptions = { 2681 accountId: 100 2682 }; 2683 try { 2684 userAuth.auth(challenge, authType, authTrustLevel, options, { 2685 onResult: (result: number, extraInfo: osAccount.AuthResult) => { 2686 console.log('auth result = ' + result); 2687 console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); 2688 } 2689 }); 2690 } catch (e) { 2691 console.log('auth exception = ' + JSON.stringify(e)); 2692 } 2693 ``` 2694 2695### authUser<sup>8+</sup> 2696 2697authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array; 2698 2699Performs authentication of the specified user. This API uses an asynchronous callback to return the result. 2700 2701**System API**: This is a system API. 2702 2703**System capability**: SystemCapability.Account.OsAccount 2704 2705**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2706 2707**Parameters** 2708 2709| Name | Type | Mandatory| Description | 2710| --------------- | ---------------------------------------------------- | --- | ------------------------------------ | 2711| userId | number | Yes | User ID. | 2712| challenge | Uint8Array | Yes | Challenge value, which is a random number used to improve security. | 2713| authType | [AuthType](#authtype8) | Yes | Authentication credential type. | 2714| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | Yes | Trust level of the authentication result. | 2715| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback used to return the authentication result. | 2716 2717**Return value** 2718 2719| Type | Description | 2720| ---------- | ------------------ | 2721| Uint8Array | ID of the context for canceling the authentication.| 2722 2723**Error codes** 2724 2725| ID| Error Message | 2726| -------- | --------------------- | 2727| 201 | Permission denied.| 2728| 202 | Not system application.| 2729| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2730| 12300001 | The system service works abnormally. | 2731| 12300002 | Invalid challenge, authType or authTrustLevel. | 2732| 12300003 | Account not found. | 2733| 12300013 | Network exception. | 2734| 12300101 | The credential is incorrect. | 2735| 12300102 | The credential does not exist. | 2736| 12300105 | The trust level is not supported. | 2737| 12300106 | The authentication type is not supported. | 2738| 12300109 | The authentication, enrollment, or update operation is canceled. | 2739| 12300110 | The authentication is locked. | 2740| 12300111 | The authentication time out. | 2741| 12300112 | The authentication service is busy. | 2742| 12300113 | The authentication service does not exist. | 2743| 12300114 | The authentication service works abnormally. | 2744| 12300117 | PIN is expired. | 2745| 12300211 | Server unreachable. | 2746 2747**Example** 2748 ```ts 2749 let userAuth = new osAccount.UserAuth(); 2750 let userID: number = 100; 2751 let challenge: Uint8Array = new Uint8Array([0]); 2752 let authType: osAccount.AuthType = osAccount.AuthType.PIN; 2753 let authTrustLevel: osAccount.AuthTrustLevel = osAccount.AuthTrustLevel.ATL1; 2754 try { 2755 userAuth.authUser(userID, challenge, authType, authTrustLevel, { 2756 onResult: (result,extraInfo) => { 2757 console.log('authUser result = ' + result); 2758 console.log('authUser extraInfo = ' + JSON.stringify(extraInfo)); 2759 } 2760 }); 2761 } catch (e) { 2762 console.log('authUser exception = ' + JSON.stringify(e)); 2763 } 2764 ``` 2765 2766### cancelAuth<sup>8+</sup> 2767 2768cancelAuth(contextID: Uint8Array): void 2769 2770Cancels an authentication. 2771 2772**System API**: This is a system API. 2773 2774**System capability**: SystemCapability.Account.OsAccount 2775 2776**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 2777 2778**Parameters** 2779 2780| Name | Type | Mandatory | Description | 2781| ----------| ---------- | ---- | ------------------------------------------ | 2782| contextId | Uint8Array | Yes | ID of the authentication context. The context ID is dynamically generated.| 2783 2784**Error codes** 2785 2786| ID| Error Message | 2787| -------- | ------------------ | 2788| 201 | Permission denied.| 2789| 202 | Not system application.| 2790| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2791| 12300001 | The system service works abnormally. | 2792| 12300002 | Invalid contextId. | 2793 2794**Example** 2795 ```ts 2796 let userAuth = new osAccount.UserAuth(); 2797 let pinAuth: osAccount.PINAuth = new osAccount.PINAuth(); 2798 let challenge = new Uint8Array([0]); 2799 let contextId: Uint8Array = userAuth.auth(challenge, osAccount.AuthType.PIN, osAccount.AuthTrustLevel.ATL1, { 2800 onResult: (result: number, extraInfo: osAccount.AuthResult) => { 2801 console.log('auth result = ' + result); 2802 console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); 2803 } 2804 }); 2805 try { 2806 userAuth.cancelAuth(contextId); 2807 } catch (e) { 2808 console.log('cancelAuth exception = ' + JSON.stringify(e)); 2809 } 2810 ``` 2811 2812## PINAuth<sup>8+</sup> 2813 2814Provides APIs for PIN authentication. 2815 2816**System API**: This is a system API. 2817 2818### constructor<sup>8+</sup> 2819 2820constructor() 2821 2822Creates a PIN authentication instance. 2823 2824**System API**: This is a system API. 2825 2826**System capability**: SystemCapability.Account.OsAccount 2827 2828**Error codes** 2829 2830| ID| Error Message | 2831| -------- | ------------- | 2832| 202 | Not system application.| 2833 2834**Example** 2835 ```ts 2836 let pinAuth: osAccount.PINAuth = new osAccount.PINAuth(); 2837 ``` 2838 2839### registerInputer<sup>8+</sup> 2840 2841registerInputer(inputer: IInputer): void 2842 2843Registers a PIN inputer. 2844 2845**System API**: This is a system API. 2846 2847**System capability**: SystemCapability.Account.OsAccount 2848 2849**Required permissions**: ohos.permission.ACCESS_PIN_AUTH 2850 2851**Parameters** 2852 2853| Name | Type | Mandatory| Description | 2854| ----------| ----------------------- | --- | -------------------------- | 2855| inputer | [IInputer](#iinputer8) | Yes | PIN inputer, which is used to obtain the PIN.| 2856 2857**Error codes** 2858 2859| ID| Error Message | 2860| -------- | --------------------------- | 2861| 201 | Permission denied.| 2862| 202 | Not system application.| 2863| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2864| 12300001 | The system service works abnormally. | 2865| 12300002 | Invalid inputer. | 2866| 12300103 | The credential inputer already exists. | 2867 2868**Example** 2869 ```ts 2870 let pinAuth: osAccount.PINAuth = new osAccount.PINAuth(); 2871 let password = new Uint8Array([0, 0, 0, 0, 0]); 2872 try { 2873 pinAuth.registerInputer({ 2874 onGetData: (authSubType: osAccount.AuthSubType, callback: osAccount.IInputData) => { 2875 callback.onSetData(authSubType, password); 2876 } 2877 }); 2878 console.log('registerInputer success.'); 2879 } catch (e) { 2880 console.log('registerInputer exception = ' + JSON.stringify(e)); 2881 } 2882 ``` 2883 2884### unregisterInputer<sup>8+</sup> 2885 2886unregisterInputer(): void 2887 2888Unregisters this PIN inputer. 2889 2890**System API**: This is a system API. 2891 2892**System capability**: SystemCapability.Account.OsAccount 2893 2894**Required permissions**: ohos.permission.ACCESS_PIN_AUTH 2895 2896**Error codes** 2897 2898| ID| Error Message | 2899| -------- | --------------------------- | 2900| 201 | Permission denied.| 2901| 202 | Not system application.| 2902 2903**Example** 2904 ```ts 2905 let pinAuth: osAccount.PINAuth = new osAccount.PINAuth(); 2906 pinAuth.unregisterInputer(); 2907 ``` 2908 2909## InputerManager <sup>9+</sup> 2910 2911Provides APIs for managing credential inputers. 2912 2913### registerInputer<sup>9+</sup> 2914 2915static registerInputer(authType: AuthType, inputer: IInputer): void 2916 2917Registers a credential inputer. 2918 2919**System API**: This is a system API. 2920 2921**System capability**: SystemCapability.Account.OsAccount 2922 2923**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL or ohos.permission.MANAGE_USER_IDM 2924 2925**Parameters** 2926 2927| Name | Type | Mandatory| Description | 2928| ----------| ----------------------- | --- | -------------------------- | 2929| authType | [AuthType](#authtype8) | Yes | Authentication credential type.| 2930| inputer | [IInputer](#iinputer8) | Yes | Credential inputer to register.| 2931 2932**Error codes** 2933 2934| ID| Error Message | 2935| -------- | --------------------------- | 2936| 201 | Permission denied.| 2937| 202 | Not system application.| 2938| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2939| 12300001 | The system service works abnormally. | 2940| 12300002 | Invalid authType or inputer. | 2941| 12300103 | The credential inputer already exists. | 2942| 12300106 | The authentication type is not supported. | 2943 2944**Example** 2945 ```ts 2946 let authType: osAccount.AuthType = osAccount.AuthType.DOMAIN; 2947 let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0]); 2948 try { 2949 osAccount.InputerManager.registerInputer(authType, { 2950 onGetData: (authSubType: osAccount.AuthSubType, callback: osAccount.IInputData) => { 2951 callback.onSetData(authSubType, password); 2952 } 2953 }); 2954 console.log('registerInputer success.'); 2955 } catch (e) { 2956 console.log('registerInputer exception = ' + JSON.stringify(e)); 2957 } 2958 ``` 2959 2960### unregisterInputer<sup>9+</sup> 2961 2962static unregisterInputer(authType: AuthType): void 2963 2964Unregisters this credential inputer. 2965 2966**System API**: This is a system API. 2967 2968**System capability**: SystemCapability.Account.OsAccount 2969 2970**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL or ohos.permission.MANAGE_USER_IDM 2971 2972**Parameters** 2973 2974| Name | Type | Mandatory| Description | 2975| ----------| ----------------------- | --- | -------------------------- | 2976| authType | [AuthType](#authtype8) | Yes | Authentication credential type.| 2977 2978**Error codes** 2979 2980| ID| Error Message | 2981| -------- | --------------------------- | 2982| 201 | Permission denied.| 2983| 202 | Not system application.| 2984| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2985| 12300002 | Invalid authType. | 2986 2987**Example** 2988 ```ts 2989 let authType: osAccount.AuthType = osAccount.AuthType.DOMAIN; 2990 try { 2991 osAccount.InputerManager.unregisterInputer(authType); 2992 console.log('unregisterInputer success.'); 2993 } catch(err) { 2994 console.log('unregisterInputer err:' + JSON.stringify(err)); 2995 } 2996 ``` 2997 2998## DomainPlugin<sup>9+</sup> 2999 3000Provides APIs for domain account authentication. 3001 3002**System API**: This is a system API. 3003 3004### auth<sup>9+</sup> 3005 3006auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void 3007 3008Authenticates a domain account. 3009 3010**System API**: This is a system API. 3011 3012**System capability**: SystemCapability.Account.OsAccount 3013 3014**Parameters** 3015 3016| Name | Type | Mandatory| Description | 3017| ---------- | --------------------------------------- | ---- | --------------- | 3018| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3019| credential | Uint8Array | Yes | Credentials of the domain account.| 3020| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback used to return the authentication result.| 3021 3022**Example** 3023 ```ts 3024 import { AsyncCallback } from '@kit.BasicServicesKit'; 3025 let plugin: osAccount.DomainPlugin = { 3026 auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, 3027 callback: osAccount.IUserAuthCallback) => { 3028 // mock authentication 3029 // notify authentication result 3030 let result: osAccount.AuthResult = { 3031 token: new Uint8Array([0]), 3032 remainTimes: 5, 3033 freezingTime: 0 3034 }; 3035 callback.onResult(0, result); 3036 }, 3037 authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, 3038 callback: osAccount.IUserAuthCallback) => {}, 3039 authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3040 callback: osAccount.IUserAuthCallback) => {}, 3041 getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, 3042 callback: AsyncCallback<osAccount.DomainAccountInfo>) => {}, 3043 getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, 3044 callback: AsyncCallback<osAccount.AuthStatusInfo>) => {}, 3045 bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, 3046 callback: AsyncCallback<void>) => {}, 3047 unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 3048 isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3049 callback: AsyncCallback<boolean>) => {}, 3050 getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 3051 } 3052 osAccount.DomainAccountManager.registerPlugin(plugin); 3053 let userAuth = new osAccount.UserAuth(); 3054 let challenge: Uint8Array = new Uint8Array([0]); 3055 let authType: osAccount.AuthType = osAccount.AuthType.DOMAIN; 3056 let authTrustLevel: osAccount.AuthTrustLevel = osAccount.AuthTrustLevel.ATL1; 3057 try { 3058 userAuth.auth(challenge, authType, authTrustLevel, { 3059 onResult: (resultCode: number, authResult: osAccount.AuthResult) => { 3060 console.log('auth resultCode = ' + resultCode); 3061 console.log('auth authResult = ' + JSON.stringify(authResult)); 3062 } 3063 }); 3064 } catch (err) { 3065 console.log('auth exception = ' + JSON.stringify(err)); 3066 } 3067 ``` 3068 3069### authWithPopup<sup>10+</sup> 3070 3071authWithPopup(domainAccountInfo: DomainAccountInfo, callback: IUserAuthCallback): void 3072 3073Authenticates a domain account in a pop-up window. 3074 3075**System API**: This is a system API. 3076 3077**System capability**: SystemCapability.Account.OsAccount 3078 3079**Parameters** 3080 3081| Name | Type | Mandatory| Description | 3082| ---------- | --------------------------------------- | ---- | --------------- | 3083| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3084| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback used to return the authentication result.| 3085 3086**Example** 3087 ```ts 3088 import { AsyncCallback } from '@kit.BasicServicesKit'; 3089 let plugin: osAccount.DomainPlugin = { 3090 auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, 3091 callback: osAccount.IUserAuthCallback) => {}, 3092 authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, 3093 callback: osAccount.IUserAuthCallback) => { 3094 // mock authentication 3095 // notify authentication result 3096 let result: osAccount.AuthResult = { 3097 token: new Uint8Array([0]), 3098 remainTimes: 5, 3099 freezingTime: 0 3100 }; 3101 callback.onResult(0, result); 3102 }, 3103 authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3104 callback: osAccount.IUserAuthCallback) => {}, 3105 getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, 3106 callback: AsyncCallback<osAccount.DomainAccountInfo>) => {}, 3107 getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, 3108 callback: AsyncCallback<osAccount.AuthStatusInfo>) => {}, 3109 bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, 3110 callback: AsyncCallback<void>) => {}, 3111 unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 3112 isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3113 callback: AsyncCallback<boolean>) => {}, 3114 getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 3115 } 3116 osAccount.DomainAccountManager.registerPlugin(plugin) 3117 ``` 3118 3119### authWithToken<sup>10+</sup> 3120 3121authWithToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: IUserAuthCallback): void 3122 3123Authenticates a domain account by the authorization token. 3124 3125**System API**: This is a system API. 3126 3127**System capability**: SystemCapability.Account.OsAccount 3128 3129**Parameters** 3130 3131| Name | Type | Mandatory| Description | 3132| ---------- | --------------------------------------- | ---- | --------------- | 3133| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3134| token | Uint8Array | Yes | Authorization token generated when the PIN or biometric authentication is successful.| 3135| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback used to return the authentication result.| 3136 3137**Example** 3138 ```ts 3139 import { AsyncCallback } from '@kit.BasicServicesKit'; 3140 let plugin: osAccount.DomainPlugin = { 3141 auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, 3142 callback: osAccount.IUserAuthCallback) => {}, 3143 authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, 3144 callback: osAccount.IUserAuthCallback) => {}, 3145 authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3146 callback: osAccount.IUserAuthCallback) => { 3147 // mock authentication 3148 // notify authentication result 3149 let result: osAccount.AuthResult = { 3150 token: new Uint8Array([0]), 3151 remainTimes: 5, 3152 freezingTime: 0 3153 }; 3154 callback.onResult(0, result); 3155 }, 3156 getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, 3157 callback: AsyncCallback<osAccount.DomainAccountInfo>) => {}, 3158 getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, 3159 callback: AsyncCallback<osAccount.AuthStatusInfo>) => {}, 3160 bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, 3161 callback: AsyncCallback<void>) => {}, 3162 unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 3163 isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3164 callback: AsyncCallback<boolean>) => {}, 3165 getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 3166 } 3167 osAccount.DomainAccountManager.registerPlugin(plugin) 3168 ``` 3169 3170### getAccountInfo<sup>10+</sup> 3171 3172getAccountInfo(options: GetDomainAccountInfoPluginOptions, callback: AsyncCallback<DomainAccountInfo>): void 3173 3174Obtains information about a domain account. 3175 3176**System API**: This is a system API. 3177 3178**System capability**: SystemCapability.Account.OsAccount 3179 3180**Parameters** 3181 3182| Name | Type | Mandatory| Description | 3183| ---------- | --------------------------------------- | ---- | --------------- | 3184| options | [GetDomainAccountInfoPluginOptions](#getdomainaccountinfopluginoptions10) | Yes | Domain account information.| 3185| callback | AsyncCallback<[DomainAccountInfo](#domainaccountinfo8)> | Yes | Callback used to return the result.| 3186 3187**Example** 3188 ```ts 3189 import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 3190 let plugin: osAccount.DomainPlugin = { 3191 auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, 3192 callback: osAccount.IUserAuthCallback) => {}, 3193 authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, 3194 callback: osAccount.IUserAuthCallback) => {}, 3195 authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3196 callback: osAccount.IUserAuthCallback) => {}, 3197 getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, 3198 callback: AsyncCallback<osAccount.DomainAccountInfo>) => { 3199 // mock getting account information 3200 // notify result 3201 let code: BusinessError = { 3202 code: 0, 3203 name: "", 3204 message: "" 3205 }; 3206 let accountInfo: osAccount.DomainAccountInfo = { 3207 domain: options.domain ? options.domain : "", 3208 accountName: options.accountName, 3209 accountId: 'xxxx' 3210 }; 3211 callback(code, accountInfo); 3212 }, 3213 getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, 3214 callback: AsyncCallback<osAccount.AuthStatusInfo>) => {}, 3215 bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, 3216 callback: AsyncCallback<void>) => {}, 3217 unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 3218 isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3219 callback: AsyncCallback<boolean>) => {}, 3220 getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 3221 } 3222 osAccount.DomainAccountManager.registerPlugin(plugin) 3223 ``` 3224 3225### getAuthStatusInfo<sup>10+</sup> 3226 3227getAuthStatusInfo(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback<AuthStatusInfo>): void 3228 3229Obtains the authentication status of a domain account. 3230 3231**System API**: This is a system API. 3232 3233**System capability**: SystemCapability.Account.OsAccount 3234 3235**Parameters** 3236 3237| Name | Type | Mandatory| Description | 3238| ---------- | --------------------------------------- | ---- | --------------- | 3239| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3240| callback | AsyncCallback<[AuthStatusInfo](#authstatusinfo10)> | Yes | Callback used to return the result.| 3241 3242**Example** 3243 ```ts 3244 import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 3245 let plugin: osAccount.DomainPlugin = { 3246 auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, 3247 callback: osAccount.IUserAuthCallback) => {}, 3248 authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, 3249 callback: osAccount.IUserAuthCallback) => {}, 3250 authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3251 callback: osAccount.IUserAuthCallback) => {}, 3252 getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, 3253 callback: AsyncCallback<osAccount.DomainAccountInfo>) => {}, 3254 getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, 3255 callback: AsyncCallback<osAccount.AuthStatusInfo>) => { 3256 let code: BusinessError = { 3257 code: 0, 3258 name: "", 3259 message: "" 3260 }; 3261 let statusInfo: osAccount.AuthStatusInfo = { 3262 remainTimes: 5, 3263 freezingTime: 0 3264 }; 3265 callback(code, statusInfo); 3266 }, 3267 bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, 3268 callback: AsyncCallback<void>) => {}, 3269 unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 3270 isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3271 callback: AsyncCallback<boolean>) => {}, 3272 getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 3273 } 3274 osAccount.DomainAccountManager.registerPlugin(plugin) 3275 ``` 3276 3277### bindAccount<sup>10+</sup> 3278 3279bindAccount(domainAccountInfo: DomainAccountInfo, localId: number, callback: AsyncCallback<void>): void 3280 3281Binds a domain account. 3282 3283**System API**: This is a system API. 3284 3285**System capability**: SystemCapability.Account.OsAccount 3286 3287**Parameters** 3288 3289| Name | Type | Mandatory| Description | 3290| ---------- | --------------------------------------- | ---- | --------------- | 3291| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3292| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3293 3294**Example** 3295 ```ts 3296 import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 3297 let plugin: osAccount.DomainPlugin = { 3298 auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, 3299 callback: osAccount.IUserAuthCallback) => {}, 3300 authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, 3301 callback: osAccount.IUserAuthCallback) => {}, 3302 authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3303 callback: osAccount.IUserAuthCallback) => {}, 3304 getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, 3305 callback: AsyncCallback<osAccount.DomainAccountInfo>) => {}, 3306 getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, 3307 callback: AsyncCallback<osAccount.AuthStatusInfo>) => {}, 3308 bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, 3309 callback: AsyncCallback<void>) => { 3310 // mock unbinding operation 3311 // notify binding result 3312 let code: BusinessError = { 3313 code: 0, 3314 name: "", 3315 message: "" 3316 }; 3317 callback(code); 3318 }, 3319 unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 3320 isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3321 callback: AsyncCallback<boolean>) => {}, 3322 getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 3323 } 3324 osAccount.DomainAccountManager.registerPlugin(plugin) 3325 ``` 3326 3327### unbindAccount<sup>10+</sup> 3328 3329unbindAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback<void>): void 3330 3331Unbinds a domain account. 3332 3333**System API**: This is a system API. 3334 3335**System capability**: SystemCapability.Account.OsAccount 3336 3337**Parameters** 3338 3339| Name | Type | Mandatory| Description | 3340| ---------- | --------------------------------------- | ---- | --------------- | 3341| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3342| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3343 3344**Example** 3345 ```ts 3346 import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 3347 let plugin: osAccount.DomainPlugin = { 3348 auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, 3349 callback: osAccount.IUserAuthCallback) => {}, 3350 authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, 3351 callback: osAccount.IUserAuthCallback) => {}, 3352 authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3353 callback: osAccount.IUserAuthCallback) => {}, 3354 getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, 3355 callback: AsyncCallback<osAccount.DomainAccountInfo>) => {}, 3356 getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, 3357 callback: AsyncCallback<osAccount.AuthStatusInfo>) => {}, 3358 bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, 3359 callback: AsyncCallback<void>) => {}, 3360 unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => { 3361 // mock unbinding operation 3362 // notify unbinding result 3363 let code: BusinessError = { 3364 code: 0, 3365 name: "", 3366 message: "" 3367 }; 3368 callback(code); 3369 }, 3370 isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3371 callback: AsyncCallback<boolean>) => {}, 3372 getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 3373 } 3374 osAccount.DomainAccountManager.registerPlugin(plugin) 3375 ``` 3376 3377### isAccountTokenValid<sup>10+</sup> 3378 3379isAccountTokenValid(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: AsyncCallback<boolean>): void 3380 3381Checks whether the specified domain account token is valid. 3382 3383**System API**: This is a system API. 3384 3385**System capability**: SystemCapability.Account.OsAccount 3386 3387**Parameters** 3388 3389| Name | Type | Mandatory| Description | 3390| ---------- | --------------------------------------- | ---- | --------------- | 3391| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3392| token | Uint8Array | Yes| Domain account token to check.| 3393| callback | AsyncCallback<boolean> | Yes | Callback used to return the result.| 3394 3395**Example** 3396 ```ts 3397 import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 3398 let plugin: osAccount.DomainPlugin = { 3399 auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, 3400 callback: osAccount.IUserAuthCallback) => {}, 3401 authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, 3402 callback: osAccount.IUserAuthCallback) => {}, 3403 authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3404 callback: osAccount.IUserAuthCallback) => {}, 3405 getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, 3406 callback: AsyncCallback<osAccount.DomainAccountInfo>) => {}, 3407 getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, 3408 callback: AsyncCallback<osAccount.AuthStatusInfo>) => {}, 3409 bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, 3410 callback: AsyncCallback<void>) => {}, 3411 unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 3412 isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3413 callback: AsyncCallback<boolean>) => { 3414 // mock checking operation 3415 // notify checking result 3416 let code: BusinessError = { 3417 code: 0, 3418 name: "", 3419 message: "" 3420 }; 3421 callback(code, true); 3422 }, 3423 getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 3424 } 3425 osAccount.DomainAccountManager.registerPlugin(plugin) 3426 ``` 3427 3428### getAccessToken<sup>10+</sup> 3429 3430getAccessToken(options: GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>): void 3431 3432Obtains the domain access token based on the specified conditions. 3433 3434**System API**: This is a system API. 3435 3436**System capability**: SystemCapability.Account.OsAccount 3437 3438**Parameters** 3439 3440| Name | Type | Mandatory| Description | 3441| ---------- | --------------------------------------- | ---- | --------------- | 3442| options | [GetDomainAccessTokenOptions](#getdomainaccesstokenoptions10) | Yes | Options specified for obtaining the domain access token.| 3443| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.| 3444 3445**Example** 3446 ```ts 3447 import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 3448 let plugin: osAccount.DomainPlugin = { 3449 auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, 3450 callback: osAccount.IUserAuthCallback) => {}, 3451 authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, 3452 callback: osAccount.IUserAuthCallback) => {}, 3453 authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3454 callback: osAccount.IUserAuthCallback) => {}, 3455 getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, 3456 callback: AsyncCallback<osAccount.DomainAccountInfo>) => {}, 3457 getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, 3458 callback: AsyncCallback<osAccount.AuthStatusInfo>) => {}, 3459 bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, 3460 callback: AsyncCallback<void>) => {}, 3461 unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 3462 isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3463 callback: AsyncCallback<boolean>) => {}, 3464 getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => { 3465 // mock getting operation 3466 // notify result 3467 let code: BusinessError = { 3468 code: 0, 3469 name: "", 3470 message: "" 3471 }; 3472 let token: Uint8Array = new Uint8Array([0]); 3473 callback(code, token); 3474 } 3475 } 3476 osAccount.DomainAccountManager.registerPlugin(plugin) 3477 ``` 3478 3479## DomainAccountManager <sup>9+</sup> 3480Provides APIs for domain account management. 3481 3482### registerPlugin<sup>9+</sup> 3483 3484static registerPlugin(plugin: DomainPlugin): void 3485 3486Registers a domain plug-in. 3487 3488**System API**: This is a system API. 3489 3490**System capability**: SystemCapability.Account.OsAccount 3491 3492**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 3493 3494**Parameters** 3495 3496| Name | Type | Mandatory| Description | 3497| ----------| ----------------------- | --- | -------------------------- | 3498| plugin | [DomainPlugin](#domainplugin9) | Yes | Domain plug-in to register.| 3499 3500**Error codes** 3501 3502| ID| Error Message | 3503| -------- | --------------------------- | 3504| 201 | Permission denied.| 3505| 202 | Not system application.| 3506| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3507| 12300201 | The domain plugin has been registered. | 3508 3509**Example** 3510 ```ts 3511 import { AsyncCallback } from '@kit.BasicServicesKit'; 3512 let plugin: osAccount.DomainPlugin = { 3513 auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, 3514 callback: osAccount.IUserAuthCallback) => {}, 3515 authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, 3516 callback: osAccount.IUserAuthCallback) => {}, 3517 authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3518 callback: osAccount.IUserAuthCallback) => {}, 3519 getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, 3520 callback: AsyncCallback<osAccount.DomainAccountInfo>) => {}, 3521 getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, 3522 callback: AsyncCallback<osAccount.AuthStatusInfo>) => {}, 3523 bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, 3524 callback: AsyncCallback<void>) => {}, 3525 unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback<void>) => {}, 3526 isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, 3527 callback: AsyncCallback<boolean>) => {}, 3528 getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback<Uint8Array>) => {} 3529 } 3530 try { 3531 osAccount.DomainAccountManager.registerPlugin(plugin); 3532 console.log('registerPlugin success.'); 3533 } catch(err) { 3534 console.log('registerPlugin err:' + JSON.stringify(err)); 3535 } 3536 ``` 3537 3538### unregisterPlugin<sup>9+</sup> 3539 3540static unregisterPlugin(): void 3541 3542Unregisters this domain plug-in. 3543 3544**System API**: This is a system API. 3545 3546**System capability**: SystemCapability.Account.OsAccount 3547 3548**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 3549 3550**Error codes** 3551 3552| ID| Error Message | 3553| -------- | --------------------------- | 3554| 201 | Permission denied.| 3555| 202 | Not system application.| 3556 3557**Example** 3558 ```ts 3559 try { 3560 osAccount.DomainAccountManager.unregisterPlugin(); 3561 console.log('unregisterPlugin success.'); 3562 } catch(err) { 3563 console.log('unregisterPlugin err:' + JSON.stringify(err)); 3564 } 3565 ``` 3566 3567### auth<sup>10+</sup> 3568 3569auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void 3570 3571Authenticates a domain account. 3572 3573**System API**: This is a system API. 3574 3575**System capability**: SystemCapability.Account.OsAccount 3576 3577**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 3578 3579**Parameters** 3580 3581| Name | Type | Mandatory| Description | 3582| ---------- | --------------------------------------- | ---- | --------------- | 3583| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3584| credential | Uint8Array | Yes | Credentials of the domain account.| 3585| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback used to return the authentication result.| 3586 3587**Error codes** 3588 3589| ID| Error Message | 3590| -------- | --------------------------- | 3591| 201 | Permission denied.| 3592| 202 | Not system application.| 3593| 401 |Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3594| 801 | Capability not supported.| 3595| 12300001 | The system service works abnormally. | 3596| 12300002 | Invalid domainAccountInfo or credential. | 3597| 12300003 | Domain account does not exist. | 3598| 12300013 | Network exception. | 3599| 12300101 | Authentication failed. | 3600| 12300109 | The authentication, enrollment, or update operation is canceled. | 3601| 12300110 | The authentication is locked. | 3602| 12300111 | The authentication time out. | 3603| 12300112 | The authentication service is busy. | 3604| 12300113 | The account authentication service does not exist. | 3605| 12300114 | The account authentication service works abnormally. | 3606| 12300211 | Server unreachable. | 3607 3608**Example** 3609 ```ts 3610 let domainAccountInfo: osAccount.DomainAccountInfo = { 3611 domain: 'CHINA', 3612 accountName: 'zhangsan' 3613 } 3614 let credential = new Uint8Array([0]) 3615 try { 3616 osAccount.DomainAccountManager.auth(domainAccountInfo, credential, { 3617 onResult: (resultCode: number, authResult: osAccount.AuthResult) => { 3618 console.log('auth resultCode = ' + resultCode); 3619 console.log('auth authResult = ' + JSON.stringify(authResult)); 3620 } 3621 }); 3622 } catch (err) { 3623 console.log('auth exception = ' + JSON.stringify(err)); 3624 } 3625 ``` 3626 3627### authWithPopup<sup>10+</sup> 3628 3629authWithPopup(callback: IUserAuthCallback): void 3630 3631Authenticates this domain account with a dialog box. 3632 3633**System API**: This is a system API. 3634 3635**System capability**: SystemCapability.Account.OsAccount 3636 3637**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 3638 3639No permission is required since API version 11. Use the SDK of the latest version. 3640 3641**Parameters** 3642 3643| Name | Type | Mandatory| Description | 3644| ---------- | --------------------------------------- | ---- | --------------- | 3645| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback used to return the authentication result.| 3646 3647**Error codes** 3648 3649| ID| Error Message | 3650| -------- | --------------------------- | 3651| 201 | Permission denied.| 3652| 202 | Not system application.| 3653| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3654| 801 | Capability not supported.| 3655| 12300001 | The system service works abnormally. | 3656| 12300003 | No domain account is bound. | 3657| 12300013 | Network exception. | 3658| 12300101 | Authentication failed. | 3659| 12300109 | The authentication, enrollment, or update operation is canceled. | 3660| 12300110 | The authentication is locked. | 3661| 12300111 | The authentication time out. | 3662| 12300112 | The authentication service is busy. | 3663| 12300113 | The account authentication service does not exist. | 3664| 12300114 | The account authentication service works abnormally. | 3665| 12300211 | Server unreachable. | 3666 3667**Example** 3668 ```ts 3669 try { 3670 osAccount.DomainAccountManager.authWithPopup({ 3671 onResult: (resultCode: number, authResult: osAccount.AuthResult) => { 3672 console.log('auth resultCode = ' + resultCode); 3673 console.log('auth authResult = ' + JSON.stringify(authResult)); 3674 } 3675 }) 3676 } catch (err) { 3677 console.log('auth exception = ' + JSON.stringify(err)); 3678 } 3679 ``` 3680 3681### authWithPopup<sup>10+</sup> 3682 3683authWithPopup(localId: number, callback: IUserAuthCallback): void 3684 3685Authenticates this domain account with a dialog box. 3686 3687**System API**: This is a system API. 3688 3689**System capability**: SystemCapability.Account.OsAccount 3690 3691**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL 3692 3693No permission is required since API version 11. Use the SDK of the latest version. 3694 3695**Parameters** 3696 3697| Name | Type | Mandatory| Description | 3698| ---------- | --------------------------------------- | ---- | --------------- | 3699| localId | number | Yes | Local ID of the system account bound to the domain account.| 3700| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback used to return the authentication result.| 3701 3702**Error codes** 3703 3704| ID| Error Message | 3705| -------- | --------------------------- | 3706| 201 | Permission denied.| 3707| 202 | Not system application.| 3708| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3709| 801 | Capability not supported.| 3710| 12300001 | The system service works abnormally. | 3711| 12300002 | Invalid localId. | 3712| 12300003 | No domain account is bound. | 3713| 12300013 | Network exception. | 3714| 12300101 | Authentication failed. | 3715| 12300109 | The authentication, enrollment, or update operation is canceled. | 3716| 12300110 | The authentication is locked. | 3717| 12300111 | The authentication time out. | 3718| 12300112 | The authentication service is busy. | 3719| 12300113 | The account authentication service does not exist. | 3720| 12300114 | The account authentication service works abnormally. | 3721| 12300211 | Server unreachable. | 3722 3723**Example** 3724 ```ts 3725 try { 3726 osAccount.DomainAccountManager.authWithPopup(100, { 3727 onResult: (resultCode: number, authResult: osAccount.AuthResult) => { 3728 console.log('authWithPopup resultCode = ' + resultCode); 3729 console.log('authWithPopup authResult = ' + JSON.stringify(authResult)); 3730 } 3731 }) 3732 } catch (err) { 3733 console.log('authWithPopup exception = ' + JSON.stringify(err)); 3734 } 3735 ``` 3736 3737### hasAccount<sup>10+</sup> 3738 3739hasAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback<boolean>): void 3740 3741Checks whether a domain account exists. 3742 3743**System API**: This is a system API. 3744 3745**System capability**: SystemCapability.Account.OsAccount 3746 3747**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 3748 3749**Parameters** 3750 3751| Name | Type | Mandatory| Description | 3752| ---------- | --------------------------------------- | ---- | --------------- | 3753| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3754| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. | 3755 3756**Error codes** 3757 3758| ID| Error Message | 3759| -------- | --------------------------- | 3760| 201 | Permission denied.| 3761| 202 | Not system application.| 3762| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3763| 801 | Capability not supported.| 3764| 12300001 | The system service works abnormally. | 3765| 12300002 | Invalid domainAccountInfo. | 3766| 12300013 | Network exception. | 3767| 12300014 | Not authenticated. | 3768| 12300111 | The operation time out. | 3769| 12300114 | The authentication service works abnormally. | 3770| 12300211 | Server unreachable. | 3771 3772**Example** 3773 ```ts 3774 import { BusinessError } from '@kit.BasicServicesKit'; 3775 let domainAccountInfo: osAccount.DomainAccountInfo = { 3776 domain: 'CHINA', 3777 accountName: 'zhangsan' 3778 } 3779 try { 3780 osAccount.DomainAccountManager.hasAccount(domainAccountInfo, (err: BusinessError, result: boolean) => { 3781 if (err) { 3782 console.log('call hasAccount failed, error: ' + JSON.stringify(err)); 3783 } else { 3784 console.log('hasAccount result: ' + result); 3785 } 3786 }); 3787 } catch (err) { 3788 console.log('hasAccount exception = ' + JSON.stringify(err)); 3789 } 3790 ``` 3791 3792### hasAccount<sup>10+</sup> 3793 3794hasAccount(domainAccountInfo: DomainAccountInfo): Promise<boolean> 3795 3796Checks whether a domain account exists. 3797 3798**System API**: This is a system API. 3799 3800**System capability**: SystemCapability.Account.OsAccount 3801 3802**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 3803 3804**Parameters** 3805 3806| Name | Type | Mandatory| Description | 3807| ---------- | --------------------------------------- | ---- | --------------- | 3808| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3809 3810**Return value** 3811 3812| Type | Description | 3813| :------------------------ | ----------------------- | 3814| Promise<boolean> | Promise used to return the result.| 3815 3816**Error codes** 3817 3818| ID| Error Message | 3819| -------- | --------------------------- | 3820| 201 | Permission denied.| 3821| 202 | Not system application.| 3822| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3823| 801 | Capability not supported.| 3824| 12300001 | The system service works abnormally. | 3825| 12300002 | Invalid domainAccountInfo. | 3826| 12300013 | Network exception. | 3827| 12300014 | Not authenticated. | 3828| 12300111 | The operation time out. | 3829| 12300114 | The authentication service works abnormally. | 3830| 12300211 | Server unreachable. | 3831 3832**Example** 3833 ```ts 3834 import { BusinessError } from '@kit.BasicServicesKit'; 3835 let domainAccountInfo: osAccount.DomainAccountInfo = { 3836 domain: 'CHINA', 3837 accountName: 'zhangsan' 3838 } 3839 try { 3840 osAccount.DomainAccountManager.hasAccount(domainAccountInfo).then((result: boolean) => { 3841 console.log('hasAccount result: ' + result); 3842 }).catch((err: BusinessError) => { 3843 console.log('call hasAccount failed, error: ' + JSON.stringify(err)); 3844 }); 3845 } catch (err) { 3846 console.log('hasAccount exception = ' + JSON.stringify(err)); 3847 } 3848 ``` 3849 3850### updateAccountToken<sup>10+</sup> 3851 3852updateAccountToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: AsyncCallback<void>): void 3853 3854Updates the token of a domain account. An empty token means an invalid token. This API uses an asynchronous callback to return the result. 3855 3856**System API**: This is a system API. 3857 3858**System capability**: SystemCapability.Account.OsAccount 3859 3860**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 3861 3862**Parameters** 3863 3864| Name | Type | Mandatory| Description | 3865| ---------- | --------------------------------------- | ---- | --------------- | 3866| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3867| token | Uint8Array | Yes | New domain account token.| 3868| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the token is successfully updated, **err** is **null**. Otherwise, **err** is an error object.| 3869 3870**Error codes** 3871 3872| ID| Error Message | 3873| -------- | --------------------------- | 3874| 201 | Permission denied.| 3875| 202 | Not system application.| 3876| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3877| 12300001 | The system service works abnormally. | 3878| 12300002 | Invalid token. | 3879| 12300003 | Account not found. | 3880 3881**Example** 3882 ```ts 3883 import { BusinessError } from '@kit.BasicServicesKit'; 3884 let domainAccountInfo: osAccount.DomainAccountInfo = { 3885 domain: 'CHINA', 3886 accountName: 'zhangsan', 3887 accountId: '123456' 3888 } 3889 let token = new Uint8Array([0]) 3890 try { 3891 osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token, (err: BusinessError) => { 3892 if (err != null) { 3893 console.log('updateAccountToken failed, error: ' + JSON.stringify(err)); 3894 } else { 3895 console.log('updateAccountToken successfully'); 3896 } 3897 }) 3898 } catch (err) { 3899 console.log('updateAccountToken exception = ' + JSON.stringify(err)); 3900 } 3901 ``` 3902 3903### updateAccountToken<sup>10+</sup> 3904 3905updateAccountToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array): Promise<void> 3906 3907Updates the token of a domain account. An empty token means an invalid token. This API uses a promise to return the result. 3908 3909**System API**: This is a system API. 3910 3911**System capability**: SystemCapability.Account.OsAccount 3912 3913**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 3914 3915**Parameters** 3916 3917| Name | Type | Mandatory| Description | 3918| ---------- | --------------------------------------- | ---- | --------------- | 3919| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 3920| token | Uint8Array | Yes | New domain account token.| 3921 3922**Return value** 3923 3924| Type | Description | 3925| :------------------------ | ----------------------- | 3926| Promise<void> | Promise that returns no value.| 3927 3928**Error codes** 3929 3930| ID| Error Message | 3931| -------- | --------------------------- | 3932| 201 | Permission denied.| 3933| 202 | Not system application.| 3934| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3935| 12300001 | The system service works abnormally. | 3936| 12300002 | Invalid token. | 3937| 12300003 | Account not found. | 3938 3939**Example** 3940 ```ts 3941 import { BusinessError } from '@kit.BasicServicesKit'; 3942 let domainAccountInfo: osAccount.DomainAccountInfo = { 3943 domain: 'CHINA', 3944 accountName: 'zhangsan', 3945 accountId: '123456' 3946 } 3947 let token = new Uint8Array([0]) 3948 try { 3949 osAccount.DomainAccountManager.updateAccountToken(domainAccountInfo, token).then(() => { 3950 console.log('updateAccountToken successfully'); 3951 }).catch((err: BusinessError) => { 3952 console.log('updateAccountToken failed, error: ' + JSON.stringify(err)); 3953 }); 3954 } catch (err) { 3955 console.log('updateAccountToken exception = ' + JSON.stringify(err)); 3956 } 3957 ``` 3958### updateAccountInfo<sup>12+</sup> 3959 3960updateAccountInfo(oldAccountInfo: DomainAccountInfo, newAccountInfo: DomainAccountInfo): Promise<void> 3961 3962Updates information about the specified domain account. This API uses a promise to return the result. 3963 3964**System API**: This is a system API. 3965 3966**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 3967 3968**System capability**: SystemCapability.Account.OsAccount 3969 3970**Parameters** 3971 3972| Name | Type | Mandatory| Description | 3973| ---------- | --------------------------------------- | ---- | --------------- | 3974| oldAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information. | 3975| newAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | New domain account information. | 3976 3977**Error codes** 3978 3979| ID| Error Message | 3980| -------- | --------------------------- | 3981| 201 | Permission denied.| 3982| 202 | Not system application.| 3983| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3984| 801 | Capability not supported.| 3985| 12300001 | The system service works abnormally. | 3986| 12300002 | The new account info is invalid. | 3987| 12300003 | The old account not found. | 3988| 12300004 | The new account already exists. | 3989 3990**Example** 3991 ```ts 3992 import { BusinessError } from '@kit.BasicServicesKit'; 3993 let oldDomainInfo: osAccount.DomainAccountInfo = 3994 {domain: 'testDomain', accountName: 'oldtestAccountName'}; 3995 let newDomainInfo: osAccount.DomainAccountInfo = 3996 {domain: 'testDomain', accountName: 'newtestAccountName'}; 3997 try { 3998 osAccount.DomainAccountManager.updateAccountInfo(oldDomainInfo, newDomainInfo).then(() => { 3999 console.log('updateAccountInfo, success'); 4000 }).catch((err: BusinessError) => { 4001 console.log('updateAccountInfo err: ' + err); 4002 }); 4003 } catch (e) { 4004 console.log('updateAccountInfo exception: ' + e); 4005 } 4006 ``` 4007 4008### getAccountInfo<sup>10+</sup> 4009 4010getAccountInfo(options: GetDomainAccountInfoOptions, callback: AsyncCallback<DomainAccountInfo>): void 4011 4012Obtains information about the specified domain account. This API uses an asynchronous callback to return the result. 4013 4014**System API**: This is a system API. 4015 4016**System capability**: SystemCapability.Account.OsAccount 4017 4018**Required permissions**: ohos.permission.GET_DOMAIN_ACCOUNTS 4019 4020**Parameters** 4021 4022| Name | Type | Mandatory| Description | 4023| ---------- | --------------------------------------- | ---- | --------------- | 4024| options | [GetDomainAccountInfoOptions](#getdomainaccountinfooptions10) | Yes | Domain account information.| 4025| callback | AsyncCallback<DomainAccountInfo> | Yes | Callback used to return the result.| 4026 4027**Error codes** 4028 4029| ID| Error Message | 4030| -------- | --------------------------- | 4031| 201 | Permission denied.| 4032| 202 | Not system application.| 4033| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4034| 801 | Capability not supported.| 4035| 12300001 | The system service works abnormally. | 4036| 12300003 | Account not found. | 4037| 12300013 | Network exception. | 4038| 12300014 | Not authenticated. | 4039| 12300111 | The operation time out. | 4040| 12300114 | The authentication service works abnormally. | 4041| 12300211 | Server unreachable. | 4042 4043**Example** 4044 ```ts 4045 import { BusinessError } from '@kit.BasicServicesKit'; 4046 let domainAccountInfo: osAccount.GetDomainAccountInfoOptions = { 4047 domain: 'CHINA', 4048 accountName: 'zhangsan' 4049 } 4050 try { 4051 osAccount.DomainAccountManager.getAccountInfo(domainAccountInfo, 4052 (err: BusinessError, result: osAccount.DomainAccountInfo) => { 4053 if (err) { 4054 console.log('call getAccountInfo failed, error: ' + JSON.stringify(err)); 4055 } else { 4056 console.log('getAccountInfo result: ' + result); 4057 } 4058 }); 4059 } catch (err) { 4060 console.log('getAccountInfo exception = ' + JSON.stringify(err)); 4061 } 4062 ``` 4063 4064### getAccountInfo<sup>10+</sup> 4065 4066getAccountInfo(options: GetDomainAccountInfoOptions): Promise<DomainAccountInfo> 4067 4068Obtains information about the specified domain account. This API uses a promise to return the result. 4069 4070**System API**: This is a system API. 4071 4072**System capability**: SystemCapability.Account.OsAccount 4073 4074**Required permissions**: ohos.permission.GET_DOMAIN_ACCOUNTS 4075 4076**Parameters** 4077 4078| Name | Type | Mandatory| Description | 4079| ---------- | --------------------------------------- | ---- | --------------- | 4080| options | [GetDomainAccountInfoOptions](#getdomainaccountinfooptions10) | Yes | Domain account information.| 4081 4082**Return value** 4083 4084| Type | Description | 4085| :------------------------ | ----------------------- | 4086| Promise<DomainAccountInfo> | Promise used to return the domain account information obtained.| 4087 4088**Error codes** 4089 4090| ID| Error Message | 4091| -------- | --------------------------- | 4092| 201 | Permission denied.| 4093| 202 | Not system application.| 4094| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4095| 801 | Capability not supported.| 4096| 12300001 | The system service works abnormally. | 4097| 12300003 | Account not found. | 4098| 12300013 | Network exception. | 4099| 12300014 | Not authenticated. | 4100| 12300111 | The operation time out. | 4101| 12300114 | The authentication service works abnormally. | 4102| 12300211 | Server unreachable. | 4103 4104**Example** 4105 ```ts 4106 import { BusinessError } from '@kit.BasicServicesKit'; 4107 let domainAccountInfo: osAccount.GetDomainAccountInfoOptions = { 4108 domain: 'CHINA', 4109 accountName: 'zhangsan' 4110 } 4111 try { 4112 osAccount.DomainAccountManager.getAccountInfo(domainAccountInfo) 4113 .then((result: osAccount.DomainAccountInfo) => { 4114 console.log('getAccountInfo result: ' + result); 4115 }).catch((err: BusinessError) => { 4116 console.log('call getAccountInfo failed, error: ' + JSON.stringify(err)); 4117 }); 4118 } catch (err) { 4119 console.log('getAccountInfo exception = ' + JSON.stringify(err)); 4120 } 4121 ``` 4122 4123### getAccessToken<sup>11+</sup> 4124 4125getAccessToken(businessParams: Record<string, Object>, callback: AsyncCallback<Uint8Array>): void 4126 4127Obtains the service access token of this domain account. This API uses an asynchronous callback to return the result. 4128 4129**System API**: This is a system API. 4130 4131**System capability**: SystemCapability.Account.OsAccount 4132 4133**Parameters** 4134 4135| Name | Type | Mandatory| Description | 4136| ---------- | --------------------------------------- | ---- | --------------- | 4137| businessParams | Record<string, Object> | Yes | Service parameters. The specific formats vary depending on the domain plug-in.| 4138| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, an error object is returned.| 4139 4140**Error codes** 4141 4142| ID| Error Message | 4143| -------- | --------------------------- | 4144| 202 | Not system application.| 4145| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4146| 801 | Capability not supported.| 4147| 12300001 | The system service works abnormally. | 4148| 12300002 | Invalid business parameters. | 4149| 12300003 | Domain account not found. | 4150| 12300013 | Network exception. | 4151| 12300014 | The domain account is not authenticated. | 4152| 12300111 | The operation time out. | 4153| 12300114 | The authentication service works abnormally. | 4154| 12300211 | Server unreachable. | 4155 4156**Example** 4157 ```ts 4158 import { BusinessError } from '@kit.BasicServicesKit'; 4159 let businessParams: Record<string, Object> = { 4160 'clientId': 'xxx', 4161 'secretId': 'yyy' 4162 }; // depends on the implementation of the domain plugin 4163 try { 4164 osAccount.DomainAccountManager.getAccessToken(businessParams, 4165 (err: BusinessError, result: Uint8Array) => { 4166 if (err) { 4167 console.log('getAccessToken failed, error: ' + JSON.stringify(err)); 4168 } else { 4169 console.log('getAccessToken result: ' + result); 4170 } 4171 }); 4172 } catch (err) { 4173 console.log('getAccessToken exception = ' + JSON.stringify(err)); 4174 } 4175 ``` 4176 4177### getAccessToken<sup>11+</sup> 4178 4179getAccessToken(businessParams: Record<string, Object>): Promise<Uint8Array> 4180 4181Obtains the service access token of this domain account. This API uses a promise to return the result. 4182 4183**System API**: This is a system API. 4184 4185**System capability**: SystemCapability.Account.OsAccount 4186 4187**Parameters** 4188 4189| Name | Type | Mandatory| Description | 4190| ---------- | --------------------------------------- | ---- | --------------- | 4191| businessParams | Record<string, Object> | Yes | Service parameters. The specific formats vary depending on the domain plug-in.| 4192 4193**Return value** 4194 4195| Type | Description | 4196| :------------------------ | ----------------------- | 4197| Promise<Uint8Array> | Promise used to return the service access token obtained.| 4198 4199**Error codes** 4200 4201| ID| Error Message | 4202| -------- | --------------------------- | 4203| 202 | Not system application.| 4204| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4205| 801 | Capability not supported.| 4206| 12300001 | The system service works abnormally. | 4207| 12300002 | Invalid business parameters. | 4208| 12300003 | Domain account not found. | 4209| 12300013 | Network exception. | 4210| 12300014 | The domain account is not authenticated. | 4211| 12300111 | The operation time out. | 4212| 12300114 | The authentication service works abnormally. | 4213| 12300211 | Server unreachable. | 4214 4215**Example** 4216 ```ts 4217 import { BusinessError } from '@kit.BasicServicesKit'; 4218 let businessParams: Record<string, Object> = { 4219 'clientId': 'xxx', 4220 'secretId': 'yyy' 4221 }; // depends on the implementation of the domain plugin 4222 try { 4223 osAccount.DomainAccountManager.getAccessToken(businessParams) 4224 .then((result: Uint8Array) => { 4225 console.log('getAccessToken result: ' + result); 4226 }).catch((err: BusinessError) => { 4227 console.log('getAccessToken failed, error: ' + JSON.stringify(err)); 4228 }); 4229 } catch (err) { 4230 console.log('getAccessToken exception = ' + JSON.stringify(err)); 4231 } 4232 ``` 4233 4234### isAuthenticationExpired<sup>12+</sup> 4235 4236isAuthenticationExpired(domainAccountInfo: DomainAccountInfo): Promise<boolean>; 4237 4238Checks whether the authentication of a domain account has expired. This API uses a promise to return the result. 4239 4240**System API**: This is a system API. 4241 4242**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 4243 4244**System capability**: SystemCapability.Account.OsAccount 4245 4246**Parameters** 4247 4248| Name | Type | Mandatory| Description | 4249| ---------- | --------------------------------------- | ---- | --------------- | 4250| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 4251 4252**Return value** 4253 4254| Type | Description | 4255| :------------------------ | ----------------------- | 4256| Promise<boolean> | Promise used to return the result.| 4257 4258**Error codes** 4259 4260| ID| Error Message | 4261| -------- | --------------------------- | 4262| 201 | Permission denied.| 4263| 202 | Not system application.| 4264| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4265| 801 | Capability not supported.| 4266| 12300001 | The system service works abnormally. | 4267| 12300003 | Domain account not found. | 4268 4269**Example** 4270 ```ts 4271 import { BusinessError } from '@kit.BasicServicesKit'; 4272 let domainInfo: osAccount.DomainAccountInfo = 4273 {domain: 'testDomain', accountName: 'testAccountName'}; 4274 try { 4275 osAccount.DomainAccountManager.isAuthenticationExpired(domainInfo).then((result: boolean) => { 4276 console.log('isAuthenticationExpired, result: ' + result); 4277 }).catch((err: BusinessError) => { 4278 console.log('isAuthenticationExpired err: ' + err); 4279 }); 4280 } catch (e) { 4281 console.log('isAuthenticationExpired exception: ' + e); 4282 } 4283 ``` 4284 4285## UserIdentityManager<sup>8+</sup> 4286 4287Provides APIs for user IDM. 4288 4289**System API**: This is a system API. 4290 4291### constructor<sup>8+</sup> 4292 4293A **constructor()** used to create an instance for user IDM. 4294 4295**System API**: This is a system API. 4296 4297**System capability**: SystemCapability.Account.OsAccount 4298 4299**Error codes** 4300 4301| ID| Error Message | 4302| -------- | --------------------------- | 4303| 202 | Not system application.| 4304 4305**Example** 4306 ```ts 4307 let userIDM = new osAccount.UserIdentityManager(); 4308 ``` 4309 4310### openSession<sup>8+</sup> 4311 4312openSession(callback: AsyncCallback<Uint8Array>): void 4313 4314Opens a session to obtain the challenge value. This API uses an asynchronous callback to return the result. 4315 4316**System API**: This is a system API. 4317 4318**System capability**: SystemCapability.Account.OsAccount 4319 4320**Required permissions**: ohos.permission.MANAGE_USER_IDM 4321 4322**Parameters** 4323 4324| Name | Type | Mandatory| Description | 4325| -------- | -------------------------------- | ---- | -------------------------------------------------------------- | 4326| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the challenge value obtained. Otherwise, **err** is an error object.| 4327 4328**Error codes** 4329 4330| ID| Error Message | 4331| -------- | --------------------------- | 4332| 201 | Permission denied.| 4333| 202 | Not system application.| 4334| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4335| 12300001 | The system service works abnormally. | 4336 4337**Example** 4338 ```ts 4339 import { BusinessError } from '@kit.BasicServicesKit'; 4340 let userIDM = new osAccount.UserIdentityManager(); 4341 try { 4342 userIDM.openSession((err: BusinessError, challenge: Uint8Array) => { 4343 console.log('openSession error = ' + JSON.stringify(err)); 4344 console.log('openSession challenge = ' + JSON.stringify(challenge)); 4345 }); 4346 } catch (e) { 4347 console.log('openSession exception = ' + JSON.stringify(e)); 4348 } 4349 ``` 4350 4351### openSession<sup>8+</sup> 4352 4353openSession(accountId?: number): Promise<Uint8Array> 4354 4355Opens a session. This API returns a challenge value, which can be used to determine whether the subsequent identity authentication is in this session. This can prevent replay attacks. This API uses a promise to return the result. 4356 4357**System API**: This is a system API. 4358 4359**System capability**: SystemCapability.Account.OsAccount 4360 4361**Required permissions**: ohos.permission.MANAGE_USER_IDM 4362 4363**Parameters** 4364 4365| Name | Type | Mandatory| Description | 4366| --------- | ------- | ---- | ----------- | 4367| accountId<sup>12+</sup> | number | No | System account ID, which is left blank by default.| 4368 4369**Return value** 4370 4371| Type | Description | 4372| :------------------------ | ----------------------- | 4373| Promise<Uint8Array> | Promise used to return the challenge value obtained.| 4374 4375**Error codes** 4376 4377| ID| Error Message | 4378| -------- | --------------------------- | 4379| 201 | Permission denied.| 4380| 202 | Not system application.| 4381| 401 | Parameter error. Possible causes: Incorrect parameter types. | 4382| 12300001 | The system service works abnormally. | 4383| 12300003 | Account not found. | 4384| 12300008 | Restricted account. | 4385 4386**Example** 4387 ```ts 4388 import { BusinessError } from '@kit.BasicServicesKit'; 4389 let userIDM = new osAccount.UserIdentityManager(); 4390 let accountId = 100; 4391 try { 4392 userIDM.openSession(accountId).then((challenge: Uint8Array) => { 4393 console.info('openSession challenge = ' + JSON.stringify(challenge)); 4394 }).catch((err: BusinessError) => { 4395 console.info('openSession error = ' + JSON.stringify(err)); 4396 }); 4397 } catch (e) { 4398 console.log('openSession exception = ' + JSON.stringify(e)); 4399 } 4400 ``` 4401 4402### addCredential<sup>8+</sup> 4403 4404addCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void 4405 4406Adds credential information, including the credential type, subtype, and token (if a non-PIN credential is added). 4407 4408**System API**: This is a system API. 4409 4410**System capability**: SystemCapability.Account.OsAccount 4411 4412**Required permissions**: ohos.permission.MANAGE_USER_IDM 4413 4414**Parameters** 4415 4416| Name | Type | Mandatory| Description | 4417| --------------- | ------------------------------------ | --- | ---------------------------- | 4418| credentialInfo | [CredentialInfo](#credentialinfo8) | Yes | Credential information to add. | 4419| callback | [IIdmCallback](#iidmcallback8) | Yes | Callback used to return the result. | 4420 4421**Error codes** 4422 4423| ID| Error Message | 4424| -------- | ------------------- | 4425| 201 | Permission denied.| 4426| 202 | Not system application.| 4427| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4428| 12300001 | The system service works abnormally. | 4429| 12300002 | Invalid credentialInfo, i.e. authType or authSubType. | 4430| 12300003 | Account not found. | 4431| 12300008 | Restricted account. | 4432| 12300101 | The token is invalid. | 4433| 12300106 | The authentication type is not supported. | 4434| 12300109 | The authentication, enrollment, or update operation is canceled. | 4435| 12300111 | The operation time out. | 4436| 12300115 | The number of credentials reaches the upper limit. | 4437| 12300116 | Credential complexity verification failed. | 4438 4439**Example** 4440 ```ts 4441 import { BusinessError } from '@kit.BasicServicesKit'; 4442 let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]); 4443 let pinAuth: osAccount.PINAuth = new osAccount.PINAuth(); 4444 pinAuth.registerInputer({ 4445 onGetData: (authSubType: osAccount.AuthSubType, callback: osAccount.IInputData) => { 4446 callback.onSetData(authSubType, password); 4447 } 4448 }); 4449 let credentialInfo: osAccount.CredentialInfo = { 4450 credType: osAccount.AuthType.PIN, 4451 credSubType: osAccount.AuthSubType.PIN_SIX, 4452 token: new Uint8Array([]), 4453 }; 4454 let userIDM = new osAccount.UserIdentityManager(); 4455 userIDM.openSession((err: BusinessError, challenge: Uint8Array) => { 4456 try { 4457 userIDM.addCredential(credentialInfo, { 4458 onResult: (result: number, extraInfo: osAccount.RequestResult) => { 4459 console.log('addCredential result = ' + result); 4460 console.log('addCredential extraInfo = ' + extraInfo); 4461 } 4462 }); 4463 } catch (e) { 4464 console.log('addCredential exception = ' + JSON.stringify(e)); 4465 } 4466 }); 4467 ``` 4468 4469### updateCredential<sup>8+</sup> 4470 4471updateCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void 4472 4473Updates credential information. This API uses an asynchronous callback to return the result. 4474 4475**System API**: This is a system API. 4476 4477**System capability**: SystemCapability.Account.OsAccount 4478 4479**Required permissions**: ohos.permission.MANAGE_USER_IDM 4480 4481**Parameters** 4482 4483| Name | Type | Mandatory| Description | 4484| --------------- | ------------------------------------- | --- | ------------------------- | 4485| credentialInfo | [CredentialInfo](#credentialinfo8) | Yes | Credential information to add. | 4486| callback | [IIdmCallback](#iidmcallback8) | Yes | Callback used to return the result.| 4487 4488**Error codes** 4489 4490| ID| Error Message | 4491| -------- | ------------------- | 4492| 201 | Permission denied.| 4493| 202 | Not system application.| 4494| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4495| 12300001 | The system service works abnormally. | 4496| 12300002 | Invalid credentialInfo, i.e. authType or authSubType. | 4497| 12300003 | Account not found. | 4498| 12300101 | The token is invalid. | 4499| 12300102 | The credential does not exist. | 4500| 12300106 | The authentication type is not supported. | 4501| 12300109 | The authentication, enrollment, or update operation is canceled. | 4502| 12300111 | The operation time out. | 4503| 12300116 | Credential complexity verification failed. | 4504 4505**Example** 4506 ```ts 4507 import { BusinessError } from '@kit.BasicServicesKit'; 4508 let userIDM = new osAccount.UserIdentityManager(); 4509 let userAuth: osAccount.UserAuth = new osAccount.UserAuth(); 4510 let pinAuth: osAccount.PINAuth = new osAccount.PINAuth(); 4511 let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]); 4512 let credentialInfo: osAccount.CredentialInfo = { 4513 credType: osAccount.AuthType.PIN, 4514 credSubType: osAccount.AuthSubType.PIN_SIX, 4515 token: new Uint8Array([]), 4516 }; 4517 pinAuth.registerInputer({ 4518 onGetData: (authSubType: osAccount.AuthSubType, callback: osAccount.IInputData) => { 4519 callback.onSetData(authSubType, password); 4520 } 4521 }); 4522 userIDM.openSession((err: BusinessError, challenge: Uint8Array) => { 4523 userAuth.auth(challenge, credentialInfo.credType, osAccount.AuthTrustLevel.ATL1, { 4524 onResult: (result: number, extraInfo: osAccount.AuthResult) => { 4525 if (result != osAccount.ResultCode.SUCCESS) { 4526 return; 4527 } 4528 if (extraInfo.token != null) { 4529 credentialInfo.token = extraInfo.token; 4530 } 4531 try { 4532 userIDM.updateCredential(credentialInfo, { 4533 onResult: (result: number, extraInfo: osAccount.RequestResult) => { 4534 console.log('updateCredential result = ' + result); 4535 console.log('updateCredential extraInfo = ' + extraInfo); 4536 } 4537 }); 4538 } catch (e) { 4539 console.log('updateCredential exception = ' + JSON.stringify(e)); 4540 } 4541 } 4542 }); 4543 }); 4544 ``` 4545 4546### closeSession<sup>8+</sup> 4547 4548closeSession(accountId?: number): void 4549 4550Closes this session to terminate IDM. 4551 4552**System API**: This is a system API. 4553 4554**System capability**: SystemCapability.Account.OsAccount 4555 4556**Required permissions**: ohos.permission.MANAGE_USER_IDM 4557 4558**Parameters** 4559 4560| Name | Type | Mandatory| Description | 4561| --------- | ------- | ---- | ----------- | 4562| accountId<sup>12+</sup> | number | No | System account ID, which is left blank by default.| 4563 4564**Error codes** 4565 4566| ID| Error Message | 4567| -------- | --------------------------- | 4568| 201 | Permission denied.| 4569| 202 | Not system application.| 4570| 401 | Parameter error. Possible causes: Incorrect parameter types. | 4571| 12300001 | The system service works abnormally. | 4572| 12300003 | Account not found. | 4573| 12300008 | Restricted account. | 4574 4575**Example** 4576 ```ts 4577 let userIDM = new osAccount.UserIdentityManager(); 4578 let accountId = 100; 4579 userIDM.closeSession(accountId); 4580 ``` 4581 4582### cancel<sup>8+</sup> 4583 4584cancel(challenge: Uint8Array): void 4585 4586Cancels an entry based on the challenge value. 4587 4588**System API**: This is a system API. 4589 4590**System capability**: SystemCapability.Account.OsAccount 4591 4592**Required permissions**: ohos.permission.MANAGE_USER_IDM 4593 4594**Parameters** 4595 4596| Name | Type | Mandatory| Description | 4597| -------- | ----------- | ---- | ----- | 4598| challenge | Uint8Array | Yes | Challenge value.| 4599 4600**Error codes** 4601 4602| ID| Error Message | 4603| -------- | ------------------- | 4604| 201 | Permission denied.| 4605| 202 | Not system application.| 4606| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4607| 12300001 | The system service works abnormally. | 4608| 12300002 | Invalid challenge. | 4609 4610**Example** 4611 ```ts 4612 let userIDM = new osAccount.UserIdentityManager(); 4613 let challenge: Uint8Array = new Uint8Array([0]); 4614 try { 4615 userIDM.cancel(challenge); 4616 } catch(err) { 4617 console.log('cancel err:' + JSON.stringify(err)); 4618 } 4619 ``` 4620 4621### delUser<sup>8+</sup> 4622 4623delUser(token: Uint8Array, callback: IIdmCallback): void 4624 4625Deletes a user based on the authentication token. This API uses a callback to return the result. 4626 4627**System API**: This is a system API. 4628 4629**System capability**: SystemCapability.Account.OsAccount 4630 4631**Required permissions**: ohos.permission.MANAGE_USER_IDM 4632 4633**Parameters** 4634 4635| Name | Type | Mandatory| Description | 4636| -------- | ------------------------------ | --- | ------------------------- | 4637| token | Uint8Array | Yes | Authentication token. | 4638| callback | [IIdmCallback](#iidmcallback8) | Yes | Callback used to return the result.| 4639 4640**Error codes** 4641 4642| ID| Error Message | 4643| -------- | ------------------- | 4644| 201 | Permission denied.| 4645| 202 | Not system application.| 4646| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4647| 12300001 | The system service works abnormally. | 4648| 12300101 | The token is invalid. | 4649 4650**Example** 4651 ```ts 4652 let userIDM = new osAccount.UserIdentityManager(); 4653 let token: Uint8Array = new Uint8Array([0]); 4654 try { 4655 userIDM.delUser(token, { 4656 onResult: (result: number, extraInfo: osAccount.RequestResult) => { 4657 console.log('delUser result = ' + result); 4658 console.log('delUser extraInfo = ' + JSON.stringify(extraInfo)); 4659 } 4660 }); 4661 } catch (e) { 4662 console.log('delUser exception = ' + JSON.stringify(e)); 4663 } 4664 ``` 4665 4666### delCred<sup>8+</sup> 4667 4668delCred(credentialId: Uint8Array, token: Uint8Array, callback: IIdmCallback): void 4669 4670Deletes user credential information. 4671 4672**System API**: This is a system API. 4673 4674**System capability**: SystemCapability.Account.OsAccount 4675 4676**Required permissions**: ohos.permission.MANAGE_USER_IDM 4677 4678**Parameters** 4679 4680| Name | Type | Mandatory| Description | 4681| --------------- | ----------------------------------- | --- | ---------------------------| 4682| credentialId | Uint8Array | Yes | Credential ID. | 4683| token | Uint8Array | Yes | Authentication token. | 4684| callback | [IIdmCallback](#iidmcallback8) | Yes | Callback used to return the result.| 4685 4686**Error codes** 4687 4688| ID| Error Message | 4689| -------- | ------------------- | 4690| 201 | Permission denied.| 4691| 202 | Not system application.| 4692| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4693| 12300001 | The system service works abnormally. | 4694| 12300002 | Invalid credentialId. | 4695| 12300101 | The token is invalid. | 4696| 12300102 | The credential does not exist. | 4697 4698**Example** 4699 ```ts 4700 let userIDM = new osAccount.UserIdentityManager(); 4701 let credentialId: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0]); 4702 let token: Uint8Array = new Uint8Array([0]); 4703 try { 4704 userIDM.delCred(credentialId, token, { 4705 onResult: (result: number, extraInfo: osAccount.RequestResult) => { 4706 console.log('delCred result = ' + result); 4707 console.log('delCred extraInfo = ' + JSON.stringify(extraInfo)); 4708 } 4709 }); 4710 } catch (e) { 4711 console.log('delCred exception = ' + JSON.stringify(e)); 4712 } 4713 ``` 4714 4715### getAuthInfo<sup>8+</sup> 4716 4717getAuthInfo(callback: AsyncCallback<Array<EnrolledCredInfo>>): void 4718 4719Obtains authentication information. This API uses an asynchronous callback to return the result. 4720 4721**System API**: This is a system API. 4722 4723**System capability**: SystemCapability.Account.OsAccount 4724 4725**Required permissions**: ohos.permission.USE_USER_IDM 4726 4727**Parameters** 4728 4729| Name | Type | Mandatory| Description | 4730| -------- | ------------------------------------------------------------------------ | ---- | --------------------------------------------- | 4731| callback | AsyncCallback<Array<[EnrolledCredInfo](#enrolledcredinfo8)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is information about all registered credentials of the user. Otherwise, **err** is an error object.| 4732 4733**Error codes** 4734 4735| ID| Error Message | 4736| -------- | --------------------- | 4737| 201 | Permission denied.| 4738| 202 | Not system application.| 4739| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4740| 12300001 | The system service works abnormally. | 4741 4742**Example** 4743 ```ts 4744 import { BusinessError } from '@kit.BasicServicesKit'; 4745 let userIDM = new osAccount.UserIdentityManager(); 4746 try { 4747 userIDM.getAuthInfo((err: BusinessError, result: osAccount.EnrolledCredInfo[]) => { 4748 console.log('getAuthInfo err = ' + JSON.stringify(err)); 4749 console.log('getAuthInfo result = ' + JSON.stringify(result)); 4750 }); 4751 } catch (e) { 4752 console.log('getAuthInfo exception = ' + JSON.stringify(e)); 4753 } 4754 ``` 4755 4756### getAuthInfo<sup>8+</sup> 4757 4758getAuthInfo(authType: AuthType, callback: AsyncCallback<Array<EnrolledCredInfo>>): void 4759 4760Obtains authentication information of the specified type. This API uses an asynchronous callback to return the result. 4761 4762**System API**: This is a system API. 4763 4764**System capability**: SystemCapability.Account.OsAccount 4765 4766**Required permissions**: ohos.permission.USE_USER_IDM 4767 4768**Parameters** 4769 4770| Name | Type | Mandatory| Description | 4771| -------- | -------------------------------------------------- | ---- | -------------------------------------------------- | 4772| authType | [AuthType](#authtype8) | Yes | Authentication credential type. | 4773| callback | AsyncCallback<Array<[EnrolledCredInfo](#enrolledcredinfo8)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the information about all enrolled credentials of the specified type. Otherwise, **err** is an error object.| 4774 4775**Error codes** 4776 4777| ID| Error Message | 4778| -------- | ------------------- | 4779| 201 | Permission denied.| 4780| 202 | Not system application.| 4781| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4782| 12300001 | The system service works abnormally. | 4783| 12300002 | Invalid authType. | 4784 4785**Example** 4786 ```ts 4787 import { BusinessError } from '@kit.BasicServicesKit'; 4788 let userIDM = new osAccount.UserIdentityManager(); 4789 try { 4790 userIDM.getAuthInfo(osAccount.AuthType.PIN, 4791 (err: BusinessError, result: osAccount.EnrolledCredInfo[]) => { 4792 console.log('getAuthInfo err = ' + JSON.stringify(err)); 4793 console.log('getAuthInfo result = ' + JSON.stringify(result)); 4794 }); 4795 } catch (e) { 4796 console.log('getAuthInfo exception = ' + JSON.stringify(e)); 4797 } 4798 ``` 4799 4800### getAuthInfo<sup>8+</sup> 4801 4802getAuthInfo(authType?: AuthType): Promise<Array<EnrolledCredInfo>>; 4803 4804Obtains authentication information. This API uses a promise to return the result. 4805 4806**System API**: This is a system API. 4807 4808**System capability**: SystemCapability.Account.OsAccount 4809 4810**Required permissions**: ohos.permission.USE_USER_IDM 4811 4812**Parameters** 4813 4814| Name | Type | Mandatory| Description | 4815| -------- | ----------------------------------- | ---- | -------- | 4816| authType | [AuthType](#authtype8) | No | Authentication type. By default, this parameter is left blank, which means to obtain information about all authentication types.| 4817 4818**Return value** 4819 4820| Type | Description | 4821| :------------------------------------------- | :----------------------------------------------------------------------- | 4822| Promise<Array<[EnrolledCredInfo](#enrolledcredinfo8)>> | Promise used to return the information about all the enrolled credentials of the specified type.| 4823 4824**Error codes** 4825 4826| ID| Error Message | 4827| -------- | ------------------- | 4828| 201 | Permission denied.| 4829| 202 | Not system application.| 4830| 401 | Parameter error. Possible causes: Incorrect parameter types. | 4831| 12300001 | The system service works abnormally. | 4832| 12300002 | Invalid authType. | 4833 4834**Example** 4835 ```ts 4836 import { BusinessError } from '@kit.BasicServicesKit'; 4837 let userIDM = new osAccount.UserIdentityManager(); 4838 try { 4839 userIDM.getAuthInfo(osAccount.AuthType.PIN).then((result: osAccount.EnrolledCredInfo[]) => { 4840 console.log('getAuthInfo result = ' + JSON.stringify(result)) 4841 }).catch((err: BusinessError) => { 4842 console.log('getAuthInfo error = ' + JSON.stringify(err)); 4843 }); 4844 } catch (e) { 4845 console.log('getAuthInfo exception = ' + JSON.stringify(e)); 4846 } 4847 ``` 4848 4849### getAuthInfo<sup>12+</sup> 4850 4851getAuthInfo(options?: GetAuthInfoOptions): Promise<Array<EnrolledCredInfo>> 4852 4853Obtains authentication information. This API uses a promise to return the result. 4854 4855**System API**: This is a system API. 4856 4857**System capability**: SystemCapability.Account.OsAccount 4858 4859**Required permissions**: ohos.permission.USE_USER_IDM 4860 4861**Parameters** 4862 4863| Name | Type | Mandatory| Description | 4864| -------- | ----------------------------------- | ---- | -------- | 4865| options | [GetAuthInfoOptions](#getauthinfooptions12) | No | Optional parameters for obtaining authentication information.| 4866 4867**Return value** 4868 4869| Type | Description | 4870| :------------------------------------------- | :----------------------------------------------------------------------- | 4871| Promise<Array<[EnrolledCredInfo](#enrolledcredinfo8)>> | Promise used to return the information about all the enrolled credentials of the specified type.| 4872 4873**Error codes** 4874 4875| ID| Error Message | 4876| -------- | ------------------- | 4877| 201 | Permission denied.| 4878| 202 | Not system application.| 4879| 401 | Parameter error. Possible causes: Incorrect parameter types. | 4880| 12300001 | The system service works abnormally. | 4881| 12300002 | Invalid options. | 4882| 12300003 | Account not found. | 4883 4884**Example** 4885 ```ts 4886 import { BusinessError } from '@kit.BasicServicesKit'; 4887 let userIDM = new osAccount.UserIdentityManager(); 4888 let options: osAccount.GetAuthInfoOptions = { 4889 authType: osAccount.AuthType.PIN, 4890 accountId: 100, 4891 }; 4892 try { 4893 userIDM.getAuthInfo(options).then((result: osAccount.EnrolledCredInfo[]) => { 4894 console.log('getAuthInfo result = ' + JSON.stringify(result)) 4895 }).catch((err: BusinessError) => { 4896 console.log('getAuthInfo error = ' + JSON.stringify(err)); 4897 }); 4898 } catch (e) { 4899 console.log('getAuthInfo exception = ' + JSON.stringify(e)); 4900 } 4901 ``` 4902 4903### getEnrolledId<sup>12+</sup> 4904 4905getEnrolledId(authType: AuthType, accountId?: number): Promise<Uint8Array> 4906 4907Obtains the ID of the enrolled credential based on the credential type and account ID (optional). This API uses a promise to return the result. 4908 4909**System API**: This is a system API. 4910 4911**System capability**: SystemCapability.Account.OsAccount 4912 4913**Required permissions**: ohos.permission.USE_USER_IDM 4914 4915**Parameters** 4916 4917| Name | Type | Mandatory| Description | 4918| -------- | ---------------------- | ---- | -------- | 4919| authType | [AuthType](#authtype8) | Yes | Credential type.| 4920| accountId | number | No | System account ID, which is left blank by default.| 4921 4922**Return value** 4923 4924| Type | Description | 4925| :------------------------ | :----------------------------------------------------------------------- | 4926| Promise<Uint8Array> | Promise used to return the credential ID obtained.| 4927 4928**Error codes** 4929 4930| ID| Error Message | 4931| -------- | ------------------- | 4932| 201 | Permission denied.| 4933| 202 | Not system application.| 4934| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4935| 12300001 | The system service works abnormally. | 4936| 12300002 | Invalid authType. | 4937| 12300003 | Account not found. | 4938| 12300102 | The credential does not exist. | 4939| 12300106 | The authentication type is not supported. | 4940 4941**Example** 4942 ```ts 4943 import { BusinessError } from '@kit.BasicServicesKit'; 4944 let userIDM = new osAccount.UserIdentityManager(); 4945 let authType: osAccount.AuthType = osAccount.AuthType.PIN; 4946 let accountId = 100; 4947 try { 4948 userIDM.getEnrolledId(authType, accountId).then((enrolledId: Uint8Array) => { 4949 console.info('getEnrolledId enrolledId = ' + JSON.stringify(enrolledId)); 4950 }).catch((err: BusinessError) => { 4951 console.info('getEnrolledId error = ' + JSON.stringify(err)); 4952 }); 4953 } catch (e) { 4954 console.log('getEnrolledId exception = ' + JSON.stringify(e)); 4955 } 4956 ``` 4957 4958## IInputData<sup>8+</sup> 4959 4960Provides callbacks for PIN operations. 4961 4962**System API**: This is a system API. 4963 4964### onSetData<sup>8+</sup> 4965 4966onSetData: (authSubType: AuthSubType, data: Uint8Array) => void; 4967 4968**System API**: This is a system API. 4969 4970Called to notify the caller the data is set. 4971 4972**System capability**: SystemCapability.Account.OsAccount 4973 4974**Parameters** 4975 4976| Name | Type | Mandatory| Description | 4977| ---------- | ---------------------------------------- | ---- | ----------------------------------------------- | 4978| authSubType | [AuthSubType](#authsubtype8) | Yes | Credential subtype. | 4979| data | Uint8Array | Yes | Data (credential) to set. The data is used for authentication and operations for adding and modifying credentials.| 4980 4981**Error codes** 4982 4983| ID| Error Message | 4984| -------- | ------------------- | 4985| 202 | Not system application.| 4986| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4987| 12300002 | Invalid pinSubType. | 4988 4989**Example** 4990 ```ts 4991 let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]); 4992 let passwordNumber: Uint8Array = new Uint8Array([1, 2, 3, 4]); 4993 let inputer: osAccount.IInputer = { 4994 onGetData: (authSubType: osAccount.AuthSubType, callback: osAccount.IInputData) => { 4995 if (authSubType == osAccount.AuthSubType.PIN_NUMBER) { 4996 callback.onSetData(authSubType, passwordNumber); 4997 } else { 4998 callback.onSetData(authSubType, password); 4999 } 5000 } 5001 }; 5002 ``` 5003 5004## IInputer<sup>8+</sup> 5005 5006Provides callbacks for credential inputers. 5007 5008**System API**: This is a system API. 5009 5010### onGetData<sup>8+</sup> 5011 5012onGetData: (authSubType: AuthSubType, callback: IInputData, options: GetInputDataOptions) => void; 5013 5014Called to notify the caller that data is obtained. 5015 5016**System API**: This is a system API. 5017 5018**System capability**: SystemCapability.Account.OsAccount 5019 5020**Parameters** 5021 5022| Name | Type | Mandatory| Description | 5023| ---------- | --------------------------------------- | ---- | --------------- | 5024| authSubType | [AuthSubType](#authsubtype8) | Yes| Authentication credential subtype.| 5025| callback | [IInputData](#iinputdata8) | Yes | Callback used to return the PIN data.| 5026| options | [GetInputDataOptions](#getinputdataoptions-12) | Yes| Optional parameters for the callback function.| 5027 5028**Example** 5029 ```ts 5030 let password: Uint8Array = new Uint8Array([0, 0, 0, 0, 0, 0]); 5031 let passwordNumber: Uint8Array = new Uint8Array([1, 2, 3, 4]); 5032 let inputer: osAccount.IInputer = { 5033 onGetData: (authSubType: osAccount.AuthSubType, 5034 callback: osAccount.IInputData, options: osAccount.GetInputDataOptions) => { 5035 if (authSubType == osAccount.AuthSubType.PIN_NUMBER) { 5036 callback.onSetData(authSubType, passwordNumber); 5037 } else { 5038 callback.onSetData(authSubType, password); 5039 } 5040 } 5041 }; 5042 let pinAuth: osAccount.PINAuth = new osAccount.PINAuth(); 5043 let result = pinAuth.registerInputer(inputer); 5044 console.log('registerInputer result: ' + result); 5045 ``` 5046 5047## IUserAuthCallback<sup>8+</sup> 5048 5049Provides callbacks for user authentication. 5050 5051**System API**: This is a system API. 5052 5053### onResult<sup>8+</sup> 5054 5055onResult: (result: number, extraInfo: AuthResult) => void; 5056 5057Called to return the result code and authentication result. 5058 5059**System API**: This is a system API. 5060 5061**System capability**: SystemCapability.Account.OsAccount 5062 5063**Parameters** 5064 5065| Name | Type | Mandatory| Description | 5066| --------- | --------------------------------------- | ---- | ------------------- | 5067| result | number | Yes | Authentication result code.| 5068| extraInfo | [AuthResult](#authresult8) | Yes | Specific authentication result information. If the authentication is successful, the authentication token is returned in **extrainfo**. If the authentication fails, the remaining authentication time is returned. If the authentication executor is locked, the freezing time is returned.| 5069 5070**Example** 5071 ```ts 5072 let authCallback: osAccount.IUserAuthCallback = { 5073 onResult: (result: number, extraInfo: osAccount.AuthResult) => { 5074 console.log('auth result = ' + result); 5075 console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); 5076 } 5077 }; 5078 ``` 5079 5080### onAcquireInfo?<sup>8+</sup> 5081 5082onAcquireInfo?: (module: number, acquire: number, extraInfo: Uint8Array) => void; 5083 5084Called to acquire identity authentication information. 5085 5086**System API**: This is a system API. 5087 5088**System capability**: SystemCapability.Account.OsAccount 5089 5090**Parameters** 5091 5092| Name | Type | Mandatory| Description | 5093| --------- | ------- | ---- | ----------------------------- | 5094| module | number | Yes | Type of authentication executor. | 5095| acquire | number | Yes | Tip code of the authentication executor.| 5096| extraInfo | Uint8Array | Yes | Reserved. | 5097 5098**Example** 5099 ```ts 5100 let authCallback: osAccount.IUserAuthCallback = { 5101 onResult: (result: number, extraInfo: osAccount.AuthResult) => { 5102 console.log('auth result = ' + result) 5103 console.log('auth extraInfo = ' + JSON.stringify(extraInfo)); 5104 }, 5105 onAcquireInfo: (module: number, acquire: number, extraInfo: Uint8Array) => { 5106 console.log('auth module = ' + module); 5107 console.log('auth acquire = ' + acquire); 5108 console.info('auth extraInfo = ' + JSON.stringify(extraInfo)); 5109 } 5110 }; 5111 ``` 5112 5113## IIdmCallback<sup>8+</sup> 5114 5115Provides callbacks for IDM. 5116 5117**System API**: This is a system API. 5118 5119### onResult<sup>8+</sup> 5120 5121onResult: (result: number, extraInfo: RequestResult) => void; 5122 5123Called to return the result code and request result information. 5124 5125**System API**: This is a system API. 5126 5127**System capability**: SystemCapability.Account.OsAccount 5128 5129**Parameters** 5130 5131| Name | Type | Mandatory| Description | 5132| --------- | --------------------------------------- | ---- | ----------------------- | 5133| result | number | Yes | Authentication result code. | 5134| extraInfo | [RequestResult](#requestresult8) | Yes | Specific information to be transferred.| 5135 5136**Example** 5137 ```ts 5138 let idmCallback: osAccount.IIdmCallback = { 5139 onResult: (result: number, extraInfo: osAccount.RequestResult) => { 5140 console.log('callback result = ' + result) 5141 console.info('callback extraInfo = ' + JSON.stringify(extraInfo)); 5142 } 5143 }; 5144 ``` 5145 5146### onAcquireInfo?<sup>8+</sup> 5147 5148onAcquireInfo?: (module: number, acquire: number, extraInfo: Uint8Array) => void; 5149 5150Called to acquire IDM information. 5151 5152**System API**: This is a system API. 5153 5154**System capability**: SystemCapability.Account.OsAccount 5155 5156**Parameters** 5157 5158| Name | Type | Mandatory| Description | 5159| --------- | ------- | ---- | ----------------------------- | 5160| module | number | Yes | Type of authentication executor. | 5161| acquire | number | Yes | Tip code of the authentication executor.| 5162| extraInfo | Uint8Array | Yes | Reserved. | 5163 5164**Example** 5165 ```ts 5166 let idmCallback: osAccount.IIdmCallback = { 5167 onResult: (result: number, extraInfo: Object) => { 5168 console.log('callback result = ' + result) 5169 console.log('callback onResult = ' + JSON.stringify(extraInfo)); 5170 }, 5171 onAcquireInfo: (module: number, acquire: number, extraInfo: Uint8Array) => { 5172 console.log('callback module = ' + module); 5173 console.log('callback acquire = ' + acquire); 5174 console.log('callback onacquireinfo = ' + JSON.stringify(extraInfo)); 5175 } 5176 }; 5177 ``` 5178 5179## GetPropertyRequest<sup>8+</sup> 5180 5181Defines the request for obtaining property information. 5182 5183**System API**: This is a system API. 5184 5185**System capability**: SystemCapability.Account.OsAccount 5186 5187| Name | Type | Mandatory | Description | 5188| -------- | ------------------------------------------------------------- | ----- | ----------------------- | 5189| authType | [AuthType](#authtype8) | Yes | Authentication credential type. | 5190| keys | Array<[GetPropertyType](#getpropertytype8)> | Yes | An array of the types of the properties to obtain.| 5191| accountId<sup>12+</sup> | number | No| System account ID, which is **undefined** by default.| 5192 5193## SetPropertyRequest<sup>8+</sup> 5194 5195Defines the request for setting property information. 5196 5197**System API**: This is a system API. 5198 5199**System capability**: SystemCapability.Account.OsAccount 5200 5201| Name | Type | Mandatory | Description | 5202| -------- | ------------------------------------------------ | ----- | -------------------- | 5203| authType | [AuthType](#authtype8) | Yes | Authentication credential type. | 5204| key | [SetPropertyType](#setpropertytype8) | Yes | Type of the property to set.| 5205| setInfo | Uint8Array | Yes | Information to set. | 5206 5207## ExecutorProperty<sup>8+</sup> 5208 5209Defines the executor property. 5210 5211**System API**: This is a system API. 5212 5213**System capability**: SystemCapability.Account.OsAccount 5214 5215| Name | Type | Readable| Writable| Description | 5216| ------------ | ---------------------------- | ----- | -----|----------------- | 5217| result | number | Yes | Yes | Result. | 5218| authSubType | [AuthSubType](#authsubtype8) | Yes | Yes | Authentication credential subtype.| 5219| remainTimes | number | Yes | Yes | Number of remaining authentication times. | 5220| freezingTime | number | Yes | Yes | Freezing time. | 5221| enrollmentProgress<sup>10+</sup> | string | Yes | Yes | Enrollment progress. By default, no value is passed in.| 5222| sensorInfo<sup>10+</sup> | string | Yes | Yes | Sensor information. By default, no value is passed in.| 5223| nextPhaseFreezingTime<sup>12+</sup> | number | Yes | Yes | Next freezing time, which is **undefined** by default.| 5224 5225## AuthResult<sup>8+</sup> 5226 5227Defines the authentication result information. 5228 5229**System API**: This is a system API. 5230 5231**System capability**: SystemCapability.Account.OsAccount 5232 5233| Name | Type | Mandatory | Description | 5234| ------------ | ----------- | ----- | ----------------- | 5235| token | Uint8Array | No | Authentication token. By default, no value is passed in. | 5236| remainTimes | number | No | Number of remaining authentication times. By default, no value is passed in. | 5237| freezingTime | number | No | Freezing time. By default, no value is passed in. | 5238| nextPhaseFreezingTime<sup>12+</sup> | number | No | Next freezing time, which is **undefined** by default.| 5239| credentialId<sup>12+</sup> | Uint8Array | No | Credential ID, which is left blank by default.| 5240| accountId<sup>12+</sup> | number | No | System account ID, which is **undefined** by default.| 5241| pinValidityPeriod<sup>12+</sup> | number | No | Authentication validity period, which is **undefined** by default.| 5242 5243## CredentialInfo<sup>8+</sup> 5244 5245Defines the credential information. 5246 5247**System API**: This is a system API. 5248 5249**System capability**: SystemCapability.Account.OsAccount 5250 5251| Name | Type | Mandatory | Description | 5252| ------------ | ---------------------------------------- | ----- | ----------------- | 5253| credType | [AuthType](#authtype8) | Yes | Authentication credential type. | 5254| credSubType | [AuthSubType](#authsubtype8) | Yes | Authentication credential subtype. | 5255| token | Uint8Array | Yes | Authentication token. | 5256| accountId<sup>12+</sup> | number | No | System account ID, which is **undefined** by default.| 5257 5258## RequestResult<sup>8+</sup> 5259 5260Defines the request result information. 5261 5262**System API**: This is a system API. 5263 5264**System capability**: SystemCapability.Account.OsAccount 5265 5266| Name | Type | Mandatory | Description | 5267| ------------ | ----------- | ----- | ----------------- | 5268| credentialId | Uint8Array | No | Credential ID. By default, no value is passed in. | 5269 5270## EnrolledCredInfo<sup>8+</sup> 5271 5272Defines enrolled credential information. 5273 5274**System API**: This is a system API. 5275 5276**System capability**: SystemCapability.Account.OsAccount 5277 5278| Name | Type | Mandatory | Description | 5279| ------------ | ---------------------------------------- | ----- | ------------------- | 5280| credentialId | Uint8Array | Yes | Credential ID. | 5281| authType | [AuthType](#authtype8) | Yes | Authentication credential type. | 5282| authSubType | [AuthSubType](#authsubtype8) | Yes | Credential subtype.| 5283| templateId | Uint8Array | Yes | Authentication credential template ID. | 5284 5285## GetPropertyType<sup>8+</sup> 5286 5287Enumerates the types of properties to obtain. 5288 5289**System API**: This is a system API. 5290 5291**System capability**: SystemCapability.Account.OsAccount 5292 5293| Name | Value| Description | 5294| ------------- | ------ | --------- | 5295| AUTH_SUB_TYPE | 1 | Authentication credential subtype.| 5296| REMAIN_TIMES | 2 | Number of remaining times. | 5297| FREEZING_TIME | 3 | Freezing time. | 5298| ENROLLMENT_PROGRESS<sup>10+</sup> | 4 | Enrollment progress. | 5299| SENSOR_INFO<sup>10+</sup> | 5 | Sensor information. | 5300| NEXT_PHASE_FREEZING_TIME<sup>12+</sup> | 6 | Next freezing time.| 5301 5302## SetPropertyType<sup>8+</sup> 5303 5304Enumerates the types of properties to set. 5305 5306**System API**: This is a system API. 5307 5308**System capability**: SystemCapability.Account.OsAccount 5309 5310| Name | Value| Description | 5311| -------------- | ----- | ----------- | 5312| INIT_ALGORITHM | 1 | Initialization algorithm.| 5313 5314## AuthType<sup>8+</sup> 5315 5316Enumerates the authentication credential types. 5317 5318**System API**: This is a system API. 5319 5320**System capability**: SystemCapability.Account.OsAccount 5321 5322| Name | Value| Description | 5323| ----- | ----- | ---------------- | 5324| PIN | 1 | PIN authentication.| 5325| FACE | 2 | Facial authentication.| 5326| FINGERPRINT<sup>10+</sup> | 4 | Fingerprint authentication.| 5327| RECOVERY_KEY<sup>12+</sup> | 8 | Key recovery type.| 5328| PRIVATE_PIN<sup>14+</sup> | 16 | Private PIN type.| 5329| DOMAIN<sup>9+</sup> | 1024 | Domain authentication.| 5330 5331## AuthSubType<sup>8+</sup> 5332 5333Enumerates the authentication credential subtypes. 5334 5335**System API**: This is a system API. 5336 5337**System capability**: SystemCapability.Account.OsAccount 5338 5339| Name | Value| Description | 5340| ---------- | ----- | ------------------ | 5341| PIN_SIX | 10000 | Six-digit PIN. | 5342| PIN_NUMBER | 10001 | Custom PIN.| 5343| PIN_MIXED | 10002 | Custom mixed credentials.| 5344| PIN_FOUR<sup>12+</sup> | 10003 | 4-digit credential.| 5345| PIN_PATTERN<sup>12+</sup> | 10004 | Pattern credential.| 5346| PIN_QUESTION<sup>14+</sup> | 10005 | Security question credential.| 5347| FACE_2D | 20000 | 2D face credential. | 5348| FACE_3D | 20001 | 3D face credential. | 5349| FINGERPRINT_CAPACITIVE<sup>10+</sup> | 30000 | Capacitive fingerprint. | 5350| FINGERPRINT_OPTICAL<sup>10+</sup> | 30001 | Optical fingerprint. | 5351| FINGERPRINT_ULTRASONIC<sup>10+</sup> | 30002 | Ultrasonic fingerprint. | 5352| DOMAIN_MIXED<sup>9+</sup> | 10240001 | Mixed domain authentication credentials. | 5353 5354## AuthTrustLevel<sup>8+</sup> 5355 5356Enumerates the trust levels of the authentication result. 5357 5358**System API**: This is a system API. 5359 5360**System capability**: SystemCapability.Account.OsAccount 5361 5362| Name | Value| Description | 5363| ---- | ------ | ----------- | 5364| ATL1 | 10000 | Trust level 1.| 5365| ATL2 | 20000 | Trust level 2.| 5366| ATL3 | 30000 | Trust level 3.| 5367| ATL4 | 40000 | Trust level 4.| 5368 5369## Module<sup>8+</sup> 5370 5371Enumerates the modules from which information is obtained. 5372 5373**System API**: This is a system API. 5374 5375**System capability**: SystemCapability.Account.OsAccount 5376 5377| Name | Value| Description | 5378| --------- | ------ | ------------------------ | 5379| FACE_AUTH | 1 | Facial authentication module.| 5380 5381## ResultCode<sup>8+</sup> 5382 5383Enumerates the authentication result codes. 5384 5385**System API**: This is a system API. 5386 5387**System capability**: SystemCapability.Account.OsAccount 5388 5389| Name | Value| Description | 5390| ----------------------- | ----- | ---------------------------------------- | 5391| SUCCESS | 0 | The authentication is successful or the authentication feature is supported. | 5392| FAIL | 1 | The authentication executor failed to identify the user. | 5393| GENERAL_ERROR | 2 | Other errors. | 5394| CANCELED | 3 | The authentication is canceled. | 5395| TIMEOUT | 4 | The authentication timed out. | 5396| TYPE_NOT_SUPPORT | 5 | The authentication credential type is not supported. | 5397| TRUST_LEVEL_NOT_SUPPORT | 6 | The authentication trust level is not supported. | 5398| BUSY | 7 | The authentication executor is busy. Try again after a few seconds.| 5399| INVALID_PARAMETERS | 8 | Incorrect parameters are detected. | 5400| LOCKED | 9 | The authentication executor is locked. | 5401| NOT_ENROLLED | 10 | The authentication executor is not enrolled. | 5402 5403## FaceTipsCode<sup>8+</sup> 5404 5405Enumerates the tip codes for facial authentication. 5406 5407**System API**: This is a system API. 5408 5409**System capability**: SystemCapability.Account.OsAccount 5410 5411| Name | Value| Description | 5412| ----------------------------- | ----- | ---------------------------------------- | 5413| FACE_AUTH_TIP_TOO_BRIGHT | 1 | The obtained face image is too bright. | 5414| FACE_AUTH_TIP_TOO_DARK | 2 | The obtained face image is too dark. | 5415| FACE_AUTH_TIP_TOO_CLOSE | 3 | The face is too close to the device. | 5416| FACE_AUTH_TIP_TOO_FAR | 4 | The face is too far away from the device. | 5417| FACE_AUTH_TIP_TOO_HIGH | 5 | Only the upper part of the face is captured because the device is angled too high. | 5418| FACE_AUTH_TIP_TOO_LOW | 6 | Only the lower part of the face is captured because the device is angled too low. | 5419| FACE_AUTH_TIP_TOO_RIGHT | 7 | Only the right part of the face is captured because the device is angled too much to the right.| 5420| FACE_AUTH_TIP_TOO_LEFT | 8 | Only the left part of the face is captured because the device is angled too much to the left.| 5421| FACE_AUTH_TIP_TOO_MUCH_MOTION | 9 | The face moves too fast during facial information collection. | 5422| FACE_AUTH_TIP_POOR_GAZE | 10 | The face is not facing the device. | 5423| FACE_AUTH_TIP_NOT_DETECTED | 11 | No face is detected. | 5424 5425## FingerprintTips<sup>8+</sup> 5426 5427Enumerates the tip codes for fingerprint authentication. 5428 5429**System API**: This is a system API. 5430 5431**System capability**: SystemCapability.Account.OsAccount 5432 5433| Name | Value| Description | 5434| ----------------------------- | ----- | ----------------------------------------------- | 5435| FINGERPRINT_TIP_GOOD | 0 | The captured image is clear. | 5436| FINGERPRINT_TIP_IMAGER_DIRTY | 1 | The fingerprint image has big noise due to dirt on the sensor.| 5437| FINGERPRINT_TIP_INSUFFICIENT | 2 | Failed to process the fingerprint image due to big noise. | 5438| FINGERPRINT_TIP_PARTIAL | 3 | Only part of the fingerprint image is detected. | 5439| FINGERPRINT_TIP_TOO_FAST | 4 | The fingerprint image is incomplete due to quick motion. | 5440| FINGERPRINT_TIP_TOO_SLOW | 5 | Failed to read the fingerprint image due to lack of motion. | 5441| FINGERPRINT_TIP_FINGER_DOWN<sup>10+</sup> | 6 | Press your finger. | 5442| FINGERPRINT_TIP_FINGER_UP<sup>10+</sup> | 7 | Lift your finger. | 5443 5444## OsAccountInfo 5445 5446Represents the system account information. 5447 5448**System capability**: SystemCapability.Account.OsAccount 5449 5450| Name | Type | Mandatory| Description | 5451| ----------- | ------ | ---- | ---------- | 5452| shortName<sup>12+</sup> | string | No | Short name of the system account.<br>**System API**: This is a system API and is left blank by default.| 5453| isLoggedIn<sup>12+</sup> | boolean | No | Whether the system account is logged in.<br>**System API**: This is a system API. The default value is **false**.| 5454 5455## OsAccountType 5456 5457Enumerates the system account types. 5458 5459**System capability**: SystemCapability.Account.OsAccount 5460 5461| Name | Value| Description | 5462| ------ | ------ | ----------- | 5463| PRIVATE<sup>12+</sup> | 1024 | Privacy account. Only one privacy account is allowed.<br>**System API**: This is a system API. | 5464 5465## DomainAccountInfo<sup>8+</sup> 5466 5467Represents domain account information. 5468 5469**System capability**: SystemCapability.Account.OsAccount 5470 5471| Name | Type | Mandatory| Description | 5472| ----------- | ------ | ---- | ---------- | 5473| accountId<sup>10+</sup> | string | No | Domain account ID.<br>**System API**: This is a system API and is **undefined** by default.| 5474| isAuthenticated<sup>11+</sup>| boolean | No| Whether the domain account has been authenticated.<br>**System API**: This is a system API. The default value is **false**.| 5475 5476## ConstraintSourceTypeInfo<sup>9+</sup> 5477 5478Defines the constraint source type. 5479 5480**System API**: This is a system API. 5481 5482**System capability**: SystemCapability.Account.OsAccount 5483 5484| Name | Type | Mandatory| Description | 5485| ----------- | ------ | ---- | ---------- | 5486| localId | number | Yes | ID of the target system account. | 5487| type | [ConstraintSourceType](#constraintsourcetype9) | Yes | Type of the constrain source.| 5488 5489## ConstraintSourceType<sup>9+</sup> 5490 5491Enumerates the constraint sources. 5492 5493**System API**: This is a system API. 5494 5495**System capability**: SystemCapability.Account.OsAccount 5496 5497| Name | Value| Description | 5498| ------ | ------ | ------------ | 5499| CONSTRAINT_NOT_EXIST | 0 | The constraint does not exist.| 5500| CONSTRAINT_TYPE_BASE | 1 | Constraint from system settings. | 5501| CONSTRAINT_TYPE_DEVICE_OWNER | 2 | Constraint from the device owners' settings. | 5502| CONSTRAINT_TYPE_PROFILE_OWNER | 3 | Constraint from the profile owners' settings. | 5503 5504## AuthStatusInfo<sup>10+</sup> 5505 5506Presents the authentication status information. 5507 5508**System API**: This is a system API. 5509 5510**System capability**: SystemCapability.Account.OsAccount 5511 5512| Name | Type | Mandatory| Description | 5513| ----------- | ------ | ---- | ---------- | 5514| remainTimes | number | Yes | Number of remaining times. | 5515| freezingTime | number | Yes | Freezing time.| 5516 5517## GetDomainAccessTokenOptions<sup>10+</sup> 5518 5519Defines the options for obtaining a domain access token. 5520 5521**System API**: This is a system API. 5522 5523**System capability**: SystemCapability.Account.OsAccount 5524 5525| Name | Type | Mandatory| Description | 5526| ----------- | ------ | ---- | ---------- | 5527| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information. | 5528| domainAccountToken | Uint8Array | Yes | Token of the domain account.| 5529| businessParams | Record<string, Object> | Yes | Service parameters customized by the service party based on the request protocol.| 5530| callerUid | number | Yes | Unique identifier of the caller.| 5531 5532## GetDomainAccountInfoOptions<sup>10+</sup> 5533 5534Defines the options for obtaining domain account information. 5535 5536**System API**: This is a system API. 5537 5538**System capability**: SystemCapability.Account.OsAccount 5539 5540| Name | Type | Mandatory| Description | 5541| ----------- | ------ | ---- | ---------- | 5542| accountName | string | Yes | Domain account name.| 5543| domain | string | No | Domain name, which is **undefined** by default.| 5544| serverConfigId<sup>12+</sup>| string | No| ID of the server to which the domain account belongs, which is **undefined** by default.| 5545 5546## GetDomainAccountInfoPluginOptions<sup>10+</sup> 5547 5548Defines the options for the domain plug-in to obtain the domain account information. The **GetDomainAccountInfoPluginOptions** class inherits from [**GetDomainAccountInfoOptions**](#getdomainaccountinfooptions10). 5549 5550**System API**: This is a system API. 5551 5552**System capability**: SystemCapability.Account.OsAccount 5553 5554| Name | Type | Mandatory| Description | 5555| ----------- | ------ | ---- | ---------- | 5556| callerUid | number | Yes | Unique identifier of the caller.| 5557 5558## OsAccountSwitchEventData<sup>12+</sup> 5559 5560Defines the event that indicates the start or end of a foreground-background system account switchover. 5561 5562**System API**: This is a system API. 5563 5564**System capability**: SystemCapability.Account.OsAccount 5565 5566| Name | Type | Mandatory| Description | 5567| ----------- | ------ | ---- | ---------- | 5568| fromAccountId | number | Yes | System account ID before the switchover.| 5569| toAccountId | number | Yes | System account ID after the switchover.| 5570 5571## CreateOsAccountOptions<sup>12+</sup> 5572 5573Represents the optional parameter used to create a system account. 5574 5575**System API**: This is a system API. 5576 5577**System capability**: SystemCapability.Account.OsAccount 5578 5579| Name | Type | Mandatory| Description | 5580| ----------- | ------ | ---- | ---------- | 5581| shortName | string | Yes | Short name of the account (used as the name of the personal folder).<br>**The short name cannot**:<br>Contain any of the following characters: \< \>\| : " * ? / \\<br>Contain any of the following: . or ..<br>Exceed 255 characters. | 5582 5583## CreateOsAccountForDomainOptions<sup>12+</sup> 5584 5585Represents a set of optional parameters for creating a system account bound to the specified domain account. It inherits from [CreateOsAccountOptions](#createosaccountoptions12). 5586 5587**System API**: This is a system API. 5588 5589**System capability**: SystemCapability.Account.OsAccount 5590 5591| Name | Type | Mandatory| Description | 5592| ----------- | ------ | ---- | ---------- | 5593| shortName | string | Yes | Short name of the account (used as the name of the personal folder).<br>**The short name cannot**:<br>Contain any of the following characters: \< \>\| : " * ? / \\<br>Contain any of the following: . or ..<br>Exceed 255 characters. | 5594 5595## GetAuthInfoOptions<sup>12+</sup> 5596 5597Represents a set of optional parameters for [GetAuthInfo](#getauthinfo12). 5598 5599**System API**: This is a system API. 5600 5601**System capability**: SystemCapability.Account.OsAccount 5602 5603| Name | Type | Mandatory| Description | 5604| --------- | ---------------------- | ---- | ---------- | 5605| authType | [AuthType](#authtype8) | No | Authentication type, which is **undefined** by default.| 5606| accountId | number | No | System account ID, which is **undefined** by default.| 5607 5608## AuthIntent<sup>12+</sup> 5609 5610Enumerates the authentication intents. 5611 5612**System API**: This is a system API. 5613 5614**System capability**: SystemCapability.Account.OsAccount 5615 5616| Name | Value | Description | 5617| -------- | --- | ---------- | 5618| UNLOCK | 1 | Unlock.| 5619| SILENT_AUTH<sup>14+</sup> | 2 | Silent authentication.| 5620| QUESTION_AUTH<sup>14+</sup> | 3 | Security question authentication.| 5621 5622## RemoteAuthOptions<sup>12+</sup> 5623 5624Represents a set of optional parameters for remote authentication. 5625 5626**System API**: This is a system API. 5627 5628**System capability**: SystemCapability.Account.OsAccount 5629 5630| Name | Type | Mandatory| Description | 5631| ------------------ | ------ | ---- | ---------- | 5632| verifierNetworkId | string | No | Network ID of the credential verifier, which is left blank by default.| 5633| collectorNetworkId | string | No | Network ID of the credential collector, which is left blank by default.| 5634| collectorTokenId | number | No | Token ID of the credential collector, which is **undefined** by default.| 5635 5636## AuthOptions<sup>12+</sup> 5637 5638Represents a set of optional parameters for [auth](#auth12). 5639 5640**System API**: This is a system API. 5641 5642**System capability**: SystemCapability.Account.OsAccount 5643 5644| Name | Type | Mandatory| Description | 5645| ------------------ | ------ | ---- | ---------- | 5646| accountId | number | No | System account ID, which is **undefined** by default.| 5647| authIntent | [AuthIntent](#authintent12) | No | Authentication intent, which is **undefined** by default.| 5648| remoteAuthOptions | [RemoteAuthOptions](#remoteauthoptions12) | No | Remote authentication options, which is **undefined** by default.| 5649 5650## GetInputDataOptions <sup>12+</sup> 5651 5652Represents a set of optional parameters for [onGetData](#ongetdata8). 5653 5654**System API**: This is a system API. 5655 5656**System capability**: SystemCapability.Account.OsAccount 5657 5658| Name | Type | Mandatory| Description | 5659| ------------------ | ------ | ---- | ---------- | 5660| challenge | Uint8Array | No | Challenge value, which is **undefined** by default.| 5661