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