1# @ohos.account.osAccount (System Account Management) 2 3The **osAccount** module provides basic capabilities for managing system (OS) accounts, including adding, deleting, querying, setting, subscribing to, and enabling a system account. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import account_osAccount from '@ohos.account.osAccount'; 13``` 14 15## account_osAccount.getAccountManager 16 17getAccountManager(): AccountManager 18 19Obtains an **AccountManager** instance. 20 21**System capability**: SystemCapability.Account.OsAccount 22 23**Return value** 24 25| Type | Description | 26| --------------------------------- | ---------------- | 27| [AccountManager](#accountmanager) | **AccountManager** instance obtained.| 28 29**Example** 30 31 ```ts 32 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 33 ``` 34 35## OsAccountType 36 37Enumerates the system 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 system accounts. 50 51### checkMultiOsAccountEnabled<sup>9+</sup> 52 53checkMultiOsAccountEnabled(callback: AsyncCallback<boolean>): void 54 55Checks whether multiple system accounts are supported. This API uses an asynchronous callback to return the result. 56 57**System capability**: SystemCapability.Account.OsAccount 58 59**Parameters** 60 61| Name | Type | Mandatory| Description | 62| -------- | ---------------------------- | ---- | ------------------------------------------------------ | 63| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means multiple system accounts are supported; the value **false** means the opposite.| 64 65**Error codes** 66 67| ID| Error Message | 68| -------- | ------------------- | 69| 12300001 | System service exception. | 70 71**Example** 72 73 ```ts 74 import { BusinessError } from '@ohos.base'; 75 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 76 try { 77 accountManager.checkMultiOsAccountEnabled((err: BusinessError, isEnabled: boolean) => { 78 if (err) { 79 console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`); 80 } else { 81 console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled); 82 } 83 }); 84 } catch (err) { 85 console.log('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err)); 86 } 87 ``` 88 89### checkMultiOsAccountEnabled<sup>9+</sup> 90 91checkMultiOsAccountEnabled(): Promise<boolean> 92 93Checks whether multiple system accounts are supported. This API uses a promise to return the result. 94 95**System capability**: SystemCapability.Account.OsAccount 96 97**Return value** 98 99| Type | Description | 100| :--------------------- | :--------------------------------------------------------- | 101| Promise<boolean> | Promise used to return the result. The value **true** means multiple system accounts are supported; the value **false** means the opposite.| 102 103**Error codes** 104 105| ID| Error Message | 106| -------- | ------------------- | 107| 12300001 | System service exception. | 108 109**Example** 110 111 ```ts 112 import { BusinessError } from '@ohos.base'; 113 try { 114 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 115 accountManager.checkMultiOsAccountEnabled().then((isEnabled: boolean) => { 116 console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled); 117 }).catch((err: BusinessError) => { 118 console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`); 119 }); 120 } catch (err) { 121 console.log('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err)); 122 } 123 ``` 124 125### checkOsAccountActivated<sup>(deprecated)</sup> 126 127checkOsAccountActivated(localId: number, callback: AsyncCallback<boolean>): void 128 129Checks whether a system account is activated. This API uses an asynchronous callback to return the result. 130 131> **NOTE** 132> 133> This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications. 134 135**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 136 137**System capability**: SystemCapability.Account.OsAccount 138 139**Parameters** 140 141| Name | Type | Mandatory| Description | 142| -------- | ---------------------------- | ---- | ------------------------------------------------------ | 143| localId | number | Yes | ID of the target system account. | 144| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the account is activated; the value **false** means the opposite.| 145 146**Error codes** 147 148| ID| Error Message | 149| -------- | ------------------- | 150| 12300001 | System service exception. | 151| 12300002 | Invalid localId. | 152| 12300003 | Account not found. | 153 154**Example**: Check whether system account 100 is activated. 155 156 ```ts 157 import { BusinessError } from '@ohos.base'; 158 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 159 let localId: number = 100; 160 try { 161 accountManager.checkOsAccountActivated(localId, (err: BusinessError, isActivated: boolean) => { 162 if (err) { 163 console.log('checkOsAccountActivated failed, error:' + JSON.stringify(err)); 164 } else { 165 console.log('checkOsAccountActivated successfully, isActivated:' + isActivated); 166 } 167 }); 168 } catch (err) { 169 console.log('checkOsAccountActivated exception: ' + JSON.stringify(err)); 170 } 171 ``` 172 173### checkOsAccountActivated<sup>(deprecated)</sup> 174 175checkOsAccountActivated(localId: number): Promise<boolean> 176 177Checks whether a system account is activated. This API uses a promise to return the result. 178 179> **NOTE** 180> 181> This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications. 182 183**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 184 185**System capability**: SystemCapability.Account.OsAccount 186 187**Parameters** 188 189| Name | Type | Mandatory| Description | 190| ------- | ------ | ---- | --------------------------------- | 191| localId | number | Yes | ID of the target system account.| 192 193**Return value** 194 195| Type | Description | 196| ---------------------- | ---------------------------------------------------------- | 197| Promise<boolean> | Promise used to return the result. The value **true** means the account is activated; the value **false** means the opposite.| 198 199**Error codes** 200 201| ID| Error Message | 202| -------- | ------------------- | 203| 12300001 | System service exception. | 204| 12300002 | Invalid localId. | 205| 12300003 | Account not found. | 206 207**Example**: Check whether system account 100 is activated. 208 209 ```ts 210 import { BusinessError } from '@ohos.base'; 211 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 212 let localId: number = 100; 213 try { 214 accountManager.checkOsAccountActivated(localId).then((isActivated: boolean) => { 215 console.log('checkOsAccountActivated successfully, isActivated: ' + isActivated); 216 }).catch((err: BusinessError) => { 217 console.log('checkOsAccountActivated failed, error: ' + JSON.stringify(err)); 218 }); 219 } catch (err) { 220 console.log('checkOsAccountActivated exception: ' + JSON.stringify(err)); 221 } 222 ``` 223 224### isOsAccountConstraintEnabled<sup>11+</sup> 225 226isOsAccountConstraintEnabled(constraint: string): Promise<boolean> 227 228Checks whether a constraint is enabled for this system account. This API uses a promise to return the result. 229 230**System capability**: SystemCapability.Account.OsAccount 231 232**Parameters** 233 234| Name | Type | Mandatory| Description | 235| ---------- | ------ | ---- | ---------------------------------- | 236| constraint | string | Yes | [Constraint](#constraints) to check.| 237 238**Return value** 239 240| Type | Description | 241| --------------------- | --------------------------------------------------------------------- | 242| Promise<boolean> | Promise used to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.| 243 244**Error codes** 245 246| ID| Error Message | 247| -------- | ------------------- | 248| 12300001 | System service exception. | 249 250**Example**: Check whether system account 100 is forbidden to use Wi-Fi. 251 252 ```ts 253 import { BusinessError } from '@ohos.base'; 254 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 255 let constraint: string = 'constraint.wifi'; 256 try { 257 accountManager.isOsAccountConstraintEnabled(constraint).then((isEnabled: boolean) => { 258 console.log('isOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled); 259 }).catch((err: BusinessError) => { 260 console.log('isOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err)); 261 }); 262 } catch (err) { 263 console.log('isOsAccountConstraintEnabled exception: ' + JSON.stringify(err)); 264 } 265 ``` 266 267### checkOsAccountConstraintEnabled<sup>(deprecated)</sup> 268 269checkOsAccountConstraintEnabled(localId: number, constraint: string, callback: AsyncCallback<boolean>): void 270 271Checks whether the specified constraint is enabled for a system account. This API uses an asynchronous callback to return the result. 272 273> **NOTE** 274> 275> This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications. 276 277**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 278 279**System capability**: SystemCapability.Account.OsAccount 280 281**Parameters** 282 283| Name | Type | Mandatory| Description | 284| ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- | 285| localId | number | Yes | ID of the target system account. | 286| constraint | string | Yes | [Constraint](#constraints) to check. | 287| 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.| 288 289**Error codes** 290 291| ID| Error Message | 292| -------- | ------------------- | 293| 12300001 | System service exception. | 294| 12300002 | Invalid localId or constraint. | 295| 12300003 | Account not found. | 296 297**Example**: Check whether system account 100 is forbidden to use Wi-Fi. 298 299 ```ts 300 import { BusinessError } from '@ohos.base'; 301 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 302 let localId: number = 100; 303 let constraint: string = 'constraint.wifi'; 304 try { 305 accountManager.checkOsAccountConstraintEnabled(localId, constraint, (err: BusinessError, isEnabled: boolean)=>{ 306 if (err) { 307 console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err)); 308 } else { 309 console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled); 310 } 311 }); 312 } catch (err) { 313 console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err)); 314 } 315 ``` 316 317### checkOsAccountConstraintEnabled<sup>(deprecated)</sup> 318 319checkOsAccountConstraintEnabled(localId: number, constraint: string): Promise<boolean> 320 321Checks whether the specified constraint is enabled for a system account. This API uses a promise to return the result. 322 323> **NOTE** 324> 325> This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications. 326 327**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 328 329**System capability**: SystemCapability.Account.OsAccount 330 331**Parameters** 332 333| Name | Type | Mandatory| Description | 334| ---------- | ------ | ---- | ---------------------------------- | 335| localId | number | Yes | ID of the target system account. | 336| constraint | string | Yes | [Constraint](#constraints) to check.| 337 338**Return value** 339 340| Type | Description | 341| --------------------- | --------------------------------------------------------------------- | 342| Promise<boolean> | Promise used to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.| 343 344**Error codes** 345 346| ID| Error Message | 347| -------- | ------------------- | 348| 12300001 | System service exception. | 349| 12300002 | Invalid localId or constraint. | 350| 12300003 | Account not found. | 351 352**Example**: Check whether system account 100 is forbidden to use Wi-Fi. 353 354 ```ts 355 import { BusinessError } from '@ohos.base'; 356 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 357 let localId: number = 100; 358 let constraint: string = 'constraint.wifi'; 359 try { 360 accountManager.checkOsAccountConstraintEnabled(localId, constraint).then((isEnabled: boolean) => { 361 console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled); 362 }).catch((err: BusinessError) => { 363 console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err)); 364 }); 365 } catch (err) { 366 console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err)); 367 } 368 ``` 369 370### checkOsAccountTestable<sup>9+</sup> 371 372checkOsAccountTestable(callback: AsyncCallback<boolean>): void 373 374Checks whether this system account is a test account. This API uses an asynchronous callback to return the result. 375 376**System capability**: SystemCapability.Account.OsAccount 377 378**Parameters** 379 380| Name | Type | Mandatory| Description | 381| -------- | ---------------------------- | ---- | --------------------------------------------------------------------- | 382| 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.| 383 384**Error codes** 385 386| ID| Error Message | 387| -------- | ------------------- | 388| 12300001 | System service exception. | 389 390**Example** 391 392 ```ts 393 import { BusinessError } from '@ohos.base'; 394 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 395 try { 396 accountManager.checkOsAccountTestable((err: BusinessError, isTestable: boolean) => { 397 if (err) { 398 console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err)); 399 } else { 400 console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable); 401 } 402 }); 403 } catch (err) { 404 console.log('checkOsAccountTestable error: ' + JSON.stringify(err)); 405 } 406 ``` 407 408### checkOsAccountTestable<sup>9+</sup> 409 410checkOsAccountTestable(): Promise<boolean> 411 412Checks whether this system account is a test account. This API uses a promise to return the result. 413 414**System capability**: SystemCapability.Account.OsAccount 415 416**Return value** 417 418| Type | Description | 419| ---------------------- | ------------------------------------------------------------------------ | 420| Promise<boolean> | Promise used to return the result. The value **true** means the account is a test account; the value **false** means the opposite.| 421 422**Error codes** 423 424| ID| Error Message | 425| -------- | ------------------- | 426| 12300001 | System service exception. | 427 428**Example** 429 430 ```ts 431 import { BusinessError } from '@ohos.base'; 432 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 433 try { 434 accountManager.checkOsAccountTestable().then((isTestable: boolean) => { 435 console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable); 436 }).catch((err: BusinessError) => { 437 console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err)); 438 }); 439 } catch (err) { 440 console.log('checkOsAccountTestable exception: ' + JSON.stringify(err)); 441 } 442 ``` 443 444### isOsAccountUnlocked<sup>11+</sup> 445 446isOsAccountUnlocked(): Promise<boolean> 447 448Checks whether this system account has been verified. This API uses a promise to return the result. 449 450**System capability**: SystemCapability.Account.OsAccount 451 452**Return value** 453 454| Type | Description | 455| ---------------------- | ------------------------------------------------------------------------ | 456| Promise<boolean> | Promise used to return the result. The value **true** means the system account has been verified; the value **false** means the opposite.| 457 458**Error codes** 459 460| ID| Error Message | 461| -------- | ------------------- | 462| 12300001 | System service exception. | 463 464**Example** 465 466 ```ts 467 import { BusinessError } from '@ohos.base'; 468 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 469 try { 470 accountManager.isOsAccountUnlocked().then((isVerified: boolean) => { 471 console.log('isOsAccountUnlocked successfully, isVerified: ' + isVerified); 472 }).catch((err: BusinessError) => { 473 console.log('isOsAccountUnlocked failed, error: ' + JSON.stringify(err)); 474 }); 475 } catch (err) { 476 console.log('isOsAccountUnlocked exception: ' + JSON.stringify(err)); 477 } 478 ``` 479 480### checkOsAccountVerified<sup>(deprecated)</sup> 481 482checkOsAccountVerified(callback: AsyncCallback<boolean>): void 483 484Checks whether this system account has been verified. This API uses an asynchronous callback to return the result. 485 486> **NOTE** 487> 488> This API is supported since API version 9 and deprecated since API version 11. Use [isOsAccountUnlocked](#isosaccountunlocked11) instead. 489 490**System capability**: SystemCapability.Account.OsAccount 491 492**Parameters** 493 494| Name | Type | Mandatory| Description | 495| -------- | ---------------------------- | ---- | ------------------------------------------------------------- | 496| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the system account has been verified; the value **false** means the opposite.| 497 498**Error codes** 499 500| ID| Error Message | 501| -------- | ------------------- | 502| 12300001 | System service exception. | 503 504**Example** 505 506 ```ts 507 import { BusinessError } from '@ohos.base'; 508 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 509 try { 510 accountManager.checkOsAccountVerified((err: BusinessError, isVerified: boolean) => { 511 if (err) { 512 console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); 513 } else { 514 console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); 515 } 516 }); 517 } catch (err) { 518 console.log('checkOsAccountVerified exception: ' + JSON.stringify(err)); 519 } 520 ``` 521 522### checkOsAccountVerified<sup>(deprecated)</sup> 523 524checkOsAccountVerified(): Promise<boolean> 525 526Checks whether this system account has been verified. This API uses a promise to return the result. 527 528> **NOTE** 529> 530> This API is supported since API version 9 and deprecated since API version 11. Use [isOsAccountUnlocked](#isosaccountunlocked11) instead. 531 532**System capability**: SystemCapability.Account.OsAccount 533 534**Return value** 535 536| Type | Description | 537| ---------------------- | ------------------------------------------------------------------------ | 538| Promise<boolean> | Promise used to return the result. The value **true** means the system account has been verified; the value **false** means the opposite.| 539 540**Error codes** 541 542| ID| Error Message | 543| -------- | ------------------- | 544| 12300001 | System service exception. | 545 546**Example** 547 548 ```ts 549 import { BusinessError } from '@ohos.base'; 550 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 551 try { 552 accountManager.checkOsAccountVerified().then((isVerified: boolean) => { 553 console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); 554 }).catch((err: BusinessError) => { 555 console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); 556 }); 557 } catch (err) { 558 console.log('checkOsAccountVerified exception: ' + JSON.stringify(err)); 559 } 560 ``` 561 562### checkOsAccountVerified<sup>(deprecated)</sup> 563 564checkOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void 565 566Checks whether a system account has been verified. This API uses an asynchronous callback to return the result. 567 568> **NOTE** 569> 570> This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications. 571 572**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 573 574**System capability**: SystemCapability.Account.OsAccount 575 576**Parameters** 577 578| Name | Type | Mandatory| Description | 579| -------- | ---------------------------- | ---- | ------------------------------------------------------------- | 580| localId | number | Yes | ID of the target system account. | 581| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the system account has been verified; the value **false** means the opposite.| 582 583**Error codes** 584 585| ID| Error Message | 586| -------- | ------------------- | 587| 12300001 | System service exception. | 588| 12300002 | Invalid localId. | 589| 12300003 | Account not found. | 590 591**Example** 592 593 ```ts 594 import { BusinessError } from '@ohos.base'; 595 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 596 let localId: number = 100; 597 try { 598 accountManager.checkOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => { 599 if (err) { 600 console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); 601 } else { 602 console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); 603 } 604 }); 605 } catch (err) { 606 console.log('checkOsAccountVerified exception: ' + err); 607 } 608 ``` 609 610### checkOsAccountVerified<sup>(deprecated)</sup> 611 612checkOsAccountVerified(localId: number): Promise<boolean> 613 614Checks whether a system account has been verified. This API uses a promise to return the result. 615 616> **NOTE** 617> 618> This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications. 619 620**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 621 622**System capability**: SystemCapability.Account.OsAccount 623 624**Parameters** 625 626| Name | Type | Mandatory| Description | 627| ------- | ------ | ---- | --------------------------------------------------------------- | 628| localId | number | Yes | ID of the target system account. If this parameter is not specified, this API checks whether the current system account has been verified.| 629 630**Return value** 631 632| Type | Description | 633| ---------------------- | ----------------------------------------------------------------- | 634| Promise<boolean> | Promise used to return the result. The value **true** means the system account has been verified; the value **false** means the opposite.| 635 636**Error codes** 637 638| ID| Error Message | 639| -------- | ------------------- | 640| 12300001 | System service exception. | 641| 12300002 | Invalid localId. | 642| 12300003 | Account not found. | 643 644**Example** 645 646 ```ts 647 import { BusinessError } from '@ohos.base'; 648 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 649 let localId: number = 100; 650 try { 651 accountManager.checkOsAccountVerified(localId).then((isVerified: boolean) => { 652 console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); 653 }).catch((err: BusinessError) => { 654 console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); 655 }); 656 } catch (err) { 657 console.log('checkOsAccountVerified exception: ' + JSON.stringify(err)); 658 } 659 ``` 660 661### checkOsAccountVerified<sup>9+</sup> 662 663checkOsAccountVerified(): Promise<boolean> 664 665Checks whether this system account has been verified. This API uses a promise to return the result. 666 667**System capability**: SystemCapability.Account.OsAccount 668 669**Return value** 670 671| Type | Description | 672| ---------------------- | ----------------------------------------------------------------- | 673| Promise<boolean> | Promise used to return the result. If **true** is returned, the current account has been verified. If **false** is returned, the current account has not been verified.| 674 675**Error codes** 676 677| ID| Error Message | 678| -------- | ------------------- | 679| 12300001 | System service exception. | 680 681**Example** 682 683 ```ts 684 import { BusinessError } from '@ohos.base'; 685 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 686 try { 687 accountManager.checkOsAccountVerified().then((isVerified: boolean) => { 688 console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified); 689 }).catch((err: BusinessError) => { 690 console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err)); 691 }); 692 } catch (err) { 693 console.log('checkOsAccountVerified exception: ' + JSON.stringify(err)); 694 } 695 ``` 696 697### getOsAccountCount<sup>9+</sup> 698 699getOsAccountCount(callback: AsyncCallback<number>): void 700 701Obtains the number of system accounts created. This API uses an asynchronous callback to return the result. 702 703**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 704 705**System capability**: SystemCapability.Account.OsAccount 706 707**Parameters** 708 709| Name | Type | Mandatory| Description | 710| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- | 711| 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 system accounts. If the operation fails, **err** is an error object.| 712 713**Error codes** 714 715| ID| Error Message | 716| -------- | ------------------- | 717| 12300001 | System service exception. | 718 719**Example** 720 721 ```ts 722 import { BusinessError } from '@ohos.base'; 723 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 724 try { 725 accountManager.getOsAccountCount((err: BusinessError, count: number) => { 726 if (err) { 727 console.log('getOsAccountCount failed, error: ' + JSON.stringify(err)); 728 } else { 729 console.log('getOsAccountCount successfully, count: ' + count); 730 } 731 }); 732 } catch (err) { 733 console.log('getOsAccountCount exception: ' + JSON.stringify(err)); 734 } 735 ``` 736 737### getOsAccountCount<sup>9+</sup> 738 739getOsAccountCount(): Promise<number> 740 741Obtains the number of system accounts created. This API uses a promise to return the result. 742 743**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 744 745**System capability**: SystemCapability.Account.OsAccount 746 747**Return value** 748 749| Type | Description | 750| --------------------- | -------------------------------------- | 751| Promise<number> | Promise used to return the number of created system accounts.| 752 753**Error codes** 754 755| ID| Error Message | 756| -------- | ------------------- | 757| 12300001 | System service exception. | 758 759**Example** 760 761 ```ts 762 import { BusinessError } from '@ohos.base'; 763 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 764 try { 765 accountManager.getOsAccountCount().then((count: number) => { 766 console.log('getOsAccountCount successfully, count: ' + count); 767 }).catch((err: BusinessError) => { 768 console.log('getOsAccountCount failed, error: ' + JSON.stringify(err)); 769 }); 770 } catch(err) { 771 console.log('getOsAccountCount exception: ' + JSON.stringify(err)); 772 } 773 ``` 774 775### getOsAccountLocalId<sup>9+</sup> 776 777getOsAccountLocalId(callback: AsyncCallback<number>): void 778 779Obtains the ID of the system account to which the current process belongs. This API uses an asynchronous callback to return the result. 780 781**System capability**: SystemCapability.Account.OsAccount 782 783**Parameters** 784 785| Name | Type | Mandatory| Description | 786| -------- | --------------------------- | ---- | ---------------------------------------------------------------------------- | 787| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account ID obtained. Otherwise, **err** is an error object.| 788 789**Error codes** 790 791| ID| Error Message | 792| -------- | ------------------- | 793| 12300001 | System service exception. | 794 795**Example** 796 797 ```ts 798 import { BusinessError } from '@ohos.base'; 799 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 800 try { 801 accountManager.getOsAccountLocalId((err: BusinessError, localId: number) => { 802 if (err) { 803 console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err)); 804 } else { 805 console.log('getOsAccountLocalId successfully, localId: ' + localId); 806 } 807 }); 808 } catch (err) { 809 console.log('getOsAccountLocalId exception: ' + JSON.stringify(err)); 810 } 811 ``` 812 813### getOsAccountLocalId<sup>9+</sup> 814 815getOsAccountLocalId(): Promise<number> 816 817Obtains the ID of the system account to which the current process belongs. This API uses a promise to return the result. 818 819**System capability**: SystemCapability.Account.OsAccount 820 821**Return value** 822 823| Type | Description | 824| --------------------- | ---------------------------------------- | 825| Promise<number> | Promise used to return the system account ID obtained.| 826 827**Error codes** 828 829| ID| Error Message | 830| -------- | ------------------- | 831| 12300001 | System service exception. | 832 833**Example** 834 835 ```ts 836 import { BusinessError } from '@ohos.base'; 837 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 838 try { 839 accountManager.getOsAccountLocalId().then((localId: number) => { 840 console.log('getOsAccountLocalId successfully, localId: ' + localId); 841 }).catch((err: BusinessError) => { 842 console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err)); 843 }); 844 } catch (err) { 845 console.log('getOsAccountLocalId exception: ' + JSON.stringify(err)); 846 } 847 ``` 848 849### getOsAccountLocalIdForUid<sup>9+</sup> 850 851getOsAccountLocalIdForUid(uid: number, callback: AsyncCallback<number>): void 852 853Obtains the system account ID based on the process UID. This API uses an asynchronous callback to return the result. 854 855**System capability**: SystemCapability.Account.OsAccount 856 857**Parameters** 858 859| Name | Type | Mandatory| Description | 860| -------- | --------------------------- | ---- | --------------------------------------------------------------------- | 861| uid | number | Yes | Process UID. | 862| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account ID obtained. Otherwise, **data** is an error object.| 863 864**Error codes** 865 866| ID| Error Message | 867| -------- | --------------- | 868| 12300001 | System service exception. | 869| 12300002 | Invalid uid. | 870 871**Example**: Obtain the ID of the system account whose process UID is **12345678**. 872 873 ```ts 874 import { BusinessError } from '@ohos.base'; 875 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 876 let uid: number = 12345678; 877 try { 878 accountManager.getOsAccountLocalIdForUid(uid, (err: BusinessError, localId: number) => { 879 if (err) { 880 console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err)); 881 } 882 console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId); 883 }); 884 } catch (err) { 885 console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err)); 886 } 887 ``` 888 889### getOsAccountLocalIdForUid<sup>9+</sup> 890 891getOsAccountLocalIdForUid(uid: number): Promise<number> 892 893Obtains the system account ID based on the process UID. This API uses a promise to return the result. 894 895**System capability**: SystemCapability.Account.OsAccount 896 897**Parameters** 898 899| Name| Type | Mandatory| Description | 900| ------ | ------ | ---- | --------- | 901| uid | number | Yes | Process UID.| 902 903**Return value** 904 905| Type | Description | 906| --------------------- | --------------------------------------- | 907| Promise<number> | Promise used to return the system account ID obtained.| 908 909**Error codes** 910 911| ID| Error Message | 912| -------- | ------------- | 913| 12300001 | System service exception. | 914| 12300002 | Invalid uid. | 915 916**Example**: Obtain the ID of the system account whose process UID is **12345678**. 917 918 ```ts 919 import { BusinessError } from '@ohos.base'; 920 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 921 let uid: number = 12345678; 922 try { 923 accountManager.getOsAccountLocalIdForUid(uid).then((localId: number) => { 924 console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId); 925 }).catch((err: BusinessError) => { 926 console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err)); 927 }); 928 } catch (err) { 929 console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err)); 930 } 931 ``` 932 933### getOsAccountLocalIdForUidSync<sup>10+</sup> 934 935getOsAccountLocalIdForUidSync(uid: number): number 936 937Obtains the system account ID based on the process UID. The API returns the result synchronously. 938 939**System capability**: SystemCapability.Account.OsAccount 940 941**Parameters** 942 943| Name| Type | Mandatory| Description | 944| ------ | ------ | ---- | --------- | 945| uid | number | Yes | Process UID.| 946 947**Return value** 948 949| Type | Description | 950| --------------------- | --------------------------------------- | 951| number | System account ID obtained.| 952 953**Error codes** 954 955| ID| Error Message | 956| -------- | ------------- | 957| 12300002 | Invalid uid. | 958 959**Example**: Obtain the ID of the system account whose process UID is **12345678**. 960 961 ```ts 962 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 963 let uid: number = 12345678; 964 try { 965 let localId : number = accountManager.getOsAccountLocalIdForUidSync(uid); 966 console.log('getOsAccountLocalIdForUidSync successfully, localId: ' + localId); 967 } catch (err) { 968 console.log('getOsAccountLocalIdForUidSync exception: ' + JSON.stringify(err)); 969 } 970 ``` 971 972### getOsAccountLocalIdForDomain<sup>9+</sup> 973 974getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void 975 976Obtains the system account ID based on the domain account information. This API uses an asynchronous callback to return the result. 977 978**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 979 980**System capability**: SystemCapability.Account.OsAccount 981 982**Parameters** 983 984| Name | Type | Mandatory| Description | 985| ---------- | --------------------------------------- | ---- | -------------------------------------------------------------------------- | 986| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information. | 987| 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 system account associated with the domain account. Otherwise, **err** is an error object.| 988 989**Error codes** 990 991| ID| Error Message | 992| -------- | ------------- | 993| 12300001 | System service exception. | 994| 12300002 | Invalid domainInfo. | 995 996**Example** 997 998 ```ts 999 import { BusinessError } from '@ohos.base'; 1000 let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'}; 1001 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1002 try { 1003 accountManager.getOsAccountLocalIdForDomain(domainInfo, (err: BusinessError, localId: number) => { 1004 if (err) { 1005 console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err)); 1006 } else { 1007 console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId); 1008 } 1009 }); 1010 } catch (err) { 1011 console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err)); 1012 } 1013 ``` 1014 1015### getOsAccountLocalIdForDomain<sup>9+</sup> 1016 1017getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo): Promise<number> 1018 1019Obtains the system account ID based on the domain account information. This API uses a promise to return the result. 1020 1021**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1022 1023**System capability**: SystemCapability.Account.OsAccount 1024 1025**Parameters** 1026 1027| Name | Type | Mandatory| Description | 1028| ---------- | --------------------------------------- | ---- | ------------ | 1029| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 1030 1031**Return value** 1032 1033| Type | Description | 1034| :-------------------- | :------------------------------------- | 1035| Promise<number> | Promise used to return the ID of the system account associated with the domain account.| 1036 1037**Error codes** 1038 1039| ID| Error Message | 1040| -------- | ------------- | 1041| 12300001 | System service exception. | 1042| 12300002 | Invalid domainInfo. | 1043 1044**Example** 1045 1046 ```ts 1047 import { BusinessError } from '@ohos.base'; 1048 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1049 let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'}; 1050 try { 1051 accountManager.getOsAccountLocalIdForDomain(domainInfo).then((localId: number) => { 1052 console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId); 1053 }).catch((err: BusinessError) => { 1054 console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err)); 1055 }); 1056 } catch (err) { 1057 console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err)); 1058 } 1059 ``` 1060 1061### getOsAccountConstraints<sup>(deprecated)</sup> 1062 1063getOsAccountConstraints(localId: number, callback: AsyncCallback<Array<string>>): void 1064 1065Obtains all constraints enabled for a system account. This API uses an asynchronous callback to return the result. 1066 1067> **NOTE** 1068> 1069> This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications. 1070 1071**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1072 1073**System capability**: SystemCapability.Account.OsAccount 1074 1075**Parameters** 1076 1077| Name | Type | Mandatory| Description | 1078| -------- | ---------------------------------------- | ---- | -------------------------------------------------------------------------------------------- | 1079| localId | number | Yes | ID of the target system account. | 1080| 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.| 1081 1082**Error codes** 1083 1084| ID| Error Message | 1085| -------- | ------------------- | 1086| 12300001 | System service exception. | 1087| 12300002 | Invalid localId. | 1088| 12300003 | Account not found. | 1089 1090**Example**: Obtain all constraints of system account 100. 1091 1092 ```ts 1093 import { BusinessError } from '@ohos.base'; 1094 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1095 let localId: number = 100; 1096 try { 1097 accountManager.getOsAccountConstraints(localId, (err: BusinessError, constraints: string[]) => { 1098 if (err) { 1099 console.log('getOsAccountConstraints failed, err: ' + JSON.stringify(err)); 1100 } else { 1101 console.log('getOsAccountConstraints successfully, constraints: ' + JSON.stringify(constraints)); 1102 } 1103 }); 1104 } catch (err) { 1105 console.log('getOsAccountConstraints exception: ' + JSON.stringify(err)); 1106 } 1107 ``` 1108 1109### getOsAccountConstraints<sup>(deprecated)</sup> 1110 1111getOsAccountConstraints(localId: number): Promise<Array<string>> 1112 1113Obtains all constraints enabled for a system account. This API uses a promise to return the result. 1114 1115> **NOTE** 1116> 1117> This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications. 1118 1119**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1120 1121**System capability**: SystemCapability.Account.OsAccount 1122 1123**Parameters** 1124 1125| Name | Type | Mandatory| Description | 1126| ------- | ------ | ---- | ------------ | 1127| localId | number | Yes | ID of the target system account.| 1128 1129**Return value** 1130 1131| Type | Description | 1132| ---------------------------------- | ---------------------------------------------------------- | 1133| Promise<Array<string>> | Promise used to return all the [constraints](#constraints) enabled for the system account.| 1134 1135**Error codes** 1136 1137| ID| Error Message | 1138| -------- | ------------------- | 1139| 12300001 | System service exception. | 1140| 12300002 | Invalid localId. | 1141| 12300003 | Account not found. | 1142 1143**Example**: Obtain all constraints of system account 100. 1144 1145 ```ts 1146 import { BusinessError } from '@ohos.base'; 1147 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1148 let localId: number = 100; 1149 try { 1150 accountManager.getOsAccountConstraints(localId).then((constraints: string[]) => { 1151 console.log('getOsAccountConstraints, constraints: ' + constraints); 1152 }).catch((err: BusinessError) => { 1153 console.log('getOsAccountConstraints err: ' + JSON.stringify(err)); 1154 }); 1155 } catch (e) { 1156 console.log('getOsAccountConstraints exception: ' + JSON.stringify(e)); 1157 } 1158 ``` 1159 1160### getActivatedOsAccountLocalIds<sup>9+</sup> 1161 1162getActivatedOsAccountLocalIds(callback: AsyncCallback<Array<number>>): void 1163 1164Obtains information about all activated system accounts. This API uses an asynchronous callback to return the result. 1165 1166**System capability**: SystemCapability.Account.OsAccount 1167 1168**Parameters** 1169 1170| Name | Type | Mandatory| Description | 1171| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ | 1172| 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 system accounts. Otherwise, **data** is an error object.| 1173 1174**Error codes** 1175 1176| ID| Error Message | 1177| -------- | ------------- | 1178| 12300001 | System service exception. | 1179 1180**Example** 1181 1182 ```ts 1183 import { BusinessError } from '@ohos.base'; 1184 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1185 try { 1186 accountManager.getActivatedOsAccountLocalIds((err: BusinessError, idArray: number[])=>{ 1187 console.log('getActivatedOsAccountLocalIds err:' + JSON.stringify(err)); 1188 console.log('getActivatedOsAccountLocalIds idArray length:' + idArray.length); 1189 for(let i=0;i<idArray.length;i++) { 1190 console.info('activated os account id: ' + idArray[i]); 1191 } 1192 }); 1193 } catch (e) { 1194 console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e)); 1195 } 1196 ``` 1197 1198### getActivatedOsAccountLocalIds<sup>9+</sup> 1199 1200getActivatedOsAccountLocalIds(): Promise<Array<number>> 1201 1202Obtains information about all activated system accounts. This API uses a promise to return the result. 1203 1204**System capability**: SystemCapability.Account.OsAccount 1205 1206**Return value** 1207 1208| Type | Description | 1209| :--------------------------------- | :------------------------------------------------ | 1210| Promise<Array<number>> | Promise used to return the information about all activated system accounts.| 1211 1212**Error codes** 1213 1214| ID| Error Message | 1215| -------- | ------------- | 1216| 12300001 | System service exception. | 1217 1218**Example** 1219 1220 ```ts 1221 import { BusinessError } from '@ohos.base'; 1222 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1223 try { 1224 accountManager.getActivatedOsAccountLocalIds().then((idArray: number[]) => { 1225 console.log('getActivatedOsAccountLocalIds, idArray: ' + idArray); 1226 }).catch((err: BusinessError) => { 1227 console.log('getActivatedOsAccountLocalIds err: ' + JSON.stringify(err)); 1228 }); 1229 } catch (e) { 1230 console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e)); 1231 } 1232 ``` 1233 1234### getCurrentOsAccount<sup>(deprecated)</sup> 1235 1236getCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void 1237 1238Obtains information about the system account to which the current process belongs. This API uses an asynchronous callback to return the result. 1239 1240> **NOTE** 1241> 1242> This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications. 1243 1244**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.GET_LOCAL_ACCOUNTS<sup>10+</sup> 1245 1246**System capability**: SystemCapability.Account.OsAccount 1247 1248**Parameters** 1249 1250| Name | Type | Mandatory| Description | 1251| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | 1252| callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account information obtained. Otherwise, **data** is an error object.| 1253 1254**Error codes** 1255 1256| ID| Error Message | 1257| -------- | ------------------- | 1258| 12300001 | System service exception. | 1259 1260**Example** 1261 1262 ```ts 1263 import { BusinessError } from '@ohos.base'; 1264 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1265 try { 1266 accountManager.getCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{ 1267 console.log('getCurrentOsAccount err:' + JSON.stringify(err)); 1268 console.log('getCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo)); 1269 }); 1270 } catch (e) { 1271 console.log('getCurrentOsAccount exception: ' + JSON.stringify(e)); 1272 } 1273 ``` 1274 1275### getCurrentOsAccount<sup>(deprecated)</sup> 1276 1277getCurrentOsAccount(): Promise<OsAccountInfo> 1278 1279Obtains information about the system account to which the current process belongs. This API uses a promise to return the result. 1280 1281> **NOTE** 1282> 1283> This API is supported since API version 9 and deprecated since API version 11. The substitute API is available only to system applications. 1284 1285**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.GET_LOCAL_ACCOUNTS<sup>10+</sup> 1286 1287**System capability**: SystemCapability.Account.OsAccount 1288 1289**Return value** 1290 1291| Type | Description | 1292| ---------------------------------------------- | ----------------------------------------- | 1293| Promise<[OsAccountInfo](#osaccountinfo)> | Promise used to return the system account information obtained.| 1294 1295**Error codes** 1296 1297| ID| Error Message | 1298| -------- | ------------------- | 1299| 12300001 | System service exception. | 1300 1301**Example** 1302 1303 ```ts 1304 import { BusinessError } from '@ohos.base'; 1305 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1306 try { 1307 accountManager.getCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => { 1308 console.log('getCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo)); 1309 }).catch((err: BusinessError) => { 1310 console.log('getCurrentOsAccount err: ' + JSON.stringify(err)); 1311 }); 1312 } catch (e) { 1313 console.log('getCurrentOsAccount exception: ' + JSON.stringify(e)); 1314 } 1315 ``` 1316 1317### getOsAccountType<sup>9+</sup> 1318 1319getOsAccountType(callback: AsyncCallback<OsAccountType>): void 1320 1321Obtains the type of the account to which the current process belongs. This API uses an asynchronous callback to return the result. 1322 1323**System capability**: SystemCapability.Account.OsAccount 1324 1325**Parameters** 1326 1327| Name | Type | Mandatory| Description | 1328| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- | 1329| callback | AsyncCallback<[OsAccountType](#osaccounttype)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account type obtained. Otherwise, **err** is an error object.| 1330 1331**Error codes** 1332 1333| ID| Error Message | 1334| -------- | ------------------- | 1335| 12300001 | System service exception. | 1336 1337**Example** 1338 1339 ```ts 1340 import { BusinessError } from '@ohos.base'; 1341 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1342 try { 1343 accountManager.getOsAccountType((err: BusinessError, accountType: account_osAccount.OsAccountType) => { 1344 console.log('getOsAccountType err: ' + JSON.stringify(err)); 1345 console.log('getOsAccountType accountType: ' + accountType); 1346 }); 1347 } catch (e) { 1348 console.log('getOsAccountType exception: ' + JSON.stringify(e)); 1349 } 1350 ``` 1351 1352### getOsAccountType<sup>9+</sup> 1353 1354getOsAccountType(): Promise<OsAccountType> 1355 1356Obtains the type of the account to which the current process belongs. This API uses a promise to return the result. 1357 1358**System capability**: SystemCapability.Account.OsAccount 1359 1360**Return value** 1361 1362| Type | Description | 1363| ---------------------------------------------- | ----------------------------------------------- | 1364| Promise<[OsAccountType](#osaccounttype)> | Promise used to return the system account type obtained.| 1365 1366**Error codes** 1367 1368| ID| Error Message | 1369| -------- | ------------------- | 1370| 12300001 | System service exception. | 1371 1372**Example** 1373 1374 ```ts 1375 import { BusinessError } from '@ohos.base'; 1376 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1377 try { 1378 accountManager.getOsAccountType().then((accountType: account_osAccount.OsAccountType) => { 1379 console.log('getOsAccountType, accountType: ' + accountType); 1380 }).catch((err: BusinessError) => { 1381 console.log('getOsAccountType err: ' + JSON.stringify(err)); 1382 }); 1383 } catch (e) { 1384 console.log('getOsAccountType exception: ' + JSON.stringify(e)); 1385 } 1386 ``` 1387 1388### queryDistributedVirtualDeviceId<sup>9+</sup> 1389 1390queryDistributedVirtualDeviceId(callback: AsyncCallback<string>): void 1391 1392Queries the ID of the distributed virtual device. This API uses an asynchronous callback to return the result. 1393 1394**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS 1395 1396**System capability**: SystemCapability.Account.OsAccount 1397 1398**Parameters** 1399 1400| Name | Type | Mandatory| Description | 1401| -------- | --------------------------- | ---- | --------------------------------------------------------------------- | 1402| 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.| 1403 1404**Error codes** 1405 1406| ID| Error Message | 1407| -------- | ------------------- | 1408| 12300001 | System service exception. | 1409 1410**Example** 1411 1412 ```ts 1413 import { BusinessError } from '@ohos.base'; 1414 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1415 try { 1416 accountManager.queryDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => { 1417 console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err)); 1418 console.log('queryDistributedVirtualDeviceId virtualID: ' + virtualID); 1419 }); 1420 } catch (e) { 1421 console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e)); 1422 } 1423 ``` 1424 1425### queryDistributedVirtualDeviceId<sup>9+</sup> 1426 1427queryDistributedVirtualDeviceId(): Promise<string> 1428 1429Queries the ID of the distributed virtual device. This API uses a promise to return the result. 1430 1431**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS 1432 1433**System capability**: SystemCapability.Account.OsAccount 1434 1435**Return value** 1436 1437| Type | Description | 1438| --------------------- | --------------------------------- | 1439| Promise<string> | Promise used to return the distributed virtual device ID obtained.| 1440 1441**Error codes** 1442 1443| ID| Error Message | 1444| -------- | ------------------- | 1445| 12300001 | System service exception. | 1446 1447**Example** 1448 1449 ```ts 1450 import { BusinessError } from '@ohos.base'; 1451 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1452 try { 1453 accountManager.queryDistributedVirtualDeviceId().then((virtualID: string) => { 1454 console.log('queryDistributedVirtualDeviceId, virtualID: ' + virtualID); 1455 }).catch((err: BusinessError) => { 1456 console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err)); 1457 }); 1458 } catch (e) { 1459 console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e)); 1460 } 1461 ``` 1462 1463### getOsAccountLocalIdForSerialNumber<sup>9+</sup> 1464 1465getOsAccountLocalIdForSerialNumber(serialNumber: number, callback: AsyncCallback<number>): void 1466 1467Obtains the system account ID based on the SN. This API uses an asynchronous callback to return the result. 1468 1469**System capability**: SystemCapability.Account.OsAccount 1470 1471**Parameters** 1472 1473| Name | Type | Mandatory| Description | 1474| ------------ | --------------------------- | ---- | ---------------------------------------------------------------------------- | 1475| serialNumber | number | Yes | Account SN. | 1476| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account ID obtained. Otherwise, **err** is an error object.| 1477 1478**Error codes** 1479 1480| ID| Error Message | 1481| -------- | ------------------- | 1482| 12300001 | System service exception. | 1483| 12300002 | Invalid serialNumber. | 1484| 12300003 | The account indicated by serialNumber dose not exist. | 1485 1486**Example**: Obtain the ID of the system account whose SN is 12345. 1487 1488 ```ts 1489 import { BusinessError } from '@ohos.base'; 1490 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1491 let serialNumber: number = 12345; 1492 try { 1493 accountManager.getOsAccountLocalIdForSerialNumber(serialNumber, (err: BusinessError, localId: number)=>{ 1494 console.log('ger localId err:' + JSON.stringify(err)); 1495 console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber); 1496 }); 1497 } catch (e) { 1498 console.log('ger localId exception: ' + JSON.stringify(e)); 1499 } 1500 ``` 1501 1502### getOsAccountLocalIdForSerialNumber<sup>9+</sup> 1503 1504getOsAccountLocalIdForSerialNumber(serialNumber: number): Promise<number> 1505 1506Obtains the system account ID based on the SN. This API uses a promise to return the result. 1507 1508**System capability**: SystemCapability.Account.OsAccount 1509 1510**Parameters** 1511 1512| Name | Type | Mandatory| Description | 1513| ------------ | ------ | ---- | ---------- | 1514| serialNumber | number | Yes | Account SN.| 1515 1516**Return value** 1517 1518| Type | Description | 1519| --------------------- | -------------------------------------------- | 1520| Promise<number> | Promise used to return the system account ID obtained.| 1521 1522**Error codes** 1523 1524| ID| Error Message | 1525| -------- | ------------------- | 1526| 12300001 | System service exception. | 1527| 12300002 | Invalid serialNumber. | 1528| 12300003 | The account indicated by serialNumber dose not exist. | 1529 1530**Example**: Obtain the ID of the system account whose SN is 12345. 1531 1532 ```ts 1533 import { BusinessError } from '@ohos.base'; 1534 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1535 let serialNumber: number = 12345; 1536 try { 1537 accountManager.getOsAccountLocalIdForSerialNumber(serialNumber).then((localId: number) => { 1538 console.log('getOsAccountLocalIdForSerialNumber localId: ' + localId); 1539 }).catch((err: BusinessError) => { 1540 console.log('getOsAccountLocalIdForSerialNumber err: ' + JSON.stringify(err)); 1541 }); 1542 } catch (e) { 1543 console.log('getOsAccountLocalIdForSerialNumber exception: ' + JSON.stringify(e)); 1544 } 1545 ``` 1546 1547### getSerialNumberForOsAccountLocalId<sup>9+</sup> 1548 1549getSerialNumberForOsAccountLocalId(localId: number, callback: AsyncCallback<number>): void 1550 1551Obtains the SN of a system account based on the account ID. This API uses an asynchronous callback to return the result. 1552 1553**System capability**: SystemCapability.Account.OsAccount 1554 1555**Parameters** 1556 1557| Name | Type | Mandatory| Description | 1558| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- | 1559| localId | number | Yes | ID of the target system account. | 1560| 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.| 1561 1562**Error codes** 1563 1564| ID| Error Message | 1565| -------- | ------------------- | 1566| 12300001 | System service exception. | 1567| 12300002 | Invalid localId. | 1568| 12300003 | Account not found. | 1569 1570**Example**: Obtain the SN of the system account 100. 1571 1572 ```ts 1573 import { BusinessError } from '@ohos.base'; 1574 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1575 let localId: number = 100; 1576 try { 1577 accountManager.getSerialNumberForOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{ 1578 console.log('ger serialNumber err:' + JSON.stringify(err)); 1579 console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId); 1580 }); 1581 } catch (e) { 1582 console.log('ger serialNumber exception: ' + JSON.stringify(e)); 1583 } 1584 ``` 1585 1586### getSerialNumberForOsAccountLocalId<sup>9+</sup> 1587 1588getSerialNumberForOsAccountLocalId(localId: number): Promise<number> 1589 1590Obtains the SN of a system account based on the account ID. This API uses a promise to return the result. 1591 1592**System capability**: SystemCapability.Account.OsAccount 1593 1594**Parameters** 1595 1596| Name | Type | Mandatory| Description | 1597| ------- | ------ | ---- | ----------- | 1598| localId | number | Yes | ID of the target system account.| 1599 1600**Return value** 1601 1602| Type | Description | 1603| :-------------------- | :------------------------------------- | 1604| Promise<number> | Promise used to return the SN obtained.| 1605 1606**Error codes** 1607 1608| ID| Error Message | 1609| -------- | ------------------- | 1610| 12300001 | System service exception. | 1611| 12300002 | Invalid localId. | 1612| 12300003 | Account not found. | 1613 1614**Example**: Obtain the SN of the system account 100. 1615 1616 ```ts 1617 import { BusinessError } from '@ohos.base'; 1618 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1619 let localId: number = 100; 1620 try { 1621 accountManager.getSerialNumberForOsAccountLocalId(localId).then((serialNumber: number) => { 1622 console.log('getSerialNumberForOsAccountLocalId serialNumber: ' + serialNumber); 1623 }).catch((err: BusinessError) => { 1624 console.log('getSerialNumberForOsAccountLocalId err: ' + JSON.stringify(err)); 1625 }); 1626 } catch (e) { 1627 console.log('getSerialNumberForOsAccountLocalId exception: ' + JSON.stringify(e)); 1628 } 1629 ``` 1630 1631### isMultiOsAccountEnable<sup>(deprecated)</sup> 1632 1633isMultiOsAccountEnable(callback: AsyncCallback<boolean>): void 1634 1635Checks whether multiple system accounts are supported. This API uses an asynchronous callback to return the result. 1636 1637> **NOTE** 1638> 1639> This API is supported since API version 7 and deprecated since API version 9. Use [checkMultiOsAccountEnabled](#checkmultiosaccountenabled9) instead. 1640 1641**System capability**: SystemCapability.Account.OsAccount 1642 1643**Parameters** 1644 1645| Name | Type | Mandatory| Description | 1646| -------- | ---------------------------- | ---- | ------------------------------------------------------ | 1647| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means multiple system accounts are supported; the value **false** means the opposite.| 1648 1649**Example** 1650 1651 ```ts 1652 import { BusinessError } from '@ohos.base'; 1653 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1654 accountManager.isMultiOsAccountEnable((err: BusinessError, isEnabled: boolean) => { 1655 if (err) { 1656 console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err)); 1657 } else { 1658 console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled); 1659 } 1660 }); 1661 ``` 1662 1663### isMultiOsAccountEnable<sup>(deprecated)</sup> 1664 1665isMultiOsAccountEnable(): Promise<boolean> 1666 1667Checks whether multiple system accounts are supported. This API uses a promise to return the result. 1668 1669> **NOTE** 1670> 1671> This API is supported since API version 7 and deprecated since API version 9. Use [checkMultiOsAccountEnabled](#checkmultiosaccountenabled9-1) instead. 1672 1673**System capability**: SystemCapability.Account.OsAccount 1674 1675**Return value** 1676 1677| Type | Description | 1678| :--------------------- | :--------------------------------------------------------- | 1679| Promise<boolean> | Promise used to return the result. The value **true** means multiple system accounts are supported; the value **false** means the opposite.| 1680 1681**Example** 1682 1683 ```ts 1684 import { BusinessError } from '@ohos.base'; 1685 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1686 accountManager.isMultiOsAccountEnable().then((isEnabled: boolean) => { 1687 console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled); 1688 }).catch((err: BusinessError) => { 1689 console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err)); 1690 }); 1691 ``` 1692 1693### isOsAccountActived<sup>(deprecated)</sup> 1694 1695isOsAccountActived(localId: number, callback: AsyncCallback<boolean>): void 1696 1697Checks whether a system account is activated. This API uses an asynchronous callback to return the result. 1698 1699> **NOTE** 1700> 1701> This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications. 1702 1703**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1704 1705**System capability**: SystemCapability.Account.OsAccount 1706 1707**Parameters** 1708 1709| Name | Type | Mandatory| Description | 1710| -------- | ---------------------------- | ---- | ------------------------------------------------------ | 1711| localId | number | Yes | ID of the target system account. | 1712| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the account is activated; the value **false** means the opposite.| 1713 1714**Example**: Check whether system account 100 is activated. 1715 1716 ```ts 1717 import { BusinessError } from '@ohos.base'; 1718 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1719 let localId: number = 100; 1720 accountManager.isOsAccountActived(localId, (err: BusinessError, isActived: boolean) => { 1721 if (err) { 1722 console.log('isOsAccountActived failed, err:' + JSON.stringify(err)); 1723 } else { 1724 console.log('isOsAccountActived successfully, isActived:' + isActived); 1725 } 1726 }); 1727 ``` 1728 1729### isOsAccountActived<sup>(deprecated)</sup> 1730 1731isOsAccountActived(localId: number): Promise<boolean> 1732 1733Checks whether a system account is activated. This API uses a promise to return the result. 1734 1735> **NOTE** 1736> 1737> This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications. 1738 1739**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1740 1741**System capability**: SystemCapability.Account.OsAccount 1742 1743**Parameters** 1744 1745| Name | Type | Mandatory| Description | 1746| ------- | ------ | ---- | --------------------------------- | 1747| localId | number | Yes | ID of the target system account.| 1748 1749**Return value** 1750 1751| Type | Description | 1752| --------------------- | ----------------------------------------------------------- | 1753| Promise<boolean> | Promise used to return the result. The value **true** means the account is activated; the value **false** means the opposite.| 1754 1755**Example**: Check whether system account 100 is activated. 1756 1757 ```ts 1758 import { BusinessError } from '@ohos.base'; 1759 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1760 let localId: number = 100; 1761 accountManager.isOsAccountActived(localId).then((isActived: boolean) => { 1762 console.log('isOsAccountActived successfully, isActived: ' + isActived); 1763 }).catch((err: BusinessError) => { 1764 console.log('isOsAccountActived failed, error: ' + JSON.stringify(err)); 1765 }); 1766 ``` 1767 1768### isOsAccountConstraintEnable<sup>(deprecated)</sup> 1769 1770isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback<boolean>): void 1771 1772Checks whether the specified constraint is enabled for a system account. This API uses an asynchronous callback to return the result. 1773 1774> **NOTE** 1775> 1776> This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications. 1777 1778**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1779 1780**System capability**: SystemCapability.Account.OsAccount 1781 1782**Parameters** 1783 1784| Name | Type | Mandatory| Description | 1785| ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- | 1786| localId | number | Yes | ID of the target system account. | 1787| constraint | string | Yes | [Constraint](#constraints) to check. | 1788| 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.| 1789 1790**Example**: Check whether system account 100 is forbidden to use Wi-Fi. 1791 1792 ```ts 1793 import { BusinessError } from '@ohos.base'; 1794 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1795 let localId: number = 100; 1796 let constraint: string = 'constraint.wifi'; 1797 accountManager.isOsAccountConstraintEnable(localId, constraint, (err: BusinessError, isEnabled: boolean) => { 1798 if (err) { 1799 console.log('isOsAccountConstraintEnable failed, error: ' + JSON.stringify(err)); 1800 } else { 1801 console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled); 1802 } 1803 }); 1804 ``` 1805 1806### isOsAccountConstraintEnable<sup>(deprecated)</sup> 1807 1808isOsAccountConstraintEnable(localId: number, constraint: string): Promise<boolean> 1809 1810Checks whether the specified constraint is enabled for a system account. This API uses a promise to return the result. 1811 1812> **NOTE** 1813> 1814> This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications. 1815 1816**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 1817 1818**System capability**: SystemCapability.Account.OsAccount 1819 1820**Parameters** 1821 1822| Name | Type | Mandatory| Description | 1823| ---------- | ------ | ---- | ---------------------------------- | 1824| localId | number | Yes | ID of the target system account. | 1825| constraint | string | Yes | [Constraint](#constraints) to check.| 1826 1827**Return value** 1828 1829| Type | Description | 1830| ---------------------- | --------------------------------------------------------------------- | 1831| Promise<boolean> | Promise used to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.| 1832 1833**Example**: Check whether system account 100 is forbidden to use Wi-Fi. 1834 1835 ```ts 1836 import { BusinessError } from '@ohos.base'; 1837 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1838 let localId: number = 100; 1839 let constraint: string = 'constraint.wifi'; 1840 accountManager.isOsAccountConstraintEnable(localId, constraint).then((isEnabled: boolean) => { 1841 console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled); 1842 }).catch((err: BusinessError) => { 1843 console.log('isOsAccountConstraintEnable err: ' + JSON.stringify(err)); 1844 }); 1845 ``` 1846 1847### isTestOsAccount<sup>(deprecated)</sup> 1848 1849isTestOsAccount(callback: AsyncCallback<boolean>): void 1850 1851Checks whether this system account is a test account. This API uses an asynchronous callback to return the result. 1852 1853> **NOTE** 1854> 1855> This API is supported since API version 7 and deprecated since API version 9. Use [checkOsAccountTestable](#checkosaccounttestable9) instead. 1856 1857**System capability**: SystemCapability.Account.OsAccount 1858 1859**Parameters** 1860 1861| Name | Type | Mandatory| Description | 1862| -------- | ---------------------------- | ---- | --------------------------------------------------------------------- | 1863| 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.| 1864 1865**Example** 1866 1867 ```ts 1868 import { BusinessError } from '@ohos.base'; 1869 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1870 accountManager.isTestOsAccount((err: BusinessError, isTestable: boolean) => { 1871 if (err) { 1872 console.log('isTestOsAccount failed, error: ' + JSON.stringify(err)); 1873 } else { 1874 console.log('isTestOsAccount successfully, isTestable: ' + isTestable); 1875 } 1876 }); 1877 ``` 1878 1879### isTestOsAccount<sup>(deprecated)</sup> 1880 1881isTestOsAccount(): Promise<boolean> 1882 1883Checks whether this system account is a test account. This API uses a promise to return the result. 1884 1885> **NOTE** 1886> 1887> This API is supported since API version 7 and deprecated since API version 9. Use [checkOsAccountTestable](#checkosaccounttestable9-1) instead. 1888 1889**System capability**: SystemCapability.Account.OsAccount 1890 1891**Return value** 1892 1893| Type | Description | 1894| ---------------------- | ------------------------------------------------------------------------ | 1895| Promise<boolean> | Promise used to return the result. The value **true** means the account is a test account; the value **false** means the opposite.| 1896 1897**Example** 1898 1899 ```ts 1900 import { BusinessError } from '@ohos.base'; 1901 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1902 accountManager.isTestOsAccount().then((isTestable: boolean) => { 1903 console.log('isTestOsAccount successfully, isTestable: ' + isTestable); 1904 }).catch((err: BusinessError) => { 1905 console.log('isTestOsAccount failed, error: ' + JSON.stringify(err)); 1906 }); 1907 ``` 1908 1909### isOsAccountVerified<sup>(deprecated)</sup> 1910 1911isOsAccountVerified(callback: AsyncCallback<boolean>): void 1912 1913Checks whether this system account has been verified. This API uses an asynchronous callback to return the result. 1914 1915> **NOTE** 1916> 1917> This API is supported since API version 7 and deprecated since API version 9. Use [checkOsAccountVerified](#checkosaccountverified9) instead. 1918 1919**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1920 1921**System capability**: SystemCapability.Account.OsAccount 1922 1923**Parameters** 1924 1925| Name | Type | Mandatory| Description | 1926| -------- | ---------------------------- | ---- | ------------------------------------------------------------- | 1927| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the system account has been verified; the value **false** means the opposite.| 1928 1929**Example** 1930 1931 ```ts 1932 import { BusinessError } from '@ohos.base'; 1933 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1934 accountManager.isOsAccountVerified((err: BusinessError, isVerified: boolean) => { 1935 if (err) { 1936 console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err)); 1937 } else { 1938 console.log('isOsAccountVerified successfully, isVerified: ' + isVerified); 1939 } 1940 }); 1941 ``` 1942 1943### isOsAccountVerified<sup>(deprecated)</sup> 1944 1945isOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void 1946 1947Checks whether a system account has been verified. This API uses an asynchronous callback to return the result. 1948 1949> **NOTE** 1950> 1951> This API is supported since API version 7 and deprecated since API version 9. Use [checkOsAccountVerified](#checkosaccountverified9-1) instead. 1952 1953**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1954 1955**System capability**: SystemCapability.Account.OsAccount 1956 1957**Parameters** 1958 1959| Name | Type | Mandatory| Description | 1960| -------- | ---------------------------- | ---- | ------------------------------------------------------------- | 1961| localId | number | Yes | ID of the target system account. | 1962| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the system account has been verified; the value **false** means the opposite.| 1963 1964**Example** 1965 1966 ```ts 1967 import { BusinessError } from '@ohos.base'; 1968 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 1969 let localId: number = 100; 1970 accountManager.isOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => { 1971 if (err) { 1972 console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err)); 1973 } else { 1974 console.log('isOsAccountVerified successfully, isVerified: ' + isVerified); 1975 } 1976 }); 1977 ``` 1978 1979### isOsAccountVerified<sup>(deprecated)</sup> 1980 1981isOsAccountVerified(localId?: number): Promise<boolean> 1982 1983Checks whether a system account has been verified. This API uses a promise to return the result. 1984 1985> **NOTE** 1986> 1987> This API is supported since API version 7 and deprecated since API version 9. Use [checkOsAccountVerified](#checkosaccountverified9-2) instead. 1988 1989**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1990 1991**System capability**: SystemCapability.Account.OsAccount 1992 1993**Parameters** 1994 1995| Name | Type | Mandatory| Description | 1996| ------- | ------ | ---- | ---------------------------------------------------------------- | 1997| localId | number | No | ID of the target system account. If this parameter is not specified, this API checks whether the current system account has been verified.| 1998 1999**Return value** 2000 2001| Type | Description | 2002| ---------------------- | ----------------------------------------------------------------- | 2003| Promise<boolean> | Promise used to return the result. The value **true** means the system account has been verified; the value **false** means the opposite.| 2004 2005**Example** 2006 2007 ```ts 2008 import { BusinessError } from '@ohos.base'; 2009 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2010 accountManager.isOsAccountVerified().then((isVerified: boolean) => { 2011 console.log('isOsAccountVerified successfully, isVerified: ' + isVerified); 2012 }).catch((err: BusinessError) => { 2013 console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err)); 2014 }); 2015 ``` 2016 2017### getCreatedOsAccountsCount<sup>(deprecated)</sup> 2018 2019getCreatedOsAccountsCount(callback: AsyncCallback<number>): void 2020 2021Obtains the number of system accounts created. This API uses an asynchronous callback to return the result. 2022 2023> **NOTE** 2024> 2025> This API is supported since API version 7 and deprecated since API version 9. Use [getOsAccountCount](#getosaccountcount9) instead. 2026 2027**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 2028 2029**System capability**: SystemCapability.Account.OsAccount 2030 2031**Parameters** 2032 2033| Name | Type | Mandatory| Description | 2034| -------- | --------------------------- | ---- | -------------------------------------------------------------------------- | 2035| 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 system accounts. If the operation fails, **err** is an error object.| 2036 2037**Example** 2038 2039 ```ts 2040 import { BusinessError } from '@ohos.base'; 2041 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2042 accountManager.getCreatedOsAccountsCount((err: BusinessError, count: number)=>{ 2043 if (err) { 2044 console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err)); 2045 } else { 2046 console.log('getCreatedOsAccountsCount successfully, count: ' + count); 2047 } 2048 }); 2049 ``` 2050 2051### getCreatedOsAccountsCount<sup>(deprecated)</sup> 2052 2053getCreatedOsAccountsCount(): Promise<number> 2054 2055Obtains the number of system accounts created. This API uses a promise to return the result. 2056 2057> **NOTE** 2058> 2059> This API is supported since API version 7 and deprecated since API version 9. Use [getOsAccountCount](#getosaccountcount9-1) instead. 2060 2061**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 2062 2063**System capability**: SystemCapability.Account.OsAccount 2064 2065**Return value** 2066 2067| Type | Description | 2068| --------------------- | -------------------------------------- | 2069| Promise<number> | Promise used to return the number of created system accounts.| 2070 2071**Example** 2072 2073 ```ts 2074 import { BusinessError } from '@ohos.base'; 2075 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2076 accountManager.getCreatedOsAccountsCount().then((count: number) => { 2077 console.log('getCreatedOsAccountsCount successfully, count: ' + count); 2078 }).catch((err: BusinessError) => { 2079 console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err)); 2080 }); 2081 ``` 2082 2083### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup> 2084 2085getOsAccountLocalIdFromProcess(callback: AsyncCallback<number>): void 2086 2087Obtains the ID of the system account to which the current process belongs. This API uses an asynchronous callback to return the result. 2088 2089> **NOTE** 2090> 2091> This API is supported since API version 7 and deprecated since API version 9. Use [getOsAccountLocalId](#getosaccountlocalid9) instead. 2092 2093**System capability**: SystemCapability.Account.OsAccount 2094 2095**Parameters** 2096 2097| Name | Type | Mandatory| Description | 2098| -------- | --------------------------- | ---- | ---------------------------------------------------------------------------- | 2099| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account ID obtained. Otherwise, **err** is an error object.| 2100 2101**Example** 2102 2103 ```ts 2104 import { BusinessError } from '@ohos.base'; 2105 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2106 accountManager.getOsAccountLocalIdFromProcess((err: BusinessError, localId: number) => { 2107 if (err) { 2108 console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err)); 2109 } else { 2110 console.log('getOsAccountLocalIdFromProcess failed, error: ' + localId); 2111 } 2112 }); 2113 ``` 2114 2115### getOsAccountLocalIdFromProcess<sup>(deprecated)</sup> 2116 2117getOsAccountLocalIdFromProcess(): Promise<number> 2118 2119Obtains the ID of the system account to which the current process belongs. This API uses a promise to return the result. 2120 2121> **NOTE** 2122> 2123> This API is supported since API version 7 and deprecated since API version 9. Use [getOsAccountLocalId](#getosaccountlocalid9-1) instead. 2124 2125**System capability**: SystemCapability.Account.OsAccount 2126 2127**Return value** 2128 2129| Type | Description | 2130| :-------------------- | :--------------------------------------- | 2131| Promise<number> | Promise used to return the system account ID obtained.| 2132 2133**Example** 2134 2135 ```ts 2136 import { BusinessError } from '@ohos.base'; 2137 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2138 accountManager.getOsAccountLocalIdFromProcess().then((localId: number) => { 2139 console.log('getOsAccountLocalIdFromProcess successfully, localId: ' + localId); 2140 }).catch((err: BusinessError) => { 2141 console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err)); 2142 }); 2143 ``` 2144 2145### getOsAccountLocalIdFromUid<sup>(deprecated)</sup> 2146 2147getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback<number>): void 2148 2149Obtains the system account ID based on the process UID. This API uses an asynchronous callback to return the result. 2150 2151> **NOTE** 2152> 2153> This API is supported since API version 7 and deprecated since API version 9. Use [getOsAccountLocalIdForUid](#getosaccountlocalidforuid9) instead. 2154 2155**System capability**: SystemCapability.Account.OsAccount 2156 2157**Parameters** 2158 2159| Name | Type | Mandatory| Description | 2160| -------- | --------------------------- | ---- | --------------------------------------------------------------------- | 2161| uid | number | Yes | Process UID. | 2162| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account ID obtained. Otherwise, **data** is an error object.| 2163 2164**Example**: Obtain the ID of the system account whose process UID is **12345678**. 2165 2166 ```ts 2167 import { BusinessError } from '@ohos.base'; 2168 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2169 let uid: number = 12345678; 2170 accountManager.getOsAccountLocalIdFromUid(uid, (err: BusinessError, localId: number) => { 2171 if (err) { 2172 console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err)); 2173 } else { 2174 console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId); 2175 } 2176 }); 2177 ``` 2178 2179### getOsAccountLocalIdFromUid<sup>(deprecated)</sup> 2180 2181getOsAccountLocalIdFromUid(uid: number): Promise<number> 2182 2183Obtains the system account ID based on the process UID. This API uses a promise to return the result. 2184 2185> **NOTE** 2186> 2187> This API is supported since API version 7 and deprecated since API version 9. Use [getOsAccountLocalIdForUid](#getosaccountlocalidforuid9-1) instead. 2188 2189**System capability**: SystemCapability.Account.OsAccount 2190 2191**Parameters** 2192 2193| Name| Type | Mandatory| Description | 2194| ------ | ------ | ---- | --------- | 2195| uid | number | Yes | Process UID.| 2196 2197**Return value** 2198 2199| Type | Description | 2200| :-------------------- | :----------------------------------- | 2201| Promise<number> | Promise used to return the system account ID obtained.| 2202 2203**Example**: Obtain the ID of the system account whose process UID is **12345678**. 2204 2205 ```ts 2206 import { BusinessError } from '@ohos.base'; 2207 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2208 let uid: number = 12345678; 2209 accountManager.getOsAccountLocalIdFromUid(uid).then((localId: number) => { 2210 console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId); 2211 }).catch((err: BusinessError) => { 2212 console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err)); 2213 }); 2214 ``` 2215 2216### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup> 2217 2218getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void 2219 2220Obtains the system account ID based on the domain account information. This API uses an asynchronous callback to return the result. 2221 2222> **NOTE** 2223> 2224> This API is supported since API version 8 and deprecated since API version 9. Use [getOsAccountLocalIdForDomain](#getosaccountlocalidfordomain9) instead. 2225 2226**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 2227 2228**System capability**: SystemCapability.Account.OsAccount 2229 2230**Parameters** 2231 2232| Name | Type | Mandatory| Description | 2233| ---------- | --------------------------------------- | ---- | --------------------------------------------------------------------------- | 2234| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information. | 2235| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account ID obtained. Otherwise, **err** is an error object.| 2236 2237**Example** 2238 2239 ```ts 2240 import { BusinessError } from '@ohos.base'; 2241 let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'}; 2242 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2243 accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err: BusinessError, localId: number) => { 2244 if (err) { 2245 console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err)); 2246 } else { 2247 console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId); 2248 } 2249 }); 2250 ``` 2251 2252### getOsAccountLocalIdFromDomain<sup>(deprecated)</sup> 2253 2254getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise<number> 2255 2256Obtains the system account ID based on the domain account information. This API uses a promise to return the result. 2257 2258> **NOTE** 2259> 2260> This API is supported since API version 8 and deprecated since API version 9. Use [getOsAccountLocalIdForDomain](#getosaccountlocalidfordomain9-1) instead. 2261 2262**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 2263 2264**System capability**: SystemCapability.Account.OsAccount 2265 2266**Parameters** 2267 2268| Name | Type | Mandatory| Description | 2269| ---------- | --------------------------------------- | ---- | ------------ | 2270| domainInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.| 2271 2272**Return value** 2273 2274| Type | Description | 2275| :-------------------- | :------------------------------------- | 2276| Promise<number> | Promise used to return the ID of the system account associated with the domain account.| 2277 2278**Example** 2279 2280 ```ts 2281 import { BusinessError } from '@ohos.base'; 2282 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2283 let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'}; 2284 accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((localId: number) => { 2285 console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId); 2286 }).catch((err: BusinessError) => { 2287 console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err)); 2288 }); 2289 ``` 2290 2291### getOsAccountAllConstraints<sup>(deprecated)</sup> 2292 2293getOsAccountAllConstraints(localId: number, callback: AsyncCallback<Array<string>>): void 2294 2295Obtains all constraints enabled for a system account. This API uses an asynchronous callback to return the result. 2296 2297> **NOTE** 2298> 2299> This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications. 2300 2301**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 2302 2303**System capability**: SystemCapability.Account.OsAccount 2304 2305**Parameters** 2306 2307| Name | Type | Mandatory| Description | 2308| -------- | ---------------------------------------- | ---- | ---------------------------------------------------------------------------------------------- | 2309| localId | number | Yes | ID of the target system account. | 2310| 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 system account. Otherwise, **err** is an error object.| 2311 2312**Example**: Obtain all constraints of system account 100. 2313 2314 ```ts 2315 import { BusinessError } from '@ohos.base'; 2316 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2317 let localId: number = 100; 2318 accountManager.getOsAccountAllConstraints(localId, (err: BusinessError, constraints: string[])=>{ 2319 console.log('getOsAccountAllConstraints err:' + JSON.stringify(err)); 2320 console.log('getOsAccountAllConstraints:' + JSON.stringify(constraints)); 2321 }); 2322 ``` 2323 2324### getOsAccountAllConstraints<sup>(deprecated)</sup> 2325 2326getOsAccountAllConstraints(localId: number): Promise<Array<string>> 2327 2328> **NOTE** 2329> 2330> This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications. 2331 2332Obtains all constraints enabled for a system account. This API uses a promise to return the result. 2333 2334**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 2335 2336**System capability**: SystemCapability.Account.OsAccount 2337 2338**Parameters** 2339 2340| Name | Type | Mandatory| Description | 2341| ------- | ------ | ---- | ------------ | 2342| localId | number | Yes | ID of the target system account.| 2343 2344**Return value** 2345 2346| Type | Description | 2347| :--------------------------------- | :----------------------------------------------------------- | 2348| Promise<Array<string>> | Promise used to return all the [constraints](#constraints) enabled for the system account.| 2349 2350**Example**: Obtain all constraints of system account 100. 2351 2352 ```ts 2353 import { BusinessError } from '@ohos.base'; 2354 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2355 let localId: number = 100; 2356 accountManager.getOsAccountAllConstraints(localId).then((constraints: string[]) => { 2357 console.log('getOsAccountAllConstraints, constraints: ' + constraints); 2358 }).catch((err: BusinessError) => { 2359 console.log('getOsAccountAllConstraints err: ' + JSON.stringify(err)); 2360 }); 2361 ``` 2362 2363### queryActivatedOsAccountIds<sup>(deprecated)</sup> 2364 2365queryActivatedOsAccountIds(callback: AsyncCallback<Array<number>>): void 2366 2367Queries information about all activated system accounts. This API uses an asynchronous callback to return the result. 2368 2369> **NOTE** 2370> 2371> This API is supported since API version 8 and deprecated since API version 9. Use [getActivatedOsAccountLocalIds](#getactivatedosaccountlocalids9) instead. 2372 2373**System capability**: SystemCapability.Account.OsAccount 2374 2375**Parameters** 2376 2377| Name | Type | Mandatory| Description | 2378| -------- | ---------------------------------------- | ---- | ------------------------------------------------------ | 2379| 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 system accounts. Otherwise, **data** is an error object.| 2380 2381**Example** 2382 2383 ```ts 2384 import { BusinessError } from '@ohos.base'; 2385 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2386 accountManager.queryActivatedOsAccountIds((err: BusinessError, idArray: number[])=>{ 2387 console.log('queryActivatedOsAccountIds err:' + JSON.stringify(err)); 2388 console.log('queryActivatedOsAccountIds idArray length:' + idArray.length); 2389 for(let i=0;i<idArray.length;i++) { 2390 console.info('activated os account id: ' + idArray[i]); 2391 } 2392 }); 2393 ``` 2394 2395### queryActivatedOsAccountIds<sup>(deprecated)</sup> 2396 2397queryActivatedOsAccountIds(): Promise<Array<number>> 2398 2399> **NOTE** 2400> 2401> This API is supported since API version 8 and deprecated since API version 9. Use [getActivatedOsAccountLocalIds](#getactivatedosaccountlocalids9-1) instead. 2402 2403Obtains information about all activated system accounts. This API uses a promise to return the result. 2404 2405**System capability**: SystemCapability.Account.OsAccount 2406 2407**Return value** 2408 2409| Type | Description | 2410| ---------------------------------- | ------------------------------------------------- | 2411| Promise<Array<number>> | Promise used to return the information about all activated system accounts.| 2412 2413**Example** 2414 2415 ```ts 2416 import { BusinessError } from '@ohos.base'; 2417 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2418 accountManager.queryActivatedOsAccountIds().then((idArray: number[]) => { 2419 console.log('queryActivatedOsAccountIds, idArray: ' + idArray); 2420 }).catch((err: BusinessError) => { 2421 console.log('queryActivatedOsAccountIds err: ' + JSON.stringify(err)); 2422 }); 2423 ``` 2424 2425### queryCurrentOsAccount<sup>(deprecated)</sup> 2426 2427queryCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void 2428 2429Queries information about the system account to which the current process belongs. This API uses an asynchronous callback to return the result. 2430 2431> **NOTE** 2432> 2433> This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications. 2434 2435**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 2436 2437**System capability**: SystemCapability.Account.OsAccount 2438 2439**Parameters** 2440 2441| Name | Type | Mandatory| Description | 2442| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | 2443| callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account information obtained. Otherwise, **data** is an error object.| 2444 2445**Example** 2446 2447 ```ts 2448 import { BusinessError } from '@ohos.base'; 2449 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2450 accountManager.queryCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{ 2451 console.log('queryCurrentOsAccount err:' + JSON.stringify(err)); 2452 console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo)); 2453 }); 2454 ``` 2455 2456### queryCurrentOsAccount<sup>(deprecated)</sup> 2457 2458queryCurrentOsAccount(): Promise<OsAccountInfo> 2459 2460Queries information about the system account to which the current process belongs. This API uses a promise to return the result. 2461 2462> **NOTE** 2463> 2464> This API is supported since API version 7 and deprecated since API version 9. The substitute API is available only to system applications. 2465 2466**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS 2467 2468**System capability**: SystemCapability.Account.OsAccount 2469 2470**Return value** 2471 2472| Type | Description | 2473| ---------------------------------------------- | ------------------------------------------ | 2474| Promise<[OsAccountInfo](#osaccountinfo)> | Promise used to return the system account information obtained.| 2475 2476**Example** 2477 2478 ```ts 2479 import { BusinessError } from '@ohos.base'; 2480 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2481 accountManager.queryCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => { 2482 console.log('queryCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo)); 2483 }).catch((err: BusinessError) => { 2484 console.log('queryCurrentOsAccount err: ' + JSON.stringify(err)); 2485 }); 2486 ``` 2487 2488### getOsAccountTypeFromProcess<sup>(deprecated)</sup> 2489 2490getOsAccountTypeFromProcess(callback: AsyncCallback<OsAccountType>): void 2491 2492Obtains the type of the account to which the current process belongs. This API uses an asynchronous callback to return the result. 2493 2494> **NOTE** 2495> 2496> This API is supported since API version 7 and deprecated since API version 9. Use [getOsAccountType](#getosaccounttype9) instead. 2497 2498**System capability**: SystemCapability.Account.OsAccount 2499 2500**Parameters** 2501 2502| Name | Type | Mandatory| Description | 2503| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------- | 2504| callback | AsyncCallback<[OsAccountType](#osaccounttype)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account type obtained. Otherwise, **err** is an error object.| 2505 2506**Example** 2507 2508 ```ts 2509 import { BusinessError } from '@ohos.base'; 2510 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2511 accountManager.getOsAccountTypeFromProcess((err: BusinessError, accountType: account_osAccount.OsAccountType) => { 2512 console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err)); 2513 console.log('getOsAccountTypeFromProcess accountType: ' + accountType); 2514 }); 2515 ``` 2516 2517### getOsAccountTypeFromProcess<sup>(deprecated)</sup> 2518 2519getOsAccountTypeFromProcess(): Promise<OsAccountType> 2520 2521Obtains the type of the account to which the current process belongs. This API uses a promise to return the result. 2522 2523> **NOTE** 2524> 2525> This API is supported since API version 7 and deprecated since API version 9. Use [getOsAccountType](#getosaccounttype9-1) instead. 2526 2527**System capability**: SystemCapability.Account.OsAccount 2528 2529**Return value** 2530 2531| Type | Description | 2532| ---------------------------------------------- | ----------------------------------------------- | 2533| Promise<[OsAccountType](#osaccounttype)> | Promise used to return the system account type obtained.| 2534 2535**Example** 2536 2537 ```ts 2538 import { BusinessError } from '@ohos.base'; 2539 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2540 accountManager.getOsAccountTypeFromProcess().then((accountType: account_osAccount.OsAccountType) => { 2541 console.log('getOsAccountTypeFromProcess, accountType: ' + accountType); 2542 }).catch((err: BusinessError) => { 2543 console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err)); 2544 }); 2545 ``` 2546 2547### getDistributedVirtualDeviceId<sup>(deprecated)</sup> 2548 2549getDistributedVirtualDeviceId(callback: AsyncCallback<string>): void 2550 2551Obtains the ID of this distributed virtual device. This API uses an asynchronous callback to return the result. 2552 2553> **NOTE** 2554> 2555> This API is supported since API version 7 and deprecated since API version 9. Use [queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9) instead. 2556 2557**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS 2558 2559**System capability**: SystemCapability.Account.OsAccount 2560 2561**Parameters** 2562 2563| Name | Type | Mandatory| Description | 2564| -------- | --------------------------- | ---- | --------------------------------------------------------------------- | 2565| 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.| 2566 2567**Example** 2568 2569 ```ts 2570 import { BusinessError } from '@ohos.base'; 2571 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2572 accountManager.getDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => { 2573 console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err)); 2574 console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID); 2575 }); 2576 ``` 2577 2578### getDistributedVirtualDeviceId<sup>(deprecated)</sup> 2579 2580getDistributedVirtualDeviceId(): Promise<string> 2581 2582Obtains the ID of this distributed virtual device. This API uses a promise to return the result. 2583 2584> **NOTE** 2585> 2586> This API is supported since API version 7 and deprecated since API version 9. Use [queryDistributedVirtualDeviceId](#querydistributedvirtualdeviceid9-1) instead. 2587 2588**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC or ohos.permission.MANAGE_LOCAL_ACCOUNTS 2589 2590**System capability**: SystemCapability.Account.OsAccount 2591 2592**Return value** 2593 2594| Type | Description | 2595| --------------------- | --------------------------------- | 2596| Promise<string> | Promise used to return the distributed virtual device ID obtained.| 2597 2598**Example** 2599 2600 ```ts 2601 import { BusinessError } from '@ohos.base'; 2602 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2603 accountManager.getDistributedVirtualDeviceId().then((virtualID: string) => { 2604 console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID); 2605 }).catch((err: BusinessError) => { 2606 console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err)); 2607 }); 2608 ``` 2609 2610### getOsAccountLocalIdBySerialNumber<sup>(deprecated)</sup> 2611 2612getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback<number>): void 2613 2614Obtains the system account ID based on the SN. This API uses an asynchronous callback to return the result. 2615 2616> **NOTE** 2617> 2618> This API is supported since API version 8 and deprecated since API version 9. Use [getOsAccountLocalIdForSerialNumber](#getosaccountlocalidforserialnumber9) instead. 2619 2620**System capability**: SystemCapability.Account.OsAccount 2621 2622**Parameters** 2623 2624| Name | Type | Mandatory| Description | 2625| ------------ | --------------------------- | ---- | -------------------------------------------------------------------------------- | 2626| serialNumber | number | Yes | Account SN. | 2627| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the system account ID obtained. Otherwise, **err** is an error object.| 2628 2629**Example**: Obtain the ID of the system account whose SN is 12345. 2630 2631 ```ts 2632 import { BusinessError } from '@ohos.base'; 2633 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2634 let serialNumber: number = 12345; 2635 accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err: BusinessError, localId: number)=>{ 2636 console.log('ger localId err:' + JSON.stringify(err)); 2637 console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber); 2638 }); 2639 ``` 2640 2641### getOsAccountLocalIdBySerialNumber<sup>(deprecated)</sup> 2642 2643getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise<number> 2644 2645Obtains the system account ID based on the SN. This API uses a promise to return the result. 2646 2647> **NOTE** 2648> 2649> This API is supported since API version 8 and deprecated since API version 9. Use [getOsAccountLocalIdForSerialNumber](#getosaccountlocalidforserialnumber9-1) instead. 2650 2651**System capability**: SystemCapability.Account.OsAccount 2652 2653**Parameters** 2654 2655| Name | Type | Mandatory| Description | 2656| ------------ | ------ | ---- | ---------- | 2657| serialNumber | number | Yes | Account SN.| 2658 2659**Return value** 2660 2661| Type | Description | 2662| --------------------- | -------------------------------------------- | 2663| Promise<number> | Promise used to return the system account ID obtained.| 2664 2665**Example**: Obtain the ID of the system account whose SN is 12345. 2666 2667 ```ts 2668 import { BusinessError } from '@ohos.base'; 2669 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2670 let serialNumber: number = 12345; 2671 accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId: number) => { 2672 console.log('getOsAccountLocalIdBySerialNumber localId: ' + localId); 2673 }).catch((err: BusinessError) => { 2674 console.log('getOsAccountLocalIdBySerialNumber err: ' + JSON.stringify(err)); 2675 }); 2676 ``` 2677 2678### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup> 2679 2680getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback<number>): void 2681 2682Obtains the SN of a system account based on the account ID. This API uses an asynchronous callback to return the result. 2683 2684> **NOTE** 2685> 2686> This API is supported since API version 8 and deprecated since API version 9. Use [getSerialNumberForOsAccountLocalId](#getserialnumberforosaccountlocalid9) instead. 2687 2688**System capability**: SystemCapability.Account.OsAccount 2689 2690**Parameters** 2691 2692| Name | Type | Mandatory| Description | 2693| -------- | --------------------------- | ---- | --------------------------------------------------------------------------- | 2694| localId | number | Yes | ID of the target system account. | 2695| 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.| 2696 2697**Example**: Obtain the SN of the system account 100. 2698 2699 ```ts 2700 import { BusinessError } from '@ohos.base'; 2701 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2702 let localId: number = 100; 2703 accountManager.getSerialNumberByOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{ 2704 console.log('ger serialNumber err:' + JSON.stringify(err)); 2705 console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId); 2706 }); 2707 ``` 2708 2709### getSerialNumberByOsAccountLocalId<sup>(deprecated)</sup> 2710 2711getSerialNumberByOsAccountLocalId(localId: number): Promise<number> 2712 2713Obtains the SN of a system account based on the account ID. This API uses a promise to return the result. 2714 2715> **NOTE** 2716> 2717> This API is supported since API version 8 and deprecated since API version 9. Use [getSerialNumberForOsAccountLocalId](#getserialnumberforosaccountlocalid9-1) instead. 2718 2719**System capability**: SystemCapability.Account.OsAccount 2720 2721**Parameters** 2722 2723| Name | Type | Mandatory| Description | 2724| ------- | ------ | ---- | ----------- | 2725| localId | number | Yes | ID of the target system account.| 2726 2727**Return value** 2728 2729| Type | Description | 2730| --------------------- | -------------------------------------- | 2731| Promise<number> | Promise used to return the SN obtained.| 2732 2733**Example**: Obtain the SN of the system account 100. 2734 2735 ```ts 2736 import { BusinessError } from '@ohos.base'; 2737 let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager(); 2738 let localId: number = 100; 2739 accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber: number) => { 2740 console.log('getSerialNumberByOsAccountLocalId serialNumber: ' + serialNumber); 2741 }).catch((err: BusinessError) => { 2742 console.log('getSerialNumberByOsAccountLocalId err: ' + JSON.stringify(err)); 2743 }); 2744 ``` 2745 2746## OsAccountInfo 2747 2748Defines the system account information. 2749 2750**System capability**: SystemCapability.Account.OsAccount 2751 2752| Name | Type | Mandatory| Description | 2753| ------------------------------ | ------------------------------------------------------------ | ---- | --------------------------------- | 2754| localId | number | Yes | ID of the target system account. | 2755| localName | string | Yes | System account name. | 2756| type | [OsAccountType](#osaccounttype) | Yes | System account type. | 2757| constraints | Array<string> | No | System account [Constraints](#constraints). By default, no value is passed.| 2758| isVerified<sup>(deprecated)</sup> | boolean | Yes | Whether to verify the system account.<br>**NOTE**<br/>This parameter is supported since API version 7 and deprecated since API version 11. | 2759| isUnlocked<sup>11+</sup> | boolean | Yes | Whether the account is unlocked (whether the **el2** directory is decrypted). | 2760| photo<sup>8+</sup> | string | No | System account avatar. By default, no value is passed. | 2761| createTime<sup>8+</sup> | number | Yes | Time when the system account was created. | 2762| lastLoginTime<sup>8+</sup> | number | No | Last login time of the system account. By default, no value is passed. | 2763| serialNumber<sup>8+</sup> | number | Yes | SN of the system account. | 2764| isActived<sup>(deprecated)</sup> | boolean | Yes | Whether the system account is activated.<br>**NOTE**<br/>This parameter is supported since API version 7 and deprecated since API version 11. | 2765| isActivated<sup>11+</sup> | boolean | Yes | Whether the system account is activated. | 2766| isCreateCompleted<sup>8+</sup> | boolean | Yes | Whether the system account information is complete. | 2767| distributedInfo | [distributedAccount.DistributedInfo](js-apis-distributed-account.md#distributedinfo) | No | Distributed account information. By default, no value is passed. | 2768| domainInfo<sup>8+</sup> | [DomainAccountInfo](#domainaccountinfo8) | No | Domain account information. By default, no value is passed. | 2769 2770## DomainAccountInfo<sup>8+</sup> 2771 2772Defines the domain account information. 2773 2774**System capability**: SystemCapability.Account.OsAccount 2775 2776| Name | Type | Mandatory| Description | 2777| ----------- | ------ | ---- | ---------- | 2778| domain | string | Yes | Domain name. | 2779| accountName | string | Yes | Domain account name.| 2780 2781## Constraints 2782 2783| Constraint | Description | 2784| ------------------------------------- | ------------------------------ | 2785| constraint.wifi | A user is not allowed to use Wi-Fi. | 2786| constraint.wifi.set | A user is not allowed to set Wi-Fi. | 2787| constraint.locale.set | A user is not allowed to change the device language. | 2788| constraint.app.accounts | A user is not allowed to add or delete app accounts. | 2789| constraint.apps.install | A user is not allowed to install apps. | 2790| constraint.apps.uninstall | A user is not allowed to uninstall apps. | 2791| constraint.location.shared | A user is not allowed to enable location sharing. | 2792| constraint.unknown.sources.install | A user is not allowed to install apps from unknown sources. | 2793| constraint.global.unknown.app.install | All users are not allowed to install apps from unknown sources.| 2794| constraint.bluetooth.set | A user is not allowed to configure Bluetooth. | 2795| constraint.bluetooth | The use of Bluetooth is prohibited on the device.| 2796| constraint.bluetooth.share | Bluetooth sharing is prohibited.| 2797| constraint.usb.file.transfer | A user is not allowed to transfer files over USB.| 2798| constraint.credentials.set | A user is not allowed to configure user credentials.| 2799| constraint.os.account.remove | An admin user is not allowed to remove users or a non-admin user is not allowed to remove itself.| 2800| constraint.managed.profile.remove | The managed profiles of this user cannot be removed.| 2801| constraint.debug.features.use | A user is not allowed to enable or access the debugging function.| 2802| constraint.vpn.set | A user is not allowed to configure a VPN.| 2803| constraint.date.time.set | A user is not allowed to set date, time, or time zone.| 2804| constraint.tethering.config | A user is not allowed to configure Tethering.| 2805| constraint.network.reset | A user is not allowed to reset network settings.| 2806| constraint.factory.reset | A user is not allowed to reset factory settings.| 2807| constraint.os.account.create | A user is not allowed to create users.| 2808| constraint.add.managed.profile | A user is not allowed to add managed profiles.| 2809| constraint.apps.verify.disable | A user is not allowed to disable app verification.| 2810| constraint.cell.broadcasts.set | A user is not allowed to configure cell broadcasts.| 2811| constraint.mobile.networks.set | A user is not allowed to configure radio networks.| 2812| constraint.control.apps | A user is not allowed to modify apps in **Settings** or the boot module.| 2813| constraint.physical.media | A user is not allowed to mount external physical media.| 2814| constraint.microphone | A user is not allowed to use microphones.| 2815| constraint.microphone.unmute | A user is not allowed to unmute the microphone.| 2816| constraint.volume.adjust | A user is not allowed to adjust the volume.| 2817| constraint.calls.outgoing | A user is not allowed to make outgoing calls.| 2818| constraint.sms.use | A user is not allowed to send or receive SMS messages.| 2819| constraint.fun | A user is not allowed to have entertainment.| 2820| constraint.windows.create | Windows other than app windows cannot be created.| 2821| constraint.system.error.dialogs | Error dialogs for crashed or unresponsive apps are prohibited.| 2822| constraint.cross.profile.copy.paste | Pasting clipboard content to other users or profiles is prohibited.| 2823| constraint.beam.outgoing | A user is not allowed to use Near Field Communications (NFC) to transfer data from apps.| 2824| constraint.wallpaper | A user is not allowed to manage wallpapers.| 2825| constraint.safe.boot | A user is not allowed to reboot the device in safe boot mode.| 2826| constraint.parent.profile.app.linking | The apps in the parent profile are allowed to handle web links from the managed profile.| 2827| constraint.audio.record | Audio recording is prohibited.| 2828| constraint.camera.use | The use of cameras is prohibited.| 2829| constraint.os.account.background.run | Running in the background is prohibited.| 2830| constraint.data.roam | A user is not allowed to use cellular data when roaming.| 2831| constraint.os.account.set.icon | A user is not allowed to change their icon.| 2832| constraint.wallpaper.set | A user is not allowed to set a wallpaper.| 2833| constraint.oem.unlock | A user is not allowed to enable OEM unlock.| 2834| constraint.device.unmute | A user is not allowed to unmute the device.| 2835| constraint.password.unified | The managed profile is not allowed to have unified lock screen challenge with the primary user.| 2836| constraint.autofill | A user is not allowed to use the autofill service.| 2837| constraint.content.capture | Capturing the content of a user's screen is prohibited.| 2838| constraint.content.suggestions | A user is not allowed to receive content suggestions.| 2839| constraint.os.account.start | User switching is blocked.| 2840| constraint.location.set | A user is not allowed to configure the location service.| 2841| constraint.airplane.mode.set | The airplane mode is prohibited on the device.| 2842| constraint.brightness.set | A user is not allowed to configure brightness.| 2843| constraint.share.into.profile | A user is not allowed to share files, images, or data from the primary user to the managed profile.| 2844| constraint.ambient.display | Ambient display is prohibited for the user.| 2845| constraint.screen.timeout.set | A user is not allowed to configure the screen off timeout.| 2846| constraint.print | A user is not allowed to print.| 2847| constraint.private.dns.set | A user is not allowed to configure a private domain name server (DNS).| 2848