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