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