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