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