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